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);
}
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);
}
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);
}
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);
}
Aggregations