A simple 5-pin MIDI helper library.
MIDI_5Pin.cpp@0:a6b78fdc6619, 2015-10-22 (annotated)
- Committer:
- mpetrut
- Date:
- Thu Oct 22 17:15:51 2015 +0000
- Revision:
- 0:a6b78fdc6619
Initial commit;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mpetrut | 0:a6b78fdc6619 | 1 | /* Simple mbed 5-pin DIN to USB MIDI Converter library |
| mpetrut | 0:a6b78fdc6619 | 2 | Marius Petrut, 2015 |
| mpetrut | 0:a6b78fdc6619 | 3 | */ |
| mpetrut | 0:a6b78fdc6619 | 4 | |
| mpetrut | 0:a6b78fdc6619 | 5 | #include "MIDI_5Pin.h" |
| mpetrut | 0:a6b78fdc6619 | 6 | #include "mbed.h" |
| mpetrut | 0:a6b78fdc6619 | 7 | |
| mpetrut | 0:a6b78fdc6619 | 8 | #define NOTE_ON 144 |
| mpetrut | 0:a6b78fdc6619 | 9 | #define CONT_CTRL 176 |
| mpetrut | 0:a6b78fdc6619 | 10 | |
| mpetrut | 0:a6b78fdc6619 | 11 | MIDI_5Pin::MIDI_5Pin(PinName txPin, PinName rxPin) : |
| mpetrut | 0:a6b78fdc6619 | 12 | _pc(USBTX, USBRX), _uart5pin(txPin, rxPin) { |
| mpetrut | 0:a6b78fdc6619 | 13 | _pc.baud(115200); |
| mpetrut | 0:a6b78fdc6619 | 14 | // 31250 is the official specification |
| mpetrut | 0:a6b78fdc6619 | 15 | _uart5pin.baud(31250); |
| mpetrut | 0:a6b78fdc6619 | 16 | } |
| mpetrut | 0:a6b78fdc6619 | 17 | |
| mpetrut | 0:a6b78fdc6619 | 18 | void MIDI_5Pin::write(char command, char param1, char param2) { |
| mpetrut | 0:a6b78fdc6619 | 19 | _uart5pin.putc(command); |
| mpetrut | 0:a6b78fdc6619 | 20 | _uart5pin.putc(param1); |
| mpetrut | 0:a6b78fdc6619 | 21 | _uart5pin.putc(param2); |
| mpetrut | 0:a6b78fdc6619 | 22 | } |
| mpetrut | 0:a6b78fdc6619 | 23 | |
| mpetrut | 0:a6b78fdc6619 | 24 | void MIDI_5Pin::noteOn(char note, char velocity) { |
| mpetrut | 0:a6b78fdc6619 | 25 | _uart5pin.putc(NOTE_ON); |
| mpetrut | 0:a6b78fdc6619 | 26 | _uart5pin.putc(note); |
| mpetrut | 0:a6b78fdc6619 | 27 | _uart5pin.putc(velocity); |
| mpetrut | 0:a6b78fdc6619 | 28 | } |
| mpetrut | 0:a6b78fdc6619 | 29 | |
| mpetrut | 0:a6b78fdc6619 | 30 | void MIDI_5Pin::noteOff(char note) { |
| mpetrut | 0:a6b78fdc6619 | 31 | _uart5pin.putc(NOTE_ON); |
| mpetrut | 0:a6b78fdc6619 | 32 | _uart5pin.putc(note); |
| mpetrut | 0:a6b78fdc6619 | 33 | _uart5pin.putc(0); |
| mpetrut | 0:a6b78fdc6619 | 34 | } |
| mpetrut | 0:a6b78fdc6619 | 35 | |
| mpetrut | 0:a6b78fdc6619 | 36 | void MIDI_5Pin::contCtrl(char ccNumber, char value) { |
| mpetrut | 0:a6b78fdc6619 | 37 | _uart5pin.putc(CONT_CTRL); |
| mpetrut | 0:a6b78fdc6619 | 38 | _uart5pin.putc(ccNumber); |
| mpetrut | 0:a6b78fdc6619 | 39 | _uart5pin.putc(value); |
| mpetrut | 0:a6b78fdc6619 | 40 | } |
| mpetrut | 0:a6b78fdc6619 | 41 | |
| mpetrut | 0:a6b78fdc6619 | 42 | void MIDI_5Pin::read() { |
| mpetrut | 0:a6b78fdc6619 | 43 | if (_uart5pin.readable()) { |
| mpetrut | 0:a6b78fdc6619 | 44 | _pc.putc(_uart5pin.getc()); |
| mpetrut | 0:a6b78fdc6619 | 45 | } |
| mpetrut | 0:a6b78fdc6619 | 46 | } |