Search in sources :

Example 1 with Fragment

use of com.xenoage.zong.musiclayout.notation.beam.Fragment in project Zong by Xenoage.

the class BeamStamper method stamp.

/**
 * Computes the stampings for the given beam and returns them.
 * @param beam    the beam to stamp
 * @param staff   the staff stamping of the first chord of the beam
 */
public List<BeamStamping> stamp(BeamSpacing beam, StaffStamping staff) {
    int beamSize = beam.chords.size();
    val leftEndSp = beam.getLeftSp();
    val rightEndSp = beam.getRightSp();
    val primaryStemDir = beam.getStemDirection(0);
    // number of beam lines
    int linesCount = beam.notation.getLinesCount();
    // first guess of the size (is correct for simple beams)
    List<BeamStamping> ret = alist(linesCount);
    // first line (8th line) is always continuous
    val beam8th = new BeamStamping(beam, staff, leftEndSp, rightEndSp, primaryStemDir);
    ret.add(beam8th);
    // this is stored in the notation
    for (int i : range(beam.notation.linesFragments)) {
        int line = i + 1;
        float lineLp = -1 * primaryStemDir.getSign() * (lineHeightIs + beam.notation.gapIs) * 2 * line;
        val beamLinePoints = new LinearInterpolationPoints(leftEndSp.lp + lineLp, rightEndSp.lp + lineLp, leftEndSp.xMm, rightEndSp.xMm);
        // create the line stampings
        float startXMm = 0;
        Fragments fragments = beam.notation.linesFragments.get(i);
        for (int iChord : range(fragments)) {
            Fragment fragment = fragments.get(iChord);
            float stemXMm = beam.getStemEndSp(iChord).xMm;
            if (fragment == Start) {
                // begin a new beam line
                startXMm = stemXMm;
            } else if (fragment == Stop) {
                // end the beam line and stem it
                float stopXMm = stemXMm;
                SP leftSp = sp(startXMm, INSTANCE.interpolateLinear(beamLinePoints, startXMm));
                SP rightSp = sp(stopXMm, INSTANCE.interpolateLinear(beamLinePoints, stopXMm));
                val stamping = new BeamStamping(beam, staff, leftSp, rightSp, primaryStemDir);
                ret.add(stamping);
            } else if (fragment == HookLeft || fragment == HookRight) {
                // left or right hook
                float lengthMm = hookLengthIs * staff.is;
                float x1Mm = (fragment == HookLeft ? stemXMm - lengthMm : stemXMm);
                float x2Mm = (fragment == HookLeft ? stemXMm : stemXMm + lengthMm);
                SP leftSp = sp(x1Mm, INSTANCE.interpolateLinear(beamLinePoints, x1Mm));
                SP rightSp = sp(x2Mm, INSTANCE.interpolateLinear(beamLinePoints, x2Mm));
                val stamping = new BeamStamping(beam, staff, leftSp, rightSp, primaryStemDir);
                ret.add(stamping);
            }
        }
    }
    return ret;
}
Also used : lombok.val(lombok.val) BeamStamping(com.xenoage.zong.musiclayout.stampings.BeamStamping) Fragments(com.xenoage.zong.musiclayout.notation.beam.Fragments) LinearInterpolationPoints(com.xenoage.utils.math.MathUtils.LinearInterpolationPoints) Fragment(com.xenoage.zong.musiclayout.notation.beam.Fragment) SP(com.xenoage.zong.core.music.format.SP)

Aggregations

LinearInterpolationPoints (com.xenoage.utils.math.MathUtils.LinearInterpolationPoints)1 SP (com.xenoage.zong.core.music.format.SP)1 Fragment (com.xenoage.zong.musiclayout.notation.beam.Fragment)1 Fragments (com.xenoage.zong.musiclayout.notation.beam.Fragments)1 BeamStamping (com.xenoage.zong.musiclayout.stampings.BeamStamping)1 lombok.val (lombok.val)1