MIDIキーボードをPS4版のFF14に接続するためのアダプタ。このプログラムはMIDI側のmbed用で、この他にPS4側のmbedが必要です。
Dependencies: USBHost USBHostMIDI2eVY1_sample mbed
Fork of USBHostMIDI2eVY1_sample by
main.cpp@1:8d5387784a62, 2018-08-18 (annotated)
- Committer:
- Lybfip
- Date:
- Sat Aug 18 06:36:36 2018 +0000
- Revision:
- 1:8d5387784a62
- Parent:
- 0:649db6499897
ELB-02?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ccutchy | 0:649db6499897 | 1 | #include "mbed.h" |
ccutchy | 0:649db6499897 | 2 | #include "USBHostMIDI.h" |
Lybfip | 1:8d5387784a62 | 3 | |
Lybfip | 1:8d5387784a62 | 4 | Serial pc(USBTX, USBRX); // デバッグ用モニタ通信 |
Lybfip | 1:8d5387784a62 | 5 | Serial uart(p9, p10); // UART |
Lybfip | 1:8d5387784a62 | 6 | DigitalOut led(LED1); // 基板上LED |
Lybfip | 1:8d5387784a62 | 7 | RawSerial midi(p28, NC); // この用途では不要 |
Lybfip | 1:8d5387784a62 | 8 | |
Lybfip | 1:8d5387784a62 | 9 | /// |
Lybfip | 1:8d5387784a62 | 10 | /// MIDI Note OFF イベント |
Lybfip | 1:8d5387784a62 | 11 | /// |
Lybfip | 1:8d5387784a62 | 12 | void onMidNoteOff (uint8_t ch, uint8_t key, uint8_t vel) { |
Lybfip | 1:8d5387784a62 | 13 | uart.printf("OF%2d", key); // キーOFFをUARTで送信。 |
Lybfip | 1:8d5387784a62 | 14 | //midi.putc(0x80|ch); midi.putc(key); midi.putc(vel); |
Lybfip | 1:8d5387784a62 | 15 | led = !led; |
Lybfip | 1:8d5387784a62 | 16 | pc.printf("NoteOff ch= %d, key= %d, vel= %d\r\n", ch, key, vel); |
Lybfip | 1:8d5387784a62 | 17 | } |
Lybfip | 1:8d5387784a62 | 18 | |
Lybfip | 1:8d5387784a62 | 19 | /// |
Lybfip | 1:8d5387784a62 | 20 | /// MIDI Note ONイベント |
Lybfip | 1:8d5387784a62 | 21 | /// |
Lybfip | 1:8d5387784a62 | 22 | void onMidNoteOn (uint8_t ch, uint8_t key, uint8_t vel) { |
Lybfip | 1:8d5387784a62 | 23 | uart.printf("ON%2d", key); // キーOFFをUARTで送信。 |
Lybfip | 1:8d5387784a62 | 24 | //midi.putc(0x90|ch); midi.putc(key); midi.putc(vel); |
Lybfip | 1:8d5387784a62 | 25 | led = !led; |
Lybfip | 1:8d5387784a62 | 26 | pc.printf("NoteOn ch= %d, key= %d, vel= %d\r\n", ch, key, vel); |
Lybfip | 1:8d5387784a62 | 27 | } |
Lybfip | 1:8d5387784a62 | 28 | |
Lybfip | 1:8d5387784a62 | 29 | /// |
Lybfip | 1:8d5387784a62 | 30 | /// MIDI コントロールチェンジイベント |
Lybfip | 1:8d5387784a62 | 31 | /// |
Lybfip | 1:8d5387784a62 | 32 | void onMidCtrlChg (uint8_t ch, uint8_t cc, uint8_t val) { |
Lybfip | 1:8d5387784a62 | 33 | //midi.putc(0xB0|ch); |
Lybfip | 1:8d5387784a62 | 34 | //midi.putc(cc); |
Lybfip | 1:8d5387784a62 | 35 | //midi.putc(val); |
Lybfip | 1:8d5387784a62 | 36 | } |
Lybfip | 1:8d5387784a62 | 37 | |
Lybfip | 1:8d5387784a62 | 38 | /// |
Lybfip | 1:8d5387784a62 | 39 | /// MIDI ピッチベンドイベント |
Lybfip | 1:8d5387784a62 | 40 | /// |
Lybfip | 1:8d5387784a62 | 41 | void onMidPitchBend (uint8_t ch, uint16_t val) { |
Lybfip | 1:8d5387784a62 | 42 | //midi.putc(0xE0|ch); |
Lybfip | 1:8d5387784a62 | 43 | //midi.putc(val&0x7F); |
Lybfip | 1:8d5387784a62 | 44 | //midi.putc(val>>7); |
Lybfip | 1:8d5387784a62 | 45 | } |
Lybfip | 1:8d5387784a62 | 46 | |
ccutchy | 0:649db6499897 | 47 | void onMidExclusive (uint8_t*, uint16_t, bool) {} |
Lybfip | 1:8d5387784a62 | 48 | |
ccutchy | 0:649db6499897 | 49 | void onMid1byte (uint8_t) {} |
Lybfip | 1:8d5387784a62 | 50 | |
ccutchy | 0:649db6499897 | 51 | void onMid2bytes (uint8_t, uint8_t) {} |
Lybfip | 1:8d5387784a62 | 52 | |
ccutchy | 0:649db6499897 | 53 | void onMid3bytes (uint8_t, uint8_t, uint8_t) {} |
Lybfip | 1:8d5387784a62 | 54 | |
Lybfip | 1:8d5387784a62 | 55 | /// |
Lybfip | 1:8d5387784a62 | 56 | /// mid_taskスレッド |
Lybfip | 1:8d5387784a62 | 57 | /// |
ccutchy | 0:649db6499897 | 58 | void mid_task(void const *) { |
ccutchy | 0:649db6499897 | 59 | USBHostMIDI mid; |
ccutchy | 0:649db6499897 | 60 | mid.attachNoteOff (onMidNoteOff ); mid.attachNoteOn (onMidNoteOn ); |
ccutchy | 0:649db6499897 | 61 | mid.attachPolyKeyPress (onMid3bytes ); mid.attachControlChange (onMidCtrlChg ); |
ccutchy | 0:649db6499897 | 62 | mid.attachProgramChange (onMid2bytes ); mid.attachChannelPressure(onMid2bytes ); |
ccutchy | 0:649db6499897 | 63 | mid.attachPitchBend (onMidPitchBend ); mid.attachSystemExclusive(onMidExclusive ); |
ccutchy | 0:649db6499897 | 64 | mid.attachSystemCommonTwoBytes (onMid2bytes ); mid.attachSingleByte (onMid1byte ); |
ccutchy | 0:649db6499897 | 65 | mid.attachSystemCommonThreeBytes (onMid3bytes ); mid.attachCableEvent (onMid3bytes ); |
ccutchy | 0:649db6499897 | 66 | mid.attachMiscellaneousFunctionCode (onMid3bytes ); |
ccutchy | 0:649db6499897 | 67 | for(;;) { while(!mid.connect()) { Thread::wait(250); } led = 1; |
ccutchy | 0:649db6499897 | 68 | while(mid.connected()) { Thread::wait(250); } led = 0; } |
ccutchy | 0:649db6499897 | 69 | } |
Lybfip | 1:8d5387784a62 | 70 | |
ccutchy | 0:649db6499897 | 71 | int main() { |
Lybfip | 1:8d5387784a62 | 72 | pc.baud(115200); // モニタのボーレート |
Lybfip | 1:8d5387784a62 | 73 | uart.baud(115200); // UARTのボーレート |
ccutchy | 0:649db6499897 | 74 | midi.baud(31250); |
Lybfip | 1:8d5387784a62 | 75 | DigitalOut hoge(P2_9); hoge = 1; // disable usb d+ pullup |
Lybfip | 1:8d5387784a62 | 76 | // MIDIタスクスレッドの起動 |
ccutchy | 0:649db6499897 | 77 | Thread midTask(mid_task, NULL, osPriorityNormal, 1024); |
ccutchy | 0:649db6499897 | 78 | const char aMsg[] = "\xF0\x43\x79\x09\x00\x50\x10" "j M,M,e,s M,b' i,i\0" "\xF7"; |
Lybfip | 1:8d5387784a62 | 79 | Thread::wait(3500); |
Lybfip | 1:8d5387784a62 | 80 | for(int i = 0; i < sizeof(aMsg)-1; midi.putc(aMsg[i++])); |
Lybfip | 1:8d5387784a62 | 81 | // 無限ループ |
ccutchy | 0:649db6499897 | 82 | for(;;) { Thread::wait(250); } |
ccutchy | 0:649db6499897 | 83 | } |