Search in sources :

Example 1 with Fraction

use of com.xenoage.utils.math.Fraction in project Zong by Xenoage.

the class Context method writeColumnElement.

/**
 * Writes the given {@link ColumnElement} at the current measure.
 * @param side     the side of the measure. If null, the current beat is used.
 */
public void writeColumnElement(ColumnElement element, MeasureSide side) {
    Fraction beat = (side == null ? mp.getBeat() : MP.Companion.getUnknownBeat());
    new ColumnElementWrite(element, score.getColumnHeader(mp.getMeasure()), beat, side).execute();
}
Also used : ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) Fraction(com.xenoage.utils.math.Fraction)

Example 2 with Fraction

use of com.xenoage.utils.math.Fraction in project Zong by Xenoage.

the class DirectionReader method readMetronome.

private Direction readMetronome() {
    MxlMetronome mxlMetronome = (MxlMetronome) currentMxlDirType;
    // compute base beat
    Fraction baseBeat = mxlMetronome.getBeatUnit().getDuration();
    baseBeat = Duration.INSTANCE.getDuration(baseBeat, mxlMetronome.getDotsCount());
    // text: TODO
    Tempo tempo = new Tempo(baseBeat, mxlMetronome.getPerMinute());
    // TODO tempo.setFont(FontInfoReader.read(currentMxlDirection, defaultFont));
    tempo.setPositioning(readPositioning());
    return tempo;
}
Also used : Fraction(com.xenoage.utils.math.Fraction)

Example 3 with Fraction

use of com.xenoage.utils.math.Fraction in project Zong by Xenoage.

the class MeasureReader method readBackupToContext.

private static void readBackupToContext(MxlBackup mxlBackup, Context context) {
    // duration
    Fraction duration = readDuration(mxlBackup.getDuration(), context.getDivisions()).invert();
    // move cursor
    context.moveCurrentBeat(duration);
}
Also used : Fraction(com.xenoage.utils.math.Fraction)

Example 4 with Fraction

use of com.xenoage.utils.math.Fraction in project Zong by Xenoage.

the class MeasureReader method readForwardToContext.

private static void readForwardToContext(MxlForward mxlForward, Context context) {
    // duration
    Fraction duration = readDuration(mxlForward.getDuration(), context.getDivisions());
    // move cursor
    context.moveCurrentBeat(duration);
}
Also used : Fraction(com.xenoage.utils.math.Fraction)

Example 5 with Fraction

use of com.xenoage.utils.math.Fraction in project Zong by Xenoage.

the class TimeMapper method createTimeMap.

public TimeMap createTimeMap() {
    // resolution per quarter note
    int resolution = score.getDivisions() * resolutionFactor;
    // for each play range compute the used beats in each measure column
    int tick = 0;
    val timeMap = new TimeMapBuilder();
    for (int iRep : range(repetitions)) {
        val range = repetitions.get(iRep);
        for (int iMeasure : range(range.start.getMeasure(), range.end.getMeasure())) {
            val usedBeats = getUsedBeats(iMeasure, range);
            Fraction lastBeat = null;
            for (int iBeat : range(usedBeats)) {
                val beat = usedBeats.get(iBeat);
                // increase tick by distance between last and this beat
                if (lastBeat != null)
                    tick += beat.sub(lastBeat).mult(resolution * 4).getNumerator();
                // add time
                timeMap.addTimeNoMs(tick, new RepTime(iRep, Companion.time(iMeasure, beat)));
                lastBeat = beat;
            }
        }
    }
    return timeMap.build();
}
Also used : lombok.val(lombok.val) Fraction(com.xenoage.utils.math.Fraction)

Aggregations

Fraction (com.xenoage.utils.math.Fraction)32 BeatOffset (com.xenoage.zong.musiclayout.spacing.BeatOffset)6 Chord (com.xenoage.zong.core.music.chord.Chord)5 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)5 lombok.val (lombok.val)5 Voice (com.xenoage.zong.core.music.Voice)4 Measure (com.xenoage.zong.core.music.Measure)3 VoiceElement (com.xenoage.zong.core.music.VoiceElement)3 Clef (com.xenoage.zong.core.music.clef.Clef)3 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)3 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)3 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)3 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 Score (com.xenoage.zong.core.Score)2 Part (com.xenoage.zong.core.music.Part)2 Note (com.xenoage.zong.core.music.chord.Note)2 Rest (com.xenoage.zong.core.music.rest.Rest)2 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1