Search in sources :

Example 16 with VoiceSpacing

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

the class MeasureElementsSpacerTest method testNeedAdditionalSpace.

/**
 * If there is not enough space left for the measure elements,
 * the voice spacings have to be moved to create enough space.
 * 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 4)
 * voice 1:   o      2
 * voice 2:    1          o
 * </pre>
 * Between VE1 and VE2, there are 6 spaces.
 * Assuming a padding width of 1 and a clef width of 6,
 * the clef can be moved two spaces to the left, but this is not
 * enough. All elements at or after beat 3 have to be moved 2 spaces
 * to the right.
 */
@Test
public void testNeedAdditionalSpace() {
    Rest[] ve = ve();
    List<VoiceSpacing> vs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 11))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 16))));
    Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
    BeatEList<Clef> innerClefs = Companion.beatEList();
    innerClefs.add(Companion.beatE(innerClef, Companion.fr(4)));
    List<ElementSpacing> mes = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
    // voice spacings
    assertEquals(2, vs.size());
    assertEqualsSpacings(ilist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 13)), vs.get(0).elements);
    assertEqualsSpacings(ilist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 18)), vs.get(1).elements);
    // clef must be at offset 13 - padding - clefwidth/2
    ElementSpacing[] se = mes.toArray(new ElementSpacing[0]);
    assertEquals(1, se.length);
    assertEquals(Companion.fr(4), se[0].beat);
    assertEquals(13 - paddingWidth - clefWidth / 2, se[0].xIs, Delta.DELTA_FLOAT);
}
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 17 with VoiceSpacing

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

the class StretchMeasuresTest method createSystemWith1MeasureGrace.

/**
 * Creates and returns a simple {@link SystemSpacing} with only one
 * measure and three notes: two main notes and two grace notes between them.
 */
public static SystemSpacing createSystemWith1MeasureGrace(float offsetChord1, float offsetChord2, float offsetMeasureEnd, float graceDistance) {
    Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
    Chord chord2grace = graceChord(Companion.pi(1, 0, 4));
    Chord chord3grace = graceChord(Companion.pi(2, 0, 4));
    Chord chord4 = chord(Companion.pi(3, 0, 4), Companion.fr(2, 4));
    Voice voice = new Voice(alist(chord1, chord2grace, chord3grace, chord4));
    List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(0, 4), offsetChord1), new BeatOffset(Companion.fr(2, 4), offsetChord2), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd));
    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(chord2grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 2 * graceDistance), new ChordSpacing(new ChordNotation(chord3grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 1 * graceDistance), new ChordSpacing(new ChordNotation(chord4), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
    MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, null);
    ColumnSpacing mcs = new ColumnSpacing(-1, alist(measureSpacing), beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd)));
    SystemSpacing system = new SystemSpacing(alist(mcs), 0, 0, offsetMeasureEnd, null, 0);
    return system;
}
Also used : ChordSpacing(com.xenoage.zong.musiclayout.spacing.ChordSpacing) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) ColumnSpacing(com.xenoage.zong.musiclayout.spacing.ColumnSpacing) MeasureSpacing(com.xenoage.zong.musiclayout.spacing.MeasureSpacing) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) 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 18 with VoiceSpacing

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

the class AlignedVoicesSpacerTest method computeTest3.

@Test
public void computeTest3() {
    float is = 4;
    // voice spacing:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 2
    // ⌎--- 0
    VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
    // given beat offsets:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 6
    // ⌎--- 2
    List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 2f), new BeatOffset(beat(2), 6f));
    // shared beats: 0, 2.
    // 
    // resulting spacing:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 6
    // ⌎--- 2
    testee.compute(voiceSpacing, beatOffsets);
    List<ElementSpacing> finalSpacing = voiceSpacing.elements;
    assertEquals(2, finalSpacing.size());
    assertEquals(beat(0), finalSpacing.get(0).beat);
    assertEquals(2f / is, finalSpacing.get(0).xIs, df);
    assertEquals(beat(2), finalSpacing.get(1).beat);
    assertEquals(6f / is, finalSpacing.get(1).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)

Example 19 with VoiceSpacing

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

the class AlignedVoicesSpacerTest method computeTest2.

@Test
public void computeTest2() {
    float is = 3;
    // voice spacing:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 2
    // ⌎--- 0
    VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 2f)));
    // given beat offsets:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 2
    // ⌎--- 0
    List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(2), 2f));
    // shared beats: 0, 2.
    // 
    // resulting spacing:
    // beats:   0.2
    // offsets: | |
    // | ⌎- 2
    // ⌎--- 0
    testee.compute(voiceSpacing, beatOffsets);
    List<ElementSpacing> finalSpacing = voiceSpacing.elements;
    assertEquals(2, finalSpacing.size());
    assertEquals(beat(0), finalSpacing.get(0).beat);
    assertEquals(0f / is, finalSpacing.get(0).xIs, df);
    assertEquals(beat(2), finalSpacing.get(1).beat);
    assertEquals(2f / is, finalSpacing.get(1).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)

Example 20 with VoiceSpacing

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

the class SingleVoiceSpacerTest method testGrace1.

/**
 * Computes a voice spacing with grace notes,
 * where the element before the grace notes has enough empty rear space
 * to take all the grace notes.
 * <pre>
 * Single elements: [-r1------------][g1][g2][--r4--]
 * Combined:        --r1----~g1~g2~~~r4---
 * </pre> (~: area used by two elements)
 */
@Test
public void testGrace1() {
    // create voice and notations
    Voice voice = new Voice(alist((VoiceElement) r1, g1, g2, r4));
    Notations notations = new Notations();
    notations.add(new RestNotation(r1, new ElementWidth(2, 2, 13), null));
    notations.add(new ChordNotation(g1, new ElementWidth(1, 2, 1)));
    notations.add(new ChordNotation(g2, new ElementWidth(1, 2, 1)));
    notations.add(new RestNotation(r4, new ElementWidth(3, 2, 3), null));
    // compute spacing
    VoiceSpacing vs = testee.compute(voice, 300f, Companion.fr(4, 4), 5, notations, layoutSettings);
    // check spacing
    ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
    ;
    float s = layoutSettings.offsetMeasureStart;
    assertEquals(5, ses.length);
    assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
    assertEquals(s + 9, ses[1].xIs, DELTA_FLOAT);
    assertEquals(s + 12, ses[2].xIs, DELTA_FLOAT);
    assertEquals(s + 17, ses[3].xIs, DELTA_FLOAT);
    assertEquals(s + 22, ses[4].xIs, DELTA_FLOAT);
    // check beats
    assertEquals(Companion.fr(0, 8), ses[0].beat);
    assertEquals(Companion.fr(2, 8), ses[1].beat);
    assertEquals(Companion.fr(2, 8), ses[2].beat);
    assertEquals(Companion.fr(2, 8), ses[3].beat);
    assertEquals(Companion.fr(6, 8), ses[4].beat);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) VoiceElement(com.xenoage.zong.core.music.VoiceElement) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) Notations(com.xenoage.zong.musiclayout.notation.Notations) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test) VoiceTest(com.xenoage.zong.core.music.VoiceTest) LayoutSettingsTest(com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)

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