 #include <SPI.h>
 #include <OPL2.h>
 #include <midi_instruments.h>
+
+#define CONTROL_VOLUME          7
+#define CONTROL_ALL_SOUND_OFF 120
+#define CONTROL_RESET_ALL     121
+#define CONTROL_ALL_NOTES_OFF 123
 
 #define MIDI_CHANNELS 16
 #define OPL2_CHANNELS 9

void onNoteOff(byte channel, byte note, byte velocity) {
  for (byte i = 0; i < OPL2_CHANNELS; i ++) {
    if (channelMap[i].midiChannel == channel && channelMap[i].midiNote == note) {
      channelMap[i].midiChannel = 255;
      channelMap[i].midiNote    = 255;
      opl2.setKeyOn(i, false);
      break;
    }
  }
}


void onProgramChange(byte channel, byte program) {
  programMap[channel] = program;
}





  // Get an available OPL2 channel and setup instrument parameters.
  byte i = getFreeChannel(channel);
  opl2.setInstrument(i, instruments[programMap[channel]]);
  channelMap[i].midiChannel  = channel;
  channelMap[i].midiNote     = note;
  channelMap[i].midiVelocity = round(velocity / 127.0);
  channelMap[i].op1Level     = round((63 - opl2.getVolume(i, OPERATOR1)) / 63.0);
  channelMap[i].op2Level     = round((63 - opl2.getVolume(i, OPERATOR2)) / 63.0);

  // Set operator output levels based on note velocity.
  setOpl2ChannelVolume(i, channel);

  // Calculate octave and note number and play note!
  note = max(24, min(note, 119));
