use of com.xenoage.zong.musiclayout.stampings.StaffTextStamping in project Zong by Xenoage.
the class LyricStamper method createUnderscoreStamping.
private StaffTextStamping createUnderscoreStamping(float startX, float endX, float baseLine, float widthUnderscore, FormattedTextStyle style, StaffStamping staff, Object element) {
// compute number of needed "_"
int countU = Math.max((int) ((endX - startX) / widthUnderscore) + 1, 1);
// create text
FormattedText text = Companion.fText(StringUtils.repeat("_", countU), style, Alignment.Left);
return new StaffTextStamping(text, sp(startX, baseLine), staff, element);
}
use of com.xenoage.zong.musiclayout.stampings.StaffTextStamping in project Zong by Xenoage.
the class LyricStamper method createUnderscoreStampings.
/**
* Creates and returns at least one {@link StaffTextStamping} containing
* an underscore line ("___") behind the given lyric stamping
* up to the given notehead stamping.
* If more than one line is needed, a stamping for each line is returned.
*
* A list of consecutive staff stampings must be given, containing at least
* the beginning and the ending staff of the underscore. If the underscore needs
* only one staff, it may also be null.
*
* The left syllable must be given, even if it is not in the current frame.
* The right notehead is optional. If not given, the underscore is drawn over
* all given following staves.
*/
public IList<StaffTextStamping> createUnderscoreStampings(StaffTextStamping syllableLeft, NoteheadStamping noteheadRight, FormattedTextStyle style, List<StaffStamping> staffStampings) {
if (syllableLeft == null)
throw new IllegalArgumentException("Left syllable must be given");
CList<StaffTextStamping> ret = clist();
// measure width of "_"
float widthU = Companion.fText("_", style, Alignment.Center).getFirstParagraph().getMetrics().getWidth();
// compute the horizontal start position, base line and element
float widthLeft = syllableLeft.getText().getFirstParagraph().getMetrics().getWidth();
// widthU / 4: just some distance
float startX = syllableLeft.position.xMm + widthLeft / 2 + widthU / 4;
float baseLine = syllableLeft.position.lp;
Object element = syllableLeft.element;
// if end notehead is given, compute the end position
float endX = 0;
if (noteheadRight != null) {
endX = noteheadRight.position.xMm;
}
// underscore line on a single staff?
if (noteheadRight != null && syllableLeft.parentStaff == noteheadRight.parentStaff) {
// simple case
ret.add(createUnderscoreStamping(startX, endX, baseLine, widthU, style, syllableLeft.parentStaff, element));
} else {
It<StaffStamping> staves = new It<>(staffStampings);
StaffStamping currentStaff = null;
// only true, when start stamping is found
boolean firstStaffFound = false;
// only true, when stop stamping is found
boolean lastStaffFound = false;
// find the start staff
StaffStamping s1 = syllableLeft.parentStaff;
while (staves.hasNext()) {
currentStaff = staves.next();
if (currentStaff == s1) {
firstStaffFound = true;
break;
}
}
// if not found, begin at the very beginning
if (!firstStaffFound) {
staves = new It<>(staffStampings);
}
// first staff (if any): begin at the stamping, go to the end of the system
if (firstStaffFound) {
ret.add(createUnderscoreStamping(startX, currentStaff.positionMm.x + currentStaff.lengthMm, baseLine, widthU, style, currentStaff, element));
}
// to the end of the system
while (staves.hasNext()) {
currentStaff = staves.next();
if (noteheadRight != null && currentStaff == noteheadRight.parentStaff) {
// stop, because this is the last staff, where we have the stop notehead
lastStaffFound = true;
break;
}
// create underscore over whole staff
ret.add(createUnderscoreStamping(currentStaff.positionMm.x, currentStaff.positionMm.x + currentStaff.lengthMm, baseLine, widthU, style, currentStaff, element));
}
// system, stop at the notehead
if (lastStaffFound) {
ret.add(createUnderscoreStamping(currentStaff.positionMm.x, noteheadRight.position.xMm, baseLine, widthU, style, currentStaff, element));
}
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.StaffTextStamping in project Zong by Xenoage.
the class DirectionStamper method stampForChord.
/**
* Creates the {@link StaffTextStamping}s for the {@link Direction}s of
* the given {@link ChordStampings}.
*/
public List<StaffTextStamping> stampForChord(ChordStampings chordStampings, SymbolPool symbolPool) {
Chord chord = chordStampings.chord;
int directionsCount = chord.getDirections().size();
if (directionsCount == 0)
return emptyList();
List<StaffTextStamping> ret = alist();
for (Direction direction : chord.getDirections()) {
if (direction instanceof Dynamic) {
ret.add(createDynamics((Dynamic) direction, chord, chordStampings, symbolPool));
}
// TODO: support more directions
}
return ret;
}
use of com.xenoage.zong.musiclayout.stampings.StaffTextStamping in project Zong by Xenoage.
the class DirectionStamper method createDynamics.
/**
* Creates a {@link StaffTextStamping} for the given {@link Dynamic}s
* below the given {@link Chord} and its {@link ChordStampings}.
*/
public StaffTextStamping createDynamics(Dynamic dynamics, Chord chord, ChordStampings chordStampings, SymbolPool symbolPool) {
StaffStamping staff = chordStampings.staff;
// positioning
// below (default): 3 IS below the base line, or 2 IS below the lowest note
// above: 2 IS above the top line, or 1 IS above the highest note
float defaultLPBelow = -3f * 2;
float defaultLPAbove = (staff.linesCount - 1) * 2 + 2 * 2;
if (chordStampings.noteheads.length > 0) {
defaultLPBelow = Math.min(defaultLPBelow, chordStampings.getFirstNotehead().position.lp - 2 * 2);
defaultLPAbove = Math.max(defaultLPAbove, chordStampings.getLastNotehead().position.lp + 1 * 2);
}
SP sp = computePosition(dynamics, staff, defaultLPBelow, defaultLPAbove, defaultLPBelow);
// create text
CList<FormattedTextElement> elements = clist();
for (CommonSymbol s : CommonSymbol.getDynamics(dynamics.getValue())) {
Symbol symbol = symbolPool.getSymbol(s);
elements.add(new FormattedTextSymbol(symbol, staff.is * FONT_SIZE_IN_IS, FormattedTextStyle.Companion.getDefaultColor()));
}
elements.close();
FormattedTextParagraph paragraph = new FormattedTextParagraph(elements, Alignment.Center);
FormattedText text = Companion.fText(paragraph);
// create stamping
return new StaffTextStamping(text, sp, staff, dynamics);
}
use of com.xenoage.zong.musiclayout.stampings.StaffTextStamping in project Zong by Xenoage.
the class LyricStamper method createHyphenStamping.
/**
* Creates and returns the {@link StaffTextStamping} containing
* a hypen ("-") between the two given lyric stampings.
*/
public StaffTextStamping createHyphenStamping(StaffTextStamping syllableLeft, StaffTextStamping syllableRight, FormattedTextStyle style) {
FormattedText text = Companion.fText("-", style, Alignment.Center);
float positionX;
float widthLeft = syllableLeft.getText().getFirstParagraph().getMetrics().getWidth();
if (syllableLeft.parentStaff == syllableRight.parentStaff) {
// syllables are in same staff
// the horizontal position of the hyphen is in the middle of the empty
// space between the left and right syllable
float widthRight = syllableRight.getText().getFirstParagraph().getMetrics().getWidth();
positionX = ((syllableLeft.position.xMm + widthLeft / 2) + (syllableRight.position.xMm - widthRight / 2)) / 2;
} else {
// right syllable is in a new staff
// place the hypen to the right side of the first syllable
positionX = (syllableLeft.position.xMm + widthLeft / 2) + 2 * text.getFirstParagraph().getMetrics().getWidth();
}
return new StaffTextStamping(text, sp(positionX, syllableLeft.position.lp), syllableLeft.parentStaff, // hyphen belongs to the left syllable
syllableLeft.getElement());
}
Aggregations