changed based on Franky47's feedback
- send: pass the message as a const ref, to avoid copies - add mSerial.begin (with Baudrate - added Settings) - ThruActivated defaults to true - class name serialMIDI => SerialMIDI
This commit is contained in:
parent
8893642b27
commit
ee4e7b3942
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ inline MidiInterface<Transport, Settings, Platform>::~MidiInterface()
|
|||
template<class Transport, class Settings, class Platform>
|
||||
void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
||||
{
|
||||
// Initialise the Serial port
|
||||
// Initialise the Transport layer
|
||||
mTransport.begin();
|
||||
|
||||
mInputChannel = inChannel;
|
||||
|
|
@ -108,7 +108,7 @@ void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
|||
mMessage.length = 0;
|
||||
|
||||
mThruFilterMode = Thru::Full;
|
||||
mThruActivated = false;
|
||||
mThruActivated = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -129,7 +129,7 @@ void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
|||
them thru.
|
||||
*/
|
||||
template<class Transport, class Settings, class Platform>
|
||||
void MidiInterface<Transport, Settings, Platform>::send(MidiMessage inMessage)
|
||||
void MidiInterface<Transport, Settings, Platform>::send(const MidiMessage& inMessage)
|
||||
{
|
||||
if (!inMessage.valid)
|
||||
return;
|
||||
|
|
@ -1189,7 +1189,7 @@ bool MidiInterface<Transport, Settings, Platform>::isChannelMessage(MidiType inT
|
|||
@{
|
||||
*/
|
||||
|
||||
template<class Transport, class Settings, class Platform> void MidiInterface<Transport, Settings, Platform>::setHandleMessage(void (*fptr)(MidiMessage)) { mMessageCallback = fptr; }
|
||||
template<class Transport, class Settings, class Platform> void MidiInterface<Transport, Settings, Platform>::setHandleMessage(void (*fptr)(const MidiMessage&)) { mMessageCallback = fptr; }
|
||||
template<class Transport, class Settings, class Platform> void MidiInterface<Transport, Settings, Platform>::setHandleNoteOff(void (*fptr)(byte channel, byte note, byte velocity)) { mNoteOffCallback = fptr; }
|
||||
template<class Transport, class Settings, class Platform> void MidiInterface<Transport, Settings, Platform>::setHandleNoteOn(void (*fptr)(byte channel, byte note, byte velocity)) { mNoteOnCallback = fptr; }
|
||||
template<class Transport, class Settings, class Platform> void MidiInterface<Transport, Settings, Platform>::setHandleAfterTouchPoly(void (*fptr)(byte channel, byte note, byte pressure)) { mAfterTouchPolyCallback = fptr; }
|
||||
|
|
|
|||
|
|
@ -4,11 +4,22 @@
|
|||
|
||||
BEGIN_MIDI_NAMESPACE
|
||||
|
||||
template <class SerialPort>
|
||||
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 SerialPort, class _Settings = DefaultSerialSettings>
|
||||
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<Settings::BaudRate>();
|
||||
#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<Type> __smt;\
|
||||
typedef MIDI_NAMESPACE::SerialMIDI<Type> __smt;\
|
||||
typedef MIDI_NAMESPACE::MidiInterface<__smt> TypedMidiInterface;\
|
||||
__smt serialMidi(SerialPort);\
|
||||
TypedMidiInterface Name((__smt&)serialMidi);
|
||||
|
|
|
|||
Loading…
Reference in New Issue