Search in sources :

Example 1 with Stem

use of com.xenoage.zong.core.music.chord.Stem 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)

Example 2 with Stem

use of com.xenoage.zong.core.music.chord.Stem in project Zong by Xenoage.

the class SingleStemDirector method compute.

public StemDirection compute(Chord chord, MusicContext context) {
    // stem specified in chord?
    Stem stem = chord.getStem();
    if (stem.getDirection() != StemDirection.Default)
        return stem.getDirection();
    // stem needed?
    if (!isStemNeeded(chord))
        return StemDirection.None;
    // compute default stem
    ChordLps chordLp = new ChordLps(chord, context);
    int linesCount = context.getLinesCount();
    return compute(chordLp, linesCount);
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) Stem(com.xenoage.zong.core.music.chord.Stem)

Aggregations

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