Search in sources :

Example 1 with LayoutSettings

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

the class LayoutSettingsReader method read.

// private static final String file = "data/musiclayout/default.xml";
/**
 * Reads the {@link LayoutSettings} from the given input stream.
 */
public static LayoutSettings read(InputStream inputStream) throws IOException {
    ChordWidths chordWidths = null, graceChordWidths;
    Spacings spacings = null;
    float scalingClefInner = 0, scalingGrace = 0;
    float offsetMeasureStart = 0;
    float offsetBeatsMinimal = 0;
    try {
        XmlReader r = platformUtils().createXmlReader(inputStream);
        r.openNextChildElement();
        while (r.openNextChildElement()) {
            String n = r.getElementName();
            switch(n) {
                case "chordwidths":
                    // load the chord layout settings
                    chordWidths = readChordWidths(r);
                    break;
                case "spacings":
                    // load the space settings
                    spacings = readSpacings(r);
                    break;
                case "scaling":
                    // load scalings
                    while (r.openNextChildElement()) {
                        String n2 = r.getElementName();
                        if (n2.equals("clef"))
                            scalingClefInner = parseFloat(r.getAttributeNotNull("inner"));
                        else if (n2.equals("grace"))
                            scalingGrace = parseFloat(r.getAttributeNotNull("scaling"));
                        r.closeElement();
                    }
                    break;
                case "offset":
                    // load offsets
                    while (r.openNextChildElement()) {
                        String n2 = r.getElementName();
                        if (n2.equals("measure"))
                            offsetMeasureStart = parseFloat(r.getAttributeNotNull("start"));
                        else if (n2.equals("beats"))
                            offsetBeatsMinimal = parseFloat(r.getAttributeNotNull("minimal"));
                        r.closeElement();
                    }
                    break;
            }
            r.closeElement();
        }
        r.close();
    } catch (Exception ex) {
        INSTANCE.log(Companion.error("Could not read the input stream", ex));
        throw new IOException(ex);
    /*
			//default values
			durationWidths.put(fr(1, 32), 1 + 1/2f);
			durationWidths.put(fr(1, 16), 1 + 3/4f);
			durationWidths.put(fr(1, 8), 2 + 1/2f);
			durationWidths.put(fr(1, 2), 4 + 3/4f);
			widthClef = 4;
			widthSharp = 1.2f;
			widthFlat = 1f;
			widthMeasureEmpty = 8f;
			scalingClefInner = 0.75f;
			offsetMeasureStart = 1;
			offsetBeatsMinimal = 1.5f;
			*/
    }
    // compute grace chord widths
    graceChordWidths = chordWidths.scale(scalingGrace);
    return new LayoutSettings(chordWidths, graceChordWidths, spacings, scalingClefInner, scalingGrace, offsetMeasureStart, offsetBeatsMinimal);
}
Also used : LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Spacings(com.xenoage.zong.musiclayout.settings.Spacings) SpacingsReader.readSpacings(com.xenoage.zong.io.musiclayout.SpacingsReader.readSpacings) ChordWidthsReader.readChordWidths(com.xenoage.zong.io.musiclayout.ChordWidthsReader.readChordWidths) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths) XmlReader(com.xenoage.utils.xml.XmlReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with LayoutSettings

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

the class Layout method updateScoreLayouts.

/**
 * Updates the {@link ScoreLayout}s belonging to the given {@link Score}.
 */
public void updateScoreLayouts(Score score) {
    ScoreFrameChain chain = getScoreFrameChain(score);
    if (chain == null)
        return;
    ScoreLayout oldScoreLayout = chain.getScoreLayout();
    // select symbol pool and layout settings
    SymbolPool symbolPool = oldScoreLayout != null ? oldScoreLayout.symbolPool : defaults.getSymbolPool();
    LayoutSettings layoutSettings = oldScoreLayout != null ? oldScoreLayout.layoutSettings : defaults.getLayoutSettings();
    CList<ScoreLayoutArea> areas = clist();
    for (ScoreFrame scoreFrame : chain.getFrames()) {
        areas.add(new ScoreLayoutArea(scoreFrame.getSize(), scoreFrame.getHFill(), scoreFrame.getVFill()));
    }
    areas.close();
    Context context = new Context(score, symbolPool, layoutSettings);
    Target target = new Target(areas, areas.get(areas.size() - 1), false);
    ScoreLayout scoreLayout = new ScoreLayouter(context, target).createScoreLayout();
    // set updated layout
    chain.setScoreLayout(scoreLayout);
}
Also used : Context(com.xenoage.zong.musiclayout.layouter.Context) Target(com.xenoage.zong.musiclayout.layouter.Target) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 3 with LayoutSettings

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

the class ChordStamper method stampCore.

/**
 * Draws the given chord, including noteheads, stem, flags, accidentals, dots,
 * articulations and leger lines.
 */
public ChordStampings stampCore(ChordNotation chord, float chordXMm, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    Chord element = chord.element;
    boolean grace = element.isGrace();
    LayoutSettings settings = context.getSettings();
    float scaling = (grace ? settings.scalingGrace : 1);
    ChordWidths chordWidths = (grace ? settings.graceChordWidths : settings.chordWidths);
    float leftNoteXMm = getLeftNoteXMm(chordXMm, chord.notes, staff.is);
    // stem
    StemStamping stem = stampStem(chord, leftNoteXMm, context);
    // type of notehead
    CommonSymbol noteheadSymbol = CommonSymbol.NoteWhole;
    Duration.Type symbolType = Duration.INSTANCE.getNoteheadSymbolType(element.getDisplayedDuration());
    if (symbolType == Duration.INSTANCE.Type.Half)
        noteheadSymbol = CommonSymbol.NoteHalf;
    else if (symbolType == Duration.INSTANCE.Type.Quarter)
        noteheadSymbol = CommonSymbol.NoteQuarter;
    // noteheads
    NotesNotation notes = chord.notes;
    NoteheadStamping[] noteheads = new NoteheadStamping[notes.getNotesCount()];
    for (int iNote : range(noteheads)) {
        NoteDisplacement note = notes.getNote(iNote);
        Symbol noteSymbol = context.getSymbol(noteheadSymbol);
        float noteXMm = getNoteheadXMm(leftNoteXMm + note.xIs * staff.is, scaling, staff, noteSymbol);
        NoteheadStamping noteSt = new NoteheadStamping(chord, iNote, noteSymbol, Color.Companion.getBlack(), staff, sp(noteXMm, note.lp), scaling);
        noteheads[iNote] = noteSt;
    }
    // flags (only drawn if there is no beam)
    int flagsCount = Duration.INSTANCE.getFlagsCount(element.getDisplayedDuration());
    Beam beam = element.getBeam();
    StemDirection stemDir = chord.stemDirection;
    FlagsStamping flags = null;
    if (beam == null && flagsCount > 0 && chord.stem != null) /* can happen when no stem is used */
    {
        FlagsStamping.FlagsDirection flag = (stemDir == StemDirection.Up ? FlagsStamping.FlagsDirection.Down : FlagsStamping.FlagsDirection.Up);
        Symbol flagSymbol = context.getSymbol(CommonSymbol.NoteFlag);
        flags = new FlagsStamping(chord, staff, flag, flagsCount, flagSymbol, scaling, sp(leftNoteXMm + notes.stemOffsetIs * staff.is, chord.stem.endSlp.lp));
    }
    // accidentals
    AccidentalsNotation accs = chord.accidentals;
    AccidentalStamping[] accsSt = new AccidentalStamping[0];
    if (accs != null) {
        accsSt = new AccidentalStamping[accs.accidentals.length];
        for (int iAcc : range(accsSt)) {
            AccidentalDisplacement acc = accs.accidentals[iAcc];
            AccidentalStamping accSt = new AccidentalStamping(chord, iAcc, staff, sp(chordXMm + (acc.xIs - chord.width.frontGap + 0.5f) * staff.is, acc.yLp), 1, context.getSymbol(CommonSymbol.getAccidental(acc.accidental)));
            accsSt[iAcc] = accSt;
        }
    }
    // dots
    int[] dotPositions = notes.dotsLp;
    int dotsPerNote = notes.getDotsPerNoteCount();
    ProlongationDotStamping[] dots = new ProlongationDotStamping[dotPositions.length * dotsPerNote];
    Symbol dotSymbol = context.getSymbol(CommonSymbol.NoteDot);
    for (int iNote : range(dotPositions)) {
        for (int iDot : range(dotsPerNote)) {
            ProlongationDotStamping dotSt = new ProlongationDotStamping(chord, staff, dotSymbol, sp(leftNoteXMm + notes.getDotsOffsetIs(iDot) * staff.is, dotPositions[iNote]));
            dots[iNote * dotsPerNote + iDot] = dotSt;
        }
    }
    // articulations
    ArticulationsNotation arts = chord.articulations;
    ArticulationStamping[] artsSt = new ArticulationStamping[0];
    if (arts != null) {
        artsSt = new ArticulationStamping[arts.articulations.length];
        float noteheadWidth = chordWidths.get(element.getDuration());
        for (int iArt : range(artsSt)) {
            ArticulationDisplacement art = arts.articulations[iArt];
            ArticulationStamping artSt = new ArticulationStamping(chord, iArt, staff, sp(leftNoteXMm + (art.xIs + (noteheadWidth / 2)) * staff.is, art.yLp), 1, context.getSymbol(CommonSymbol.getArticulation(art.articulation)));
            artsSt[iArt] = artSt;
        }
    }
    // leger lines
    LegerLineStamping[] legerLines = legerLinesStamper.stamp(chord, chordXMm, staff);
    return new ChordStampings(element, chordXMm, staff, noteheads, dots, accsSt, legerLines, artsSt, flags, stem);
}
Also used : LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) Beam(com.xenoage.zong.core.music.beam.Beam) Chord(com.xenoage.zong.core.music.chord.Chord) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) ChordStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings) lombok.val(lombok.val) Duration(com.xenoage.zong.core.music.util.Duration) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths)

