use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class SingleVoiceSpacer method compute.
public VoiceSpacing compute(Context context, Notations notations) {
Voice voice = context.score.getVoice(context.mp);
float is = context.score.getInterlineSpace(context.mp);
Fraction measureBeats = context.score.getMeasureBeats(context.mp.measure);
int staffLinesCount = context.score.getStaff(context.mp).getLinesCount();
return compute(voice, is, measureBeats, staffLinesCount, notations, context.settings);
}
use of com.xenoage.zong.core.music.Voice 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);
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class VoiceElementWriteTest method testTimeAware.
/**
* Obey the time signature. Fail is written element is too long.
*/
@Test
public void testTimeAware() {
Score score = ScoreFactory.create1Staff4Measures();
score.getHeader().getColumnHeaders().get(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
// create options
VoiceElementWrite.Options options = new VoiceElementWrite.Options();
options.checkTimeSignature = true;
// measure 0: senza misura: write 100 1/4 chords
Voice voice = score.getVoice(MP.atVoice(0, 0, 0));
for (int i : range(100)) new VoiceElementWrite(voice, atElement(0, 0, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
// measure 2: must work for 3/4, then fail
for (int i : range(3)) new VoiceElementWrite(voice, atElement(0, 2, 0, i), new Rest(Companion.fr(1, 4)), options).execute();
try {
new VoiceElementWrite(voice, atElement(0, 2, 0, 3), new Rest(Companion.fr(1, 4)), options).execute();
fail();
} catch (MeasureFullException ex) {
}
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class VoiceElementWriteTest method createTestScoreEighths.
/**
* Creates a score with a single staff, a single measure,
* two voices with each 8 quarter notes which are beamed.
*/
private Score createTestScoreEighths() {
Score score = ScoreFactory.create1Staff();
new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
for (int iVoice : range(2)) {
Voice voice = score.getVoice(atVoice(0, 0, iVoice));
List<Chord> beamChords = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Chord chord = new Chord(new Note(Companion.pi(0, 0, 4)), Companion.fr(1, 8));
// add elements by hand, since the corresonding command is tested itself in this class
chord.setParent(voice);
voice.getElements().add(chord);
beamChords.add(chord);
}
// create beam
Companion.beamFromChords(beamChords);
}
// ensure that assert method works correctly. if not, fail now
assertTestScoreEighthsOriginalState(score);
return score;
}
use of com.xenoage.zong.core.music.Voice in project Zong by Xenoage.
the class VoiceElementWriteTest method testOverwrite2.
/**
* Write<pre>
* xxxxxxxx
* into aabbccddeeffgghh
* => aaxxxxxxxxffgghh</pre>
*/
@Test
public void testOverwrite2() {
Score score = createTestScoreEighths();
// in voice 1, write a half 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(1, 2)), null);
cmd.execute();
// now, there must be the durations 1/8, 1/2, 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(1, 2), 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);
}
Aggregations