diff --git a/src/MIDI.h b/src/MIDI.h index b9183d1..a7af885 100644 --- a/src/MIDI.h +++ b/src/MIDI.h @@ -130,7 +130,7 @@ public: Channel inChannel); inline void endNrpn(Channel inChannel); - inline void send(MidiMessage); + inline void send(const MidiMessage&); public: void send(MidiType inType, @@ -167,7 +167,7 @@ public: // Input Callbacks public: - inline void setHandleMessage(void (*fptr)(MidiMessage)); + inline void setHandleMessage(void (*fptr)(const MidiMessage&)); inline void setHandleNoteOff(void (*fptr)(byte channel, byte note, byte velocity)); inline void setHandleNoteOn(void (*fptr)(byte channel, byte note, byte velocity)); inline void setHandleAfterTouchPoly(void (*fptr)(byte channel, byte note, byte pressure)); @@ -192,7 +192,7 @@ public: private: void launchCallback(); - void (*mMessageCallback)(MidiMessage message); + void (*mMessageCallback)(const MidiMessage& message); void (*mNoteOffCallback)(byte channel, byte note, byte velocity); void (*mNoteOnCallback)(byte channel, byte note, byte velocity); void (*mAfterTouchPolyCallback)(byte channel, byte note, byte velocity); diff --git a/src/MIDI.hpp b/src/MIDI.hpp index 1bb37eb..c8b2be0 100644 --- a/src/MIDI.hpp +++ b/src/MIDI.hpp @@ -85,7 +85,7 @@ inline MidiInterface::~MidiInterface() template void MidiInterface::begin(Channel inChannel) { - // Initialise the Serial port + // Initialise the Transport layer mTransport.begin(); mInputChannel = inChannel; @@ -108,7 +108,7 @@ void MidiInterface::begin(Channel inChannel) mMessage.length = 0; mThruFilterMode = Thru::Full; - mThruActivated = false; + mThruActivated = true; } // ----------------------------------------------------------------------------- @@ -129,7 +129,7 @@ void MidiInterface::begin(Channel inChannel) them thru. */ template -void MidiInterface::send(MidiMessage inMessage) +void MidiInterface::send(const MidiMessage& inMessage) { if (!inMessage.valid) return; @@ -1189,7 +1189,7 @@ bool MidiInterface::isChannelMessage(MidiType inT @{ */ -template void MidiInterface::setHandleMessage(void (*fptr)(MidiMessage)) { mMessageCallback = fptr; } +template void MidiInterface::setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; } template void MidiInterface::setHandleNoteOff(void (*fptr)(byte channel, byte note, byte velocity)) { mNoteOffCallback = fptr; } template void MidiInterface::setHandleNoteOn(void (*fptr)(byte channel, byte note, byte velocity)) { mNoteOnCallback = fptr; } template void MidiInterface::setHandleAfterTouchPoly(void (*fptr)(byte channel, byte note, byte pressure)) { mAfterTouchPolyCallback = fptr; } diff --git a/src/serialMIDI.h b/src/serialMIDI.h index 1aa2ac3..b0a0fdf 100644 --- a/src/serialMIDI.h +++ b/src/serialMIDI.h @@ -4,11 +4,22 @@ BEGIN_MIDI_NAMESPACE -template -class serialMIDI +struct DefaultSerialSettings { + /*! Override the default MIDI baudrate to transmit over USB serial, to + a decoding program such as Hairless MIDI (set baudrate to 115200)\n + http://projectgus.github.io/hairless-midiserial/ + */ + static const long BaudRate = 31250; +}; + +template +class SerialMIDI +{ + typedef _Settings Settings; + public: - serialMIDI(SerialPort& inSerial) + SerialMIDI(SerialPort& inSerial) : mSerial(inSerial) { }; @@ -16,6 +27,12 @@ public: public: void begin(MIDI_NAMESPACE::Channel inChannel = 1) { + // Initialise the Serial port + #if defined(AVR_CAKE) + mSerial. template open(); + #else + mSerial.begin(Settings::BaudRate); + #endif } bool beginTransmission(MidiType) @@ -52,7 +69,7 @@ private: Then call midi2.begin(), midi2.read() etc.. */ #define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \ - typedef MIDI_NAMESPACE::serialMIDI __smt;\ + typedef MIDI_NAMESPACE::SerialMIDI __smt;\ typedef MIDI_NAMESPACE::MidiInterface<__smt> TypedMidiInterface;\ __smt serialMidi(SerialPort);\ TypedMidiInterface Name((__smt&)serialMidi);