Handling null-velocity NoteOn as NoteOff (with setting), inlined some methods.

This commit is contained in:
Francois Best 2014-03-12 21:34:46 +01:00
parent 8f4d5e85c7
commit 3f1e5c474a
3 changed files with 26 additions and 8 deletions

View File

@ -99,8 +99,8 @@ private:
#if MIDI_BUILD_INPUT #if MIDI_BUILD_INPUT
public: public:
bool read(); inline bool read();
bool read(Channel inChannel); inline bool read(Channel inChannel);
public: public:
inline MidiType getType() const; inline MidiType getType() const;
@ -120,9 +120,10 @@ public:
static inline bool isChannelMessage(MidiType inType); static inline bool isChannelMessage(MidiType inType);
private: private:
bool inputFilter(Channel inChannel);
bool parse(); bool parse();
void resetInput(); inline void handleNullVelocityNoteOnAsNoteOff();
inline bool inputFilter(Channel inChannel);
inline void resetInput();
private: private:
StatusByte mRunningStatus_RX; StatusByte mRunningStatus_RX;

View File

@ -457,7 +457,7 @@ StatusByte MidiInterface<SerialPort>::getStatus(MidiType inType,
@see see setInputChannel() @see see setInputChannel()
*/ */
template<class SerialPort> template<class SerialPort>
bool MidiInterface<SerialPort>::read() inline bool MidiInterface<SerialPort>::read()
{ {
return read(mInputChannel); return read(mInputChannel);
} }
@ -465,13 +465,14 @@ bool MidiInterface<SerialPort>::read()
/*! \brief Read messages on a specified channel. /*! \brief Read messages on a specified channel.
*/ */
template<class SerialPort> template<class SerialPort>
bool MidiInterface<SerialPort>::read(Channel inChannel) inline bool MidiInterface<SerialPort>::read(Channel inChannel)
{ {
if (inChannel >= MIDI_CHANNEL_OFF) if (inChannel >= MIDI_CHANNEL_OFF)
return false; // MIDI Input disabled. return false; // MIDI Input disabled.
if (parse()) if (parse())
{ {
handleNullVelocityNoteOnAsNoteOff();
if (inputFilter(inChannel)) if (inputFilter(inChannel))
{ {
@ -770,9 +771,20 @@ bool MidiInterface<SerialPort>::parse()
return false; return false;
} }
// Private method, see midi_Settings.h for documentation
inline void MidiInterface<SerialPort>::handleNullVelocityNoteOnAsNoteOff()
{
#if MIDI_HANDLE_NULL_VELOCITY_NOTE_ON_AS_NOTE_OFF
if (getType() == NoteOn && getData2() == 0)
{
mMessage.type = NoteOff;
}
#endif
}
// Private method: check if the received message is on the listened channel // Private method: check if the received message is on the listened channel
template<class SerialPort> template<class SerialPort>
bool MidiInterface<SerialPort>::inputFilter(Channel inChannel) inline bool MidiInterface<SerialPort>::inputFilter(Channel inChannel)
{ {
// This method handles recognition of channel // This method handles recognition of channel
// (to know if the message is destinated to the Arduino) // (to know if the message is destinated to the Arduino)
@ -804,7 +816,7 @@ bool MidiInterface<SerialPort>::inputFilter(Channel inChannel)
// Private method: reset input attributes // Private method: reset input attributes
template<class SerialPort> template<class SerialPort>
void MidiInterface<SerialPort>::resetInput() inline void MidiInterface<SerialPort>::resetInput()
{ {
mPendingMessageIndex = 0; mPendingMessageIndex = 0;
mPendingMessageExpectedLenght = 0; mPendingMessageExpectedLenght = 0;

View File

@ -69,6 +69,11 @@
// Set to 0 if you have troubles controlling your hardware. // Set to 0 if you have troubles controlling your hardware.
#define MIDI_USE_RUNNING_STATUS 1 #define MIDI_USE_RUNNING_STATUS 1
// NoteOn with 0 velocity should be handled as NoteOf.
// Set to 1 to get NoteOff events when receiving null-velocity NoteOn messages.
// Set to 0 to get NoteOn events when receiving null-velocity NoteOn messages.
#define MIDI_HANDLE_NULL_VELOCITY_NOTE_ON_AS_NOTE_OFF 1
// Setting this to 1 will make MIDI.read parse only one byte of data for each // Setting this to 1 will make MIDI.read parse only one byte of data for each
// call when data is available. This can speed up your application if receiving // call when data is available. This can speed up your application if receiving
// a lot of traffic, but might induce MIDI Thru and treatment latency. // a lot of traffic, but might induce MIDI Thru and treatment latency.