Example 4 with LayoutSettings

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

the class WebApp method openFile.

private void openFile(String filePath) {
    // show loading, hide score
    if (loadingPanel != null)
        loadingPanel.getStyle().setDisplay(BLOCK);
    canvas.setVisible(false);
    // load score
    platformUtils().openFileAsync(filePath).thenAsync(scoreStream -> new MusicXmlScoreDocFileReader(scoreStream, null).read()).thenAsync(scoreDoc -> {
        WebApp.this.scoreDoc = scoreDoc;
        return platformUtils().openFileAsync("data/layout/default.xml");
    }).thenDo(testXmlStream -> {
        LayoutSettings layoutSettings;
        try {
            layoutSettings = LayoutSettingsReader.read(testXmlStream);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        Size2f areaSize = new Size2f(150, 10000);
        SymbolPool symbolPool = zongPlatformUtils().getSymbolPool();
        Context context = new Context(scoreDoc.getScore(), symbolPool, layoutSettings);
        Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
        paintLayout();
        // show score, hide loading
        canvas.setVisible(true);
        if (loadingPanel != null)
            loadingPanel.getStyle().setDisplay(NONE);
    }).onError(ex -> consoleLog("Error: " + ex.toString()));
}
Also used : NONE(com.google.gwt.dom.client.Style.Display.NONE) GwtLogProcessing(com.xenoage.utils.gwt.log.GwtLogProcessing) Report.fatal(com.xenoage.utils.log.Report.fatal) EntryPoint(com.google.gwt.core.client.EntryPoint) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) SymbolPool(com.xenoage.zong.symbols.SymbolPool) LayoutSettingsReader(com.xenoage.zong.io.musiclayout.LayoutSettingsReader) GwtErrorProcessing(com.xenoage.utils.gwt.error.GwtErrorProcessing) Size2i(com.xenoage.utils.math.geom.Size2i) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreDoc(com.xenoage.zong.documents.ScoreDoc) MathUtils.clamp(com.xenoage.utils.math.MathUtils.clamp) Log(com.xenoage.utils.log.Log) Label(com.google.gwt.user.client.ui.Label) BLOCK(com.google.gwt.dom.client.Style.Display.BLOCK) PlatformUtils.platformUtils(com.xenoage.utils.PlatformUtils.platformUtils) PX(com.google.gwt.dom.client.Style.Unit.PX) Log.log(com.xenoage.utils.log.Log.log) GwtCanvasLayoutRenderer(com.xenoage.zong.renderer.gwtcanvas.GwtCanvasLayoutRenderer) Window(com.google.gwt.user.client.Window) Canvas(com.google.gwt.canvas.client.Canvas) Err(com.xenoage.utils.error.Err) Context(com.xenoage.zong.musiclayout.layouter.Context) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea) ZongPlatformUtils.zongPlatformUtils(com.xenoage.zong.util.ZongPlatformUtils.zongPlatformUtils) DOM(com.google.gwt.user.client.DOM) MusicXmlScoreDocFileReader(com.xenoage.zong.io.musicxml.in.MusicXmlScoreDocFileReader) Zong(com.xenoage.zong.Zong) Target(com.xenoage.zong.musiclayout.layouter.Target) IOException(java.io.IOException) AsyncCallback(com.xenoage.utils.async.AsyncCallback) RootPanel(com.google.gwt.user.client.ui.RootPanel) Context2d(com.google.gwt.canvas.dom.client.Context2d) GwtZongPlatformUtils(com.xenoage.zong.webapp.utils.GwtZongPlatformUtils) Element(com.google.gwt.dom.client.Element) GwtPlatformUtils.consoleLog(com.xenoage.utils.gwt.GwtPlatformUtils.consoleLog) Context(com.xenoage.zong.musiclayout.layouter.Context) Target(com.xenoage.zong.musiclayout.layouter.Target) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) MusicXmlScoreDocFileReader(com.xenoage.zong.io.musicxml.in.MusicXmlScoreDocFileReader) IOException(java.io.IOException) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

