Search in sources :

Example 1 with TraditionalKey

use of com.xenoage.zong.core.music.key.TraditionalKey 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 TraditionalKey

use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.

the class Base13a method getExpectedKeys.

default TraditionalKey[] getExpectedKeys() {
    TraditionalKey[] expectedKeys = new TraditionalKey[15 * 2];
    for (int fifths = -7; fifths <= 7; fifths++) {
        expectedKeys[(fifths + 7) * 2 + 0] = new TraditionalKey(fifths, Mode.Major);
        expectedKeys[(fifths + 7) * 2 + 1] = new TraditionalKey(fifths, Mode.Minor);
    }
    return expectedKeys;
}
Also used : TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey)

Example 3 with TraditionalKey

use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.

the class AttributesReader method readKey.

private Key readKey(MxlKey mxlKey) {
    if (mxlKey == null)
        return null;
    // read fifths. currently, only -7 to 7 is supported (clamp, if needed)
    int mxlFifths = INSTANCE.clamp(mxlKey.fifths, -7, 7);
    // write to column header (TODO: attribute "number" for single staves)
    Mode mode = getEnumValue(mxlKey.mode, Mode.values());
    Key key = new TraditionalKey(mxlFifths, mode);
    return key;
}
Also used : Mode(com.xenoage.zong.core.music.key.TraditionalKey.Mode) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key)

Example 4 with TraditionalKey

use of com.xenoage.zong.core.music.key.TraditionalKey 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)

Example 5 with TraditionalKey

use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.

the class MidiSequenceWriter method writeKey.

/**
 * Writes a MIDI key signature. Only {@link TraditionalKey} is supported.
 * @param track     the index of the track where to write the event
 * @param tick      the time of the event
 * @param key       The {@link Key} to write
 */
public void writeKey(int track, long tick, Key key) {
    if (key.getMusicElementType() == MusicElementType.TraditionalKey) {
        val tradKey = (TraditionalKey) key;
        byte fifths = (byte) tradKey.getFifths();
        // minor, or (everything else) major
        byte mode = (byte) (tradKey.getMode() == TraditionalKey.Mode.Minor ? 1 : 0);
        byte[] data = { fifths, mode };
        writeMetaMessage(track, tick, typeKey, data);
    }
}
Also used : lombok.val(lombok.val) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey)

Aggregations

TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)15 Clef (com.xenoage.zong.core.music.clef.Clef)7 Score (com.xenoage.zong.core.Score)6 Key (com.xenoage.zong.core.music.key.Key)5 Test (org.junit.Test)5 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)4 Fraction (com.xenoage.utils.math.Fraction)3 Rest (com.xenoage.zong.core.music.rest.Rest)3 Cursor (com.xenoage.zong.io.selection.Cursor)3 MxlMeasure (com.xenoage.zong.musicxml.types.partwise.MxlMeasure)3 MxlPart (com.xenoage.zong.musicxml.types.partwise.MxlPart)3 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Part (com.xenoage.zong.core.music.Part)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)2 MP (com.xenoage.zong.core.position.MP)2 ElementSpacing (com.xenoage.zong.musiclayout.spacing.ElementSpacing)2 SimpleSpacing (com.xenoage.zong.musiclayout.spacing.SimpleSpacing)2 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)2 MxlKey (com.xenoage.zong.musicxml.types.MxlKey)2