use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class VoiceTest method getElementIndexTest.
@Test
public void getElementIndexTest() {
// our test example: (g: grace note)
// Beats: 0 1 2 3 4 5
// Elements |g1|-----a-----|g2|g3|--b--|--c--|g4|
// Indices 0 1 2 3 4 5 6 7
// Checked: x x x x x x
Rest a = new Rest(Companion.fr(2)), b = new Rest(Companion.fr(1)), c = new Rest(Companion.fr(1));
Chord g1 = grace(1), g2 = grace(2), g3 = grace(3), g4 = grace(4);
Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
assertEquals(1, voice.getElementIndex(Companion.fr(0)));
assertEquals(1, voice.getElementIndex(Companion.fr(1)));
assertEquals(4, voice.getElementIndex(Companion.fr(2)));
assertEquals(5, voice.getElementIndex(Companion.fr(3)));
assertEquals(7, voice.getElementIndex(Companion.fr(4)));
assertEquals(7, voice.getElementIndex(Companion.fr(5)));
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class DynamicsFinderTest method getAdvancedScore.
/**
* See {@link #testAdvanced()}.
*/
private Score getAdvancedScore() {
Score score = new Score();
Wedge w;
new PartAdd(score, new Part("", null, 2, null), 0, null).execute();
new MeasureAdd(score, 5).execute();
// time signature and repeats
new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), null, null).execute();
new ColumnElementWrite(Companion.barlineForwardRepeat(Regular), score.getColumnHeader(1), null, MeasureSide.Left).execute();
new ColumnElementWrite(Companion.barlineBackwardRepeat(Regular, 1), score.getColumnHeader(2), null, MeasureSide.Right).execute();
// staff 0
new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(0, 0)), Companion.get_0()).execute();
new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 2)), Companion.get_0()).execute();
new MeasureElementWrite(new Dynamic(f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
new MeasureElementWrite(w = new Wedge(Crescendo), score.getMeasure(atMeasure(0, 3)), Companion.get_3$4()).execute();
new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(0, 4)), Companion.get_1$4()).execute();
new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 4)), Companion.get_1$2()).execute();
// voice 0
val cursor = new Cursor(score, mp0, true);
cursor.write(new Rest(Companion.get_1()));
cursor.write(new Rest(Companion.get_1()));
cursor.write(new Rest(Companion.get_1()));
cursor.write(new Rest(Companion.get_1()));
// voice 1
cursor.setMp(atElement(0, 0, 1, 0));
cursor.write(new Rest(Companion.get_1$2()));
val chord = chord(Companion.pi(0, 4), Companion.get_1$2());
chord.addDirection(new Dynamic(mf));
cursor.write(chord);
cursor.write(new Rest(Companion.get_1()));
cursor.write(new Rest(Companion.get_1()));
cursor.setMp(atElement(0, 4, 1, 0));
cursor.write(new Rest(Companion.get_1()));
// staff 1
new MeasureElementWrite(new Dynamic(ff), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
new MeasureElementWrite(w = new Wedge(Diminuendo), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
new MeasureElementWrite(new Dynamic(p), score.getMeasure(atMeasure(1, 3)), Companion.get_0()).execute();
return score;
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class BeamIteratorTest method createTestScore.
/**
* Test score with 2 staves and 4 measures. In measure 0, there is a beam in
* staff 0 in voice 1. In measure 2, there is a beam spanning over two staves.
* In measure 3, there is a beam in staff 1 in voice 0.
*/
public static Score createTestScore() {
Score score = new Score();
Cursor cursor = new Cursor(score, MP.mp0, true);
// first beam
cursor.setMp(atElement(0, 0, 1, 0));
cursor.openBeam();
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.closeBeam();
// second beam
cursor.setMp(atElement(0, 2, 0, 0));
cursor.openBeam();
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.setMp(atElement(1, 2, 0, 0));
cursor.write(new Rest(Companion.get_1$8()));
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.closeBeam();
// third beam
cursor.setMp(atElement(1, 3, 0, 0));
cursor.openBeam();
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.write(chord(Companion.pi(Companion.getC(), 4), Companion.get_1$8()));
cursor.closeBeam();
return score;
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class MeasureElementIteratorTest method createTestScore.
/**
* Test score with 4 staves and 4 measures. In staves 1 and 3, the measures 1 and 3 have each
* three words with text "staff x, measure y, element z" on beats 1/4 and 2/4
*/
public static Score createTestScore() {
Score score = new Score();
Cursor cursor = new Cursor(score, MP.mp0, true);
for (int staff : new int[] { 1, 3 }) {
for (int measure : new int[] { 1, 3 }) {
cursor.setMp(atElement(staff, measure, 0, 0));
for (int element : range(2)) {
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write((MeasureElement) new Words(new UnformattedText("staff " + staff + ", measure " + measure + ", element " + element)));
}
}
}
return score;
}
use of com.xenoage.zong.core.music.rest.Rest in project Zong by Xenoage.
the class ChordReader method readFirstNote.
private void readFirstNote() {
mxlFirstNote = mxlNotes.get(0);
MxlNoteContentType mxlFirstNoteType = mxlFirstNote.getContent().getNoteContentType();
// type of chord/rest
// (unpitched is still unsupported)
MxlFullNote mxlFirstFullNote = mxlFirstNote.getContent().getFullNote();
MxlNormalNote mxlFirstNormalNote = null;
MxlCueNote mxlFirstCueNote = null;
MxlGraceNote mxlFirstGraceNote = null;
boolean isCue = false;
boolean isGrace = false;
if (mxlFirstNoteType == MxlNoteContentType.Normal) {
mxlFirstNormalNote = (MxlNormalNote) mxlNotes.get(0).getContent();
} else if (mxlFirstNoteType == MxlNoteContentType.Cue) {
mxlFirstCueNote = (MxlCueNote) mxlNotes.get(0).getContent();
isCue = true;
} else if (mxlFirstNoteType == MxlNoteContentType.Grace) {
mxlFirstGraceNote = (MxlGraceNote) mxlNotes.get(0).getContent();
isGrace = true;
// may also be true later, see (TODO) "Zong-Library/Discussions/MusicXML/Note - cue vs grace.txt"
isCue = false;
}
MxlFullNoteContentType mxlFNCType = mxlFirstFullNote.getContent().getFullNoteContentType();
// duration. here, the first duration is the duration of the whole chord.
Fraction duration = Companion.get_0();
if (mxlFirstNormalNote != null) {
duration = readDuration(mxlFirstNormalNote.getDuration(), context.getDivisions());
} else if (mxlFirstCueNote != null) {
duration = readDuration(mxlFirstCueNote.getDuration(), context.getDivisions());
}
// when duration of normal note is 0, ignore the chord
if (false == isGrace && false == duration.isGreater0()) {
context.reportError("duration of chord is 0");
return;
}
// create new chord or rest
if (mxlFNCType == MxlFullNoteContentType.Pitch || mxlFNCType == MxlFullNoteContentType.Unpitched) {
// create a chord
Pitch pitch;
if (mxlFNCType == MxlFullNoteContentType.Pitch)
pitch = ((MxlPitch) mxlFirstFullNote.getContent()).getPitch();
else
// TODO (ZONG-96): better support for unpitched notes
pitch = Pitch.Companion.pi(0, 4);
Grace grace = null;
if (mxlFirstGraceNote != null) {
// read grace duration from note-type ("eighth", "16th", ...)
Fraction graceDuration = Companion.fr(1, 8);
if (mxlFirstNote.getNoteType() != null)
graceDuration = mxlFirstNote.getNoteType().getDuration();
boolean slash = mxlFirstGraceNote.getSlash() == MxlYesNo.Yes;
grace = new Grace(slash, graceDuration);
chord = new Chord(alist(new Note(pitch)), grace);
} else {
chord = new Chord(alist(new Note(pitch)), duration);
}
chord.setCue(isCue);
chordOrRest = chord;
} else if (mxlFNCType == MxlFullNoteContentType.Rest) {
// create a rest
Rest rest = new Rest(duration);
rest.setCue(isCue);
chordOrRest = rest;
}
}
Aggregations