Search in sources :

Example 1 with Clef

use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.

the class VoicesBeatOffsetterTest method createTestScore1Voice.

private Score createTestScore1Voice() {
    Score score = new Score();
    score.getFormat().setInterlineSpace(1);
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new Clef(ClefType.Companion.getClefTreble()));
    cursor.write((MeasureElement) new TraditionalKey(-3));
    cursor.write(new TimeSignature(TimeType.Companion.timeType(6, 4)));
    // beats: 0, 2, 3, 4, 8.
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 4)));
    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, 2)));
    cursor.write(chord(Companion.pi(0, 0, 0), Companion.fr(1, 2)));
    return score;
}
Also used : Score(com.xenoage.zong.core.Score) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 2 with Clef

use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.

the class MeasureElementsSpacerTest method testEnoughExistingSpace.

/**
 * If there is enough space left for the measure elements,
 * the voice spacings do not have to be changed.
 * To understand the following sketch, have a look at the comments
 * in {@link MeasureElementsSpacer}.
 * <pre>
 * enough space:
 * beat:     0   2   4   6   8
 * offset:   3 5 7 9  13  17  21
 *           . . . . . . . . . .
 * clef:         *[clef]*          (on beat 6)
 * voice 1:   o          2
 * voice 2:    1              o
 * </pre>
 */
@Test
public void testEnoughExistingSpace() {
    Rest[] ve = ve();
    List<VoiceSpacing> originalVs = alist(new VoiceSpacing(null, 1, alist(spacing(ve[0], Companion.fr(1, 2), 4), spacing(ve[1], Companion.fr(6), 15))), new VoiceSpacing(null, 1, alist(spacing(ve[2], Companion.fr(1), 5), spacing(ve[3], Companion.fr(17, 2), 20))));
    List<VoiceSpacing> vs = alist(originalVs);
    Clef innerClef = new Clef(ClefType.Companion.getClefTreble());
    BeatEList<Clef> innerClefs = Companion.beatEList();
    innerClefs.add(Companion.beatE(innerClef, Companion.fr(6)));
    List<ElementSpacing> res = testee.compute(innerClefs, Companion.beatEList(), null, false, vs, 0, notations(ve, innerClef), ls);
    // clef must be at offset 15 - padding - clefwidth/2
    ElementSpacing[] mes = res.toArray(new ElementSpacing[0]);
    assertEquals(1, mes.length);
    assertEquals(Companion.fr(6), mes[0].beat);
    assertEquals(15 - paddingWidth - clefWidth / 2, mes[0].xIs, Delta.DELTA_FLOAT);
    // voice spacings must be unchanged
    assertEquals(originalVs, vs);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) Rest(com.xenoage.zong.core.music.rest.Rest) Clef(com.xenoage.zong.core.music.clef.Clef) VoiceSpacing(com.xenoage.zong.musiclayout.spacing.VoiceSpacing) Test(org.junit.Test)

Example 3 with Clef

use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.

the class LeadingSpacingMock method createGClefSpacing.

/**
 * Creates an easy MeasureLeadingSpacing (with a g-clef)
 * that has the given width in IS.
 */
public static LeadingSpacing createGClefSpacing(float widthIs) {
    ClefNotation notation = new ClefNotation(new Clef(ClefType.Companion.getClefTreble()), new ElementWidth(widthIs), 0, 1);
    ElementSpacing spacing = new SimpleSpacing(notation, Companion.fr(0), 0);
    return new LeadingSpacing(alist(spacing), widthIs);
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) LeadingSpacing(com.xenoage.zong.musiclayout.spacing.LeadingSpacing) ClefNotation(com.xenoage.zong.musiclayout.notation.ClefNotation) Clef(com.xenoage.zong.core.music.clef.Clef)

Example 4 with Clef

use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.

the class Base43e method getExpectedClefs.

static List<Tuple2<MP, Clef>> getExpectedClefs() {
    List<Tuple2<MP, Clef>> clefs = alist();
    clefs.add(t(atBeat(0, 0, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefTreble())));
    clefs.add(t(atBeat(0, 2, unknown, Companion.get_0()), new Clef(new ClefType(ClefSymbol.C, 2))));
    clefs.add(t(atBeat(1, 0, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefBass())));
    clefs.add(t(atBeat(1, 1, unknown, Companion.get_0()), new Clef(ClefType.Companion.getClefTreble())));
    return clefs;
}
Also used : Tuple2(com.xenoage.utils.kernel.Tuple2) Clef(com.xenoage.zong.core.music.clef.Clef) ClefType(com.xenoage.zong.core.music.clef.ClefType)

Example 5 with Clef

use of com.xenoage.zong.core.music.clef.Clef in project Zong by Xenoage.

the class MeasureElementsSpacer method compute.

