see http://mbed.org/users/okini3939/notebook/midi/

Dependencies:   MIDI USBDevice mbed

Fork of MIDI_sample by Suga koubou

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Tue Feb 05 00:12:25 2013 +0000
Parent:
0:1a4d28e63bef
Commit message:
usb bridge

Changed in this revision

MIDI.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.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 1a4d28e63bef -r ecf5c3927710 MIDI.lib
--- a/MIDI.lib	Mon Dec 03 14:24:33 2012 +0000
+++ b/MIDI.lib	Tue Feb 05 00:12:25 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/okini3939/code/MIDI/#713ef38fead1
+http://mbed.org/users/okini3939/code/MIDI/#0eeca7deec08
diff -r 1a4d28e63bef -r ecf5c3927710 USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Tue Feb 05 00:12:25 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#d0945750af57
diff -r 1a4d28e63bef -r ecf5c3927710 main.cpp
--- a/main.cpp	Mon Dec 03 14:24:33 2012 +0000
+++ b/main.cpp	Tue Feb 05 00:12:25 2013 +0000
@@ -1,20 +1,70 @@
-#include "mbed.h"
-#include "MIDI.h"
-
-DigitalOut led1(LED1), led2(LED2);
-
-MIDI midi(p9, p10);
-
-int main() {
-    midi.begin(4);    
-
-    for (;;) {
-        if (midi.read()) {
-            led1 = 1;
-            midi.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
-            wait(1);
-            midi.sendNoteOn(42,0,1);   // Stop the note
-            led1 = 0;
-        }
-    }
-}
+#include "mbed.h"
+#include "USBMIDI.h"
+#include "MIDI.h"
+
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
+Serial pc(USBTX, USBRX);
+
+USBMIDI usbmidi;
+MIDI midi(p9, p10);
+
+void show_message(MIDIMessage msg) {
+    switch (msg.type()) {
+    case MIDIMessage::NoteOffType:
+        midi.sendNoteOff(msg.key(), msg.pitch(), msg.channel());
+        break;
+    case MIDIMessage::NoteOnType:
+        midi.sendNoteOn(msg.key(), msg.pitch(), msg.channel());
+        break;
+    case MIDIMessage::PolyphonicAftertouchType:
+        midi.sendPolyPressure(msg.key(), msg.pressure(), msg.channel());
+        break;
+    case MIDIMessage::ControlChangeType:
+        midi.sendControlChange(msg.controller(), msg.value(), msg.channel());
+        break;
+    case MIDIMessage::ProgramChangeType:
+        midi.sendProgramChange(msg.program(), msg.channel());
+        break;
+    case MIDIMessage::ChannelAftertouchType:
+        midi.sendAfterTouch(msg.pressure(), msg.channel());
+        break;
+    case MIDIMessage::PitchWheelType:
+        midi.sendPitchBend(msg.pitch(), msg.channel());
+        break;
+    case MIDIMessage::AllNotesOffType:
+        midi.sendControlChange(123, 0, msg.channel());
+        break;
+    case MIDIMessage::ErrorType:
+    default:
+        led4 = 1;
+        break;
+    }
+    led3 = 1;
+}
+
+void isr_t () {
+    led2 = 0;
+    led3 = 0;
+    led4 = 0;
+}
+
+int main() {
+    Ticker t;
+
+    led1 = 1;
+    usbmidi.attach(show_message);
+    midi.begin();   
+    t.attach(isr_t, 0.1);
+
+    for (;;) {
+        if (midi.read()) {
+            MIDIMessage msg;
+            msg.data[0] = CABLE_NUM | (midi.getType() >> 4);
+            msg.data[1] = midi.getType() | midi.getChannel();
+            msg.data[2] = midi.getData1();
+            msg.data[3] = midi.getData2();
+            usbmidi.write(msg);
+            led2 = 1;
+        }
+    }
+}