use of com.xenoage.zong.musiclayout.settings.ChordSpacings 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.settings.ChordSpacings in project Zong by Xenoage.
the class ChordSpacingsReader method readChordSpacings.
/**
* Reads the {@link ChordSpacings} from the given {@link XmlReader} at a child element
* of the "chords" element.
*/
public static ChordSpacings readChordSpacings(XmlReader r) throws IOException {
HashMap<Fraction, Float> durationWidths = map();
// load the duration-to-width mapping
while (r.openNextChildElement()) {
if (r.getElementName().equals("chord")) {
// duration format: x/y, e.g. "1/4"
Fraction duration = Fraction.Companion.fromString(r.getAttributeNotNull("duration"));
// width format: x+y/z, eg. "3+1/2"
float width = Fraction.Companion.fromString(r.getAttributeNotNull("width")).toFloat();
durationWidths.put(duration, width);
}
r.closeElement();
}
return new ChordSpacings(durationWidths);
}
use of com.xenoage.zong.musiclayout.settings.ChordSpacings in project Zong by Xenoage.
the class SpacingsReader method readSpacings.
/**
* Reads a {@link Spacings} from the given {@link XmlReader} at the "spacings" element.
*/
public static Spacings readSpacings(XmlReader r) throws IOException {
ChordSpacings normalChordSpacings = null, graceChordSpacings = null;
float widthSharp = 0, widthFlat = 0, widthClef = 0, widthMeasureEmpty = 0, widthDistanceMin = 0;
while (r.openNextChildElement()) {
String n = r.getElementName();
switch(n) {
case "chords":
// chord spacings
while (r.openNextChildElement()) {
String n2 = r.getElementName();
if (n2.equals("normal"))
normalChordSpacings = readChordSpacings(r);
else if (n2.equals("grace"))
graceChordSpacings = readChordSpacings(r);
r.closeElement();
}
break;
case "clef":
// clef
widthClef = parseFloat(r.getAttributeNotNull("width"));
break;
case "key":
// keys
while (r.openNextChildElement()) {
String n2 = r.getElementName();
if (n2.equals("sharp"))
widthSharp = parseFloat(r.getAttributeNotNull("width"));
else if (n2.equals("flat"))
widthFlat = parseFloat(r.getAttributeNotNull("width"));
r.closeElement();
}
break;
case "measure":
// measure
widthMeasureEmpty = parseFloat(r.getAttributeNotNull("empty"));
break;
case "distance":
// distance
widthDistanceMin = parseFloat(r.getAttributeNotNull("minimal"));
break;
}
r.closeElement();
}
return new Spacings(normalChordSpacings, graceChordSpacings, widthSharp, widthFlat, widthClef, widthMeasureEmpty, widthDistanceMin);
}
Aggregations