Marius Petrut / MIDI_5Pin
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MIDI_5Pin.cpp Source File

MIDI_5Pin.cpp

00001 /* Simple mbed 5-pin DIN to USB MIDI Converter library
00002 Marius Petrut, 2015
00003 */
00004 
00005 #include "MIDI_5Pin.h"
00006 #include "mbed.h"
00007 
00008 #define NOTE_ON 144
00009 #define CONT_CTRL 176
00010 
00011 MIDI_5Pin::MIDI_5Pin(PinName txPin, PinName rxPin) :
00012     _pc(USBTX, USBRX), _uart5pin(txPin, rxPin) {
00013         _pc.baud(115200);
00014         // 31250 is the official specification
00015         _uart5pin.baud(31250);
00016     }
00017  
00018 void MIDI_5Pin::write(char command, char param1, char param2) {
00019     _uart5pin.putc(command);
00020     _uart5pin.putc(param1);
00021     _uart5pin.putc(param2);
00022 }
00023 
00024 void MIDI_5Pin::noteOn(char note, char velocity) {
00025     _uart5pin.putc(NOTE_ON);
00026     _uart5pin.putc(note);
00027     _uart5pin.putc(velocity);
00028 }
00029 
00030 void MIDI_5Pin::noteOff(char note) {
00031     _uart5pin.putc(NOTE_ON);
00032     _uart5pin.putc(note);
00033     _uart5pin.putc(0);
00034 }
00035 
00036 void MIDI_5Pin::contCtrl(char ccNumber, char value) {
00037     _uart5pin.putc(CONT_CTRL);
00038     _uart5pin.putc(ccNumber);
00039     _uart5pin.putc(value);
00040 }
00041 
00042 void MIDI_5Pin::read() {
00043     if (_uart5pin.readable()) {
00044         _pc.putc(_uart5pin.getc());
00045     }
00046 }