Search in sources :

Example 16 with TimeSignature

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

Example 17 with TimeSignature

use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.

the class ScoreTest method getMeasureBeatsTest.

@Test
public void getMeasureBeatsTest() {
    Score score = ScoreFactory.create1Staff4Measures();
    // first measure: no time, 1/4 used
    score.getVoice(atVoice(0, 0, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // second measure: 3/4 time, 2/4 used
    score.getColumnHeader(1).setTime(new TimeSignature(TimeType.Companion.getTime_3_4()));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
    score.getVoice(atVoice(0, 1, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // third measure: still 3/4 time, 1/4 used
    score.getVoice(atVoice(0, 2, 0)).addElement(new Rest(Companion.fr(1, 4)));
    // check
    assertEquals(Companion.fr(1, 4), score.getMeasureBeats(0));
    assertEquals(Companion.fr(3, 4), score.getMeasureBeats(1));
    assertEquals(Companion.fr(3, 4), score.getMeasureBeats(2));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 18 with TimeSignature

use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.

the class DynamicsFinderTest method getAdvancedScore.

/**
 * See {@link #testAdvanced()}.
 */
private Score getAdvancedScore() {
    Score score = new Score();
    Wedge w;
    new PartAdd(score, new Part("", null, 2, null), 0, null).execute();
    new MeasureAdd(score, 5).execute();
    // time signature and repeats
    new ColumnElementWrite(new TimeSignature(TimeType.Companion.getTime_4_4()), score.getColumnHeader(0), null, null).execute();
    new ColumnElementWrite(Companion.barlineForwardRepeat(Regular), score.getColumnHeader(1), null, MeasureSide.Left).execute();
    new ColumnElementWrite(Companion.barlineBackwardRepeat(Regular, 1), score.getColumnHeader(2), null, MeasureSide.Right).execute();
    // staff 0
    new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(0, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(f), score.getMeasure(atMeasure(0, 3)), Companion.get_1$2()).execute();
    new MeasureElementWrite(w = new Wedge(Crescendo), score.getMeasure(atMeasure(0, 3)), Companion.get_3$4()).execute();
    new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(0, 4)), Companion.get_1$4()).execute();
    new MeasureElementWrite(new Dynamic(pp), score.getMeasure(atMeasure(0, 4)), Companion.get_1$2()).execute();
    // voice 0
    val cursor = new Cursor(score, mp0, true);
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    // voice 1
    cursor.setMp(atElement(0, 0, 1, 0));
    cursor.write(new Rest(Companion.get_1$2()));
    val chord = chord(Companion.pi(0, 4), Companion.get_1$2());
    chord.addDirection(new Dynamic(mf));
    cursor.write(chord);
    cursor.write(new Rest(Companion.get_1()));
    cursor.write(new Rest(Companion.get_1()));
    cursor.setMp(atElement(0, 4, 1, 0));
    cursor.write(new Rest(Companion.get_1()));
    // staff 1
    new MeasureElementWrite(new Dynamic(ff), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(w = new Wedge(Diminuendo), score.getMeasure(atMeasure(1, 0)), Companion.get_0()).execute();
    new MeasureElementWrite(new WedgeEnd(w), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(mp), score.getMeasure(atMeasure(1, 2)), Companion.get_0()).execute();
    new MeasureElementWrite(new Dynamic(p), score.getMeasure(atMeasure(1, 3)), Companion.get_0()).execute();
    return score;
}
Also used : lombok.val(lombok.val) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) ColumnElementWrite(com.xenoage.zong.commands.core.music.ColumnElementWrite) Cursor(com.xenoage.zong.io.selection.Cursor) Wedge(com.xenoage.zong.core.music.direction.Wedge) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) MeasureAdd(com.xenoage.zong.commands.core.music.MeasureAdd) Rest(com.xenoage.zong.core.music.rest.Rest) Part(com.xenoage.zong.core.music.Part) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) MeasureElementWrite(com.xenoage.zong.commands.core.music.MeasureElementWrite) WedgeEnd(com.xenoage.zong.core.music.direction.WedgeEnd)

Example 19 with TimeSignature

use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.

the class AttributesReader method readToContext.

/**
 * Reads the given attributes element.
 */
public void readToContext(Context context) {
    // divisions
    Integer divisions = mxlAttributes.getDivisions();
    if (divisions != null)
        context.setDivisions(divisions);
    // key signature
    Key key = readKey(mxlAttributes.getKey());
    if (key != null)
        context.writeColumnElement(key);
    // time signature
    TimeSignature time = readTime(mxlAttributes.getTime());
    if (// TODO: attribute "number" for single staves
    time != null)
        context.writeColumnElement(time);
    // clefs
    if (mxlAttributes.getClefs() != null) {
        for (MxlClef mxlClef : mxlAttributes.getClefs()) {
            ClefReader clefReader = new ClefReader(mxlClef);
            Clef clef = clefReader.read();
            int staff = clefReader.readStaff();
            if (clef != null)
                context.writeMeasureElement(clef, staff);
        }
    }
    // transposition changes - TODO: clean solution for instrument changes
    PitchedInstrument instrument = readTransposedInstrument(mxlAttributes.getTranspose());
    if (instrument != null) {
        // write to all staves of this part
        for (int staff = 0; staff < context.getPartStaffIndices().getCount(); staff++) context.writeMeasureElement(new InstrumentChange(instrument), staff);
    }
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) PitchedInstrument(com.xenoage.zong.core.instrument.PitchedInstrument) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 20 with TimeSignature

use of com.xenoage.zong.core.music.time.TimeSignature in project Zong by Xenoage.

the class AttributesReader method readTime.

private TimeSignature readTime(MxlTime mxlTime) {
    if (mxlTime == null)
        return null;
    TimeSignature time = null;
    MxlTimeContentType type = mxlTime.getContent().getTimeContentType();
    if (type == MxlTimeContentType.SenzaMisura) {
        // senza misura
        time = new TimeSignature(Companion.getTimeSenzaMisura());
    } else if (type == MxlTimeContentType.NormalTime) {
        // normal time
        MxlNormalTime mxlNormalTime = (MxlNormalTime) mxlTime.getContent();
        // common, cut or fractional?
        if (mxlTime.getSymbol() == MxlTimeSymbol.Cut)
            time = new TimeSignature(TimeType.Companion.getTimeAllaBreve());
        else if (mxlTime.getSymbol() == MxlTimeSymbol.Common)
            time = new TimeSignature(TimeType.Companion.getTimeCommon());
        else
            // otherwise, we currently support only normal fractional time signatures
            time = new TimeSignature(Companion.timeType(mxlNormalTime.getBeats(), mxlNormalTime.getBeatType()));
    }
    return time;
}
Also used : MxlTimeContentType(com.xenoage.zong.musicxml.types.choice.MxlTimeContent.MxlTimeContentType) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Aggregations

TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)20 Score (com.xenoage.zong.core.Score)14 Cursor (com.xenoage.zong.io.selection.Cursor)12 Rest (com.xenoage.zong.core.music.rest.Rest)9 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)5 Part (com.xenoage.zong.core.music.Part)4 Clef (com.xenoage.zong.core.music.clef.Clef)4 Test (org.junit.Test)4 Fraction (com.xenoage.utils.math.Fraction)3 MeasureElementWrite (com.xenoage.zong.commands.core.music.MeasureElementWrite)3 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)3 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)3 lombok.val (lombok.val)3 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 MeasureAdd (com.xenoage.zong.commands.core.music.MeasureAdd)2 Pitch (com.xenoage.zong.core.music.Pitch)2 Staff (com.xenoage.zong.core.music.Staff)2 Voice (com.xenoage.zong.core.music.Voice)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 FontInfo (com.xenoage.utils.font.FontInfo)1