// skip grace notes
if (note.getFirstChildElement("grace") != null)
return;
Element voice = note.getFirstChildElement("voice");
if (voice != null)
parseVoice(p, Integer.parseInt(voice.getValue()));
Element pitch = note.getFirstChildElement("pitch");
if (pitch != null)
{ String sStep = pitch.getFirstChildElement("step").getValue();
switch(sStep.charAt(0))
{ case 'C': noteNumber = 0; break;
case 'D': noteNumber = 2; break;
case 'E': noteNumber = 4; break;
case 'F': noteNumber = 5; break;
case 'G': noteNumber = 7; break;
case 'A': noteNumber = 9; break;
case 'B': noteNumber = 11; break;
}
Element Alter = pitch.getFirstChildElement("alter");
if (Alter != null)
{ String sAlter = Alter.getValue();
if (sAlter != null)
{ noteNumber += Integer.parseInt(sAlter);
if (noteNumber > 11)
noteNumber = 0;
else if (noteNumber < 0)
noteNumber = 11;
}
}
Element Octave = pitch.getFirstChildElement("octave");
if (Octave != null)
{ String sOctave = Octave.getValue();
if (sOctave != null)
octaveNumber = Byte.parseByte(sOctave);
}
// Compute the actual note number, based on octave and note
int intNoteNumber = (octaveNumber * 12) + noteNumber;
if ( intNoteNumber > 127) {
throw new JFugueException(JFugueException.NOTE_OCTAVE_EXC,"", Integer.toString(intNoteNumber));
}
noteNumber = (byte)intNoteNumber;
}
else
isRest = true;
// duration
// Element type = note.getFirstChildElement("type");
// if (type == null)
{ // get duration from duration element rather than type element
Element element_duration = note.getFirstChildElement("duration");
decimalDuration = (element_duration == null)
? beats * divisions
: Double.parseDouble(element_duration.getValue()) / (beats * divisions);
}
/* else
{ String sDuration = type.getValue();
if (sDuration.compareToIgnoreCase("whole") == 0)
durationNumber = 1;
else if (sDuration.compareToIgnoreCase("half") == 0
durationNumber = 2;
else if (sDuration.compareToIgnoreCase("quarter") == 0)
durationNumber = 4;
else if (sDuration.compareToIgnoreCase("eighth") == 0)
durationNumber = 8;
else if (sDuration.compareToIgnoreCase("16th") == 0)
durationNumber = 16;
else if (sDuration.compareToIgnoreCase("32nd") == 0)
durationNumber = 32;
else if (sDuration.compareToIgnoreCase("64th") == 0)
durationNumber = 64;
else
throw new JFugueException(JFugueException.NOTE_DURATION_EXC, "", sDuration);
decimalDuration = 1.0 / durationNumber;
Element element_dot = note.getFirstChildElement("dot");
if (element_dot != null)
decimalDuration *= 1.5;
}
*/
// Tempo is in PPQ (Pulses Per Quarter). Turn that into
// "PPW", then multiply that by durationNumber for WHQITXN notes
double PPW = (double)this.getTempo() * 4.0; // 4 quarter notes in a whole note
long duration = (long)(PPW * decimalDuration);
Element notations = note.getFirstChildElement("notations");
if (notations != null)
{ // ties
Element tied = notations.getFirstChildElement("tied");
if (tied != null)
{ Attribute tiedType = tied.getAttribute("type");
{ String sTiedType = tiedType.getValue();
if (sTiedType.compareToIgnoreCase("start") == 0)
isStartOfTie = true;
else if (sTiedType.compareToIgnoreCase("end") == 0)
isEndOfTie = true;
}
}
// velocity
Element dynamics = notations.getFirstChildElement("dynamics");
if (dynamics != null)
{ Node dynamic = dynamics.getChild(0);
if (dynamic != null)
{ for (int x = 0; x < this.volumes.length; ++x)
{ if (dynamic.getValue().compareToIgnoreCase(this.volumes[x]) == 0)
{ this.curVelocity = (byte)(((this.maxVelocity - this.minVelocity)
/ (this.volumes.length - 1)) * x);
}
}
}
}
}
byte attackVelocity = this.curVelocity;
byte decayVelocity = this.curVelocity;
// Set up the note
if (isRest)
{ newNote.setRest(true);
newNote.setDuration(duration);
newNote.setAttackVelocity( (byte)0 ); // turn off sound for rest notes
newNote.setDecayVelocity( (byte)0 );
}
else
{ newNote.setValue(noteNumber);
newNote.setDuration(duration);
newNote.setStartOfTie(isStartOfTie);
newNote.setEndOfTie(isEndOfTie);
newNote.setAttackVelocity(attackVelocity);
newNote.setDecayVelocity(decayVelocity);
}
// ToDo - SEQUENTIAL
Element element_chord = note.getFirstChildElement("chord");
newNote.setType( (element_chord == null) ? Note.FIRST : Note.PARALLEL);
/* attempt to adjust for rounding errors in non-supported durations
if (newNote.getType() == Note.FIRST)
{ if ((totalMeasurePct + decimalDuration) > 1.)