use of com.xenoage.zong.utils.exceptions.MeasureFullException 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.utils.exceptions.MeasureFullException 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;
}
}
Aggregations