Austin Suszek / Mbed 2 deprecated MIDISynthesizer

Dependencies:   mbed USBDevice PinDetect

main.cpp

Committer:
asuszek
Date:
2016-04-10
Revision:
2:e21bd39bdf46
Parent:
0:cad8dafb22be
Child:
6:688698f814c0

File content as of revision 2:e21bd39bdf46:

/* Karplus Strong MIDI synthesizer.
 *
 * @author Austin Suszek
 * @author Nick Delfino
 */

#include "Constants.h"
#include "mbed.h"
#include "USBMIDI.h"

Serial pc(USBTX, USBRX);
USBMIDI midi;

void midiMessageReceived(MIDIMessage message);

int main() { 
    // Attach the function to handle all incoming MIDI events.
    midi.attach(midiMessageReceived); 
        
    while (1) {}
}

/*
 * The handler for all incoming MIDI messages.
 */
void midiMessageReceived(MIDIMessage message) {
    #ifdef DEBUG
    printf("Message Received\r\n");
    #endif
    
    switch (message.type()) {
        case MIDIMessage::NoteOnType:
            #ifdef DEBUG
            printf("\tType: Note On\r\n");
            printf("\tNote: %d\r\n", message.key());
            #endif
            break;
        case MIDIMessage::NoteOffType:
            #ifdef DEBUG
            printf("\tType: Note Off\r\n");
            #endif
            break;
        default:
            // no-op
            break;
    }
}