Example program for USBHostMIDI http://mbed.org/users/kshoji/code/USBHostMIDI/

Dependencies:   USBHostMIDI mbed

USB MIDI event handling examples for this library.

http://mbed.org/users/kshoji/code/USBHostMIDI/

Files at this revision

API Documentation at this revision

Comitter:
kshoji
Date:
Thu Dec 05 09:45:08 2013 +0000
Child:
1:01305cc0e2a2
Commit message:
wrote example code.

Changed in this revision

USBHostMIDI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHostMIDI.lib	Thu Dec 05 09:45:08 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/kshoji/code/USBHostMIDI/#bf09452b8f26
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 05 09:45:08 2013 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+#include "USBHostMIDI.h"
+ 
+void noteOn(unsigned char channel, unsigned char note, unsigned char velocity) {
+    printf("note on channel: %d, note: %d, velocity: %d\r\n", channel, note, velocity);
+}
+
+void noteOff(unsigned char channel, unsigned char note, unsigned char velocity) {
+    printf("note off channel: %d, note: %d, velocity: %d\r\n", channel, note, velocity);
+}
+
+void controlChange(unsigned char channel, unsigned char key, unsigned char value) {
+    printf("control change channel: %d, key: %d, value: %d\r\n", channel, key, value);
+}
+
+void programChange(unsigned char channel, unsigned char program) {
+    printf("progaram change channel: %d, program: %d\r\n", channel, program);
+}
+
+void pitchBend(unsigned char channel, unsigned int value) {
+    printf("pitch bend channel: %d, value: %d\r\n", channel, value);
+}
+
+void midi_task(void const*) {
+    USBHostMIDI midi;
+
+    // attach midi event callbacks
+    midi.attachNoteOn(noteOn);
+    midi.attachNoteOff(noteOff);
+    midi.attachControlChange(controlChange);
+    midi.attachProgramChange(programChange);
+    midi.attachPitchBend(pitchBend);
+
+    while(1) {
+        // try to connect a midi device
+        while(!midi.connect())
+            Thread::wait(500);
+        
+        // if the device is disconnected, we try to connect it again
+        while (1) {
+            // if device disconnected, try to connect it again
+            if (!midi.connected())
+                break;
+             
+            Thread::wait(50);
+        }
+    }
+}
+ 
+int main() {
+    Thread midiTask(midi_task, NULL, osPriorityNormal, 256 * 4);
+    while(1) {
+        Thread::wait(500);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 05 09:45:08 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4096f863f923
\ No newline at end of file