Search in sources :

Example 1 with SymbolPool

use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.

the class ScoreFrameLayouter method computeScoreFrameLayout.

/**
 * Creates a {@link ScoreFrameLayout} from the given {@link FrameSpacing}.
 *
 * @param unclosedElements  unclosed elements from the last frame, like slurs
 *                          spanning over more than one frame
 */
public ScoreFrameLayout computeScoreFrameLayout(FrameSpacing frame, int frameIndex, Notations notations, List<ContinuedElement> unclosedElements, Context layouterContext, Map<Beam, BeamSpacing> beamsSpacing) {
    layouterContext.saveMp();
    Score score = layouterContext.score;
    SymbolPool symbols = layouterContext.symbols;
    StamperContext context = new StamperContext();
    context.layouter = layouterContext;
    context.notations = notations;
    ScoreHeader header = score.getHeader();
    int stavesCount = score.getStavesCount();
    StavesList stavesList = score.getStavesList();
    ArrayList<StaffStamping> staffStampsPool = alist();
    ArrayList<Stamping> otherStampsPool = alist();
    // default lyric style
    FormattedTextStyle defaultLyricStyle = new FormattedTextStyle(score.getFormat().getLyricFont());
    // caches
    OpenSlursCache openCurvedLinesCache = new OpenSlursCache();
    OpenWedges openWedges = new OpenWedges();
    OpenLyricsCache openLyricsCache = new OpenLyricsCache();
    LastLyrics lastLyrics = new LastLyrics();
    OpenTupletsCache openTupletsCache = new OpenTupletsCache();
    OpenVolta openVolta = new OpenVolta();
    // add continued elements
    for (ContinuedElement ce : unclosedElements) {
        if (ce instanceof ContinuedSlur) {
            openCurvedLinesCache.add(SlurCache.createContinued((ContinuedSlur) ce));
        } else if (ce instanceof ContinuedVolta) {
            openVolta.volta = (ContinuedVolta) ce;
        } else if (ce instanceof ContinuedWedge) {
            openWedges.wedges.add((ContinuedWedge) ce);
        }
    }
    // create staff stampings
    StaffStampings staffStampings = staffStamper.createStaffStampings(score, frame);
    staffStampings.addAllTo(staffStampsPool);
    context.staffStampings = staffStampings;
    // go through the systems
    for (int iSystem : range(frame.getSystems())) {
        context.systemIndex = iSystem;
        SystemSpacing system = frame.getSystems().get(iSystem);
        List<StaffStamping> systemStaves = staffStampings.getAllOfSystem(iSystem);
        StaffStamping systemFirstStaff = getFirst(systemStaves);
        // add the part names (first system) or part abbreviations (other systems)
        int iStaffInPart = 0;
        for (Part part : stavesList.getParts()) {
            PartNameStamper.Style style = (frameIndex == 0 && iSystem == 0 ? PartNameStamper.Style.Full : PartNameStamper.Style.Abbreviated);
            addNotNull(otherStampsPool, partNameStamper.stamp(part, iStaffInPart, systemStaves, style));
            iStaffInPart += part.getStavesCount();
        }
        // create the brackets at the beginning of the system
        for (BracketGroup bracketGroup : stavesList.getBracketGroups()) {
            StavesRange r = bracketGroup.getStaves();
            otherStampsPool.add(new BracketStamping(systemStaves.get(r.getStart()), systemStaves.get(r.getStop()), system.getMarginLeftMm() - 1.4f, bracketGroup.getStyle()));
        }
        // create the barlines and measure numbers
        otherStampsPool.addAll(barlinesStamper.stamp(system, systemStaves, score));
        // fill the staves
        for (int iStaff : range(stavesCount)) {
            layouterContext.mp = layouterContext.mp.withStaff(iStaff);
            context.staffIndex = iStaff;
            float xMm = context.getCurrentStaffStamping().positionMm.x;
            for (int iMeasure : range(system.columns)) {
                int globalMeasureIndex = system.getStartMeasure() + iMeasure;
                layouterContext.mp = layouterContext.mp.withMeasure(globalMeasureIndex);
                context.measureIndex = globalMeasureIndex;
                ColumnSpacing measureColumnSpacing = system.columns.get(iMeasure);
                MeasureSpacing measure = measureColumnSpacing.getMeasures().get(iStaff);
                // add leading spacing elements, if available
                otherStampsPool.addAll(measureStamper.stampLeading(measure, xMm, context));
                // add directions
                otherStampsPool.addAll(directionStamper.stamp(context));
                // add measure elements within this measure
                float voicesXMm = xMm + measureColumnSpacing.getLeadingWidthMm();
                otherStampsPool.addAll(measureStamper.stampMeasure(measure, voicesXMm, context));
                // add voice elements within this measure
                otherStampsPool.addAll(voiceStamper.stampVoices(measure, voicesXMm, staffStampings, context, defaultLyricStyle, beamsSpacing, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
                xMm += measureColumnSpacing.getWidthMm();
            }
        }
        // create all voltas in this system, including open voltas from the last system
        otherStampsPool.addAll(voltaStamper.stampSystem(systemFirstStaff, openVolta, header, defaultLyricStyle));
        // create all wedges in this system
        otherStampsPool.addAll(wedgeStamper.stampSystem(system, score, staffStampings, openWedges));
    }
    // create the collected ties and slurs
    otherStampsPool.addAll(createTiesAndSlurs(openCurvedLinesCache, staffStampings, frame.getSystems().size()));
    // create the open lyric underscore lines
    for (Tuple3<StaffTextStamping, NoteheadStamping, Integer> openUnderscore : openLyricsCache.getUnderscores()) {
        // TODO: fetch style efficiently
        FormattedTextStyle style = defaultLyricStyle;
        FormattedTextElement firstElement = openUnderscore.get1().getText().getFirstParagraph().getElements().getFirst();
        if (firstElement instanceof FormattedTextString) {
            style = ((FormattedTextString) firstElement).getStyle();
        }
        otherStampsPool.addAll(lyricStamper.createUnderscoreStampings(openUnderscore.get1(), openUnderscore.get2(), style, staffStampings.getAllOfStaff(openUnderscore.get3())));
    }
    // create tuplet brackets/numbers
    for (Tuplet tuplet : openTupletsCache) {
        otherStampsPool.add(tupletStamper.createTupletStamping(tuplet, openTupletsCache, symbols));
    }
    // collect elements that have to be continued on the next frame
    ArrayList<ContinuedElement> continuedElements = alist();
    for (SlurCache clc : openCurvedLinesCache) {
        continuedElements.add(clc.getContinuedCurvedLine());
    }
    if (openVolta.volta != null)
        continuedElements.add(openVolta.volta);
    continuedElements.addAll(openWedges.wedges);
    layouterContext.restoreMp();
    return new ScoreFrameLayout(frame, staffStampsPool, otherStampsPool, continuedElements);
}
Also used : PartNameStamper(com.xenoage.zong.musiclayout.stamper.PartNameStamper) SlurCache(com.xenoage.zong.musiclayout.layouter.cache.util.SlurCache) LastLyrics(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.LastLyrics) StavesRange(com.xenoage.zong.core.music.group.StavesRange) OpenSlursCache(com.xenoage.zong.musiclayout.layouter.cache.OpenSlursCache) SymbolPool(com.xenoage.zong.symbols.SymbolPool) OpenTupletsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenTupletsCache) FormattedTextString(com.xenoage.zong.core.text.FormattedTextString) BracketGroup(com.xenoage.zong.core.music.group.BracketGroup) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) Tuplet(com.xenoage.zong.core.music.tuplet.Tuplet) StamperContext(com.xenoage.zong.musiclayout.stamper.StamperContext) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) Part(com.xenoage.zong.core.music.Part) StavesList(com.xenoage.zong.core.music.StavesList) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout) OpenLyricsCache(com.xenoage.zong.musiclayout.layouter.cache.OpenLyricsCache) StaffStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.StaffStampings) FormattedTextElement(com.xenoage.zong.core.text.FormattedTextElement)

