use of com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation in project Zong by Xenoage.
the class ArticulationsNotator method computeOtherArticulations.
/**
* Creates an {@link ArticulationsNotation} for the given {@link ArticulationType}s
* at the given notehead at the given side. The articulations are always placed
* outside the staff lines. The first one is placed as the innermost articulation,
* the last one as the outermost one.
*/
ArticulationsNotation computeOtherArticulations(List<Articulation> articulations, NoteDisplacement outerNote, VSide side, int staffLinesCount) {
// compute LP of the first articulation:
// if within staff, it must be moved outside
int lp = outerNote.lp + 2 * side.getDir();
if (// within staff
lp >= 0 && lp <= (staffLinesCount - 1) * 2)
lp = (side == VSide.Top ? (staffLinesCount - 1) * 2 + 1 : -1);
// collect displacements
ArticulationDisplacement[] arts = new ArticulationDisplacement[articulations.size()];
for (int i = 0; i < articulations.size(); i++) {
arts[i] = new ArticulationDisplacement(lp + 2 * i * side.getDir(), outerNote.xIs, articulations.get(i).getType());
}
// total height: 1 IS for each articulation
float heightIS = Math.abs(lp - outerNote.lp) / 2;
// create ArticulationsAlignment
return new ArticulationsNotation(arts, heightIS);
}
use of com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation 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.ArticulationsNotation in project Zong by Xenoage.
the class ArticulationsNotator method computeSimpleArticulation.
/**
* Creates an {@link ArticulationsNotation} for the given {@link ArticulationType}
* at the given notehead at the given side. If possible, it is placed between
* the staff lines.
*/
ArticulationsNotation computeSimpleArticulation(ArticulationType articulation, NoteDisplacement outerNote, VSide side, int staffLinesCount) {
// compute LP of the articulation: if within staff, it must be
// between the staff lines (LP 1, 3, 5, ...)
int lp = outerNote.lp + 2 * side.getDir();
if (// within staff
lp >= 0 && lp <= (staffLinesCount - 1) * 2 && lp % 2 == 0) {
// on staff line
// move one LP further
lp += side.getDir();
}
// compute ArticulationsAlignment
// 1 IS
float height = 1;
ArticulationDisplacement[] arts = { new ArticulationDisplacement(lp, outerNote.xIs, articulation) };
return new ArticulationsNotation(arts, height);
}
Aggregations