 
 
 void sendMidiNote() {
-  if(midiNoteToSend!=-1) {
-    if(midiNoteSendStart > 100) {
+  if (midiNoteToSend != -1) {
+    if (midiNoteSendStart > 100) {
       usbMIDI.sendNoteOff(midiNoteToSend, 0, midiChannel);
       midiNoteToSend = -1;
       startedMidiNoteSending = false;
-    } else if(!startedMidiNoteSending) {
+    } else if (!startedMidiNoteSending) {
       usbMIDI.sendNoteOn(midiNoteToSend, 99, midiChannel);
       startedMidiNoteSending = true;
-    }    
+    }
   }
 }
 

byte midiNoteToSend = -1;
elapsedMillis midiNoteSendStart = 0;
boolean startedMidiNoteSending = false;

void OnNoteOn(byte channel, byte note, byte velocity) {
  digitalWrite(ledPin, HIGH);

    case INIT_MODE:
      handleInitMode();
      break;
    case SONG_MODE:
      handleSongMode();
      break;
  }
}

void handleSongMode() {
  if (playing) {
    playButton.turnLedOn();
  } else {
    playButton.turnLedOff();
  }

  if (stopButton.isJustPressed()) {
    stopButton.turnLedOn();
  }

  if (stopButton.isJustReleased()) {
    midiNoteSendStart = 0;
    midiNoteToSend = STOP_MIDI_NOTE;
    stopButton.turnLedOff();
    changeMode(NORMAL_MODE);
  }

  sendMidiNote();
}

void changeMode(byte newMode) {
  mode = newMode;
  resetLeds();
  if (mode == NORMAL_MODE) {
    handleNormalMode(true);
  }
}