Example 2 with SymbolPool

use of com.xenoage.zong.symbols.SymbolPool 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 SymbolPool

use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.

the class ElementStamper method getRestSymbol.

private Symbol getRestSymbol(Duration.Type duration, StamperContext context) {
    CommonSymbol cs = durationSymbolMapping.get(duration);
    SymbolPool symbols = context.layouter.symbols;
    if (cs != null)
        return symbols.getSymbol(cs);
    else
        return symbols.getWarningSymbol();
}
Also used : SymbolPool(com.xenoage.zong.symbols.SymbolPool) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Example 4 with SymbolPool

use of com.xenoage.zong.symbols.SymbolPool in project Zong by Xenoage.

the class GwtZongPlatformUtils method init.

/**
 * Initializes the {@link GwtZongPlatformUtils} as the {@link ZongPlatformUtils} instance
 * and {@link GwtPlatformUtils} as the {@link PlatformUtils} instance.
 */
public static void init(final AsyncCallback finished) {
    GwtPlatformUtils.init();
    ZongPlatformUtils.init(instance);
    // load default symbol pool
    new SymbolPoolReader("default").produce(new AsyncResult<SymbolPool>() {

        @Override
        public void onSuccess(SymbolPool symbolPool) {
            instance.symbolPool = symbolPool;
            finished.onSuccess();
        }

        @Override
        public void onFailure(Exception ex) {
            finished.onFailure(ex);
        }
    });
}
Also used : SymbolPoolReader(com.xenoage.zong.io.symbols.SymbolPoolReader) SymbolPool(com.xenoage.zong.symbols.SymbolPool)

Example 5 with SymbolPool

use of com.xenoage.zong.symbols.SymbolPool 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)

Aggregations

SymbolPool (com.xenoage.zong.symbols.SymbolPool)8 LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)4 Size2f (com.xenoage.utils.math.geom.Size2f)3 Score (com.xenoage.zong.core.Score)3 SymbolPoolReader (com.xenoage.zong.io.symbols.SymbolPoolReader)3 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 CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)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 Label (com.google.gwt.user.client.ui.Label)1