Search in sources :

Example 81 with Score

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;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) Cursor(com.xenoage.zong.io.selection.Cursor) Wedge(com.xenoage.zong.core.music.direction.Wedge) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Rest(com.xenoage.zong.core.music.rest.Rest) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) WedgeEnd(com.xenoage.zong.core.music.direction.WedgeEnd)

Example 82 with 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;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Cursor(com.xenoage.zong.io.selection.Cursor)

Example 83 with 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;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Words(com.xenoage.zong.core.music.direction.Words) UnformattedText(com.xenoage.zong.core.text.UnformattedText) Cursor(com.xenoage.zong.io.selection.Cursor)

Example 84 with 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;
}
Also used : lombok.val(lombok.val) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Volta(com.xenoage.zong.core.music.volta.Volta)

Example 85 with 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;
}
Also used : lombok.val(lombok.val) Frame(com.xenoage.zong.layout.frames.Frame) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Page(com.xenoage.zong.layout.Page) Fraction(com.xenoage.utils.math.Fraction) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing) JsonArray(com.google.gson.JsonArray) Score(com.xenoage.zong.core.Score) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) Layout(com.xenoage.zong.layout.Layout) Size2f(com.xenoage.utils.math.geom.Size2f) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) JseMidiSequenceWriter(com.xenoage.zong.desktop.io.midi.out.JseMidiSequenceWriter) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4