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:
Fri Dec 06 03:28:49 2013 +0000
Parent:
0:78ea62ee7eab
Commit message:
example for sending MIDI messages

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
diff -r 78ea62ee7eab -r 01305cc0e2a2 USBHostMIDI.lib
--- a/USBHostMIDI.lib	Thu Dec 05 09:45:08 2013 +0000
+++ b/USBHostMIDI.lib	Fri Dec 06 03:28:49 2013 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/kshoji/code/USBHostMIDI/#bf09452b8f26
+https://mbed.org/users/kshoji/code/USBHostMIDI/#bd4759650fc0
diff -r 78ea62ee7eab -r 01305cc0e2a2 main.cpp
--- a/main.cpp	Thu Dec 05 09:45:08 2013 +0000
+++ b/main.cpp	Fri Dec 06 03:28:49 2013 +0000
@@ -1,6 +1,12 @@
 #include "mbed.h"
 #include "USBHostMIDI.h"
- 
+
+// pots on the mbed application board
+AnalogIn pot1(p19);
+AnalogIn pot2(p20);
+unsigned int lastPot1;
+unsigned int lastPot2;
+
 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);
 }
@@ -23,7 +29,7 @@
 
 void midi_task(void const*) {
     USBHostMIDI midi;
-
+    
     // attach midi event callbacks
     midi.attachNoteOn(noteOn);
     midi.attachNoteOff(noteOff);
@@ -38,6 +44,21 @@
         
         // if the device is disconnected, we try to connect it again
         while (1) {
+            if (lastPot1 != pot1.read_u16() >> 9) {
+                lastPot1 = pot1.read_u16() >> 9;
+                // channel volume
+                midi.sendControlChange(0, 7, lastPot1);
+            }
+            
+            if (lastPot2 != pot2.read_u16() >> 9) {
+                lastPot2 = pot2.read_u16() >> 9;
+                // program change
+                midi.sendProgramChange(0, lastPot2);
+            }
+            
+            // midi.sendNoteOn(0, 60, 127);
+            // midi.sendNoteOff(0, 60, 0);
+            
             // if device disconnected, try to connect it again
             if (!midi.connected())
                 break;
@@ -48,6 +69,8 @@
 }
  
 int main() {
+    lastPot1 = pot1.read_u16() >> 9;
+    lastPot2 = pot2.read_u16() >> 9;
     Thread midiTask(midi_task, NULL, osPriorityNormal, 256 * 4);
     while(1) {
         Thread::wait(500);