use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class Test03b method test.
@Test
public void test() {
Measure measure = getScore().getMeasure(mp0);
// two voices
assertEquals(2, measure.getVoices().size());
// check first voice
Voice voice = measure.getVoice(0);
assertEquals(2, voice.getElements().size());
assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(0)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
assertEquals(Companion.pi(0, 0, 4), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
// check second voice
// in Zong!, there is no "empty" space in voices. Instead, an invisible rest is used
voice = measure.getVoice(1);
assertTrue(voice.getElement(0) instanceof Rest);
assertTrue(((Rest) voice.getElement(0)).isHidden());
assertEquals(Companion.fr(1, 4), voice.getElement(0).getDuration());
assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(1)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(1).getDuration());
assertEquals(Companion.pi(5, 0, 3), ((Chord) voice.getElement(2)).getNotes().get(0).getPitch());
assertEquals(Companion.fr(1, 4), voice.getElement(2).getDuration());
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class Base46e method getExpectedStaff.
static Staff getExpectedStaff() {
Score score = ScoreFactory.create1Staff();
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new TimeSignature(TimeType.Companion.getTimeCommon()));
// measure 0, voice 0
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
// measure 1, voice 0
cursor.setMp(atElement(0, 1, 0, 0));
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('A', 0, 4), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 4)));
// measure 1, voice 1
cursor.setMp(atElement(0, 1, 1, 0));
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(chord(Companion.pi('C', 0, 4), Companion.fr(1, 4)));
return score.getStaff(0);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class ScoreReader method readToScore.
public void readToScore(Score score, ErrorHandling errorHandling) {
Context context = new Context(score, new ReaderSettings(errorHandling));
// create the measures of the parts
It<MxlPart> mxlParts = it(doc.getParts());
for (MxlPart mxlPart : mxlParts) {
// create measures
execute(new MeasureAddUpTo(score, mxlPart.getMeasures().size()));
// initialize each measure with a C clef
Part part = score.getStavesList().getParts().get(mxlParts.getIndex());
StavesRange stavesRange = score.getStavesList().getPartStaffIndices(part);
for (int staff : stavesRange.getRange()) {
execute(new MeasureElementWrite(new Clef(ClefType.Companion.getClefTreble()), score.getMeasure(MP.atMeasure(staff, 0)), Companion.get_0()));
}
}
// write a 4/4 measure and C key signature in the first measure
execute(new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), Companion.get_0(), null));
execute(new ColumnElementWrite(new TraditionalKey(0), score.getColumnHeader(0), Companion.get_0(), null));
// read the parts
mxlParts = it(doc.getParts());
for (MxlPart mxlPart : mxlParts) {
// clear part-dependent context values
context.beginNewPart(mxlParts.getIndex());
// read the measures
It<MxlMeasure> mxlMeasures = it(mxlPart.getMeasures());
for (MxlMeasure mxlMeasure : mxlMeasures) {
try {
MeasureReader.readToContext(mxlMeasure, mxlMeasures.getIndex(), context);
} catch (MusicReaderException ex) {
throw new RuntimeException("Error at " + ex.getContext().toString(), ex);
} catch (Exception ex) {
throw new RuntimeException("Error (roughly) around " + context.toString(), ex);
}
}
}
// remove unclosed elements
context.removeUnclosedWedges();
// go through the whole score, and fill empty measures (that means, measures where
// voice 0 has no single VoiceElement) with rests
Fraction measureDuration = Companion.fr(1, 4);
for (int iStaff = 0; iStaff < score.getStavesCount(); iStaff++) {
Staff staff = score.getStaff(atStaff(iStaff));
for (int iMeasure : range(staff.getMeasures())) {
Measure measure = staff.getMeasure(iMeasure);
TimeSignature newTime = score.getHeader().getColumnHeader(iMeasure).getTime();
if (newTime != null) {
// time signature has changed
measureDuration = newTime.getType().getMeasureBeats();
}
if (measureDuration == null) {
// senza misura
// use whole rest
measureDuration = Companion.fr(4, 4);
}
Voice voice0 = measure.getVoice(0);
if (voice0.isEmpty()) {
// TODO: "whole rests" or split. currently, also 3/4 rests are possible
MP mp = atElement(iStaff, iMeasure, 0, 0);
new VoiceElementWrite(score.getVoice(mp), mp, new Rest(measureDuration), null).execute();
}
}
}
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class MeasureElementsSpacerTest method testNeedAdditionalSpace.
/**
* If there is not enough space left for the measure elements,
* the voice spacings have to be moved to create enough space.
* 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 4)
* voice 1: o 2
* voice 2: 1 o
* </pre>
* Between VE1 and VE2, there are 6 spaces.
* Assuming a padding width of 1 and a clef width of 6,
* the clef can be moved two spaces to the left, but this is not
* enough. All elements at or after beat 3 have to be moved 2 spaces
* to the right.
*/
@Test
public void testNeedAdditionalSpace() {
Rest[] ve = ve();
List<VoiceSpacing> vs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 11))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 16))));
Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
BeatEList<Clef> innerClefs = Companion.beatEList();
innerClefs.add(Companion.beatE(innerClef, Companion.fr(4)));
List<ElementSpacing> mes = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
// voice spacings
assertEquals(2, vs.size());
assertEqualsSpacings(ilist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(4), 13)), vs.get(0).elements);
assertEqualsSpacings(ilist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(13, 2), 18)), vs.get(1).elements);
// clef must be at offset 13 - padding - clefwidth/2
ElementSpacing[] se = mes.toArray(new ElementSpacing[0]);
assertEquals(1, se.length);
assertEquals(Companion.fr(4), se[0].beat);
assertEquals(13 - paddingWidth - clefWidth / 2, se[0].xIs, Delta.DELTA_FLOAT);
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class SingleVoiceSpacerTest method setUp.
@Before
public void setUp() throws IOException {
r1 = new Rest(Companion.fr(1, 4));
r2 = new Rest(Companion.fr(1, 8));
r3 = new Rest(Companion.fr(1, 8));
r4 = new Rest(Companion.fr(1, 2));
g1 = VoiceTest.grace(1);
g2 = VoiceTest.grace(1);
layoutSettings = LayoutSettingsTest.loadTestSettings();
}
Aggregations