Search in sources :

Example 1 with VoiceElement

use of com.xenoage.zong.core.music.VoiceElement 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)

Example 2 with VoiceElement

use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.

the class SingleVoiceSpacerTest method testSimple.

/**
 * Computes a simple voice spacing.
 * <pre>
 * Single elements: [-r1---][-r2-][-r3--][----r4--]
 * Combined:        --r1--~~r2_~-r3_~~---r4---
 * </pre> (~: area used by two elements, _: minimal distance between elements)
 */
@Test
public void testSimple() {
    // create voice and notations
    Voice voice = new Voice(alist((VoiceElement) r1, r2, r3, r4));
    Notations notations = new Notations();
    notations.add(new RestNotation(r1, new ElementWidth(2, 2, 4), null));
    notations.add(new RestNotation(r2, new ElementWidth(2, 2, 2), null));
    notations.add(new RestNotation(r3, new ElementWidth(2, 2, 3), null));
    notations.add(new RestNotation(r4, new ElementWidth(5, 2, 3), null));
    // compute spacing
    VoiceSpacing vs = testee.compute(voice, 200f, 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 + 8, ses[1].xIs, DELTA_FLOAT);
    assertEquals(s + 12 + d, ses[2].xIs, DELTA_FLOAT);
    assertEquals(s + 19 + 2 * d, ses[3].xIs, DELTA_FLOAT);
    assertEquals(s + 24 + 2 * 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(3, 8), ses[2].beat);
    assertEquals(Companion.fr(4, 8), ses[3].beat);
    assertEquals(Companion.fr(8, 8), ses[4].beat);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) 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 3 with VoiceElement

use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.

the class VoicesBeatOffsetter method computeVoicesBeats.

/**
 * Returns a sorted list of all beats, where
 * chords or rests begin, from the given list of voice spacings.
 * There are no duplicate beats. The ending beats of the voices are not added.
 */
SortedList<Fraction> computeVoicesBeats(List<VoiceSpacing> voiceSpacings) {
    SortedList<Fraction> beats = Companion.sortedListNoDuplicates();
    Fraction beat;
    for (VoiceSpacing voiceSpacing : voiceSpacings) {
        beat = Fraction.Companion.get_0();
        for (ElementSpacing spacingElement : voiceSpacing.elements) {
            MusicElement element = spacingElement.getElement();
            if (element instanceof VoiceElement) {
                // add beat
                beats.add(beat);
                // find the next beat
                beat = beat.add(((VoiceElement) element).getDuration());
            }
        }
    // do not add beat here, because the ending beat of an incomplete measure
    // is not interesting for computing beat offsets.
    }
    return beats;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) MusicElement(com.xenoage.zong.core.music.MusicElement) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Fraction(com.xenoage.utils.math.Fraction) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing)

Example 4 with VoiceElement

use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.

the class Utils method checkGraceChords.

public static void checkGraceChords(Staff staff, Chord[] expectedChords, boolean skipRests) {
    int iChord = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Voice voice = staff.getMeasure(iM).getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Rest && skipRests)
                continue;
            // check duration, type and notes
            Chord chord = (Chord) e;
            Chord expectedChord = expectedChords[iChord];
            assertEquals("chord " + iChord, expectedChord.getDuration(), chord.getDuration());
            assertEquals("chord " + iChord, expectedChord.getGrace(), chord.getGrace());
            assertEquals("chord " + iChord, expectedChord.getNotes(), chord.getNotes());
            iChord++;
        }
    }
    assertEquals("not all chords found", expectedChords.length, iChord);
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint)

Example 5 with VoiceElement

use of com.xenoage.zong.core.music.VoiceElement in project Zong by Xenoage.

the class VoiceElementIteratorTest method test.

@Test
public void test() {
    VoiceElementIterator it = new VoiceElementIterator(createTestScore());
    for (int staff : range(4)) {
        for (int measure : range(4)) {
            if ((staff == 1 || staff == 3) && (measure == 1 || measure == 3)) {
                // expect two voices with each 4 quarter rests
                for (int voice : range(2)) {
                    for (int element : range(4)) {
                        assertTrue(it.hasNext());
                        VoiceElement e = it.next();
                        assertEquals(mp(staff, measure, voice, Companion.fr(element, 4), element), it.getMp());
                        assertEquals(Companion.fr(1, 4), e.getDuration());
                    }
                }
            } else {
                // expect a full rest
                assertTrue(it.hasNext());
                VoiceElement e = it.next();
                assertEquals(mp(staff, measure, 0, Companion.get_0(), 0), it.getMp());
                assertEquals(Companion.fr(1), e.getDuration());
            }
        }
    }
    assertFalse(it.hasNext());
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Test(org.junit.Test)

Aggregations

VoiceElement (com.xenoage.zong.core.music.VoiceElement)17 Voice (com.xenoage.zong.core.music.Voice)12 Test (org.junit.Test)11 Chord (com.xenoage.zong.core.music.chord.Chord)8 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)6 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)6 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)5 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)5 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)5 Measure (com.xenoage.zong.core.music.Measure)4 Staff (com.xenoage.zong.core.music.Staff)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 Fraction (com.xenoage.utils.math.Fraction)3 Pitch (com.xenoage.zong.core.music.Pitch)2 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)2 ToDo (musicxmltestsuite.tests.utils.ToDo)2 Score (com.xenoage.zong.core.Score)1 MusicElement (com.xenoage.zong.core.music.MusicElement)1