List<ElementSpacing> compute(BeatEList<Clef> clefs, @MaybeEmpty BeatEList<Key> keys, @MaybeNull TimeSignature time, boolean existsLeadingSpacing, List<VoiceSpacing> voiceSpacings, int staff, Notations notations, LayoutSettings layoutSettings) {
    Key key0 = null;
    if (keys.size() > 0 && keys.getFirst().getBeat().equals(Companion.get_0()))
        key0 = keys.getFirst().getElement();
    if (key0 == null && time == null && (clefs == null || clefs.size() == 0)) {
        // nothing to do
        return empty;
    }
    ArrayList<ElementSpacing> ret = alist();
    float startOffset = layoutSettings.offsetMeasureStart;
    // key and time
    // ************
    boolean isKey = !existsLeadingSpacing && key0 instanceof TraditionalKey;
    boolean isTime = time != null;
    if (isKey || isTime) {
        float currentOffset = startOffset;
        // ***
        if (isKey) {
            Notation keyNotation = notations.get(key0, staff);
            ret.add(new SimpleSpacing(keyNotation, Companion.get_0(), startOffset));
            currentOffset += keyNotation.getWidth().getUsedWidth();
        }
        // ****
        if (time != null) {
            Notation timeNotation = notations.get(time, staff);
            ret.add(new SimpleSpacing(timeNotation, Companion.get_0(), currentOffset + timeNotation.getWidth().symbolWidth / 2));
            currentOffset += timeNotation.getWidth().getUsedWidth();
        }
        // move voice elements, if not enough space before first voice element
        ElementSpacing leftSE = getFirstElementSpacing(voiceSpacings);
        if (leftSE != null) {
            float leftSEx = getLeftX(leftSE);
            // existing space
            float ES = leftSEx;
            // additional needed space
            float AS = currentOffset - ES;
            if (AS > 0) {
                shift(voiceSpacings, AS);
                startOffset += AS;
            }
        }
    }
    // voice 2:       1             o
    if (clefs != null) {
        for (BeatE<Clef> ME : clefs) {
            Fraction MEb = ME.getBeat();
            Notation MEnotation = notations.get(ME.getElement());
            float MEwidth = MEnotation.getWidth().getWidth();
            // if there is a leading spacing, ignore elements at beat 0
            if (existsLeadingSpacing && !MEb.isGreater0())
                continue;
            // find VE1 and VE2 for the current element
            ElementSpacing[] ses = getNearestSpacingElements(MEb, voiceSpacings);
            ElementSpacing VE1 = ses[0], VE2 = ses[1];
            // if VE1 is unknown, use startOffset. if VE2 is unknown, ignore this element
            float VE1x = (VE1 != null ? getRightX(VE1) : startOffset);
            if (VE2 == null)
                continue;
            float VE2x = getLeftX(VE2);
            // existing space
            float ES = VE2x - VE1x - 2 * layoutSettings.spacings.widthDistanceMin;
            if (ES < MEwidth) {
                // additional space needed
                float AS = MEwidth - ES;
                // move all elements at or after ME.beat
                VE2x += AS;
                shiftAfterBeat(voiceSpacings, AS, MEb);
            }
            // add measure element
            float MEx = VE2x - layoutSettings.spacings.widthDistanceMin - MEwidth / 2;
            ret.add(new SimpleSpacing(MEnotation, ME.getBeat(), MEx));
        }
    }
    ret.trimToSize();
    return ret;
}
Also used : ElementSpacing(com.xenoage.zong.musiclayout.spacing.ElementSpacing) SimpleSpacing(com.xenoage.zong.musiclayout.spacing.SimpleSpacing) Clef(com.xenoage.zong.core.music.clef.Clef) Fraction(com.xenoage.utils.math.Fraction) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Notation(com.xenoage.zong.musiclayout.notation.Notation) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key)

Aggregations

Clef (com.xenoage.zong.core.music.clef.Clef)14 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)8 Key (com.xenoage.zong.core.music.key.Key)5 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)5 ClefType (com.xenoage.zong.core.music.clef.ClefType)4 Rest (com.xenoage.zong.core.music.rest.Rest)4 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)4 Fraction (com.xenoage.utils.math.Fraction)3 Score (com.xenoage.zong.core.Score)3 Test (org.junit.Test)3 Tuple2 (com.xenoage.utils.kernel.Tuple2)2 InstrumentChange (com.xenoage.zong.core.music.InstrumentChange)2 Part (com.xenoage.zong.core.music.Part)2 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 Cursor (com.xenoage.zong.io.selection.Cursor)2 ClefNotation (com.xenoage.zong.musiclayout.notation.ClefNotation)2 ElementWidth (com.xenoage.zong.musiclayout.spacing.ElementWidth)2 LeadingSpacing (com.xenoage.zong.musiclayout.spacing.LeadingSpacing)2 SimpleSpacing (com.xenoage.zong.musiclayout.spacing.SimpleSpacing)2 VoiceSpacing (com.xenoage.zong.musiclayout.spacing.VoiceSpacing)2