 #include <SerialFlash.h>
 
 // GUItool: begin automatically generated code
-AudioSynthWaveformSine   sine1;          //xy=220,60
-AudioOutputI2S           i2s1;           //xy=420,64
-AudioConnection          patchCord1(sine1, 0, i2s1, 0);
-AudioConnection          patchCord2(sine1, 0, i2s1, 1);
-AudioControlSGTL5000     audioShield;
+AudioSynthWaveformSine   sine1;          //xy=339,52
+AudioSynthWaveformSine   sine2;          //xy=339,88
+AudioSynthWaveformSine   sine3;          //xy=339,124
+AudioSynthWaveformSine   sine4;          //xy=340,174
+AudioSynthWaveformSine   sine5;          //xy=340,209
+AudioSynthWaveformSine   sine6;          //xy=340,244
+AudioSynthWaveformSine   sine7;          //xy=340,291
+AudioSynthWaveformSine   sine8;          //xy=341,327
+AudioSynthWaveformSine   sine9;         //xy=341,412
+AudioSynthWaveformSine   sine10;         //xy=341,483
+AudioSynthWaveformSine   sine11;          //xy=342,363
+AudioSynthWaveformSine   sine12;         //xy=342,447
+AudioMixer4              mixer1;         //xy=459,325
+AudioMixer4              mixer2;         //xy=461,90
+AudioMixer4              mixer3;         //xy=461,208
+AudioMixer4              mixer4;         //xy=461,444
+AudioEffectEnvelope      envelope1;      //xy=591,90
+AudioEffectEnvelope      envelope2;      //xy=591,208
+AudioEffectEnvelope      envelope3;      //xy=593,326
+AudioEffectEnvelope      envelope4;      //xy=596,444
+AudioMixer4              mixer5;         //xy=759,274
+AudioOutputI2S           i2s1;           //xy=887,273
+AudioConnection          patchCord1(sine1, 0, mixer1, 0);
+AudioConnection          patchCord2(sine2, 0, mixer1, 1);
+AudioConnection          patchCord3(sine3, 0, mixer1, 2);
+AudioConnection          patchCord4(sine4, 0, mixer2, 0);
+AudioConnection          patchCord5(sine5, 0, mixer2, 1);
+AudioConnection          patchCord6(sine6, 0, mixer2, 2);
+AudioConnection          patchCord7(sine7, 0, mixer3, 0);
+AudioConnection          patchCord8(sine8, 0, mixer3, 1);
+AudioConnection          patchCord9(sine9, 0, mixer3, 2);
+AudioConnection          patchCord10(sine10, 0, mixer4, 0);
+AudioConnection          patchCord11(sine11, 0, mixer4, 1);
+AudioConnection          patchCord12(sine12, 0, mixer4, 2);
+AudioConnection          patchCord13(mixer1, envelope1);
+AudioConnection          patchCord14(mixer2, envelope2);
+AudioConnection          patchCord15(mixer3, envelope3);
+AudioConnection          patchCord16(mixer4, envelope4);
+AudioConnection          patchCord17(envelope1, 0, mixer5, 0);
+AudioConnection          patchCord18(envelope2, 0, mixer5, 1);
+AudioConnection          patchCord19(envelope3, 0, mixer5, 2);
+AudioConnection          patchCord20(envelope4, 0, mixer5, 3);
+AudioConnection          patchCord21(mixer5, 0, i2s1, 0);
+AudioConnection          patchCord22(mixer5, 0, i2s1, 1);
+AudioControlSGTL5000     audioShield;     //xy=132,494
 // GUItool: end automatically generated code
 
 void setup() {

  Serial.print(velocity, DEC);
  Serial.println();

  sine1.frequency(note2freq(note));
  sine1.amplitude(0.5);
}

void OnNoteOff(byte channel, byte note, byte velocity) {


  AudioMemory(8);
  audioShield.enable();
  audioShield.volume(0.5);

  initVoice(1);
  initVoice(2);
  initVoice(3);
  initVoice(4);

  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn);
  usbMIDI.setHandleVelocityChange(OnVelocityChange);
