Search in sources :

Example 1 with MxlStem

use of com.xenoage.zong.musicxml.types.MxlStem in project Zong by Xenoage.

the class StemReader method read.

/**
 * Reads and returns the stem of the given chord.
 * If not available, {@link Stem#defaultStem} is returned.
 * @param context   the global context
 * @param chord     the chord, whose notes are already collected
 * @param staff     the staff index of the current chord
 */
public Stem read(Context context, Chord chord, int staff) {
    if (mxlStem == null)
        return Companion.getDefaultStem();
    // direction
    StemDirection direction = readStemDirection();
    // length
    Float length = null;
    MxlPosition yPos = mxlStem.getPosition();
    if (yPos.getDefaultY() != null) {
        // convert position in tenths relative to topmost staff line into
        // a length in interline spaces measured from the outermost chord note on stem side
        float stemEndLinePosition = convertDefaultYToLP(context, yPos.getDefaultY(), staff);
        VSide side = (direction == StemDirection.Up ? VSide.Top : VSide.Bottom);
        length = Math.abs(stemEndLinePosition - getOuterNoteLp(context, chord, side, staff)) / 2;
    }
    // create stem
    return new Stem(direction, length);
}
Also used : MxlPosition(com.xenoage.zong.musicxml.types.attributes.MxlPosition) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) VSide(com.xenoage.utils.math.VSide) Stem.defaultStem(com.xenoage.zong.core.music.chord.Stem.defaultStem) MxlStem(com.xenoage.zong.musicxml.types.MxlStem) Stem(com.xenoage.zong.core.music.chord.Stem)

Aggregations

VSide (com.xenoage.utils.math.VSide)1 Stem (com.xenoage.zong.core.music.chord.Stem)1 Stem.defaultStem (com.xenoage.zong.core.music.chord.Stem.defaultStem)1 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)1 MxlStem (com.xenoage.zong.musicxml.types.MxlStem)1 MxlPosition (com.xenoage.zong.musicxml.types.attributes.MxlPosition)1