Search in sources :

Example 1 with StemNotation

use of com.xenoage.zong.musiclayout.notation.chord.StemNotation in project Zong by Xenoage.

the class BeamSpacing method getStemEndSp.

/**
 * Gets the SP of the end of the stem of the given chord.
 */
public SP getStemEndSp(int chordIndex) {
    float xMm = getStemXMm(chordIndex);
    StemNotation stem = notation.chords.get(chordIndex).stem;
    float lp;
    if (stem != null)
        lp = stem.endSlp.lp;
    else
        // it could be possible that there is no stem
        lp = notation.chords.get(chordIndex).getStemSideNoteLp() + getStemDirection(chordIndex).getSign() * 3 * 2;
    return sp(xMm, lp);
}
Also used : StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation)

Example 2 with StemNotation

use of com.xenoage.zong.musiclayout.notation.chord.StemNotation in project Zong by Xenoage.

the class ChordNotator method compute.

public ChordNotation compute(Chord chord, Context context, @MaybeNull Notations notations) {
    Score score = context.score;
    float interlineSpace = score.getInterlineSpace(context.mp);
    FontInfo lyricsFont = score.getFormat().getLyricFont();
    MusicContext mc = score.getMusicContext(context.mp, BeforeOrAt, Before);
    // grace or normal chord?
    boolean grace = chord.isGrace();
    ChordWidths chordWidths = (grace ? context.settings.graceChordWidths : context.settings.chordWidths);
    ChordSpacings spacings = (grace ? context.settings.spacings.graceChordSpacings : context.settings.spacings.normalChordSpacings);
    // use or compute stem direction
    StemDirection stemDirection = chord.getStem().getDirection();
    if (stemDirection == StemDirection.Default) {
        // if stem direction was not computed yet, compute it now
        if (notations != null)
            stemDirection = notations.getChord(chord).stemDirection;
        if (stemDirection == StemDirection.Default) {
            Map<Chord, StemDirection> computedStems = stemDirector.compute(chord);
            stemDirection = computedStems.get(chord);
            // also remember the other computed stems
            if (notations != null)
                for (Chord computedChord : computedStems.keySet()) notations.getChord(computedChord).stemDirection = computedStems.get(computedChord);
        }
    }
    // notes displacement
    NotesNotation notes = notesNotator.compute(chord, stemDirection, chordWidths, mc);
    float leftSuspendedWidth = (notes.leftSuspended ? notes.noteheadWidthIs : 0);
    // accidentals
    AccidentalsNotation accs = accidentalsNotator.compute(chord, notes, chordWidths, mc);
    // symbol's width: width of the noteheads and dots
    float symbolWidth = notes.widthIs - leftSuspendedWidth;
    float frontGap = accs.widthIs + leftSuspendedWidth;
    // rear gap: empty duration-dependent space behind the chord minus the symbol's width
    float rearGap = spacings.getWidth(chord.getDisplayedDuration()) - symbolWidth;
    // lyric width
    float lyricWidth = 0;
    TextMeasurer textMeasurer = platformUtils().getTextMeasurer();
    for (Lyric lyric : chord.getLyrics()) {
        if (lyric != null && lyric.getText() != null) {
            // width of lyric in interline spaces
            FormattedText lyricText = styleText(lyric.getText(), new FormattedTextStyle(lyricsFont));
            float l = lyricText.getWidth() / interlineSpace;
            // for start and end syllable, request "-" more space, for middle syllables "--"
            // TODO: unsymmetric - start needs space on the right, end on the left, ...
            SyllableType lyricType = lyric.getSyllableType();
            if (lyricType == SyllableType.Begin || lyricType == SyllableType.End) {
                l += textMeasurer.measure(lyricsFont, "-").getWidth() / interlineSpace;
            } else if (lyricType == SyllableType.Middle) {
                l += textMeasurer.measure(lyricsFont, "--").getWidth() / interlineSpace;
            }
            // save width of the widest lyric
            lyricWidth = Math.max(lyricWidth, l);
        }
    }
    // compute length of the stem (if any)
    float scaling = grace ? context.settings.scalingGrace : 1;
    StemNotation stem = stemNotator.compute(chord.getStem(), notes.getLps(), stemDirection, context.mp.getStaff(), Companion.staffLines(mc.getLinesCount()), scaling);
    // compute articulations
    ArticulationsNotation arts = articulationsNotator.compute(chord, stemDirection, notes, mc.getLinesCount());
    return new ChordNotation(chord, chord.getMP(), new ElementWidth(frontGap, symbolWidth, rearGap, lyricWidth), context.mp.getStaff(), notes, stemDirection, stem, accs, arts);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FormattedText(com.xenoage.zong.core.text.FormattedText) MusicContext(com.xenoage.zong.core.music.MusicContext) StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation) Score(com.xenoage.zong.core.Score) ArticulationsNotation(com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation) TextMeasurer(com.xenoage.utils.font.TextMeasurer) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths) AccidentalsNotation(com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation) Lyric(com.xenoage.zong.core.music.lyric.Lyric) ChordSpacings(com.xenoage.zong.musiclayout.settings.ChordSpacings) SyllableType(com.xenoage.zong.core.music.lyric.SyllableType) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) FontInfo(com.xenoage.utils.font.FontInfo) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 3 with StemNotation

