Search in sources :

Example 6 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method createTestScore3Voices.

private Score createTestScore3Voices() {
    Score score = new Score();
    score.getFormat().setInterlineSpace(10);
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(Companion.getTime_4_4()));
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet
    // voice 1: | 4     4     4     4     |   (staff 1)
    // voice 2: | 8  8  8  8  2           |   (staff 1)
    // voice 3: | 3   3   3   8  8  4     |   (staff 2)
    // voice 1 (staff 1)
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    // voice 2 (staff 1)
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
    // voice 3 (staff 2)
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 7 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method createTestScore1Voice.

private Score createTestScore1Voice() {
    Score score = new Score();
    score.getFormat().setInterlineSpace(1);
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new Clef(ClefType.Companion.getClefTreble()));
    cursor.write((MeasureElement) new TraditionalKey(-3));
    cursor.write(new TimeSignature(TimeType.Companion.timeType(6, 4)));
    // beats: 0, 2, 3, 4, 8.
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 8 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class Base42a method getExpectedStaff.

/**
 * Gets the expected musical data, but without the dynamics, fermatas, articulations and slurs.
 */
static Staff getExpectedStaff() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_4_4()));
    // measure 0, voice 0
    cursor.write(addLyric(chord(Companion.pi('E', 0, 5), Companion.fr(1, 2)), "This"));
    cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "is"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "the"));
    // measure 1, voice 0
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(addLyric(chord(Companion.pi('D', 0, 5), Companion.fr(1, 4)), "lyrics"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 3), Companion.fr(3, 8)), "of"));
    cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)), "Voice1"));
    // measure 0, voice 1
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(addLyric(chord(Companion.pi('C', 0, 5), Companion.fr(1, 2)), "This"));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "is"));
    cursor.write(addLyric(chord(Companion.pi('G', 0, 4), Companion.fr(1, 4)), "the"));
    // measure 1, voice 1
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(addLyric(chord(Companion.pi('B', 0, 4), Companion.fr(1, 4)), "lyrics"));
    cursor.write(addLyric(chord(Companion.pi('G', 0, 3), Companion.fr(3, 8)), "of"));
    cursor.write(addLyric(chord(Companion.pi('A', 0, 4), Companion.fr(1, 8)), "Voice2"));
    return score.getStaff(0);
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 9 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class Base42b method getExpectedStaves.

/**
 * Gets the expected musical data, but without the dynamics, articulations and slurs
 * and also without the clef changes.
 */
static Staff[] getExpectedStaves() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_6_8()));
    // staff 1, measure 0
    cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('D', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('B', 0, 3), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('F', 0, 3), Companion.fr(1, 4)));
    // staff 1, measure 1
    cursor.write(chord(Companion.pi('E', 0, 5), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('C', 0, 5), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 4), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('F', 0, 4), Companion.fr(1, 4)));
    // staff 1, measure 0
    cursor.setMp(atElement(1, 0, 0, 0));
    cursor.write(new Rest(Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi('A', 0, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('F', 1, 2), Companion.fr(1, 16)));
    cursor.write(chord(Companion.pi('G', 0, 2), Companion.fr(1, 16)));
    // staff 1, measure 1
    cursor.write(chord(new Pitch[] { Companion.pi('C', 0, 3), Companion.pi('E', 0, 3), Companion.pi('G', 0, 3), Companion.pi('C', 0, 4) }, Companion.fr(1, 4)));
    cursor.write(new Rest(Companion.fr(1, 8)));
    cursor.write(new Rest(Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi('G', 0, 3), Companion.fr(1, 8)));
    return new Staff[] { score.getStaff(0), score.getStaff(1) };
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Staff(com.xenoage.zong.core.music.Staff) Pitch(com.xenoage.zong.core.music.Pitch) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 10 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class ScoreDocScoreView method updateScreen.

@Override
public void updateScreen(Size2i screenSizePx, float zoom) {
    this.screenSizePx = screenSizePx;
    this.zoom = zoom;
    // recompute the layout, so that each page fits into the available screen space
    Size2f pageSizeMm = pxToMm(screenSizePx, zoom);
    float marginMm = pxToMm(marginPx, zoom);
    PageFormat pageFormat = new PageFormat(pageSizeMm, new PageMargins(marginMm, marginMm, marginMm, marginMm));
    Size2f frameSizeMm = new Size2f(pageFormat.getUseableWidth(), pageFormat.getUseableHeight());
    // first page needs space for title text
    titleTextHeightPx = screenSizePx.height / 20f;
    float firstFrameOffsetY = pxToMm(titleTextHeightPx, zoom);
    Size2f firstFrameSizeMm = new Size2f(frameSizeMm.width, frameSizeMm.height - firstFrameOffsetY);
    // delete unnecessary layout information, like system distances or system breaks
    Score score = doc.getScore();
    score.setFormat(new ScoreFormat());
    ScoreHeader header = score.getHeader();
    for (int i : range(header.getSystemLayouts())) {
        SystemLayout sl = header.getSystemLayout(i);
        if (sl != null)
            sl.setDistance(SystemLayout.defaultDistance);
    }
    for (int i : range(header.getColumnHeaders())) {
        ColumnHeader ch = header.getColumnHeader(i);
        if (ch.getMeasureBreak() != null)
            ch.setBreak(null);
    }
    // layout the score to find out the needed space
    Context context = new Context(score, App.getSymbolPool(), doc.getLayout().getDefaults().getLayoutSettings());
    Target target = new Target(alist(new ScoreLayoutArea(firstFrameSizeMm)), new ScoreLayoutArea(frameSizeMm), true);
    ScoreLayouter layouter = new ScoreLayouter(context, target);
    ScoreLayout scoreLayout = layouter.createScoreLayout();
    // create and fill at least one page
    Layout layout = new Layout(doc.getLayout().getDefaults());
    ScoreFrameChain chain = null;
    for (int i = 0; i < scoreLayout.frames.size(); i++) {
        Page page = new Page(pageFormat);
        Point2f position;
        Size2f size;
        if (i == 0) {
            // first page
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2 + firstFrameOffsetY);
            size = firstFrameSizeMm;
        } else {
            // other pages
            position = new Point2f(pageSizeMm.width / 2, pageSizeMm.height / 2);
            size = frameSizeMm;
        }
        ScoreFrame frame = new ScoreFrame();
        frame.setPosition(position);
        frame.setSize(size);
        page.addFrame(frame);
        layout.addPage(page);
        if (chain == null) {
            chain = new ScoreFrameChain(score);
            chain.setScoreLayout(scoreLayout);
        }
        chain.add(frame);
    }
    this.layout = layout;
}
Also used : Context(com.xenoage.zong.musiclayout.layouter.Context) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) ScoreLayouter(com.xenoage.zong.musiclayout.layouter.ScoreLayouter) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) Page(com.xenoage.zong.layout.Page) Paint(android.graphics.Paint) ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) PageMargins(com.xenoage.zong.core.format.PageMargins) PageFormat(com.xenoage.zong.core.format.PageFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Target(com.xenoage.zong.musiclayout.layouter.Target) Point2f(com.xenoage.utils.math.geom.Point2f) ScoreLayout(com.xenoage.zong.musiclayout.ScoreLayout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) Layout(com.xenoage.zong.layout.Layout) SystemLayout(com.xenoage.zong.core.format.SystemLayout) ScoreFrameChain(com.xenoage.zong.layout.frames.ScoreFrameChain) Size2f(com.xenoage.utils.math.geom.Size2f) ScoreLayoutArea(com.xenoage.zong.musiclayout.layouter.ScoreLayoutArea)

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