Search in sources :

Example 56 with Chord

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

the class Test21c method test.

@Test
public void test() {
    Score score = getScore();
    MP mp = mp0;
    for (int i = 0; i < expectedChords.length; i++) {
        Chord chord = (Chord) score.getVoice(mp).getElementAt(mp.beat);
        assertEquals("chord " + i, expectedChords[i].getNotes(), chord.getNotes());
        assertEquals("chord " + i, expectedChords[i].getDuration(), chord.getDuration());
        mp = mp.withBeat(mp.beat.add(expectedChords[i].getDuration()));
        if (mp.beat.compareTo(Companion.get_1()) >= 0) {
            mp = mp.withMeasure(mp.measure + 1).withBeat(Companion.get_0());
        }
    }
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 57 with Chord

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

the class Test21d method testMeasure1.

@Test
public void testMeasure1() {
    MP m2 = mp0.withMeasure(1);
    // chords
    Chord chord = (Chord) score.getVoice(m2).getElementAt(Companion.get_0());
    assertEquals(2, chord.getNotes().size());
    assertEquals(Companion.pi('F', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.pi('A', -1, 4), chord.getNotes().get(1).getPitch());
    assertEquals(Companion.fr(3, 8), chord.getDuration());
    chord = (Chord) score.getVoice(m2).getElementAt(Companion.fr(3, 8));
    assertEquals(2, chord.getNotes().size());
    assertEquals(Companion.pi('F', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.pi('A', -1, 4), chord.getNotes().get(1).getPitch());
    assertEquals(Companion.fr(1, 8), chord.getDuration());
    chord = (Chord) score.getVoice(m2).getElementAt(Companion.fr(2, 4));
    assertEquals(2, chord.getNotes().size());
    assertEquals(Companion.pi('G', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.pi('B', -1, 4), chord.getNotes().get(1).getPitch());
    assertEquals(Companion.fr(1, 4), chord.getDuration());
    chord = (Chord) score.getVoice(m2).getElementAt(Companion.fr(3, 4));
    assertEquals(2, chord.getNotes().size());
    assertEquals(Companion.pi('G', 0, 4), chord.getNotes().get(0).getPitch());
    assertEquals(Companion.pi('B', -1, 4), chord.getNotes().get(1).getPitch());
    assertEquals(Companion.fr(1, 4), chord.getDuration());
    // dynamics "p"
    Dynamic dynamics = (Dynamic) score.getMeasure(m2).getMeasureElements().get(Companion.get_0());
    assertEquals(DynamicValue.p, dynamics.getValue());
    assertEquals(Placement.Below, dynamics.getPositioning());
}
Also used : Dynamic(com.xenoage.zong.core.music.direction.Dynamic) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 58 with Chord

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

the class Test21f method test.

@Test
public void test() {
    Score score = getScore();
    // 1/4 with 3 notes at beat 0
    List<VoiceElement> e = score.getVoice(mp0).getElements();
    Chord chord = (Chord) e.get(0);
    assertEquals(3, chord.getNotes().size());
    assertEquals(Companion.fr(1, 4), chord.getDuration());
    // followed by 2 rests, 1/4 and 2/4
    assertEquals(Companion.fr(1, 4), ((Rest) e.get(1)).getDuration());
    assertEquals(Companion.fr(2, 4), ((Rest) e.get(2)).getDuration());
    // segno at beat 1/4 in column (moved to the end of the measure, since we accept no mid-measure segnos)
    Direction segno = (Segno) score.getColumnHeader(0).getNavigationOrigin();
    assertNotNull(segno);
    // dynamics p at beat 1/4 in measure
    Dynamic dynamics = (Dynamic) score.getMeasure(mp0).getDirections().get(Companion.fr(1, 4));
    assertNotNull(dynamics);
    assertEquals(DynamicValue.p, dynamics.getValue());
}
Also used : Score(com.xenoage.zong.core.Score) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) VoiceElement(com.xenoage.zong.core.music.VoiceElement) Segno(com.xenoage.zong.core.music.direction.Segno) Chord(com.xenoage.zong.core.music.chord.Chord) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Example 59 with Chord

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

the class Utils method gr.

/**
 * Sets the given chord to a grace chord.
 */
public static Chord gr(Fraction graceDuration, boolean slash, Pitch... pitches) {
    Grace grace = new Grace(slash, graceDuration);
    ArrayList<Note> notes = alist();
    for (Pitch pitch : pitches) notes.add(new Note(pitch));
    return new Chord(notes, grace);
}
Also used : Grace(com.xenoage.zong.core.music.chord.Grace) Note(com.xenoage.zong.core.music.chord.Note) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 60 with Chord

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

the class VoiceTest method assertEqualsVoice.

/**
 * Tests the equality of the given voices, but only the durations of the rests
 * and the durations and notes of the chords.
 */
public static void assertEqualsVoice(Voice expectedVoice, Voice voice, MP voiceMP) {
    assertEquals("" + voiceMP, expectedVoice.getElements().size(), voice.getElements().size());
    for (int i : range(expectedVoice.getElements())) {
        VoiceElement expElement = expectedVoice.getElement(i);
        VoiceElement element = voice.getElement(i);
        assertEquals(expElement.getClass(), element.getClass());
        assertEquals(expElement.getDuration(), element.getDuration());
        if (expElement instanceof Chord)
            assertEqualsChord((Chord) expElement, (Chord) element, voiceMP.withElement(i));
    }
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Chord(com.xenoage.zong.core.music.chord.Chord) ChordTest.assertEqualsChord(musicxmltestsuite.tests.utils.ChordTest.assertEqualsChord)

Aggregations

Chord (com.xenoage.zong.core.music.chord.Chord)63 Test (org.junit.Test)34 MP (com.xenoage.zong.core.position.MP)16 Pitch (com.xenoage.zong.core.music.Pitch)12 Score (com.xenoage.zong.core.Score)11 Voice (com.xenoage.zong.core.music.Voice)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)10 VoiceElement (com.xenoage.zong.core.music.VoiceElement)8 Note (com.xenoage.zong.core.music.chord.Note)6 Rest (com.xenoage.zong.core.music.rest.Rest)6 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Fraction (com.xenoage.utils.math.Fraction)5 Staff (com.xenoage.zong.core.music.Staff)4 Beam (com.xenoage.zong.core.music.beam.Beam)4 Grace (com.xenoage.zong.core.music.chord.Grace)4 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)4 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)4 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)4 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)4