use of com.xenoage.zong.musiclayout.notation.chord.StemNotation in project Zong by Xenoage.

the class TwoStavesBeamSpacer method compute.

BeamSpacing compute(BeamNotation beam, SystemSpacing system) {
    // compute slant
    val slant = twoStavesBeamSlanter.compute(beam);
    // compute the ends of the first and last stem
    val chords = beamSpacer.getBeamChordSpacings(beam, system);
    val stems = BeamedStems.fromBeam(chords);
    val placement = twoStavesBeamPlacer.compute(slant, stems, beam, system);
    // adjust the stem lengths by interpolating
    // the end LPs of the stems have then to be relative to the beam's staff (the staff of the first chord)
    int beamStaffIndex = beam.mp.getStaff();
    float leftEndYMm = system.getYMm(placement.leftSlp);
    float rightEndYMm = system.getYMm(placement.rightSlp);
    // may be on different staff, so this is not always equal to placement.rightSlp.lp
    float beamRightEndLp = 0;
    for (int iChord : range(stems)) {
        float yMm = INSTANCE.interpolateLinear(leftEndYMm, rightEndYMm, stems.leftXIs, stems.rightXIs, stems.get(iChord).xIs);
        float lp = system.getLp(beamStaffIndex, yMm);
        if (iChord == stems.getCount() - 1)
            beamRightEndLp = lp;
        // so that it touches each beam line
        if (stems.get(iChord).dir != stems.primaryStemDir) {
            int linesCountAtChord = INSTANCE.getFlagsCount(beam.chords.get(iChord).element.getDuration());
            lp += stems.get(iChord).dir.getSign() * 2 * ((linesCountAtChord - 1) * beam.lineHeightIs + linesCountAtChord * beam.gapIs);
        }
        StemNotation stem = beam.chords.get(iChord).stem;
        if (// it could be possible that there is no stem
        stem != null)
            // before, maybe the end LP was relative to another staff
            stem.endSlp = slp(beamStaffIndex, lp);
    }
    return new BeamSpacing(beam, placement.leftSlp.lp, beamRightEndLp, chords);
}
Also used : lombok.val(lombok.val) BeamSpacing(com.xenoage.zong.musiclayout.spacing.BeamSpacing) StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation)

Example 4 with StemNotation

use of com.xenoage.zong.musiclayout.notation.chord.StemNotation in project Zong by Xenoage.

the class StemNotatorTest method testPitch.

private void testPitch(Pitch[] pitches, float start, float end) {
    MusicContext context = MusicContext.Companion.getSimpleInstance();
    Chord chord;
    NotesNotation chordNotesAlignment;
    StemNotation chordStemAlignment;
    Fraction fraction = Companion.fr(1, 1);
    chord = ChordFactory.chord(pitches, fraction);
    ChordLps linepositions = new ChordLps(chord, context);
    StemDirection stemDirection = singleStemDirector.compute(linepositions, 5);
    chordNotesAlignment = notesNotator.compute(chord, stemDirection, defaultChordWidthsNormal, context);
    chordStemAlignment = testee.compute(Stem.Companion.getDefaultStem(), chordNotesAlignment.getLps(), stemDirection, 0, Companion.getStaff5Lines(), 1);
    assertEquals(start, chordStemAlignment.startSlp.lp, Delta.DELTA_FLOAT);
    assertEquals(end, chordStemAlignment.endSlp.lp, Delta.DELTA_FLOAT);
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Fraction(com.xenoage.utils.math.Fraction) MusicContext(com.xenoage.zong.core.music.MusicContext) Chord(com.xenoage.zong.core.music.chord.Chord) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation)

Aggregations

StemNotation (com.xenoage.zong.musiclayout.notation.chord.StemNotation)4 MusicContext (com.xenoage.zong.core.music.MusicContext)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)2 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)2 FontInfo (com.xenoage.utils.font.FontInfo)1 TextMeasurer (com.xenoage.utils.font.TextMeasurer)1 Fraction (com.xenoage.utils.math.Fraction)1 Score (com.xenoage.zong.core.Score)1 Lyric (com.xenoage.zong.core.music.lyric.Lyric)1 SyllableType (com.xenoage.zong.core.music.lyric.SyllableType)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)1 AccidentalsNotation (com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation)1 ArticulationsNotation (com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation)1 ChordLps (com.xenoage.zong.musiclayout.notation.chord.ChordLps)1 ChordSpacings (com.xenoage.zong.musiclayout.settings.ChordSpacings)1 ChordWidths (com.xenoage.zong.musiclayout.settings.ChordWidths)1 BeamSpacing (com.xenoage.zong.musiclayout.spacing.BeamSpacing)1