use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class MeasureElementsSpacerTest method testEnoughExistingSpace.
/**
* If there is enough space left for the measure elements,
* the voice spacings do not have to be changed.
* To understand the following sketch, have a look at the comments
* in {@link MeasureElementsSpacer}.
* <pre>
* enough space:
* beat: 0 2 4 6 8
* offset: 3 5 7 9 13 17 21
* . . . . . . . . . .
* clef: *[clef]* (on beat 6)
* voice 1: o 2
* voice 2: 1 o
* </pre>
*/
@Test
public void testEnoughExistingSpace() {
Rest[] ve = ve();
List<VoiceSpacing> originalVs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(6), 15))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(17, 2), 20))));
List<VoiceSpacing> vs = alist(originalVs);
Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
BeatEList<Clef> innerClefs = Companion.beatEList();
innerClefs.add(Companion.beatE(innerClef, Companion.fr(6)));
List<ElementSpacing> res = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
// clef must be at offset 15 - padding - clefwidth/2
ElementSpacing[] mes = res.toArray(new ElementSpacing[0]);
assertEquals(1, mes.length);
assertEquals(Companion.fr(6), mes[0].beat);
assertEquals(15 - paddingWidth - clefWidth / 2, mes[0].xIs, Delta.DELTA_FLOAT);
// voice spacings must be unchanged
assertEquals(originalVs, vs);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class Base42a method getExpectedStaff.
/**
* Gets the expected musical data, but without the dynamics, fermatas, articulations and slurs.
*/
static Staff getExpectedStaff() {
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTime_4_4()));
// measure 0, voice 0
cursor.write(addLyric(chord(Companion.pi('E', 0, 5), Companion.fr(1, 2)), "This"));
cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "is"));
cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "the"));
// measure 1, voice 0
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "lyrics"));
cursor.write(addLyric(chord(Companion.pi('B', 0, 3), Companion.fr(3, 8)), "of"));
cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)), "Voice1"));
// measure 0, voice 1
cursor.setMp(atElement(0, 0, 1, 0));
cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 2)), "This"));
cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "is"));
cursor.write(addLyric(chord(Companion.pi('G', 0, 4), Companion.fr(1, 4)), "the"));
// measure 1, voice 1
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "lyrics"));
cursor.write(addLyric(chord(Companion.pi('G', 0, 3), Companion.fr(3, 8)), "of"));
cursor.write(addLyric(chord(Companion.pi('A', 0, 4), Companion.fr(1, 8)), "Voice2"));
return score.getStaff(0);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class Base42b method getExpectedStaves.
/**
* Gets the expected musical data, but without the dynamics, articulations and slurs
* and also without the clef changes.
*/
static Staff[] getExpectedStaves() {
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTime_6_8()));
// staff 1, measure 0
cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('D', 0, 4), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('B', 0, 3), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('F', 0, 3), Companion.fr(1, 4)));
// staff 1, measure 1
cursor.write(chord(Companion.pi('E', 0, 5), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
// staff 1, measure 0
cursor.setMp(atElement(1, 0, 0, 0));
cursor.write(new Rest(Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
cursor.write(chord(Companion.pi('A', 0, 2), Companion.fr(1, 16)));
cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
cursor.write(chord(Companion.pi('F', 1, 2), Companion.fr(1, 16)));
cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
// staff 1, measure 1
cursor.write(chord(new Pitch[] { Companion.pi('C', 0, 3), Companion.pi('E', 0, 3), Companion.pi('G', 0, 3), Companion.pi('C', 0, 4) }, Companion.fr(1, 4)));
cursor.write(new Rest(Companion.fr(1, 8)));
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
return new Staff[] { score.getStaff(0), score.getStaff(1) };
}
use of com.xenoage.zong.core.music.rest.Rest 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.rest.Rest 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) {
}
}
Aggregations