Search in sources :

Example 1 with VoiceSpacing

use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.

the class MeasureElementsSpacerTest method testEnoughExistingSpace.

/**
 * If there is enough space left for the measure elements,
 * the voice spacings do not have to be changed.
 * To understand the following sketch, have a look at the comments
 * in {@link MeasureElementsSpacer}.
 * <pre>
 * enough space:
 * beat:     0   2   4   6   8
 * offset:   3 5 7 9  13  17  21
 *           . . . . . . . . . .
 * clef:         *[clef]*          (on beat 6)
 * voice 1:   o          2
 * voice 2:    1              o
 * </pre>
 */
@Test
public void testEnoughExistingSpace() {
    Rest[] ve = ve();
    List<VoiceSpacing> originalVs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(6), 15))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(17, 2), 20))));
    List<VoiceSpacing> vs = alist(originalVs);
    Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
    BeatEList<Clef> innerClefs = Companion.beatEList();
    innerClefs.add(Companion.beatE(innerClef, Companion.fr(6)));
    List<ElementSpacing> res = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
    // clef must be at offset 15 - padding - clefwidth/2
    ElementSpacing[] mes = res.toArray(new ElementSpacing[0]);
    assertEquals(1, mes.length);
    assertEquals(Companion.fr(6), mes[0].beat);
    assertEquals(15 - paddingWidth - clefWidth / 2, mes[0].xIs, Delta.DELTA_FLOAT);
    // voice spacings must be unchanged
    assertEquals(originalVs, vs);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Rest(com.xenoage.zong.core.music.rest.Rest) Clef(com.xenoage.zong.core.music.clef.Clef) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 2 with VoiceSpacing

use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method createSystemWith1Measure.

/**
 * Creates and returns a simple {@link SystemSpacing} with only one
 * measure with a clef and two notes, using the given parameters.
 * @param leadingWidth  width of the leading spacing in mm
 * @param offsetBeat0   offset of beat 1/4 in mm
 * @param offsetBeat1   offset of beat 3/4 in mm
 * @param offsetBeat2   width of the voice spacing in mm
 */
public static SystemSpacing createSystemWith1Measure(float leadingWidth, float offsetBeat0, float offsetBeat1, float offsetBeat2) {
    Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
    Chord chord2 = chord(Companion.pi(1, 0, 4), Companion.fr(2, 4));
    Voice voice = new Voice(alist(chord1, chord2));
    List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(1, 4), offsetBeat0), new BeatOffset(Companion.fr(3, 4), offsetBeat1), new BeatOffset(Companion.fr(5, 4), offsetBeat2));
    float is = 1;
    List<VoiceSpacing> voiceSpacings = alist(new VoiceSpacing(voice, is, alist(new ChordSpacing(new ChordNotation(chord1), beatOffsets.get(0).getBeat(), beatOffsets.get(0).getOffsetMm()), new ChordSpacing(new ChordNotation(chord2), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
    MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, LeadingSpacingMock.createGClefSpacing(leadingWidth));
    List<MeasureSpacing> measureSpacings = alist(measureSpacing);
    ColumnSpacing mcs = new ColumnSpacing(-1, measureSpacings, beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(6, 4), offsetBeat2)));
    SystemSpacing system = new SystemSpacing(ilist(mcs), 0, 0, leadingWidth + offsetBeat2, null, 0);
    return system;
}
Also used : ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) ChordSpacing(com.xenoage.zong.musiclayout.spacing.ChordSpacing) MeasureSpacing(com.xenoage.zong.musiclayout.spacing.MeasureSpacing) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) ChordFactory.graceChord(com.xenoage.zong.core.music.chord.ChordFactory.graceChord) Chord(com.xenoage.zong.core.music.chord.Chord) Voice(com.xenoage.zong.core.music.Voice)

Example 3 with VoiceSpacing

use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method computeSystemArrangementTestGrace.

/**
 * Checking if the elements are stretched correctly in a simple system
 * where there are grace notes. The space between grace notes and their following
 * full chord may not be stretched.
 */
@Test
public void computeSystemArrangementTestGrace() {
    // create an easy system for testing
    float offsetChord1 = 3;
    float offsetChord2 = 12;
    float offsetMeasureEnd = 16;
    float graceDistance = 2;
    SystemSpacing system = createSystemWith1MeasureGrace(offsetChord1, offsetChord2, offsetMeasureEnd, graceDistance);
    // stretch the system
    float newWidth = 28;
    testee.compute(system, newWidth);
    // compare the result
    ColumnSpacing newCol = system.columns.get(0);
    float stretch = (newWidth - +newCol.getLeadingWidthMm()) / offsetMeasureEnd;
    // beat offsets
    assertEquals(offsetChord1 * stretch, newCol.getBeatOffsets().get(0).getOffsetMm(), df);
    assertEquals(offsetChord2 * stretch, newCol.getBeatOffsets().get(1).getOffsetMm(), df);
    // element spacings
    VoiceSpacing newVoice = newCol.measures.get(0).voices.get(0);
    assertEquals(offsetChord1 * stretch, newVoice.elements.get(0).xIs, df);
    assertEquals(offsetChord2 * stretch - 2 * graceDistance, newVoice.elements.get(1).xIs, df);
    assertEquals(offsetChord2 * stretch - 1 * graceDistance, newVoice.elements.get(2).xIs, df);
    assertEquals(offsetChord2 * stretch, newVoice.elements.get(3).xIs, df);
}
Also used : ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 4 with VoiceSpacing

