Search in sources :

Example 6 with SymbolPool

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

the class TimeRenderer method draw.

/**
 * Draws the given {@link TimeStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    TimeStamping s = (TimeStamping) stamping;
    SymbolPool symbolPool = args.symbolPool;
    float interlineSpace = s.parentStaff.is;
    float linesCount = s.parentStaff.linesCount;
    // write numerator digits
    float offsetX = s.numeratorOffsetIs * interlineSpace;
    String num = Integer.toString(s.time.element.getType().getNumerator());
    for (int i = 0; i < num.length(); i++) {
        int d = num.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount + 1), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
    // write denominator digits
    offsetX = s.denominatorOffsetIs * interlineSpace;
    String den = Integer.toString(s.time.element.getType().getDenominator());
    for (int i = 0; i < den.length(); i++) {
        int d = den.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount - 3), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
}
Also used : Symbol(com.xenoage.zong.symbols.Symbol) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) TimeStamping(com.xenoage.zong.musiclayout.stampings.TimeStamping) SymbolPool(com.xenoage.zong.symbols.SymbolPool)

Example 7 with SymbolPool

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

Example 8 with SymbolPool

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

the class ScoreLayouterTest method testSampleFiles.

/**
 * Try to layout all official MusicXML 1.1 and 2.0 sample files.
 * We can not test for the correct layout of course, but at least
 * we want to have no exceptions.
 */
@Test
public void testSampleFiles() throws Exception {
    SymbolPool symbolPool = sync(new SymbolPoolReader("default"));
    LayoutSettings layoutSettings = LayoutSettingsReader.read(jsePlatformUtils().openFile("data/test/layout/LayoutSettingsTest.xml"));
    for (String file : MusicXmlScoreFileInputTest.getSampleFiles()) {
        try {
            // System.out.println(file);
            Score score = new MusicXmlScoreFileInput().read(jsePlatformUtils().openFile(file), file);
            Size2f areaSize = new Size2f(150, 10000);
            Context context = new Context(score, symbolPool, layoutSettings);
            Target target = Target.completeLayoutTarget(new ScoreLayoutArea(areaSize));
            ScoreLayouter layouter = new ScoreLayouter(context, target);
            layouter.createLayoutWithExceptions();
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to layout file: " + file);
        }
    }
}
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) MusicXmlScoreFileInput(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInput) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

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