use of com.xenoage.zong.musiclayout.notation.chord.NoteSuspension in project Zong by Xenoage.
the class NotesNotator method computeNotes.
private NoteDisplacement[] computeNotes(ChordLps lps, StemDirection sd, float stemOffset) {
NoteDisplacement[] notes = new NoteDisplacement[lps.getNotesCount()];
// if stem direction is down or none, begin with the highest note,
// otherwise with the lowest
int dir = (sd == StemDirection.Up) ? 1 : -1;
int startIndex = (dir == 1) ? 0 : lps.getNotesCount() - 1;
int endIndex = lps.getNotesCount() - 1 - startIndex;
// default side of the stem. 1 = right, 0 = left
int stemSide = (sd == StemDirection.Up) ? 1 : 0;
int lastSide = stemSide;
for (int i = startIndex; dir * i <= dir * endIndex; i += dir) {
int side = 1 - stemSide;
NoteSuspension suspension = NoteSuspension.None;
if (i == startIndex) {
// first note: use default side
} else {
// following note: change side, if last note is 1 or 0 LPs away
if (abs(lps.get(i) - lps.get(i - dir)) <= 1) {
// change side
side = 1 - lastSide;
if (side != 1 - stemSide) {
if (side == 0)
suspension = NoteSuspension.Left;
else
suspension = NoteSuspension.Right;
}
}
}
notes[i] = new NoteDisplacement(lps.get(i), side * stemOffset, suspension);
lastSide = side;
}
return notes;
}
use of com.xenoage.zong.musiclayout.notation.chord.NoteSuspension in project Zong by Xenoage.
the class LegerLinesStamper method stamp.
public LegerLineStamping[] stamp(ChordNotation chordNotation, float chordXMm, StaffStamping staffStamping) {
NotesNotation notes = chordNotation.notes;
int bottomCount = getBottomCount(notes.getBottomNote().lp);
int topCount = getTopCount(notes.getTopNote().lp, staffStamping.linesCount);
if (bottomCount > 0 || topCount > 0) {
// horizontal position and width (may differ above and below staff, dependent on suspended notes)
NoteSuspension bottomSuspension = getBottomSuspension(notes.notes);
float xTopMm = getXMm(chordXMm, notes.noteheadWidthIs, bottomSuspension, staffStamping.is);
float widthBottomIs = getWidthIs(bottomSuspension != None);
NoteSuspension topSuspension = getTopSuspension(notes.notes, staffStamping.linesCount);
float xBottomMm = getXMm(chordXMm, notes.noteheadWidthIs, topSuspension, staffStamping.is);
float widthTopIs = getWidthIs(bottomSuspension != None);
// vertical positions
int[] bottomLps = getBottomLps(bottomCount);
int[] topLps = getTopLps(topCount, staffStamping.linesCount);
// create stampings
LegerLineStamping[] ret = new LegerLineStamping[bottomCount + topCount];
for (int i : range(bottomCount)) ret[i] = new LegerLineStamping(sp(xBottomMm, bottomLps[i]), widthBottomIs, staffStamping);
for (int i : range(topCount)) ret[bottomCount + i] = new LegerLineStamping(sp(xTopMm, topLps[i]), widthTopIs, staffStamping);
return ret;
} else {
return empty;
}
}
Aggregations