pitchToMidiPitch function

int pitchToMidiPitch(
  1. String step,
  2. double alter,
  3. String octave
)

Convert MusicXML pitch representation to MIDI pitch number.

Implementation

int pitchToMidiPitch(String step, double alter, String octave) {
  var pitchClass = 0;
  switch (step) {
    case 'C':
      pitchClass = 0;
      break;
    case 'D':
      pitchClass = 2;
      break;
    case 'E':
      pitchClass = 4;
      break;
    case 'F':
      pitchClass = 5;
      break;
    case 'G':
      pitchClass = 7;
      break;
    case 'A':
      pitchClass = 9;
      break;
    case 'B':
      pitchClass = 11;
      break;
    default:
      // Raise exception for unknown step (ex: 'Q')
      throw XmlParserException('Unable to parse pitch step $step');
  }

  pitchClass = (pitchClass + alter.toInt()) % 12;
  return (12 + pitchClass) + (int.parse(octave) * 12);
}