use of com.xenoage.zong.core.music.lyric.Lyric 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.core.music.lyric.Lyric in project Zong by Xenoage.
the class ChordStamper method stampAll.
/**
* Returns all the stampings for the given {@link Chord}, including beams,
* tuplets, slurs and other attachments.
*
* The given {@link OpenSlursCache},
* {@link OpenLyricsCache}, {@link LastLyrics} and {@link OpenTupletsCache} may be modified.
*/
public List<Stamping> stampAll(ChordNotation chord, float xMm, BeamSpacing beam, StaffStampings staffStampings, StamperContext context, FormattedTextStyle defaultLyricStyle, OpenSlursCache openSlursCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
List<Stamping> ret = alist();
Chord element = chord.getElement();
int staffIndex = context.staffIndex;
int systemIndex = context.systemIndex;
// noteheads, leger lines, dots, accidentals, stem, flags, articulations
ChordStampings chordSt = stampCore(chord, xMm, context);
chordSt.addAllTo(ret);
// beam
if (beam != null) {
// stamp the whole beam (when we find the beginning of the beam)
// TIDY: create/store beam stampings elsewhere?
Beam beamElement = beam.notation.element;
int chordIndex = beamElement.getWaypointIndex(element);
if (chordIndex == 0) {
ret.addAll(beamStamper.stamp(beam, context.getCurrentStaffStamping()));
}
}
// ties and slurs
for (Slur slur : element.getSlurs()) {
SlurWaypoint wp = slur.getWaypoint(element);
WaypointPosition pos = slur.getWaypointPosition(element);
// TODO: choose top/bottom
int noteIndex = notNull(wp.getNoteIndex(), 0);
NoteheadStamping notehead = chordSt.noteheads[noteIndex];
// define the placement: above or below (TODO: better strategy)
VSide side = slurStamper.getSide(slur);
// compute position
val staff = staffStampings.get(systemIndex, notehead.parentStaff.staffIndex);
val slurCache = openSlursCache.getOrCreate(slur);
float distanceIs = slurStamper.getAdditionalDistanceIs(chord, slur.getSide());
SP defaultSp = sp(notehead.position.xMm, notehead.position.lp + side.getDir() * distanceIs * 2);
if (pos == WaypointPosition.Start)
slurCache.setStart(defaultSp, staff, systemIndex);
else
slurCache.setStop(defaultSp, staff, systemIndex);
}
// lyric
List<Lyric> lyrics = element.getLyrics();
if (lyrics.size() > 0) {
float baseLine = -10;
for (Lyric lyric : lyrics) {
if (lyric != null) {
SyllableType lyricType = lyric.getSyllableType();
StaffTextStamping lastLyric = lastLyrics.get(staffIndex, lyric.getVerse());
if (lyricType == SyllableType.Extend) {
// extend
if (// TODO: frame breaks...
lastLyric != null) {
// remember it
openLyricsCache.setUnderscore((Lyric) lastLyric.getElement(), lastLyric, chordSt.noteheads[0], /* TODO*/
staffIndex);
}
} else {
// normal lyric
// create text stamping
StaffTextStamping sts = lyricStamper.createSyllableStamping(lyric, defaultLyricStyle, context.getCurrentStaffStamping(), chordSt.noteheads[0].position.xMm, baseLine);
ret.add(sts);
// when middle or end syllable, add a hypen between the preceding syllable and this syllable
if (// TODO: frame breaks...
lastLyric != null) {
if (lyricType == SyllableType.Middle || lyricType == SyllableType.End) {
StaffTextStamping hyphenStamping = lyricStamper.createHyphenStamping(lastLyric, sts, defaultLyricStyle);
ret.add(hyphenStamping);
}
}
// remember this lyric as the currently last one in the current staff and verse
lastLyrics.set(staffIndex, lyric.getVerse(), sts);
}
}
baseLine += -5;
}
}
// directions
ret.addAll(directionStamper.stampForChord(chordSt, context.layouter.symbols));
// tuplet
Tuplet tuplet = element.getTuplet();
if (tuplet != null) {
openTupletsCache.addChord(element, tuplet, chordSt);
}
return ret;
}
use of com.xenoage.zong.core.music.lyric.Lyric in project Zong by Xenoage.
the class LyricReader method readLyrics.
private List<Lyric> readLyrics() {
// not supported yet: in MusicXML also rests can have lyrics. see measure 36 in Echigo-Jishi
List<Lyric> ret = alist();
for (MxlNote mxlNote : mxlNotes) {
for (MxlLyric mxlLyric : it(mxlNote.getLyrics())) {
int verse = readVerse(mxlLyric);
MxlLyricContentType mxlLCType = mxlLyric.getContent().getLyricContentType();
if (mxlLCType == MxlLyricContentType.SyllabicText) {
MxlSyllabicText mxlSyllabicText = (MxlSyllabicText) mxlLyric.getContent();
SyllableType syllableType = readSyllableType(mxlLyric);
// the next element must be the text element
ret.add(new Lyric(Companion.ut(mxlSyllabicText.getText().getValue()), syllableType, verse));
} else if (mxlLCType == MxlLyricContentType.Extend) {
// extend - TODO: extension to next chord!
ret.add(Lyric.Companion.lyricExtend(verse));
}
}
}
return ret;
}
Aggregations