use of com.xenoage.zong.core.music.InstrumentChange 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(Companion.fr(1, 4)));
cursor.write(new Rest(Companion.fr(1, 4)));
cursor.write(new Rest(Companion.fr(1, 4)));
// write clef at 1/4
Clef clef1 = new Clef(ClefType.Companion.getClefBass());
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write(clef1);
BeatEList<Clef> clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(1, clefs.size());
assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
// write clef at 2/4
Clef clef2 = new Clef(ClefType.Companion.getClefTreble());
cursor.setMp(atElement(0, 0, 0, 2));
cursor.write(clef2);
clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(2, clefs.size());
assertEquals(Companion.beatE(clef1, Companion.fr(1, 4)), clefs.getFirst());
assertEquals(Companion.beatE(clef2, Companion.fr(2, 4)), clefs.getElements().get(1));
// overwrite clef at 1/4
Clef clef3 = new Clef(ClefType.Companion.getClefTreble());
cursor.setMp(atElement(0, 0, 0, 1));
cursor.write(clef3);
clefs = score.getMeasure(atMeasure(0, 0)).getClefs();
assertEquals(2, clefs.size());
assertEquals(Companion.beatE(clef3, Companion.fr(1, 4)), clefs.getFirst());
assertEquals(Companion.beatE(clef2, Companion.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.Companion.getDefaultInstrument());
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).getElement());
assertEquals(key, all.getElements().get(1).getElement());
assertEquals(direction1, all.getElements().get(2).getElement());
assertEquals(direction2, all.getElements().get(3).getElement());
assertEquals(instrChange, all.getElements().get(4).getElement());
assertEquals(clef2, all.getElements().get(5).getElement());
}
use of com.xenoage.zong.core.music.InstrumentChange 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);
}
}
use of com.xenoage.zong.core.music.InstrumentChange in project Zong by Xenoage.
the class Test72c method testTransposes.
@Test
public void testTransposes() {
// start instrument
Part part = score.getStavesList().getParts().get(0);
PitchedInstrument instrument = (PitchedInstrument) part.getFirstInstrument();
assertEquals(expectedTransposes[0], instrument.getTranspose());
// instrument change in measure 1
InstrumentChange instrChange = score.getMeasure(MP.atMeasure(0, 1)).getInstrumentChanges().get(Companion.get_0());
instrument = (PitchedInstrument) instrChange.getInstrument();
assertEquals(expectedTransposes[1], instrument.getTranspose());
}
Aggregations