Search in sources :

Example 6 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping 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 7 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.

the class DirectionStamper method stamp.

/**
 * Creates all direction stampings for the given measure.
 */
public List<Stamping> stamp(StamperContext context) {
    List<Stamping> ret = alist();
    val directionsWithBeats = context.getCurrentMeasure().getDirections().clone();
    // over first staff, also add tempo directions for the whole column
    if (context.staffIndex == 0) {
        directionsWithBeats.addAll(context.getCurrentColumnHeader().getTempos());
    }
    for (BeatE<Direction> elementWithBeat : directionsWithBeats) {
        Direction element = elementWithBeat.getElement();
        Stamping stamping = null;
        if (MusicElementType.Tempo.is(element))
            stamping = directionStamper.createTempo((Tempo) element, context);
        else if (MusicElementType.Dynamic.is(element))
            stamping = directionStamper.createDynamics((Dynamic) element, context);
        else if (MusicElementType.Pedal.is(element))
            stamping = directionStamper.createPedal((Pedal) element, context);
        else if (MusicElementType.Words.is(element))
            stamping = directionStamper.createWords((Words) element, context);
        if (stamping != null)
            ret.add(stamping);
    }
    return ret;
}
Also used : lombok.val(lombok.val) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) StaffSymbolStamping(com.xenoage.zong.musiclayout.stampings.StaffSymbolStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping)

Example 8 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.

the class MeasureStamper method stampLeading.

/**
 * Stamps the {@link MeasureElement}s of the leading spacing.
 * @param leadingXMm  the horizontal position on the staff in mm, where
 *                    the leading spacing of the measure starts.
 */
public List<Stamping> stampLeading(MeasureSpacing measure, float leadingXMm, StamperContext context) {
    LeadingSpacing leading = measure.leading;
    if (leading == null)
        return emptyList;
    List<Stamping> ret = alist(leading.elements.size());
    for (ElementSpacing element : leading.elements) {
        MusicElement me = element.getElement();
        if (me != null) {
            float xMm = leadingXMm + element.xIs * measure.interlineSpace;
            Notation notation = context.getNotation(me);
            if (notation == null)
                throw new RuntimeException("No notation for element " + me + " at " + MP.getMP(me));
            ret.add(stamp(notation, xMm, context));
        }
    }
    return ret;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) MusicElement(com.xenoage.zong.core.music.MusicElement) LeadingSpacing(com.xenoage.zong.musiclayout.spacing.LeadingSpacing) Notation(com.xenoage.zong.musiclayout.notation.Notation) ClefNotation(com.xenoage.zong.musiclayout.notation.ClefNotation) TimeNotation(com.xenoage.zong.musiclayout.notation.TimeNotation) TraditionalKeyNotation(com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)

Example 9 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.

the class VoiceStamper method stampVoices.

public List<Stamping> stampVoices(MeasureSpacing measure, float voicesXMm, StaffStampings staffStampings, StamperContext context, // TODO:
FormattedTextStyle defaultLyricStyle, Map<Beam, BeamSpacing> beams, OpenSlursCache openCurvedLinesCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
    List<Stamping> ret = alist();
    context.layouter.saveMp();
    // iterate over the voices
    for (int iVoice : range(measure.voices)) {
        context.layouter.mp = context.layouter.mp.withVoice(iVoice);
        VoiceSpacing voice = measure.voices.get(iVoice);
        // don't stamp leading rests in non-first voices
        boolean stampLeadingRests = (iVoice == 0);
        // create voice stampings
        ret.addAll(stampVoice(voice, voicesXMm, staffStampings, stampLeadingRests, context, defaultLyricStyle, beams, openCurvedLinesCache, openLyricsCache, lastLyrics, openTupletsCache));
    }
    context.layouter.restoreMp();
    return ret;
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing)

Example 10 with Stamping

use of com.xenoage.zong.musiclayout.stampings.Stamping in project Zong by Xenoage.

the class ScoreFrameLayoutTest method getLayoutElementAt.

@Test
public void getLayoutElementAt() {
    /* 0    5   10   15    20    | 0
		 *                             
		 *       ***********           2
		 *  +----*   [0]   *     
		 *  |    *         *~~~~~~~    4
		 *  |[1] ***********      |
		 *  +--------+       [2]  |    6
		 *     |                  |
		 *     ~~~~~~~~~~~~~~~~~~~~    8
		 */
    Stamping[] stampings = new Stamping[3];
    StampingMock s1 = new StampingMock(Level.Music, new Rectangle2f(6, 2, 10, 3));
    stampings[0] = s1;
    StampingMock s2 = new StampingMock(Level.Staff, new Rectangle2f(1, 3, 9, 3));
    stampings[1] = s2;
    StampingMock s3 = new StampingMock(Level.EmptySpace, new Rectangle2f(4, 4, 19, 4));
    stampings[2] = s3;
    ScoreFrameLayout layout = new ScoreFrameLayout(null, new ArrayList<>(), alist(stampings), new ArrayList<>());
    // no hit (but empty space)
    assertTrue(isNot(layout.getStampingAt(new Point2f(0, 0)), s1, s2, s3));
    assertTrue(isNot(layout.getStampingAt(new Point2f(3, 7)), s1, s2, s3));
    assertTrue(isNot(layout.getStampingAt(new Point2f(17, 3)), s1, s2, s3));
    // single hit
    assertEquals(s1, layout.getStampingAt(new Point2f(10, 2)));
    assertEquals(s2, layout.getStampingAt(new Point2f(3, 5)));
    assertEquals(s3, layout.getStampingAt(new Point2f(22, 8)));
    // intersection hit
    assertEquals(s1, layout.getStampingAt(new Point2f(15, 4)));
    assertEquals(s2, layout.getStampingAt(new Point2f(5, 5)));
    assertEquals(s1, layout.getStampingAt(new Point2f(8, 4)));
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) StampingMock(com.xenoage.zong.musiclayout.stampings.StampingMock) Test(org.junit.Test)

Aggregations

Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)10 MusicElement (com.xenoage.zong.core.music.MusicElement)4 Notation (com.xenoage.zong.musiclayout.notation.Notation)3 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)3 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)3 Point2f (com.xenoage.utils.math.geom.Point2f)2 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)2 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)2 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)2 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)2 TimeNotation (com.xenoage.zong.musiclayout.notation.TimeNotation)2 TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)2 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)2 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 Chord (com.xenoage.zong.core.music.chord.Chord)1 BarlineGroup (com.xenoage.zong.core.music.group.BarlineGroup)1 MPElement (com.xenoage.zong.core.position.MPElement)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1