Search in sources :

Example 61 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class FrameSpacer method compute.

/**
 * Arranges an optimum number of systems in a frame, beginning at the given measure,
 * if possible.
 * @param context         the context of the layouter, with the {@link MP} set to the start measure
 * @param startSystem     the index of the system where to start
 * @param usableSizeMm    the usable size within the score frame in mm
 * @param isAdditional    true, when this frame is created for a complete score layout,
 *                         but is not part of the defined layout
 * @param columnSpacings  a list of all measure column spacings without leading spacings
 * @param notations       the notations of the elements, needed when a column has to be recomputed
 *                        because of a leading spacing
 */
public FrameSpacing compute(Context context, int startSystem, Size2f usableSizeMm, boolean isAdditional, List<ColumnSpacing> columnSpacings, Notations notations) {
    context.saveMp();
    int startMeasure = context.mp.measure;
    Score score = context.score;
    ScoreFormat scoreFormat = score.getFormat();
    ScoreHeader scoreHeader = score.getHeader();
    int measuresCount = score.getMeasuresCount();
    int measureIndex = startMeasure;
    int systemIndex = startSystem;
    // top margin
    float offsetY = getTopSystemDistance(systemIndex, scoreFormat, scoreHeader);
    // append systems to the frame
    List<SystemSpacing> systems = alist();
    while (measureIndex < measuresCount) {
        // try to create system on this frame
        context.mp = atMeasure(measureIndex);
        boolean isFirst = (systems.size() == 0);
        SystemSpacing system = systemSpacer.compute(context, usableSizeMm, offsetY, systemIndex, isFirst, isAdditional, columnSpacings, notations).orNull();
        // was there enough place for this system?
        if (system != null) {
            // yes, there is enough place. add system
            systems.add(system);
            // update offset and start measure index for next system
            // add height of this system
            offsetY += system.getHeightMm();
            // add system distance of the following system
            offsetY += getSystemDistance(systemIndex + 1, scoreFormat, scoreHeader);
            // increase indexes
            systemIndex++;
            measureIndex = system.getEndMeasure() + 1;
        } else {
            break;
        }
    }
    context.restoreMp();
    return new FrameSpacing(systems, usableSizeMm);
}
Also used : ScoreFormat(com.xenoage.zong.core.format.ScoreFormat) Score(com.xenoage.zong.core.Score) ScoreHeader(com.xenoage.zong.core.header.ScoreHeader) FrameSpacing(com.xenoage.zong.musiclayout.spacing.FrameSpacing) SystemSpacing(com.xenoage.zong.musiclayout.spacing.SystemSpacing)

Example 62 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class StemDirector method compute.

/**
 * Computes the {@link StemDirection} of the given chord (and maybe connected
 * ones) and returns them. The chord must be part of a score.
 */
public Map<Chord, StemDirection> compute(Chord chord) {
    Map<Chord, StemDirection> ret = map();
    Beam beam = chord.getBeam();
    Score score = chord.getScore();
    if (beam != null) {
        // compute stem directions for all chords of the beam
        StemDirection[] beamedStems = beamedStemDirector.compute(beam, score);
        for (int iChord : range(beam.size())) ret.put(beam.getChord(iChord), beamedStems[iChord]);
    } else {
        // compute stem direction for single chord
        MP mp = MP.getMP(chord);
        StemDirection stem = singleStemDirector.compute(chord, score.getMusicContext(mp, BeforeOrAt, Before));
        ret.put(chord, stem);
    }
    // but it was bad and outdated, so we removed it.
    return ret;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Score(com.xenoage.zong.core.Score) MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) StemDirection(com.xenoage.zong.core.music.chord.StemDirection)

Example 63 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class Notator method computeAll.

/**
 * Computes the {@link Notation}s of all elements and returns them.
 */
