![](/media/cache/profiles/c7217b04fe11f374f9a6737901025606.50x50_q85.jpg)
My porting of USBHostMIDI library Example.
Dependencies: F401RE-USBHost mbed
Diff: main.cpp
- Revision:
- 1:a03b21ba2647
- Parent:
- 0:02a6abbd7331
- Child:
- 2:0ed13d8db901
--- a/main.cpp Wed Jun 25 21:20:23 2014 +0000 +++ b/main.cpp Wed Sep 17 13:52:20 2014 +0000 @@ -3,50 +3,74 @@ #include "USBHostMIDI.h" DigitalOut led(LED1); +Serial midiOut(PC_6,PA_12); 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); + led = 1; +// printf("note on channel: %d, note: %d, velocity: %d\r\n", channel, note, velocity); + midiOut.putc(0x90); // status:ch0,noteon + midiOut.putc(note); // data:noteNo + midiOut.putc(velocity);// data: 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); + led = 0; +// printf("note off channel: %d, note: %d, velocity: %d\r\n", channel, note, velocity); + midiOut.putc(0x80); // status:ch0,noteoff + midiOut.putc(note); // data:noteNo + midiOut.putc(velocity);// data: velocity } -void pitchBend(unsigned char channel, unsigned int value) { - printf("pitch bend channel: %d, value: %d\r\n", channel, value); -} +//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); +//} int main() { - - USBHostMIDI midi; + led = 1; + USBHostMIDI usbmidi; + midiOut.baud(31250); // attach midi event callbacks - midi.attachNoteOn(noteOn); - midi.attachNoteOff(noteOff); - midi.attachControlChange(controlChange); - midi.attachProgramChange(programChange); - midi.attachPitchBend(pitchBend); + usbmidi.attachNoteOn(noteOn); + usbmidi.attachNoteOff(noteOff); + //usbmidi.attachControlChange(controlChange); + //usbmidi.attachProgramChange(programChange); + //usbmidi.attachPitchBend(pitchBend); while(1) { // try to connect a midi device - while(!midi.connect()) + while(!usbmidi.connect()) { wait_ms(500); + led = 0; + } + + led = 1; + wait_ms(200); + led = 0; + wait_ms(200); + led = 1; + wait_ms(200); + led = 0; + wait_ms(200); + led = 1; + wait_ms(200); + led = 0; // 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; + if (!usbmidi.connected()) break; // polling USB task - midi.poll(); + USBHost::poll(); } } } \ No newline at end of file