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);
|
Channel inChannel);
|
||||||
inline void endNrpn(Channel inChannel);
|
inline void endNrpn(Channel inChannel);
|
||||||
|
|
||||||
inline void send(MidiMessage);
|
inline void send(const MidiMessage&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void send(MidiType inType,
|
void send(MidiType inType,
|
||||||
|
|
@ -167,7 +167,7 @@ public:
|
||||||
// Input Callbacks
|
// Input Callbacks
|
||||||
|
|
||||||
public:
|
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 setHandleNoteOff(void (*fptr)(byte channel, byte note, byte velocity));
|
||||||
inline void setHandleNoteOn(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));
|
inline void setHandleAfterTouchPoly(void (*fptr)(byte channel, byte note, byte pressure));
|
||||||
|
|
@ -192,7 +192,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void launchCallback();
|
void launchCallback();
|
||||||
|
|
||||||
void (*mMessageCallback)(MidiMessage message);
|
void (*mMessageCallback)(const MidiMessage& message);
|
||||||
void (*mNoteOffCallback)(byte channel, byte note, byte velocity);
|
void (*mNoteOffCallback)(byte channel, byte note, byte velocity);
|
||||||
void (*mNoteOnCallback)(byte channel, byte note, byte velocity);
|
void (*mNoteOnCallback)(byte channel, byte note, byte velocity);
|
||||||
void (*mAfterTouchPolyCallback)(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>
|
template<class Transport, class Settings, class Platform>
|
||||||
void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
||||||
{
|
{
|
||||||
// Initialise the Serial port
|
// Initialise the Transport layer
|
||||||
mTransport.begin();
|
mTransport.begin();
|
||||||
|
|
||||||
mInputChannel = inChannel;
|
mInputChannel = inChannel;
|
||||||
|
|
@ -108,7 +108,7 @@ void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
||||||
mMessage.length = 0;
|
mMessage.length = 0;
|
||||||
|
|
||||||
mThruFilterMode = Thru::Full;
|
mThruFilterMode = Thru::Full;
|
||||||
mThruActivated = false;
|
mThruActivated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -129,7 +129,7 @@ void MidiInterface<Transport, Settings, Platform>::begin(Channel inChannel)
|
||||||
them thru.
|
them thru.
|
||||||
*/
|
*/
|
||||||
template<class Transport, class Settings, class Platform>
|
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)
|
if (!inMessage.valid)
|
||||||
return;
|
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>::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>::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; }
|
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
|
BEGIN_MIDI_NAMESPACE
|
||||||
|
|
||||||
template <class SerialPort>
|
struct DefaultSerialSettings
|
||||||
class serialMIDI
|
|
||||||
{
|
{
|
||||||
|
/*! 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:
|
public:
|
||||||
serialMIDI(SerialPort& inSerial)
|
SerialMIDI(SerialPort& inSerial)
|
||||||
: mSerial(inSerial)
|
: mSerial(inSerial)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
@ -16,6 +27,12 @@ public:
|
||||||
public:
|
public:
|
||||||
void begin(MIDI_NAMESPACE::Channel inChannel = 1)
|
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)
|
bool beginTransmission(MidiType)
|
||||||
|
|
@ -52,7 +69,7 @@ private:
|
||||||
Then call midi2.begin(), midi2.read() etc..
|
Then call midi2.begin(), midi2.read() etc..
|
||||||
*/
|
*/
|
||||||
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
|
#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;\
|
typedef MIDI_NAMESPACE::MidiInterface<__smt> TypedMidiInterface;\
|
||||||
__smt serialMidi(SerialPort);\
|
__smt serialMidi(SerialPort);\
|
||||||
TypedMidiInterface Name((__smt&)serialMidi);
|
TypedMidiInterface Name((__smt&)serialMidi);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue