Search in sources :

Example 16 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class VoiceElementWriteTest method testOverwrite3.

/**
 * Write<pre>
 *       xxxxxxxx
 * into  aabbccddeeffgghh
 *  =>   xxxxxxxxeeffgghh</pre>
 */
@Test
public void testOverwrite3() {
    Score score = createTestScoreEighths();
    // in voice 1, write a half rest at 0/8
    MP mp = atElement(0, 0, 1, 0);
    Voice voice = score.getVoice(mp);
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 2)), null);
    cmd.execute();
    // now, there must be the durations 1/2, 1/8, 1/8, 1/8, 1/8 in voice 1
    assertEquals(5, voice.getElements().size());
    assertEquals(Companion.fr(1, 2), getDur(voice, 0));
    assertEquals(Companion.fr(1, 8), getDur(voice, 1));
    assertEquals(Companion.fr(1, 8), getDur(voice, 2));
    assertEquals(Companion.fr(1, 8), getDur(voice, 3));
    assertEquals(Companion.fr(1, 8), getDur(voice, 4));
    // test undo
    cmd.undo();
    assertTestScoreEighthsOriginalState(score);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 17 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class VoiceElementWriteTest method testOverwrite1.

/**
 * Write<pre>
 *         xxxxxxx
 * into  aabbccddeeffgghh
 *  =>   aaxxxxxxx_ffgghh</pre>
 */
@Test
public void testOverwrite1() {
    Score score = createTestScoreEighths();
    // in voice 1, write a 7/16 rest at 1/8
    MP mp = atElement(0, 0, 1, 1);
    Voice voice = score.getVoice(mp);
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(7, 16)), null);
    cmd.execute();
    // now, there must be the durations 1/8, 7/16, 1/8, 1/8, 1/8 in voice 1
    assertEquals(5, voice.getElements().size());
    assertEquals(Companion.fr(1, 8), getDur(voice, 0));
    assertEquals(Companion.fr(7, 16), getDur(voice, 1));
    assertEquals(Companion.fr(1, 8), getDur(voice, 2));
    assertEquals(Companion.fr(1, 8), getDur(voice, 3));
    assertEquals(Companion.fr(1, 8), getDur(voice, 4));
    // test undo
    cmd.undo();
    assertTestScoreEighthsOriginalState(score);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) MP(com.xenoage.zong.core.position.MP) Voice(com.xenoage.zong.core.music.Voice) Test(org.junit.Test)

Example 18 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class Test31a method test.

@ToDo("add support for multiple direction-types within a single MusicXML direction")
@Test
public void test() {
    Score score = getScore();
    // test directions
    for (Tuple2<MP, ?> item : expectedDirections) {
        MP mp = item.get1();
        List<?> directions = null;
        // in the column header instead, and not in the measure
        if (item.get2() instanceof Tempo)
            directions = score.getColumnHeader(mp.measure).getTempos().getAll(mp.beat);
        else if (item.get2() instanceof NavigationSign)
            directions = score.getColumnHeader(mp.measure).getOtherDirections().getAll(mp.beat);
        else
            directions = score.getMeasure(mp).getDirections().getAll(mp.beat);
        // check correct classes
        if (item.get2() instanceof Direction) {
            // single direction at this beat expected
            assertEquals("" + mp, 1, directions.size());
            assertEquals("" + mp, item.get2().getClass(), directions.get(0).getClass());
        } else if (item.get2() instanceof List<?>) {
        // List<?> l = (List<?>) item.get2();
        // multiple directions at this beat expected
        // TODO: add support for multiple direction-types within a single MusicXML direction
        // assertEquals(""+mp, l.size(), directions.size());
        // for (int i : range(l))
        // assertEquals(""+mp+"["+i+"]", l.get(i).getClass(), directions.get(i).getClass());
        }
    }
    // segno and coda
    assertEquals(MusicElementType.Segno, score.getColumnHeader(1).getNavigationTarget().getMusicElementType());
    assertEquals(MusicElementType.Coda, score.getColumnHeader(1).getNavigationOrigin().getMusicElementType());
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Tempo(com.xenoage.zong.core.music.direction.Tempo) NavigationSign(com.xenoage.zong.core.music.direction.NavigationSign) Direction(com.xenoage.zong.core.music.direction.Direction) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 19 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class Test31c method test.

@Test
public void test() {
    Score score = getScore();
    for (Tuple2<MP, Tempo> tempo : expectedTempos) {
        MP mp = tempo.get1();
        List<Tempo> temposAtBeat = score.getColumnHeader(mp.measure).getTempos().getAll(mp.beat);
        assertEquals(1, temposAtBeat.size());
        // TODO: add equals for tempo
        assertEquals(tempo.get2().getBaseBeat(), temposAtBeat.get(0).getBaseBeat());
        assertEquals(tempo.get2().getBeatsPerMinute(), temposAtBeat.get(0).getBeatsPerMinute());
    }
}
Also used : Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Tempo(com.xenoage.zong.core.music.direction.Tempo) Test(org.junit.Test)

Example 20 with MP

use of com.xenoage.zong.core.position.MP in project Zong by Xenoage.

the class Test32a method test.

@Test
public void test() {
    Score score = getScore();
    for (Tuple2<MP, ?> item : expectedAnnotations) {
        MP mp = item.get1();
        List<?> annotations = null;
        Chord chord = (Chord) score.getVoice(mp).getElementAt(mp.beat);
        assertNotNull("" + mp, chord);
        // in this test, the chords contain either directions or annotations
        if (false == chord.getDirections().isEmpty())
            annotations = chord.getDirections();
        else
            annotations = chord.getAnnotations();
        // check correct classes
        if (item.get2() instanceof Direction) {
            // single direction at this beat expected
            assertEquals("" + mp, 1, annotations.size());
            assertEquals("" + mp, item.get2().getClass(), annotations.get(0).getClass());
        } else if (item.get2() instanceof List<?>) {
            // list of annotations
            // we ignore the order here (MusicXML does not contain a order)
            assertEquals("" + mp, set((List<?>) item.get2()), set(annotations));
        } else {
            // single annotation
            assertEquals("" + mp, 1, annotations.size());
            assertEquals("" + mp, item.get2(), annotations.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) Direction(com.xenoage.zong.core.music.direction.Direction) Test(org.junit.Test)

Aggregations

MP (com.xenoage.zong.core.position.MP)46 Test (org.junit.Test)30 Score (com.xenoage.zong.core.Score)19 Chord (com.xenoage.zong.core.music.chord.Chord)16 Voice (com.xenoage.zong.core.music.Voice)14 Rest (com.xenoage.zong.core.music.rest.Rest)11 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Pitch (com.xenoage.zong.core.music.Pitch)4 Measure (com.xenoage.zong.core.music.Measure)3 Direction (com.xenoage.zong.core.music.direction.Direction)3 MP.atVoice (com.xenoage.zong.core.position.MP.atVoice)3 VoiceTest.assertEqualsVoice (musicxmltestsuite.tests.utils.VoiceTest.assertEqualsVoice)3 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)2 VoiceElementWrite (com.xenoage.zong.commands.core.music.VoiceElementWrite)2 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Staff (com.xenoage.zong.core.music.Staff)2 Beam (com.xenoage.zong.core.music.beam.Beam)2 Tempo (com.xenoage.zong.core.music.direction.Tempo)2 Position (com.xenoage.zong.core.music.format.Position)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2