Search in sources :

Example 6 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class ScoreSelectionLayouter method setCursor.

/**
 * Sets a {@link StaffCursorStamping} for the given {@link Cursor}.
 */
private void setCursor(Cursor cursor) {
    // remove old stampings
    removeSelectionStampings();
    // find frame
    MP mp = cursor.getMP();
    int measure = mp.measure;
    ScoreFrameLayout frame = scoreLayout.getScoreFrameLayout(measure);
    if (frame != null) {
        StaffStamping staff = frame.getStaffStamping(mp.staff, measure);
        if (staff != null) {
            frame.setSelectionStampings(ilist(new StaffCursorStamping(frame.getPositionX(mp.getTime()), -0.5f, staff)));
        }
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) StaffCursorStamping(com.xenoage.zong.musiclayout.stampings.StaffCursorStamping) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 7 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class ScoreFrameRenderer method paintTransformed.

@Override
protected void paintTransformed(Frame frame, Canvas canvas, RendererArgs args) {
    Rectangle2f rect = getLocalRect(frame);
    // draw musical elements
    ScoreFrame scoreFrame = (ScoreFrame) frame;
    ScoreFrameLayout scoreLayout = scoreFrame.getScoreFrameLayout();
    if (scoreLayout != null) {
        // the coordinates of the layout elements are relative to the upper left
        // corner, so we have to translate them
        canvas.transformSave();
        canvas.transformTranslate(rect.x1(), rect.y1());
        // get musical stampings, and in interactive mode, also
        // stampings like for playback and selection
        Iterable<Stamping> stampings = (canvas.getDecoration() == CanvasDecoration.Interactive ? scoreLayout.getAllStampings() : scoreLayout.getMusicalStampings());
        // render them
        for (Stamping s : stampings) {
            StampingRenderer.drawAny(s, canvas, args);
        }
        // restore old transformation
        canvas.transformRestore();
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Example 8 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class Test01a method test.

@ToDo("the editiorial sharp (sharp in parenthesis) in the last measure is not supported yet")
@Test
public void test() {
    int[] expectedLPs = getExpectedLPs();
    Staff staff = getFirstStaff();
    ScoreFrameLayout scoreFrameLayout = getScoreFrameLayout();
    int chordIndex = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Measure measure = staff.getMeasures().get(iM);
        Voice voice = measure.getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Chord) {
            // check LP
            // TODO
            }
        }
    }
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Measure(com.xenoage.zong.core.music.Measure) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 9 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout 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)

Example 10 with ScoreFrameLayout

use of com.xenoage.zong.musiclayout.ScoreFrameLayout in project Zong by Xenoage.

the class PlaybackLayouter method setCursorAt.

/**
 * Sets a {@link SystemCursorStamping} at the given {@link MP},
 * representing the current playback position.
 */
public void setCursorAt(Time time) {
    // remove old playback cursors
    removePlaybackStampings();
    // create new one
    SystemCursorStamping cursor = createCursorAt(time);
    // find frame
    if (cursor != null) {
        ScoreFrameLayout frame = scoreLayout.getScoreFrameLayout(time.getMeasure());
        frame.setPlaybackStampings(ilist(cursor));
    }
}
Also used : SystemCursorStamping(com.xenoage.zong.musiclayout.stampings.SystemCursorStamping) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Aggregations

ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)10 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 Score (com.xenoage.zong.core.Score)2 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)2 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Fraction (com.xenoage.utils.math.Fraction)1 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)1 Measure (com.xenoage.zong.core.music.Measure)1 MusicElement (com.xenoage.zong.core.music.MusicElement)1 Part (com.xenoage.zong.core.music.Part)1 Staff (com.xenoage.zong.core.music.Staff)1 StavesList (com.xenoage.zong.core.music.StavesList)1 Voice (com.xenoage.zong.core.music.Voice)1 VoiceElement (com.xenoage.zong.core.music.VoiceElement)1 Beam (com.xenoage.zong.core.music.beam.Beam)1