Search in sources :

Example 1 with BarlineGroup

use of com.xenoage.zong.core.music.group.BarlineGroup in project Zong by Xenoage.

the class StavesListTest method addBarlineGroupTest.

@Test
public void addBarlineGroupTest() {
    StavesList stavesList = create5Staves();
    // add barline groups from staves 0 to 2 and 1 to 3. should merge to 0 to 3
    stavesList.addBarlineGroup(new StavesRange(0, 2), BarlineGroup.Style.Common);
    stavesList.addBarlineGroup(new StavesRange(1, 3), BarlineGroup.Style.Common);
    assertEquals(1, stavesList.getBarlineGroups().size());
    assertEquals(new BarlineGroup(new StavesRange(0, 3), BarlineGroup.Style.Common), stavesList.getBarlineGroups().get(0));
}
Also used : StavesRange(com.xenoage.zong.core.music.group.StavesRange) BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup) Test(org.junit.Test)

Example 2 with BarlineGroup

use of com.xenoage.zong.core.music.group.BarlineGroup 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 3 with BarlineGroup

use of com.xenoage.zong.core.music.group.BarlineGroup in project Zong by Xenoage.

the class StavesListTest method checkBarlineGroups.

public static void checkBarlineGroups(StavesList stavesList, BarlineGroup... expectedBarlineGroups) {
    List<BarlineGroup> groups = stavesList.getBarlineGroups();
    for (BarlineGroup expectedGroup : expectedBarlineGroups) assertContains(groups, expectedGroup);
    assertEquals(expectedBarlineGroups.length, groups.size());
}
Also used : BarlineGroup(com.xenoage.zong.core.music.group.BarlineGroup)

Aggregations

BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)3 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1 Barline (com.xenoage.zong.core.music.barline.Barline)1 StavesRange (com.xenoage.zong.core.music.group.StavesRange)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 BarlineStamping (com.xenoage.zong.musiclayout.stampings.BarlineStamping)1 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)1 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)1 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)1 Test (org.junit.Test)1