Search in sources :

Example 16 with TraditionalKey

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

the class CursorTest method write_MeasureElement_Test.

@Test
public void write_MeasureElement_Test() {
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mpe0, true);
    cursor.write(new Rest(fr(1, 4)));
    cursor.write(new Rest(fr(1, 4)));
    cursor.write(new Rest(fr(1, 4)));
    // write clef at 1/4
    Clef clef1 = new Clef(ClefType.clefBass);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef1);
    BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(1, clefs.size());
    assertEquals(beatE(clef1, fr(1, 4)), clefs.getFirst());
    // write clef at 2/4
    Clef clef2 = new Clef(ClefType.clefTreble);
    cursor.setMp(atElement(0, 0, 0, 2));
    cursor.write(clef2);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(beatE(clef1, fr(1, 4)), clefs.getFirst());
    assertEquals(beatE(clef2, fr(2, 4)), clefs.getElements().get(1));
    // overwrite clef at 1/4
    Clef clef3 = new Clef(ClefType.clefTreble);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(clef3);
    clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
    assertEquals(2, clefs.size());
    assertEquals(beatE(clef3, fr(1, 4)), clefs.getFirst());
    assertEquals(beatE(clef2, fr(2, 4)), clefs.getElements().get(1));
    // write key at 1/4
    Key key = new TraditionalKey(5, Mode.Major);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) key);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // write direction at 1/4
    Direction direction1 = new Dynamic(DynamicValue.ff);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction1);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write another direction at 1/4, which does not replace the first one
    Direction direction2 = new Coda();
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write((MeasureElement) direction2);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // now two directions
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    // write instrument change at 1/4
    InstrumentChange instrChange = new InstrumentChange(Instrument.defaultInstrument);
    cursor.setMp(atElement(0, 0, 0, 1));
    cursor.write(instrChange);
    // clefs must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getClefs().size());
    // key must still be there
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getPrivateKeys().size());
    // directions must still be there
    assertEquals(2, score.getMeasure(atMeasure(0, 0)).getDirections().size());
    assertEquals(1, score.getMeasure(atMeasure(0, 0)).getInstrumentChanges().size());
    // check all added elements
    BeatEList<MeasureElement> all = score.getMeasure(atMeasure(0, 0)).getMeasureElements();
    assertEquals(6, all.size());
    assertEquals(clef3, all.getElements().get(0).element);
    assertEquals(key, all.getElements().get(1).element);
    assertEquals(direction1, all.getElements().get(2).element);
    assertEquals(direction2, all.getElements().get(3).element);
    assertEquals(instrChange, all.getElements().get(4).element);
    assertEquals(clef2, all.getElements().get(5).element);
}
Also used : InstrumentChange(com.xenoage.zong.core.music.InstrumentChange) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Coda(com.xenoage.zong.core.music.direction.Coda) Clef(com.xenoage.zong.core.music.clef.Clef) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Direction(com.xenoage.zong.core.music.direction.Direction) MeasureElement(com.xenoage.zong.core.music.MeasureElement) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Key(com.xenoage.zong.core.music.key.Key) Test(org.junit.Test)

Example 17 with TraditionalKey

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

the class Test13a method test.

// @ToDo("Zong! supports only -7 to +7, starting in measure 9, ending in measure 38")
@Test
public void test() {
    Score score = getScore();
    TraditionalKey[] expectedKeys = getExpectedKeys();
    int iKey = 0;
    for (int i = 8; i <= 37; i++) {
        ColumnHeader column = score.getColumnHeader(i);
        TraditionalKey key = (TraditionalKey) column.getKeys().get(_0);
        assertEquals("measure " + i, expectedKeys[iKey].getFifths(), key.getFifths());
        assertEquals("measure " + i, expectedKeys[iKey].getMode(), key.getMode());
        iKey++;
    }
}
Also used : Score(com.xenoage.zong.core.Score) ColumnHeader(com.xenoage.zong.core.header.ColumnHeader) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Test(org.junit.Test)

Aggregations

TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)17 Clef (com.xenoage.zong.core.music.clef.Clef)8 Score (com.xenoage.zong.core.Score)7 Key (com.xenoage.zong.core.music.key.Key)6 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)5 Test (org.junit.Test)5 Fraction (com.xenoage.utils.math.Fraction)4 Rest (com.xenoage.zong.core.music.rest.Rest)4 Part (com.xenoage.zong.core.music.Part)3 Chord (com.xenoage.zong.core.music.chord.Chord)3 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)3 Cursor (com.xenoage.zong.io.selection.Cursor)3 ColumnElementWrite (com.xenoage.zong.commands.core.music.ColumnElementWrite)2 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)2 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)2 Instrument (com.xenoage.zong.core.instrument.Instrument)2 StavesRange (com.xenoage.zong.core.music.group.StavesRange)2 MxlAttributes (com.xenoage.zong.musicxml.types.MxlAttributes)2 MxlKey (com.xenoage.zong.musicxml.types.MxlKey)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2