use of com.xenoage.zong.commands.core.music.MeasureElementWrite in project Zong by Xenoage.
the class Context method writeMeasureElement.
/**
* Writes the given {@link MeasureElement} at the given staff (index relative to first
* staff in current part), current measure and current beat.
*/
public void writeMeasureElement(MeasureElement element, int staffIndexInPart) {
int staffIndex = getPartStaffIndices().getStart() + staffIndexInPart;
MP mp = this.mp.withStaff(staffIndex);
new MeasureElementWrite(element, score.getMeasure(mp), mp.getBeat()).execute();
}
use of com.xenoage.zong.commands.core.music.MeasureElementWrite in project Zong by Xenoage.
the class TimeMapperTest method getScore.
/**
* Creates the following score (each space is a quarter note)
*
* measures:
* repetitions: voltas/signs: 1───┐2───┐ d.c. senza rep
* barlines: | |: | :| |1 ||
* part 0: staff 0: voice 0: |1 |1 |2 2 |1 |1 ||
* voice 1: | |442 |42 4|1 d |1 || //d = direction
* staff 1: voice 0: |2 44|1 | |1 |1 ||
* part 1: staff 2: voice 0: |1 |1 |2 2 | |2 2 ||
*
* play ranges: 0---------------
* 1---- 2---------
* 3--------- 4---------
*/
private Score getScore() {
val score = new Score();
new PartAdd(score, new Part("p0", null, 2, null), 0, null).execute();
new PartAdd(score, new Part("p1", null, 1, null), 1, null).execute();
new MeasureAdd(score, 5).execute();
// time, barlines, voltas and signs
score.getColumnHeader(0).setTime(new TimeSignature(TimeType.Companion.getTime_4_4()));
score.getColumnHeader(1).setStartBarline(Companion.barlineForwardRepeat(Regular));
score.getColumnHeader(2).setVolta(new Volta(1, range(1, 1), "1", true));
score.getColumnHeader(2).setEndBarline(Companion.barlineBackwardRepeat(Regular, 1));
score.getColumnHeader(3).setVolta(new Volta(1, range(2, 2), "2", true));
score.getColumnHeader(4).setNavigationOrigin(new DaCapo(false));
// staff 0, voice 0
val cursor = new Cursor(score, mp0, true);
cursor.write(e(1));
cursor.write(e(1));
cursor.write(e(2));
cursor.write(e(2));
cursor.write(e(1));
cursor.write(e(1));
// staff 0, voice 1
cursor.setMp(atElement(0, 1, 1, 0));
cursor.write(e(4));
cursor.write(e(4));
cursor.write(e(2));
cursor.write(e(4));
cursor.write(e(2));
cursor.write(e(4));
cursor.write(e(1));
cursor.write(e(1));
new MeasureElementWrite(new Dynamic(DynamicValue.f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
// staff 1, voice 0
cursor.setMp(atElement(1, 0, 0, 0));
cursor.write(e(2));
cursor.write(e(4));
cursor.write(e(4));
cursor.write(e(1));
cursor.setMp(atElement(1, 2, 0, 0));
cursor.write(e(1));
cursor.write(e(1));
// staff 2, voice 0
cursor.setMp(atElement(2, 0, 0, 0));
cursor.write(e(1));
cursor.write(e(1));
cursor.write(e(2));
cursor.write(e(2));
cursor.setMp(atElement(2, 4, 0, 0));
cursor.write(e(2));
cursor.write(e(2));
return score;
}
use of com.xenoage.zong.commands.core.music.MeasureElementWrite 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.commands.core.music.MeasureElementWrite 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.commands.core.music.MeasureElementWrite in project Zong by Xenoage.
the class Context method writeInstrumentChange.
/**
* Changes the current instrument.
*/
public void writeInstrumentChange(String instrumentID) {
// find instrument
Part part = getScore().getStavesList().getPartByStaffIndex(mp.getStaff());
Instrument newInstrument = null;
for (Instrument instr : it(part.getInstruments())) {
if (instr.getId().equals(instrumentID)) {
newInstrument = instr;
break;
}
}
if (newInstrument == null) {
// error: instrument is unknown to this part
reportError("Unknown instrument: \"" + instrumentID + "\"");
}
// apply instrument change
new MeasureElementWrite(new InstrumentChange(newInstrument), score.getMeasure(this.mp), mp.getBeat()).execute();
}
Aggregations