Search in sources :

Example 6 with ElementWidth

use of com.xenoage.zong.musiclayout.spacing.ElementWidth in project Zong by Xenoage.

the class RestNotator method compute.

public RestNotation compute(Rest rest, Context context) {
    float width = context.settings.spacings.normalChordSpacings.getWidth(rest.getDuration());
    Duration.Type duration = Duration.INSTANCE.getRestType(rest.getDuration());
    return new RestNotation(rest, new ElementWidth(width), duration);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) Duration(com.xenoage.zong.core.music.util.Duration)

Example 7 with ElementWidth

use of com.xenoage.zong.musiclayout.spacing.ElementWidth in project Zong by Xenoage.

the class TimeNotator method compute.

public TimeNotation compute(TimeSignature time, Context context) {
    // front and rear gap: 1 space
    float gap = 1f;
    // gap between digits: 0.1 space
    float digitGap = 0.1f;
    // the numbers of a normal time signature are centered.
    // the width of the time signature is the width of the wider number
    float numeratorWidth = context.symbols.computeNumberWidth(time.getType().getNumerator(), digitGap);
    float denominatorWidth = context.symbols.computeNumberWidth(time.getType().getDenominator(), digitGap);
    float width = Math.max(numeratorWidth, denominatorWidth);
    // create element layout
    float numeratorOffset = (width - numeratorWidth) / 2;
    float denominatorOffset = (width - denominatorWidth) / 2;
    return new TimeNotation(time, new ElementWidth(gap, width, gap), numeratorOffset, denominatorOffset, digitGap);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) TimeNotation(com.xenoage.zong.musiclayout.notation.TimeNotation)

Example 8 with ElementWidth

use of com.xenoage.zong.musiclayout.spacing.ElementWidth 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 9 with ElementWidth

use of com.xenoage.zong.musiclayout.spacing.ElementWidth in project Zong by Xenoage.

the class SingleVoiceSpacer method compute.

VoiceSpacing compute(Voice voice, float interlineSpace, Fraction measureBeats, int staffLinesCount, Notations notations, LayoutSettings layoutSettings) {
    LinkedList<ElementSpacing> ret = llist();
    // special case: no elements in the measure.
    if (voice.getElements().size() == 0) {
        return new VoiceSpacing(voice, interlineSpace, alist((ElementSpacing) new BorderSpacing(Fraction.Companion.get_0(), 0), new BorderSpacing(measureBeats, layoutSettings.spacings.widthMeasureEmpty)));
    }
    // we compute the spacings in reverse order. this is easier, since grace chords
    // use shared space when possible, but are aligned to the right. so we begin
    // at position 0, and create the spacings in reverse direction (thus we find negative positions).
    // at the end, we shift the voice spacing to the right to be aligned at the left measure border,
    // which is position 0.
    // last symbol offset:
    // real offset where the last element's symbol started
    // since we do not know the right border yet, we start at 0
    float lastSymbolOffset = 0;
    // front gap offset:
    // offset where the last element (including front gap) started.
    float lastFrontGapOffset = lastSymbolOffset;
    // last full element offset:
    // lastSymbolOffset of the last full (non-grace) element
    float lastFullSymbolOffset = lastSymbolOffset;
    // at last beat
    Fraction curBeat = voice.getFilledBeats();
    ret.addFirst(new BorderSpacing(curBeat, lastFrontGapOffset));
    // iterate through the elements in reverse order
    for (VoiceElement element : Companion.reverseIt(voice.getElements())) {
        // get the notation
        Notation notation = notations.get(element);
        if (notation == null)
            throw new IllegalStateException("No notation for element " + element);
        // get the width of the element (front gap, symbol's width, rear gap, lyric's width)
        ElementWidth elementWidth = notation.getWidth();
        // add spacing for voice element
        float symbolOffset;
        boolean grace = !element.getDuration().isGreater0();
        if (!grace) {
            // full element
            // share this rear gap and the front gap of the following
            // element + the space of following grace elements, when possible
            // (but use at least minimal distance)
            symbolOffset = Math.min(lastFrontGapOffset - layoutSettings.spacings.widthDistanceMin, lastFullSymbolOffset - elementWidth.rearGap) - elementWidth.symbolWidth;
            lastFullSymbolOffset = symbolOffset;
            // update beat cursor
            curBeat = curBeat.sub(element.getDuration());
        } else {
            // grace element
            // share this rear gap and the front gap of the following element, when possible
            symbolOffset = Math.min(lastFrontGapOffset, lastSymbolOffset - elementWidth.rearGap) - elementWidth.symbolWidth;
        }
        ElementSpacing elementSpacing = null;
        if (notation instanceof RestNotation) {
            // rest spacing
            elementSpacing = restSpacer.compute((RestNotation) notation, curBeat, symbolOffset, staffLinesCount);
        } else {
            // chord spacing
            elementSpacing = new ChordSpacing((ChordNotation) notation, curBeat, symbolOffset);
        }
        ret.addFirst(elementSpacing);
        lastFrontGapOffset = symbolOffset - elementWidth.frontGap;
        lastSymbolOffset = symbolOffset;
    }
    // shift spacings to the right
    float shift = (-lastFrontGapOffset) + layoutSettings.offsetMeasureStart;
    for (ElementSpacing e : ret) e.xIs += shift;
    return new VoiceSpacing(voice, interlineSpace, ilist(ret));
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) Fraction(com.xenoage.utils.math.Fraction) Notation(com.xenoage.zong.musiclayout.notation.Notation) RestNotation(com.xenoage.zong.musiclayout.notation.RestNotation) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ChordSpacing(com.xenoage.zong.musiclayout.spacing.ChordSpacing) BorderSpacing(com.xenoage.zong.musiclayout.spacing.BorderSpacing) VoiceElement(com.xenoage.zong.core.music.VoiceElement) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing)

Example 10 with ElementWidth

use of com.xenoage.zong.musiclayout.spacing.ElementWidth 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

ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)12 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)7 RestNotation (com.xenoage.zong.musiclayout.notation.RestNotation)6 VoiceElement (com.xenoage.zong.core.music.VoiceElement)5 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)5 Notations (com.xenoage.zong.musiclayout.notation.Notations)5 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)5 Voice (com.xenoage.zong.core.music.Voice)4 VoiceTest (com.xenoage.zong.core.music.VoiceTest)4 LayoutSettingsTest (com.xenoage.zong.musiclayout.settings.LayoutSettingsTest)4 Test (org.junit.Test)4 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)3 MusicContext (com.xenoage.zong.core.music.MusicContext)2 Clef (com.xenoage.zong.core.music.clef.Clef)2 TraditionalKeyNotation (com.xenoage.zong.musiclayout.notation.TraditionalKeyNotation)2 LeadingSpacing (com.xenoage.zong.musiclayout.spacing.LeadingSpacing)2 FontInfo (com.xenoage.utils.font.FontInfo)1 TextMeasurer (com.xenoage.utils.font.TextMeasurer)1 Fraction (com.xenoage.utils.math.Fraction)1 Score (com.xenoage.zong.core.Score)1