Search in sources :

Example 1 with TraditionalKeyNotation

use of com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation in project Zong by Xenoage.

the class LeadingSpacer method compute.

/**
 * Computes the {@link LeadingSpacing} for the current measure.
 */
public LeadingSpacing compute(Context context, Notations notations) {
    float xOffset = context.settings.offsetMeasureStart;
    boolean useKey = false;
    MusicContext musicContext = context.getMusicContext(At, null);
    Key key = musicContext.getKey();
    if (key instanceof TraditionalKey) {
        useKey = true;
    }
    List<ElementSpacing> elements = alist(useKey ? 2 : 1);
    // it is not the same element instance, but has the same meaning
    Clef clef = new Clef(musicContext.getClef());
    ClefNotation clefNotation = new ClefNotation(clef, new ElementWidth(0, context.settings.spacings.widthClef, 0), musicContext.getClef().getLp(), 1);
    notations.add(clefNotation);
    xOffset += context.settings.spacings.widthClef / 2;
    elements.add(new SimpleSpacing(clefNotation, Companion.fr(0), xOffset));
    xOffset += context.settings.spacings.widthClef / 2;
    if (useKey) {
        TraditionalKey tkey = (TraditionalKey) key;
        xOffset += context.settings.spacings.widthDistanceMin;
        // it is not the same element instance, but has the same meaning
        TraditionalKey tradKey = new TraditionalKey(tkey.getFifths(), tkey.getMode());
        TraditionalKeyNotation keyNotation = traditionalKeyNotator.compute(tradKey, context);
        notations.add(keyNotation);
        elements.add(new SimpleSpacing(keyNotation, Companion.fr(0), xOffset));
        xOffset += keyNotation.getWidth().getWidth();
    }
    return new LeadingSpacing(elements, xOffset);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) LeadingSpacing(com.xenoage.zong.musiclayout.spacing.LeadingSpacing) SimpleSpacing(com.xenoage.zong.musiclayout.spacing.SimpleSpacing) Clef(com.xenoage.zong.core.music.clef.Clef) ClefNotation(com.xenoage.zong.musiclayout.notation.ClefNotation) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) MusicContext(com.xenoage.zong.core.music.MusicContext) ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) TraditionalKeyNotation(com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key)

Example 2 with TraditionalKeyNotation

use of com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation in project Zong by Xenoage.

the class TraditionalKeyNotator method compute.

public TraditionalKeyNotation compute(TraditionalKey key, Context context) {
    // compute width
    float width = 0;
    int fifth = key.getFifths();
    if (fifth > 0)
        width = fifth * context.settings.spacings.widthSharp;
    else
        width = -fifth * context.settings.spacings.widthFlat;
    ElementWidth keyWidth = new ElementWidth(0, width, 1);
    // compute LPs
    ClefType contextClef = context.score.getClef(context.mp, Before);
    int c4Lp = contextClef.getLp(Companion.pi(0, 0, 4));
    int minLp = contextClef.getKeySignatureLowestLp(fifth);
    return new TraditionalKeyNotation(key, keyWidth, c4Lp, minLp);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) TraditionalKeyNotation(com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation) ClefType(com.xenoage.zong.core.music.clef.ClefType)

Aggregations

TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)2 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)2 MusicContext (com.xenoage.zong.core.music.MusicContext)1 Clef (com.xenoage.zong.core.music.clef.Clef)1 ClefType (com.xenoage.zong.core.music.clef.ClefType)1 Key (com.xenoage.zong.core.music.key.Key)1 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)1 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)1 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)1 LeadingSpacing (com.xenoage.zong.musiclayout.spacing.LeadingSpacing)1 SimpleSpacing (com.xenoage.zong.musiclayout.spacing.SimpleSpacing)1