Search in sources :

Example 1 with BeamRules

use of com.xenoage.zong.musiclayout.notator.beam.lines.BeamRules in project Zong by Xenoage.

the class SingleStaffBeamPlacer method shorten.

/**
 * Shortens the stem lengths of the given placement candidate by one quarter space,
 * if possible and when no stem gets shorter than the {@link BeamRules} allow it.
 * This rule not found explicitly mentioned by Ross, but applies to many examples and
 * conforms to the general rule that beamed stems tend to be shortened (p. 103, last
 * paragraph). See for example:
 * <ul>
 * 	<li>p104 r1 c1: could be 3.5/sit, but is 3.25/straddle</li>
 *  <li>p104 r6 c1: could be 3.75/straddle and 3.5/hang, but is 3.5/sit and 3.25/straddle</li>
 *  <li>p105 r1 c2: could be 3.5/hang, but is 3.25/staddle</li>
 * </ul>
 */
Placement shorten(Placement candidate, StemDirection stemDir, BeamedStems stems, int beamLinesCount, StaffLines staffLines) {
    // shorten
    Placement shorterCandidate = new Placement(candidate.leftEndLp - stemDir.getSign() * 0.5f, candidate.rightEndLp - stemDir.getSign() * 0.5f);
    // stems still long enough?
    float slantIs = (shorterCandidate.rightEndLp - shorterCandidate.leftEndLp) / 2;
    BeamRules beamRules = BeamRules.getRules(beamLinesCount);
    for (val stem : stems) {
        float distanceToBeam = abs(getDistanceToLineLp(stem.noteSlp.lp, stem.xIs, slantIs, stems.leftXIs, stems.rightXIs) - shorterCandidate.leftEndLp) / 2;
        if (distanceToBeam < beamRules.getMinimumStemLengthIs())
            // shortening not possible
            return candidate;
    }
    // edges correct?
    if (isPlacementCorrect(shorterCandidate, stemDir, beamLinesCount, staffLines))
        // success
        return shorterCandidate;
    else
        // shortening not possible
        return candidate;
}
Also used : lombok.val(lombok.val) BeamRules(com.xenoage.zong.musiclayout.notator.beam.lines.BeamRules)

Example 2 with BeamRules

use of com.xenoage.zong.musiclayout.notator.beam.lines.BeamRules in project Zong by Xenoage.

the class BeamNotator method compute.

@MaybeNull
public BeamNotation compute(Beam beam, Notations notations) {
    // compute fragments
    List<Fragments> fragments = beamFragmenter.compute(beam);
    // get minimum stem length and gap
    BeamRules beamRules = BeamRules.getRules(beam);
    float gapIs = beamRules.getGapIs();
    // collect chords
    List<ChordNotation> chords = notations.getBeamChords(beam);
    // create notation
    BeamNotation beamNotation = new BeamNotation(beam, beam.getMP(), fragments, gapIs, chords);
    return beamNotation;
}
Also used : ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) Fragments(com.xenoage.zong.musiclayout.notation.beam.Fragments) BeamRules(com.xenoage.zong.musiclayout.notator.beam.lines.BeamRules) BeamNotation(com.xenoage.zong.musiclayout.notation.BeamNotation) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Aggregations

BeamRules (com.xenoage.zong.musiclayout.notator.beam.lines.BeamRules)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 BeamNotation (com.xenoage.zong.musiclayout.notation.BeamNotation)1 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)1 Fragments (com.xenoage.zong.musiclayout.notation.beam.Fragments)1 lombok.val (lombok.val)1