parsePartElementInstruments(p, partHeaders[x].midi_instruments);
}
}
}
Elements measures = part.getChildElements("measure");
for (int m = 0; m < measures.size(); ++m)
{ Element measure = measures.get(m);
Element attributes = measure.getFirstChildElement("attributes");
if (attributes != null)
{ // default key = Cmaj
byte key = 0, scale = 0; // scale 0 = minor, 1 = major
Element attr = attributes.getFirstChildElement("key");
if (attr != null)
{ Element eKey = attr.getFirstChildElement("fifths");
if (eKey != null)
key = Byte.parseByte(eKey.getValue());
Element eMode = attr.getFirstChildElement("mode");
if (eMode != null)
{ String mode = eMode.getValue();
if (mode.compareToIgnoreCase("major") == 0)
scale = 0;
else if (mode.compareToIgnoreCase("minor") == 0)
scale = 1;
else
throw new JFugueException(JFugueException.KEYSIG_EXC, mode);
}
}
else
scale = 0; // default = major
fireKeySignatureEvent(new KeySignature(key, scale));
// divisions and beats used to calculate duration when note type not present
Element element_divisions = attributes.getFirstChildElement("divisions");
if (element_divisions != null)
this.divisions = Byte.valueOf(element_divisions.getValue());
Element element_time = attributes.getFirstChildElement("time");
if (element_time != null)
{ Element element_beats = element_time.getFirstChildElement("beats");
if (element_beats != null)
this.beats = Byte.valueOf(element_beats.getValue());
}
}
// tempo
Element direction = measure.getFirstChildElement("direction");
if (direction != null)
{ Element directionType = direction.getFirstChildElement("direction-type");
if (directionType != null)
{ Element metronome = directionType.getFirstChildElement("metronome");
if (metronome != null)
{ Element beatUnit = metronome.getFirstChildElement("beat-unit");
String sBeatUnit = beatUnit.getValue();
if (sBeatUnit.compareToIgnoreCase("quarter") != 0)
throw new JFugueException(JFugueException.BEAT_UNIT_MUST_BE_QUARTER, sBeatUnit);
Element bpm = metronome.getFirstChildElement("per-minute");
if (bpm != null)
{ this.setTempo(BPMtoPPM(Float.parseFloat(bpm.getValue())));
fireTempoEvent(new Tempo(this.getTempo()));
}
}
}
}
// notes
Elements notes = measure.getChildElements("note");
// totalMeasurePct = 0.f;
for (int n = 0; n < notes.size(); ++n)
parseNote(p, notes.get(n));
/* attempt to adjust for rounding errors with un-supported durations
// if the total length of all the notes doesn't equal a full measure,
// add a pad rest
float minDif = (1.f / (beats * divisions));
double padDur = (1. - totalMeasurePct);