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);
}
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);
}
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;
}
}
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());
}
}
}
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());
}
Aggregations