Example 5 with LayoutSettings

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

the class DemoScoreLayoutTry method main.

public static void main(String... args) throws Exception {
    SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
    LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
    try {
        Score score = ScoreRevolutionary.createScore();
        Size2f areaSize = new Size2f(150, 10000);
        Context context = new Context(score, symbolPool, layoutSettings);
        Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
        ScoreLayout layout = new ScoreLayouter(context, target).createLayoutWithExceptions();
        System.out.println(layout.toString());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) Score(com.xenoage.zong.core.Score) LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) Size2f(com.xenoage.utils.math.geom.Size2f) SymbolPool(com.xenoage.zong.symbols.SymbolPool) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout)

Aggregations

LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)6 SymbolPool (com.xenoage.zong.symbols.SymbolPool)4 Size2f (com.xenoage.utils.math.geom.Size2f)3 Score (com.xenoage.zong.core.Score)2 SymbolPoolReader (com.xenoage.zong.io.symbols.SymbolPoolReader)2 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)2 Context (com.xenoage.zong.musiclayout.layouter.Context)2 ScoreLayoutArea (com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)2 Target (com.xenoage.zong.musiclayout.layouter.Target)2 ChordWidths (com.xenoage.zong.musiclayout.settings.ChordWidths)2 IOException (java.io.IOException)2 Canvas (com.google.gwt.canvas.client.Canvas)1 Context2d (com.google.gwt.canvas.dom.client.Context2d)1 EntryPoint (com.google.gwt.core.client.EntryPoint)1 Element (com.google.gwt.dom.client.Element)1 BLOCK (com.google.gwt.dom.client.Style.Display.BLOCK)1 NONE (com.google.gwt.dom.client.Style.Display.NONE)1 PX (com.google.gwt.dom.client.Style.Unit.PX)1 DOM (com.google.gwt.user.client.DOM)1 Window (com.google.gwt.user.client.Window)1