Search in sources :

Example 1 with KeySignatureStamping

use of com.xenoage.zong.musiclayout.stampings.KeySignatureStamping in project Zong by Xenoage.

the class ElementStamper method createKeyStamping.

/**
 * Creates a stamping for the given key signature.
 */
public KeySignatureStamping createKeyStamping(TraditionalKeyNotation key, float xMm, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    boolean useSharps = key.element.getFifths() > 0;
    Symbol symbol = context.getSymbol(useSharps ? CommonSymbol.AccidentalSharp : CommonSymbol.AccidentalFlat);
    Spacings spacings = context.getSettings().spacings;
    float distance = (useSharps ? spacings.widthSharp : spacings.widthFlat);
    return new KeySignatureStamping(key, xMm, staff, symbol, distance);
}
Also used : lombok.val(lombok.val) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) Spacings(com.xenoage.zong.musiclayout.settings.Spacings) KeySignatureStamping(com.xenoage.zong.musiclayout.stampings.KeySignatureStamping)

Example 2 with KeySignatureStamping

use of com.xenoage.zong.musiclayout.stampings.KeySignatureStamping in project Zong by Xenoage.

the class KeySignatureRenderer method draw.

/**
 * Draws the given {@link KeySignatureStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    KeySignatureStamping s = (KeySignatureStamping) stamping;
    int fifths = s.key.element.getFifths();
    if (fifths == 0)
        return;
    boolean useSharps = (fifths > 0);
    float distance = s.distanceMm;
    Symbol symbol = args.symbolPool.getSymbol(useSharps ? CommonSymbol.AccidentalSharp : CommonSymbol.AccidentalFlat);
    // paint sharps/flats
    fifths = Math.abs(fifths);
    float interlineSpace = s.parentStaff.is;
    for (int i = 0; i < fifths; i++) {
        int linePosition = TraditionalKey.Companion.getLinePosition(i, useSharps, s.key.c4Lp, s.key.minLp);
        StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + i * distance * interlineSpace, linePosition), 1, s.parentStaff, false, canvas, args);
    }
}
Also used : KeySignatureStamping(com.xenoage.zong.musiclayout.stampings.KeySignatureStamping) Symbol(com.xenoage.zong.symbols.Symbol) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Aggregations

KeySignatureStamping (com.xenoage.zong.musiclayout.stampings.KeySignatureStamping)2 Symbol (com.xenoage.zong.symbols.Symbol)2 CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)2 Spacings (com.xenoage.zong.musiclayout.settings.Spacings)1 lombok.val (lombok.val)1