@SuppressWarnings("unchecked")
public static void render(Score score, OutputStream out) {
double normalizedMeasureSize = 1d * score.getNumerator() * 4 / score.getDenominator();
ScorePartwise root = new ScorePartwise();
root.setMovementTitle(score.getTitle());
int idx = 1;
for (Part part : score.getPartArray()) {
ScorePartDefinition def = new ScorePartDefinition();
def.setPartName(instrumentNames.get(part.getInstrument()));
def.setId("P" + idx);
root.getPartDefinitionList().add(def);
ScorePart xmlPart = new ScorePart();
xmlPart.setId(def.getId());
double currentMeasureSize = 0;
List<Note> partNotes = new ArrayList<Note>();
for (Phrase phrase : part.getPhraseArray()) {
partNotes.addAll(phrase.getNoteList());
}
Iterator<Note> noteIterator = partNotes.iterator();
int measureNumber = 1;
Measure currentMeasure = createMeasure(score, measureNumber++);
while (noteIterator.hasNext()) {
Note note = noteIterator.next();
NoteElement xmlNote = new NoteElement();
int length = (int) (getClosestLength(note.getRhythmValue()) * 10000);
switch(length) {
case (int) (THIRTYSECOND_NOTE * 10000): xmlNote.setType("32nd"); break;
case (int) (SIXTEENTH_NOTE * 10000): xmlNote.setType("16th"); break;
case (int) (EIGHTH_NOTE * 10000): xmlNote.setType("eighth"); break;
case (int) (QUARTER_NOTE * 10000): xmlNote.setType("quarter"); break;
case (int) (DOTTED_QUARTER_NOTE * 10000): xmlNote.setType("quarter"); xmlNote.setDot(""); break;
case (int) (HALF_NOTE * 10000): xmlNote.setType("half"); break;
case (int) (WHOLE_NOTE * 10000): xmlNote.setType("whole"); break;
default: xmlNote.setType("/" + (length / 10000d));
}
xmlNote.setDuration((int) (note.getRhythmValue() * 2));
xmlNote.setVoice(idx);
if (!note.isRest()) {
xmlNote.setPitch(new Pitch());
int pitch = note.getPitch() % 12;
String sPitch = NOTES[pitch];
int octave = note.getPitch() / 12 - 1;
xmlNote.getPitch().setOctave(octave);
if (sPitch.length() > 1) {
xmlNote.getPitch().setAlter((byte) (sPitch.contains("#") ? 1 : -1));
sPitch = sPitch.substring(0, 1);
}
xmlNote.getPitch().setStep(sPitch);
} else {
xmlNote.setRest(new RestElement());
}
currentMeasure.getNotes().add(xmlNote);
currentMeasureSize += note.getRhythmValue();
if (currentMeasureSize >= normalizedMeasureSize) {
currentMeasureSize = 0;
xmlPart.getMeasures().add(currentMeasure);
currentMeasure = createMeasure(score, measureNumber++);
}
}
root.getPartList().add(xmlPart);
idx++;
}
try {
//XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(out, (String) marshaller.getProperty(Marshaller.JAXB_ENCODING));