Search in sources :

Example 36 with MP

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

the class VoiceElementWriteTest method testOverwrite5.

/**
 * Write<pre>
 *       x
 * into  aabbccddeeffgghh
 *  =>   x_bbccddeeffgghh</pre>
 */
@Test
public void testOverwrite5() {
    Score score = createTestScoreEighths();
    // in voice 1, write a 1/16 rest at 4/8
    MP mp = atElement(0, 0, 1, 0);
    Voice voice = score.getVoice(mp);
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, new Rest(Companion.fr(1, 16)), null);
    cmd.execute();
    // now, there must be the durations 1/16, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8, 1/8 in voice 1
    assertEquals(8, voice.getElements().size());
    assertEquals(Companion.fr(1, 16), 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));
    assertEquals(Companion.fr(1, 8), getDur(voice, 5));
    assertEquals(Companion.fr(1, 8), getDur(voice, 6));
    assertEquals(Companion.fr(1, 8), getDur(voice, 7));
    // 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 37 with MP

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

the class VoiceElementWriteTest method testGraceInsert3.

/**
 * Writes elements in a voice that contains grace notes.
 * <pre>
 *         xxxx___xxxx_xx
 * into  ..aaaa...bbbb.cccc..
 *  =>   ..xxxx___xxxx_xx__..</pre>
 */
@Test
public void testGraceInsert3() {
    Score score = createTestScoreGraces();
    // in voice 0, write a 5/8 rest at position 2
    MP mp = atElement(0, 0, 0, 2);
    Voice voice = score.getVoice(mp);
    Rest r = new Rest(Companion.fr(5, 8));
    VoiceElementWrite cmd = new VoiceElementWrite(voice, mp, r, null);
    cmd.execute();
    // check notes
    assertEquals(5, voice.getElements().size());
    // here 1st grace note has step 0, 2nd 1, ...
    assertEquals(0, getStep(voice, 0));
    assertEquals(1, getStep(voice, 1));
    assertEquals(r, voice.getElement(2));
    assertEquals(6, getStep(voice, 3));
    assertEquals(0, getStep(voice, 4));
    // test undo
    cmd.undo();
    assertTestScoreGracesOriginalState(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 38 with MP

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

the class Context method writeVoiceElement.

/**
 * Writes the given {@link VoiceElement} to the current position
 * without moving the cursor forward. When the element could be written, true is returned,
 * otherwise (e.g. when the measure was full), false is returned.
 */
public boolean writeVoiceElement(VoiceElement element, int staffIndexInPart, int voice) {
    MP mp = this.mp.withStaff(getPartStaffIndices().getStart() + staffIndexInPart).withVoice(voice);
    try {
        // create voice if needed
        Measure measure = score.getMeasure(mp);
        if (measure.getVoices().size() < voice + 1)
            execute(new VoiceAdd(measure, voice));
        execute(new VoiceElementWrite(score.getVoice(mp), mp, element, writeVoicElementOptions));
        return true;
    } catch (MeasureFullException ex) {
        reportError(ex.getMessage());
        return false;
    }
}
Also used : VoiceElementWrite(com.xenoage.zong.commands.core.music.VoiceElementWrite) MP(com.xenoage.zong.core.position.MP) VoiceAdd(com.xenoage.zong.commands.core.music.VoiceAdd) MeasureFullException(com.xenoage.zong.utils.exceptions.MeasureFullException)

Example 39 with MP

use of com.xenoage.zong.core.position.MP 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 40 with MP

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

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