use of com.xenoage.zong.core.Score 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.Score 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.Score 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.Score in project Zong by Xenoage.
the class VoltaGroupFinderTest method createScore.
private Score createScore() {
Score score = ScoreFactory.create1Staff();
new MeasureAdd(score, getLast(getLast(voltaGroups)) + 4).execute();
for (val voltaGroup : voltaGroups) {
for (int iVolta = 0; iVolta < voltaGroup.length - 1; iVolta++) {
int startMeasure = voltaGroup[iVolta];
int length = voltaGroup[iVolta + 1] - voltaGroup[iVolta];
val numbers = range(iVolta + 1, iVolta + 1);
score.getHeader().getColumnHeader(startMeasure).setVolta(new Volta(length, numbers, numbers.toString(), false));
}
}
return score;
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class CursorOutput method write.
public JsonObject write(ScoreDoc doc) {
JsonObject ret = new JsonObject();
// create midi sequence and mp mappings
Score score = doc.getScore();
val seq = MidiConverter.convertToSequence(score, optionsForFileExport, new JseMidiSequenceWriter());
// save time map
JsonArray jsonMPs = new JsonArray();
val timeMap = seq.getTimeMap();
for (int iRep : range(timeMap.getRepetitionsCount())) {
for (val time : timeMap.getTimesSorted(iRep)) {
val midiTime = timeMap.getByRepTime(iRep, time);
JsonObject jsonMP = new JsonObject();
jsonMP.addProperty("measure", time.measure);
jsonMP.addProperty("beat", "" + time.beat);
jsonMP.addProperty("ms", midiTime.ms);
jsonMPs.add(jsonMP);
}
}
ret.add("mps", jsonMPs);
// collect data
int measuresCount = score.getMeasuresCount();
ArrayList<System> systems = new ArrayList<>();
ArrayList<Measure> measures = new ArrayList<>();
for (int i = 0; i < measuresCount; i++) {
measures.add(new Measure());
}
int systemCount = 0;
Layout layout = doc.getLayout();
for (int iPage : range(layout.getPages())) {
Page page = layout.getPages().get(iPage);
Size2f pageSize = page.getFormat().getSize();
for (Frame frame : page.getFrames()) {
if (frame instanceof ScoreFrame) {
Point2f absPos = frame.getAbsolutePosition();
float offsetX = absPos.x - frame.getSize().width / 2;
float offsetY = absPos.y - frame.getSize().height / 2;
ScoreFrameLayout sfl = ((ScoreFrame) frame).getScoreFrameLayout();
for (SystemSpacing systemSpacing : sfl.getFrameSpacing().getSystems()) {
// read system data
int systemIndex = systemCount + systemSpacing.getSystemIndexInFrame();
while (systems.size() - 1 < systemIndex) systems.add(new System());
System system = systems.get(systemIndex);
system.page = iPage;
system.top = (offsetY + systemSpacing.offsetYMm) / pageSize.height;
system.bottom = (offsetY + systemSpacing.offsetYMm + systemSpacing.getHeightMm()) / pageSize.height;
// read measure beats
float systemOffsetX = systemSpacing.marginLeftMm;
for (int iMeasure : systemSpacing.getMeasures()) {
Measure measure = measures.get(iMeasure);
measure.system = systemIndex;
measure.left = (offsetX + systemOffsetX + systemSpacing.getMeasureStartMm(iMeasure)) / pageSize.width;
measure.right = (offsetX + systemOffsetX + systemSpacing.getMeasureEndMm(iMeasure)) / pageSize.width;
for (BeatOffset bo : systemSpacing.getColumn(iMeasure).getBeatOffsets()) {
measure.beats.put(bo.getBeat(), (offsetX + systemOffsetX + bo.getOffsetMm()) / pageSize.width);
}
}
}
systemCount += sfl.getFrameSpacing().getSystems().size();
}
}
}
// save systems
JsonArray jsonSystems = new JsonArray();
for (int i = 0; i < systems.size(); i++) {
System system = systems.get(i);
JsonObject jsonSystem = new JsonObject();
jsonSystem.addProperty("number", i);
jsonSystem.addProperty("page", system.page);
jsonSystem.addProperty("top", system.top);
jsonSystem.addProperty("bottom", system.bottom);
jsonSystems.add(jsonSystem);
}
ret.add("systems", jsonSystems);
// save measures
JsonArray jsonMeasures = new JsonArray();
for (int i = 0; i < measuresCount; i++) {
Measure measure = measures.get(i);
JsonObject jsonMeasure = new JsonObject();
jsonMeasure.addProperty("number", i);
jsonMeasure.addProperty("system", measure.system);
jsonMeasure.addProperty("left", measure.left);
jsonMeasure.addProperty("right", measure.right);
// beats
JsonArray jsonBeats = new JsonArray();
ArrayList<Fraction> sortedBeats = new ArrayList<>(measure.beats.keySet());
Collections.sort(sortedBeats);
for (Fraction beat : sortedBeats) {
JsonObject jsonBeat = new JsonObject();
jsonBeat.addProperty("at", "" + beat);
jsonBeat.addProperty("x", measure.beats.get(beat));
jsonBeats.add(jsonBeat);
}
jsonMeasure.add("beats", jsonBeats);
jsonMeasures.add(jsonMeasure);
}
ret.add("measures", jsonMeasures);
// save time cursors
JsonArray jsonTCs = new JsonArray();
for (int iRep : range(timeMap.getRepetitionsCount())) {
for (val time : timeMap.getTimesSorted(iRep)) {
val midiTime = timeMap.getByRepTime(iRep, time);
JsonObject jsonTC = new JsonObject();
jsonTC.addProperty("time", midiTime.ms);
Measure measure = measures.get(time.measure);
System system = systems.get(measure.system);
jsonTC.addProperty("page", system.page);
jsonTC.addProperty("top", system.top);
jsonTC.addProperty("left", measure.beats.get(time.beat));
jsonTC.addProperty("bottom", system.bottom);
jsonTCs.add(jsonTC);
}
}
ret.add("timecursors", jsonTCs);
return ret;
}
Aggregations