public Notations computeAll(Context context) {
    context.saveMp();
    Score score = context.score;
    Notations notations = new Notations();
    // iterate over all column elements, measure elements and voice elements
    ColumnElementIterator itC = new ColumnElementIterator(score);
    for (ColumnElement e : itC) {
        // column elements: one notation for each staff
        for (int iStaff : range(context.score.getStavesCount())) {
            context.mp = itC.getMp().withStaff(iStaff);
            notations.add(compute(e, context, notations), iStaff);
        }
    }
    MeasureElementIterator itM = new MeasureElementIterator(score);
    for (MeasureElement e : itM) {
        context.mp = itM.getMp();
        notations.add(compute(e, context, notations));
    }
    VoiceElementIterator itV = new VoiceElementIterator(score);
    for (VoiceElement e : itV) {
        context.mp = itV.getMp();
        notations.add(compute(e, context, notations));
    }
    BeamIterator itB = new BeamIterator(score);
    for (Beam e : itB) {
        context.mp = itB.getMp();
        notations.add(compute(e, context, notations));
    }
    context.restoreMp();
    return notations;
}
Also used : Beam(com.xenoage.zong.core.music.beam.Beam) Score(com.xenoage.zong.core.Score) VoiceElementIterator(com.xenoage.zong.core.util.VoiceElementIterator) Notations(com.xenoage.zong.musiclayout.notation.Notations) BeamIterator(com.xenoage.zong.core.util.BeamIterator) ColumnElementIterator(com.xenoage.zong.core.util.ColumnElementIterator) MeasureElementIterator(com.xenoage.zong.core.util.MeasureElementIterator)

Example 64 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method computeTest2.

/**
 * Compute offsets of the common beats,
 * this time for an incomplete measure.
 */
@Test
public void computeTest2() {
    Score score = createTestScore3VoicesIncomplete();
    BeatOffset[] beatOffsets = testee.compute(createVoiceSpacings(score), Companion.fr(4, 4), minimalBeatsOffsetIs).toArray(new BeatOffset[0]);
    float is = score.getFormat().getInterlineSpace();
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, x: missing (empty)
    // ^: dominating voice
    // voice 1:   | 4     4     4     8  xxx|
    // ^^^^^^^^^^^^
    // voice 2:   | 8  8  8  8  4     xxxxxx|
    // ^^^^^^^^^^^^
    // voice 3:   | 3   3   3   8  xxxxxxxxx|
    // 
    // used:        *  ** * **  *     *  °  *    (°: total final used beat)
    // checked:     *     *     *     *  *  *
    assertEquals(10, beatOffsets.length);
    assertEquals(Companion.fr(0, 4), beatOffsets[0].getBeat());
    assertEquals((0) * is, beatOffsets[0].getOffsetMm(), df);
    assertEquals(Companion.fr(1, 4), beatOffsets[3].getBeat());
    assertEquals((2 * width_1_8) * is, beatOffsets[3].getOffsetMm(), df);
    assertEquals(Companion.fr(2, 4), beatOffsets[6].getBeat());
    assertEquals((4 * width_1_8) * is, beatOffsets[6].getOffsetMm(), df);
    assertEquals(Companion.fr(3, 4), beatOffsets[7].getBeat());
    assertEquals((4 * width_1_8 + width_1_4) * is, beatOffsets[7].getOffsetMm(), df);
    assertEquals(Companion.fr(7, 8), beatOffsets[8].getBeat());
    assertEquals((4 * width_1_8 + width_1_4 + width_1_8) * is, beatOffsets[8].getOffsetMm(), df);
    assertEquals(Companion.fr(4, 4), beatOffsets[9].getBeat());
    assertEquals((4 * width_1_8 + width_1_4 + width_1_8 + minimalBeatsOffsetIs) * is, beatOffsets[9].getOffsetMm(), df);
}
Also used : Score(com.xenoage.zong.core.Score) MusicXmlScoreFileInputTest(com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest) Test(org.junit.Test)

Example 65 with Score

use of com.xenoage.zong.core.Score in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method createTestScore3VoicesIncomplete.

private Score createTestScore3VoicesIncomplete() {
    Score score = new Score();
    score.getFormat().setInterlineSpace(2);
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(Companion.getTime_4_4()));
    // 2: half note, 4: quarter note, 8: eighth note, 3: quarter triplet, x: missing (empty)
    // voice 1: | 4     4     4     8  xxx|   (staff 1)
    // voice 2: | 8  8  8  8  4     xxxxxx|   (staff 1)
    // voice 3: | 3   3   3   8  xxxxxxxxx|   (staff 2)
    // voice 1
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    // voice 2
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    // voice 3
    cursor.setMp(atElement(0, 0, 2, 0));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 6)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 8)));
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4