Search in sources :

Example 11 with ColumnHeader

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

the class BarlinesStamper method stamp.

public List<Stamping> stamp(SystemSpacing system, List<StaffStamping> systemStaves, Score score) {
    List<Stamping> ret = alist();
    StaffStamping firstStaff = getFirst(systemStaves);
    int stavesCount = systemStaves.size();
    int systemIndex = system.getSystemIndexInFrame();
    float xOffset = firstStaff.positionMm.x;
    // common barline at the beginning, when system has at least one measure
    if (system.columns.size() > 0) {
        ret.add(new BarlineStamping(Barline.Companion.barlineRegular(), systemStaves, xOffset, BarlineGroup.Style.Common));
    }
    // barlines within the system and measure numbers
    for (int iMeasure : range(system.columns)) {
        float xLeft = xOffset;
        // measure numbering
        MeasureNumbering measureNumbering = score.getFormat().getMeasureNumbering();
        int globalMeasureIndex = system.getStartMeasure() + iMeasure;
        boolean showMeasureNumber = false;
        if (measureNumbering == MeasureNumbering.System) {
            // measure number at the beginning of each system (except the first one)
            showMeasureNumber = (iMeasure == 0 && globalMeasureIndex > 0);
        } else if (measureNumbering == MeasureNumbering.Measure) {
            // measure number at each measure (except the first one)
            showMeasureNumber = (globalMeasureIndex > 0);
        }
        if (showMeasureNumber) {
            FormattedText text = Companion.fText("" + (globalMeasureIndex + 1), new FormattedTextStyle(8), Alignment.Left);
            ret.add(new StaffTextStamping(text, sp(xLeft, firstStaff.linesCount * 2), firstStaff, null));
        }
        // for the first measure in the system: begin after leading spacing
        if (iMeasure == 0)
            xLeft += system.columns.get(iMeasure).getLeadingWidthMm();
        xOffset += system.columns.get(iMeasure).getWidthMm();
        float xRight = xOffset;
        // regard the groups of the score
        for (int iStaff : range(stavesCount)) {
            ColumnHeader columnHeader = score.getColumnHeader(globalMeasureIndex);
            BarlineGroup.Style barlineGroupStyle = BarlineGroup.Style.Single;
            BarlineGroup group = score.getStavesList().getBarlineGroupByStaff(iStaff);
            if (group != null)
                barlineGroupStyle = group.getStyle();
            List<StaffStamping> groupStaves = getBarlineGroupStaves(systemStaves, group);
            // start barline
            Barline startBarline = columnHeader.getStartBarline();
            if (startBarline != null) {
                // don't draw a regular barline at the left side of first measure of a system
                if ((startBarline.getStyle() == BarlineStyle.Regular && systemIndex == 0) == false)
                    ret.add(new BarlineStamping(startBarline, groupStaves, xLeft, barlineGroupStyle));
            }
            // end barline. if none is set, use a regular one.
            Barline endBarline = columnHeader.getEndBarline();
            if (endBarline == null)
                endBarline = Barline.Companion.barlineRegular();
            ret.add(new BarlineStamping(endBarline, groupStaves, xRight, barlineGroupStyle));
            // middle barlines
            for (BeatE<Barline> middleBarline : columnHeader.getMiddleBarlines()) {
                ret.add(new BarlineStamping(middleBarline.getElement(), groupStaves, xLeft + system.columns.get(iMeasure).getBarlineOffsetMm(middleBarline.getBeat()), barlineGroupStyle));
            }
            // go to next group
            if (group != null)
                iStaff = group.getStaves().getStop();
        }
    }
    return ret;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) FormattedText(com.xenoage.zong.core.text.FormattedText) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) BarlineStamping(com.xenoage.zong.musiclayout.stampings.BarlineStamping) MeasureNumbering(com.xenoage.zong.core.format.MeasureNumbering) Barline(com.xenoage.zong.core.music.barline.Barline) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Example 12 with ColumnHeader

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

the class ColumnElementWriteTest method test.

@Test
public void test() {
    Score score = ScoreFactory.create1Staff4Measures();
    CommandPerformer cmd = score.getCommandPerformer();
    ColumnHeader column2 = score.getColumnHeader(2);
    // write start barline, middle barline and end barline
    Barline b1 = Barline.Companion.barlineRegular();
    Barline b2 = Barline.Companion.barlineRegular();
    Barline b3 = Barline.Companion.barline(BarlineStyle.LightHeavy);
    cmd.execute(new ColumnElementWrite(b1, column2, null, MeasureSide.Left));
    cmd.execute(new ColumnElementWrite(b2, column2, Companion.fr(1, 4), null));
    cmd.execute(new ColumnElementWrite(b3, column2, null, MeasureSide.Right));
    assertEquals(b1, column2.getStartBarline());
    assertEquals(b2, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
    assertEquals(b3, column2.getEndBarline());
    // overwrite middle barline
    Barline b4 = Barline.Companion.barlineRegular();
    cmd.execute(new ColumnElementWrite(b4, column2, Companion.fr(1, 4), null));
    assertEquals(b4, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
    // undo. b2 should be here again
    cmd.undo();
    assertEquals(b2, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
    // undo all steps. the middle barline should not exist any more
    cmd.undoMultipleSteps(3);
    assertEquals(0, column2.getMiddleBarlines().size());
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) Barline(com.xenoage.zong.core.music.barline.Barline) CommandPerformer(com.xenoage.utils.document.command.CommandPerformer) Test(org.junit.Test)

Example 13 with ColumnHeader

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

the class Test13a method test.

// @ToDo("Zong! supports only -7 to +7, starting in measure 9, ending in measure 38")
@Test
public void test() {
    Score score = getScore();
    TraditionalKey[] expectedKeys = getExpectedKeys();
    int iKey = 0;
    for (int i = 8; i <= 37; i++) {
        ColumnHeader column = score.getColumnHeader(i);
        TraditionalKey key = (TraditionalKey) column.getKeys().get(Companion.get_0());
        assertEquals("measure " + i, expectedKeys[iKey].getFifths(), key.getFifths());
        assertEquals("measure " + i, expectedKeys[iKey].getMode(), key.getMode());
        iKey++;
    }
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Test(org.junit.Test)

Aggregations

ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)13 Score (com.xenoage.zong.core.Score)7 Test (org.junit.Test)6 Barline (com.xenoage.zong.core.music.barline.Barline)3 CommandPerformer (com.xenoage.utils.document.command.CommandPerformer)2 Measure (com.xenoage.zong.core.music.Measure)2 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)2 MP (com.xenoage.zong.core.position.MP)2 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)2 Paint (android.graphics.Paint)1 Fraction (com.xenoage.utils.math.Fraction)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 Size2f (com.xenoage.utils.math.geom.Size2f)1 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 PageFormat (com.xenoage.zong.core.format.PageFormat)1 PageMargins (com.xenoage.zong.core.format.PageMargins)1 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)1 SystemLayout (com.xenoage.zong.core.format.SystemLayout)1 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)1 MusicContext (com.xenoage.zong.core.music.MusicContext)1