use of com.xenoage.zong.musicxml.types.MxlAttributes in project Zong by Xenoage.
the class MeasureReader method readToContext.
/**
* Reads the given measure element.
*/
public static void readToContext(MxlMeasure mxlMeasure, int measureIndex, Context context) {
// begin a new measure
context.beginNewMeasure(measureIndex);
// list all elements
List<MxlMusicDataContent> content = mxlMeasure.getMusicData().getContent();
for (int i = 0; i < content.size(); i++) {
// i may be modified within this loop
MxlMusicDataContent mxlMDC = content.get(i);
switch(mxlMDC.getMusicDataContentType()) {
case Note:
{
MxlNote mxlNote = ((MxlNote) mxlMDC);
// when it is a chord, ignore it, because we did already read it
if (mxlNote.getContent().getFullNote().isChord()) {
continue;
}
// instrument change?
MxlInstrument mxlInstrument = mxlNote.getInstrument();
if (mxlInstrument != null) {
String instrumentID = mxlInstrument.getId();
if (context.getInstrumentID() == null || !context.getInstrumentID().equals(instrumentID)) {
// instrument change detected!
context.writeInstrumentChange(instrumentID);
}
}
// collect all following notes which have a chord-element
// inbetween there may be direction elements, so we collect the
// notes until the first non-chord or non-direction element and after
// that go on at the current position + 1
List<MxlNote> mxlNotes = alist(mxlNote);
for (int i2 = i + 1; i2 < content.size(); i2++) {
MxlMusicDataContent mxlMDC2 = content.get(i2);
boolean goOn = false;
if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Note) {
MxlNote mxlNote2 = (MxlNote) mxlMDC2;
if (mxlNote2.getContent().getFullNote().isChord()) {
mxlNotes.add(mxlNote2);
goOn = true;
}
} else if (mxlMDC2.getMusicDataContentType() == MxlMusicDataContentType.Direction) {
goOn = true;
}
if (!goOn)
break;
}
new ChordReader(mxlNotes).readToContext(context);
break;
}
case Attributes:
new AttributesReader((MxlAttributes) mxlMDC).readToContext(context);
break;
case Backup:
readBackupToContext((MxlBackup) mxlMDC, context);
break;
case Forward:
readForwardToContext((MxlForward) mxlMDC, context);
break;
case Print:
new PrintReader((MxlPrint) mxlMDC).readToContext(context);
break;
case Direction:
new DirectionReader((MxlDirection) mxlMDC).readToContext(context);
break;
case Barline:
new BarlineReader((MxlBarline) mxlMDC).readToContext(context);
break;
}
}
}
use of com.xenoage.zong.musicxml.types.MxlAttributes in project Zong by Xenoage.
the class Test11a method test.
@Test
public void test() {
MxlPart part = getFirstPart();
int iTime = 0;
for (int i = 0; i < part.getMeasures().size(); i++) {
MxlMeasure measure = part.getMeasures().get(i);
for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
if (data.getMusicDataContentType() == MxlMusicDataContentType.Attributes) {
// check type
MxlAttributes attr = (MxlAttributes) data;
MxlNormalTime mxlTime = (MxlNormalTime) attr.getTime().getContent();
TimeType expectedTime = expectedTimes[iTime++];
assertEquals("time " + iTime, expectedTime.getNumerator(), mxlTime.getBeats());
assertEquals("time " + iTime, expectedTime.getDenominator(), mxlTime.getBeatType());
if (i == 0)
// TODO: bug in MusicXML file, should be "Cut"
assertEquals("time " + iTime, MxlTimeSymbol.Common, attr.getTime().getSymbol());
else if (i == 1)
assertEquals("time " + iTime, MxlTimeSymbol.Common, attr.getTime().getSymbol());
else
// = Normal
assertNull("time " + iTime, attr.getTime().getSymbol());
// no more time signature in this measure
break;
}
}
}
assertEquals("not all times found", expectedTimes.length, iTime);
}
use of com.xenoage.zong.musicxml.types.MxlAttributes 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() {
MxlPart part = getFirstPart();
TraditionalKey[] expectedKeys = getExpectedKeys();
int iKey = 0;
for (int i = 8; i <= 37; i++) {
MxlMeasure measure = part.getMeasures().get(i);
for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
if (data.getMusicDataContentType() == MxlMusicDataContentType.Attributes) {
// check type
MxlAttributes attr = (MxlAttributes) data;
MxlKey key = attr.getKey();
assertEquals(expectedKeys[iKey].getFifths(), key.getFifths());
assertEquals(expectedKeys[iKey].getMode(), getEnumValue("" + key.getMode(), Mode.values()));
iKey++;
}
}
}
}
use of com.xenoage.zong.musicxml.types.MxlAttributes in project Zong by Xenoage.
the class Test13b method test.
@Test
public void test() {
TraditionalKey[] expectedKeys = getExpectedKeys();
MxlPart part = getFirstPart();
int iKey = 0;
for (int i = 0; i <= 2; i++) {
MxlMeasure measure = part.getMeasures().get(i);
for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
if (data.getMusicDataContentType() == MxlMusicDataContentType.Attributes) {
// check type
MxlAttributes attr = (MxlAttributes) data;
MxlKey key = attr.getKey();
assertEquals(expectedKeys[iKey].getFifths(), key.getFifths());
assertEquals(expectedKeys[iKey].getMode(), getEnumValue("" + key.getMode(), Mode.values()));
iKey++;
if (iKey >= expectedKeys.length)
break;
}
}
}
assertEquals("not all keys found", expectedKeys.length, iKey);
}
Aggregations