aboutsummaryrefslogtreecommitdiffstats
path: root/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
diff options
context:
space:
mode:
authorJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
committerJun Wako <wakojun@gmail.com>2015-04-24 16:26:14 +0900
commit1fe4406f374291ab2e86e95a97341fd9c475fcb8 (patch)
tree1be0e16b4b07b5a31ea97ec50a9eb13a288c3d27 /tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
parenta20ef7052c6e937d2f7672dd59456e55a5c08296 (diff)
downloadfirmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.gz
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.tar.bz2
firmware-1fe4406f374291ab2e86e95a97341fd9c475fcb8.zip
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
Diffstat (limited to 'tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp')
-rw-r--r--tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp b/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
new file mode 100644
index 000000000..b0a6cd381
--- /dev/null
+++ b/tool/mbed/mbed-sdk/libraries/tests/usb/device/midi/main.cpp
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "USBMIDI.h"
+
+USBMIDI midi;
+Serial pc(USBTX, USBRX);
+
+// MIDI IN
+void transmitMessage(MIDIMessage msg) {
+ switch (msg.type()) {
+ case MIDIMessage::NoteOnType:
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOn(msg.key()));
+ break;
+ case MIDIMessage::NoteOffType:
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOff(msg.key()));
+ break;
+ case MIDIMessage::ProgramChangeType:
+ wait(0.1);
+ midi.write(MIDIMessage::ProgramChange(msg.program()));
+ break;
+ case MIDIMessage::SysExType:
+ wait(0.1);
+ unsigned char tmp[64];
+ for(int i=0;i<msg.length-1;i++) {
+ tmp[i]=msg.data[i+1];
+ }
+ midi.write(MIDIMessage::SysEx(tmp,msg.length-1));
+ break;
+ default:
+ break;
+ }
+}
+
+int main(void)
+{
+ wait(5);
+ // MIDI OUT
+
+ // set piano
+ midi.write(MIDIMessage::ProgramChange(1));
+ wait(0.1);
+
+ // play A
+ midi.write(MIDIMessage::NoteOn(21));
+ wait(0.1);
+ midi.write(MIDIMessage::NoteOff(21));
+ wait(0.1);
+
+ // GM reset
+ unsigned char gm_reset[]={0xF0,0x7E,0x7F,0x09,0x01,0xF7};
+ midi.write(MIDIMessage::SysEx(gm_reset,6));
+ wait(0.1);
+
+ // GM Master volume max
+ unsigned char gm_master_vol_max[]={0xF0,0x7F,0x7F,0x04,0x01,0x7F,0x7F,0xF7};
+ midi.write(MIDIMessage::SysEx(gm_master_vol_max,8));
+ wait(0.1);
+
+ // GS reset
+ unsigned char gs_reset[]={0xF0,0x41,0x10,0x42,0x12,0x40,0x00,0x7F,0x00,0x41,0xF7};
+ midi.write(MIDIMessage::SysEx(gs_reset,11));
+ wait(0.1);
+
+ // GS Master volume max
+ unsigned char gs_master_vol_max[]={0xF0,0x41,0x10,0x42,0x12,0x40,0x00,0x04,0x7F,0x3D,0xF7};
+ midi.write(MIDIMessage::SysEx(gs_master_vol_max,11));
+ wait(0.1);
+
+ midi.attach(transmitMessage);
+
+ while(1);
+}