Search in sources :

Example 1 with ElementSpacing

use of com.xenoage.zong.musiclayout.spacing.ElementSpacing 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 ElementSpacing

use of com.xenoage.zong.musiclayout.spacing.ElementSpacing 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)

Example 3 with ElementSpacing

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

the class AlignedVoicesSpacerTest method testComputeSharedBeats.

@Test
public void testComputeSharedBeats() {
    // list 1 beats: 0  3   789
    // list 2 beats: 0    5 7 9
    // shared beats: 0      7 9
    List<ElementSpacing> list1 = alist(spacing(beat(0), 0f), spacing(beat(3), 0f), spacing(beat(7), 0f), spacing(beat(8), 0f), spacing(beat(9), 0f));
    List<BeatOffset> list2 = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(5), 0f), new BeatOffset(beat(7), 0f), new BeatOffset(beat(9), 0f));
    List<BeatOffset> res = testee.computeSharedBeats(list1, list2);
    assertEquals(3, res.size());
    assertEquals(beat(0), res.get(0).getBeat());
    assertEquals(beat(7), res.get(1).getBeat());
    assertEquals(beat(9), res.get(2).getBeat());
    // list 1 beats: 01 3
    // list 2 beats:   2 4
    // shared beats: (none)
    list1 = alist(spacing(beat(0), 0f), spacing(beat(1), 0f), spacing(beat(3), 0f));
    list2 = alist(new BeatOffset(beat(2), 0f), new BeatOffset(beat(4), 0f));
    res = testee.computeSharedBeats(list1, list2);
    assertEquals(0, res.size());
    // list 1 beats: 000033
    // list 2 beats: 0123
    // shared beats: 0 and 3 (no duplicate values!)
    list1 = alist(spacing(beat(0), 0f), spacing(beat(0), 0f), spacing(beat(0), 0f), spacing(beat(0), 0f), spacing(beat(3), 0f), spacing(beat(3), 0f));
    list2 = alist(new BeatOffset(beat(0), 0f), new BeatOffset(beat(1), 0f), new BeatOffset(beat(2), 0f), new BeatOffset(beat(3), 0f));
    res = testee.computeSharedBeats(list1, list2);
    assertEquals(2, res.size());
    assertEquals(beat(0), res.get(0).getBeat());
    assertEquals(beat(3), res.get(1).getBeat());
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) Test(org.junit.Test)

Example 4 with ElementSpacing

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

the class AlignedVoicesSpacerTest method computeTestGrace.

/**
 * Tests the strategy with a voice that uses grace notes.
 * The distance of grace notes to their main notes should not be stretched,
 * but should stay the same.
 */
@Test
public void computeTestGrace() {
    float is = 2;
    // voice spacing:
    // beats:   0.2...gg8
    // offsets: | |   |||
    // | |   ||⌎- 60
    // | |   |⌎-- 59 (grace note)
    // | |   ⌎--- 58 (grace note)
    // | ⌎------- 51
    // ⌎--------- 50
    VoiceSpacing voiceSpacing = new VoiceSpacing(Companion.voice(), is, alist(spacing(beat(0), 0f), spacing(beat(2), 1f), graceSpacing(beat(8), 8f), graceSpacing(beat(8), 9f), spacing(beat(8), 10f)));
    // given beat offsets:
    // beats:   0.......8
    // offsets: |       |
    // |       ⌎- 30
    // ⌎--------- 10
    List<BeatOffset> beatOffsets = alist(new BeatOffset(beat(0), 10f), new BeatOffset(beat(8), 30f));
    // shared beats: 4, 8.
    // 
    // resulting spacing:
    // beats:   0.2...gg8
    // offsets: | |   |||
    // | |   ||⌎- (30 - 10) / (60 - 50) * (60 - 50) + 10 = 30 = x } (shared beats 0 and 8)
    // | |   |⌎-- x - (10 - 9) = 30 - (1 * IS) = 28 (because it is a grace note in front of x)
    // | |   ⌎--- x - (10 - 8) = 30 - (2 * IS) = 26 (because it is a grace note in front of x)
    // | ⌎------- (30 - 10) / (60 - 50) * (51 - 50) + 10 = 12 } (shared beats 0 and 8)
    // ⌎--------- (30 - 10) / (60 - 50) * (50 - 50) + 10 = 10 } (shared beats 0 and 8)
    testee.compute(voiceSpacing, beatOffsets);
    List<ElementSpacing> finalSpacing = voiceSpacing.elements;
    assertEquals(5, finalSpacing.size());
    assertEquals(beat(0), finalSpacing.get(0).beat);
    assertEquals(10f / is, finalSpacing.get(0).xIs, df);
    assertEquals(beat(2), finalSpacing.get(1).beat);
    assertEquals(12f / is, finalSpacing.get(1).xIs, df);
    assertEquals(beat(8), finalSpacing.get(2).beat);
    assertEquals(26f / is, finalSpacing.get(2).xIs, df);
    assertEquals(beat(8), finalSpacing.get(3).beat);
    assertEquals(28f / is, finalSpacing.get(3).xIs, df);
    assertEquals(beat(8), finalSpacing.get(4).beat);
    assertEquals(30f / is, finalSpacing.get(4).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 5 with ElementSpacing

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

the class SingleVoiceSpacerTest method testGrace2.

/**
 * Computes a voice spacing with grace notes,
 * where the element before the grace notes has enough empty rear space
 * to take at least one of the grace notes.
 * <pre>
 * Single elements: [-r1------][g1][g2][--r4--]
 * Combined:        --r1_~g1~g2~~~r4---
 * </pre> (~: area used by two elements, _: minimal distance between elements)
 */
@Test
public void testGrace2() {
    // 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, 7), 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, 400f, Companion.fr(4, 4), 5, notations, layoutSettings);
    // check spacing
    ElementSpacing[] ses = vs.elements.toArray(new ElementSpacing[0]);
    ;
    float s = layoutSettings.offsetMeasureStart;
    float d = layoutSettings.spacings.widthDistanceMin;
    assertEquals(5, ses.length);
    assertEquals(s + 2, ses[0].xIs, DELTA_FLOAT);
    assertEquals(s + 5 + d, ses[1].xIs, DELTA_FLOAT);
    assertEquals(s + 8 + d, ses[2].xIs, DELTA_FLOAT);
    assertEquals(s + 13 + d, ses[3].xIs, DELTA_FLOAT);
    assertEquals(s + 18 + d, 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

ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)26 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)17 Test (org.junit.Test)11 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)10 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)7 Fraction (com.xenoage.utils.math.Fraction)6 VoiceElement (com.xenoage.zong.core.music.VoiceElement)6 Voice (com.xenoage.zong.core.music.Voice)5 Clef (com.xenoage.zong.core.music.clef.Clef)5 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)5 Notation (com.xenoage.zong.musiclayout.notation.Notation)5 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)5 MusicElement (com.xenoage.zong.core.music.MusicElement)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)4 Notations (com.xenoage.zong.musiclayout.notation.Notations)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 LeadingSpacing (com.xenoage.zong.musiclayout.spacing.LeadingSpacing)4 TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)3 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)3