Search in sources :

Example 1 with Barline

use of com.xenoage.zong.core.music.barline.Barline in project Zong by Xenoage.

the class BarlinesBeatOffsetter method compute.

public Result compute(List<BeatOffset> baseOffsets, ColumnHeader columnHeader, float maxInterlineSpace) {
    ArrayList<BeatOffset> retNotes = alist(baseOffsets);
    ArrayList<BeatOffset> retBarlines = alist();
    // start barline
    retBarlines.add(new BeatOffset(Fraction.Companion.get_0(), 0));
    Barline startBarline = columnHeader.getStartBarline();
    if (startBarline != null && startBarline.getRepeat() == BarlineRepeat.Forward) {
        // forward repeat: move all beats REPEAT_SPACE IS backward
        float move = repeatSpace * maxInterlineSpace;
        for (int i = 0; i < retNotes.size(); i++) {
            BeatOffset oldOffset = retNotes.get(i);
            retNotes.set(i, new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
        }
    }
    // mid-measure barlines
    for (BeatE<Barline> midBarline : columnHeader.getMiddleBarlines()) {
        // get beat of barline, find it in the note offsets and move the following ones
        Fraction beat = midBarline.getBeat();
        int i = 0;
        float move = 0;
        for (; i < retNotes.size(); i++) {
            if (retNotes.get(i).getBeat().compareTo(beat) >= 0) {
                BarlineRepeat repeat = midBarline.getElement().getRepeat();
                if (repeat == BarlineRepeat.Backward) {
                    // backward repeat: additional space before barline
                    move += repeatSpace * maxInterlineSpace;
                    BeatOffset oldOffset = retNotes.get(i);
                    retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
                } else if (repeat == BarlineRepeat.Forward) {
                    // forward repeat: additional space after barline
                    BeatOffset oldOffset = retNotes.get(i);
                    retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
                    move += repeatSpace * maxInterlineSpace;
                } else if (repeat == BarlineRepeat.Both) {
                    // forward and backward repeat: additional space before and after barline
                    move += repeatSpace * maxInterlineSpace;
                    BeatOffset oldOffset = retNotes.get(i);
                    retBarlines.add(new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
                    move += repeatSpace * maxInterlineSpace;
                } else {
                    retBarlines.add(retNotes.get(i));
                }
                move += midBarlineSpace * maxInterlineSpace;
                break;
            }
        }
        for (; i < retNotes.size(); i++) {
            // move following notes
            BeatOffset oldOffset = retNotes.get(i);
            retNotes.set(i, new BeatOffset(oldOffset.getBeat(), oldOffset.getOffsetMm() + move));
        }
    }
    // end barline
    BeatOffset lastOffset = retNotes.get(retNotes.size() - 1);
    Barline endBarline = columnHeader.getEndBarline();
    if (endBarline != null && endBarline.getRepeat() == BarlineRepeat.Backward) {
        // backward repeat: additional space before end barline
        float move = repeatSpace * maxInterlineSpace;
        retBarlines.add(new BeatOffset(lastOffset.getBeat(), lastOffset.getOffsetMm() + move));
    } else {
        retBarlines.add(lastOffset);
    }
    // return result
    retBarlines.trimToSize();
    return new Result(retNotes, retBarlines);
}
Also used : BarlineRepeat(com.xenoage.zong.core.music.barline.BarlineRepeat) BeatOffset(com.xenoage.zong.musiclayout.spacing.BeatOffset) Fraction(com.xenoage.utils.math.Fraction) Barline(com.xenoage.zong.core.music.barline.Barline)

Example 2 with Barline

use of com.xenoage.zong.core.music.barline.Barline in project Zong by Xenoage.

the class ColumnElementRemoveTest method test.

@Test
public void test() {
    Score score = ScoreFactory.create1Staff4Measures();
    CommandPerformer cmd = score.getCommandPerformer();
    ColumnHeader column2 = score.getColumnHeader(2);
    // write middle barline
    Barline b = Barline.Companion.barline(BarlineStyle.LightHeavy);
    cmd.execute(new ColumnElementWrite(b, column2, Companion.fr(1, 4), null));
    // remove it
    cmd.execute(new ColumnElementRemove(column2, b));
    assertEquals(0, column2.getMiddleBarlines().size());
    // undo. should be here again
    cmd.undo();
    assertEquals(b, column2.getMiddleBarlines().get(Companion.fr(1, 4)));
}
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 3 with Barline

use of com.xenoage.zong.core.music.barline.Barline 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 4 with Barline

use of com.xenoage.zong.core.music.barline.Barline 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)

Aggregations

Barline (com.xenoage.zong.core.music.barline.Barline)4 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)3 CommandPerformer (com.xenoage.utils.document.command.CommandPerformer)2 Score (com.xenoage.zong.core.Score)2 Test (org.junit.Test)2 Fraction (com.xenoage.utils.math.Fraction)1 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 BarlineRepeat (com.xenoage.zong.core.music.barline.BarlineRepeat)1 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)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