Search in sources :

Example 1 with NoteSuspension

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;
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NoteSuspension(com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)

Example 2 with NoteSuspension

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;
    }
}
Also used : NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) LegerLineStamping(com.xenoage.zong.musiclayout.stampings.LegerLineStamping) NoteSuspension(com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)

Aggregations

NoteSuspension (com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)2 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)1 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)1 LegerLineStamping (com.xenoage.zong.musiclayout.stampings.LegerLineStamping)1