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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations