Search in sources :

Example 6 with Notations

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

Example 7 with Notations

use of com.xenoage.zong.musiclayout.notation.Notations in project Zong by Xenoage.

the class SingleVoiceSpacerTest method testGrace3.

/**
 * Computes a voice spacing with grace notes,
 * where the element before the grace notes has not enough empty rear space
 * to take even a single 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 testGrace3() {
    // 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, 3), 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

Notations (com.xenoage.zong.musiclayout.notation.Notations)7 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)5 Voice (com.xenoage.zong.core.music.Voice)4 VoiceElement (com.xenoage.zong.core.music.VoiceElement)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)4 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)4 Test (org.junit.Test)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)3 Beam (com.xenoage.zong.core.music.beam.Beam)2 Score (com.xenoage.zong.core.Score)1 BeamIterator (com.xenoage.zong.core.util.BeamIterator)1 ColumnElementIterator (com.xenoage.zong.core.util.ColumnElementIterator)1 MeasureElementIterator (com.xenoage.zong.core.util.MeasureElementIterator)1 VoiceElementIterator (com.xenoage.zong.core.util.VoiceElementIterator)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)1 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)1