use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.

the class StretchMeasuresTest method computeTest.

@Test
public void computeTest() {
    // create an easy system for testing
    float leadingWidth = 4;
    float offsetBeat1 = 3;
    float offsetBeat2 = 7;
    float offsetBeat3 = 12;
    SystemSpacing system = createSystemWith1Measure(leadingWidth, offsetBeat1, offsetBeat2, offsetBeat3);
    // stretch the system
    float newWidth = 20;
    testee.compute(system, newWidth);
    // compare the result
    // since the leading spacing (4 spaces) is not scaled, the
    // remaining 12 spaces of the voices width have to be scaled
    float stretch = (newWidth - leadingWidth) / offsetBeat3;
    ColumnSpacing newCol = system.columns.get(0);
    // beat offsets
    assertEquals(offsetBeat1 * stretch, newCol.getBeatOffsets().get(0).getOffsetMm(), df);
    assertEquals(offsetBeat2 * stretch, newCol.getBeatOffsets().get(1).getOffsetMm(), df);
    // element spacings
    VoiceSpacing newVoice = newCol.measures.get(0).voices.get(0);
    assertEquals(offsetBeat1 * stretch, newVoice.elements.get(0).xIs, df);
    assertEquals(offsetBeat2 * stretch, newVoice.elements.get(1).xIs, df);
}
Also used : ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 5 with VoiceSpacing

use of com.xenoage.zong.musiclayout.spacing.VoiceSpacing in project Zong by Xenoage.

the class AlignedVoicesSpacerTest method computeTest1.

@Test
public void computeTest1() {
    float is = 2;
    // voice spacing:
    // beats:   ..2.4..78
    // offsets:   | |  ||
    // | |  |⌎- 6
    // | |  ⌎-- 4
    // | ⌎----- 2
    // ⌎------- 1
    VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(2), 1f), spacing(beat(4), 2f), spacing(beat(7), 4f), spacing(beat(8), 6f)));
    // given beat offsets:
    // beats:   0...4...8
    // offsets: |   |   |
    // |   |   ⌎- 20
    // |   ⌎----- 8
    // ⌎--------- 0
    List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(4), 8f), new BeatOffset(beat(8), 20f));
    // shared beats: 4, 8.
    // 
    // resulting spacing:
    // beats:   ..2.4..78
    // offsets:   | |  ||
    // | |  |⌎- (20 - 8) / (6 - 2) * (6 - 2) + 8 = 20 } (shared beats 4 and 8)
    // | |  ⌎-- (20 - 8) / (6 - 2) * (4 - 2) + 8 = 14 } (shared beats 4 and 8)
    // | ⌎-----  (8 - 0) / (2 - 0) * (2 - 0) + 0 =  8 } (shared beats 0 and 4)
    // ⌎-------  (8 - 0) / (2 - 0) * (1 - 0) + 0 =  4 } (shared beats 0 and 4)
    testee.compute(voiceSpacing, beatOffsets);
    List<ElementSpacing> finalSpacing = voiceSpacing.elements;
    assertEquals(4, finalSpacing.size());
    assertEquals(beat(2), finalSpacing.get(0).beat);
    assertEquals(4f / is, finalSpacing.get(0).xIs, df);
    assertEquals(beat(4), finalSpacing.get(1).beat);
    assertEquals(8f / is, finalSpacing.get(1).xIs, df);
    assertEquals(beat(7), finalSpacing.get(2).beat);
    assertEquals(14f / is, finalSpacing.get(2).xIs, df);
    assertEquals(beat(8), finalSpacing.get(3).beat);
    assertEquals(20f / is, finalSpacing.get(3).xIs, df);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Aggregations

VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)22 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)17 Test (org.junit.Test)12 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)9 Voice (com.xenoage.zong.core.music.Voice)7 VoiceElement (com.xenoage.zong.core.music.VoiceElement)6 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)6 ColumnSpacing (com.xenoage.zong.musiclayout.spacing.ColumnSpacing)6 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)5 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)5 Fraction (com.xenoage.utils.math.Fraction)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 Notations (com.xenoage.zong.musiclayout.notation.Notations)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 MeasureSpacing (com.xenoage.zong.musiclayout.spacing.MeasureSpacing)4 SystemSpacing (com.xenoage.zong.musiclayout.spacing.SystemSpacing)4 ChordSpacing (com.xenoage.zong.musiclayout.spacing.ChordSpacing)3 Chord (com.xenoage.zong.core.music.chord.Chord)2 ChordFactory.graceChord (com.xenoage.zong.core.music.chord.ChordFactory.graceChord)2 Clef (com.xenoage.zong.core.music.clef.Clef)2