41#define MIDI_LIBRARY_VERSION 0x050000
42#define MIDI_LIBRARY_VERSION_MAJOR 5
43#define MIDI_LIBRARY_VERSION_MINOR 0
44#define MIDI_LIBRARY_VERSION_PATCH 0
53template<
class Transport,
class _Settings = DefaultSettings,
class _Platform = DefaultPlatform>
57 typedef _Settings Settings;
58 typedef _Platform Platform;
66 void begin(Channel inChannel = 1);
84 DataByte inControlValue,
87 inline void sendPitchBend(
int inPitchValue, Channel inChannel);
88 inline void sendPitchBend(
double inPitchValue, Channel inChannel);
92 Channel inChannel) __attribute__ ((deprecated));
102 bool inArrayContainsBoundaries =
false);
105 DataByte inValuesNibble);
124 inline void beginRpn(
unsigned inNumber,
131 inline void sendRpnIncrement(
byte inAmount,
133 inline void sendRpnDecrement(
byte inAmount,
135 inline void endRpn(Channel inChannel);
144 inline void sendNrpnIncrement(
byte inAmount,
146 inline void sendNrpnDecrement(
byte inAmount,
148 inline void endNrpn(Channel inChannel);
163 inline bool read(Channel inChannel);
172 inline bool check()
const;
175 inline Channel getInputChannel()
const;
181 static inline bool isChannelMessage(
MidiType inType);
187 inline void setHandleMessage(
void (*fptr)(
const MidiMessage&)) { mMessageCallback = fptr; };
188 inline void setHandleError(ErrorCallback fptr) { mErrorCallback = fptr; }
189 inline void setHandleNoteOff(NoteOffCallback fptr) { mNoteOffCallback = fptr; }
190 inline void setHandleNoteOn(NoteOnCallback fptr) { mNoteOnCallback = fptr; }
191 inline void setHandleAfterTouchPoly(AfterTouchPolyCallback fptr) { mAfterTouchPolyCallback = fptr; }
192 inline void setHandleControlChange(ControlChangeCallback fptr) { mControlChangeCallback = fptr; }
193 inline void setHandleProgramChange(ProgramChangeCallback fptr) { mProgramChangeCallback = fptr; }
194 inline void setHandleAfterTouchChannel(AfterTouchChannelCallback fptr) { mAfterTouchChannelCallback = fptr; }
195 inline void setHandlePitchBend(PitchBendCallback fptr) { mPitchBendCallback = fptr; }
196 inline void setHandleSystemExclusive(SystemExclusiveCallback fptr) { mSystemExclusiveCallback = fptr; }
197 inline void setHandleTimeCodeQuarterFrame(TimeCodeQuarterFrameCallback fptr) { mTimeCodeQuarterFrameCallback = fptr; }
198 inline void setHandleSongPosition(SongPositionCallback fptr) { mSongPositionCallback = fptr; }
199 inline void setHandleSongSelect(SongSelectCallback fptr) { mSongSelectCallback = fptr; }
200 inline void setHandleTuneRequest(TuneRequestCallback fptr) { mTuneRequestCallback = fptr; }
201 inline void setHandleClock(ClockCallback fptr) { mClockCallback = fptr; }
202 inline void setHandleStart(StartCallback fptr) { mStartCallback = fptr; }
203 inline void setHandleTick(TickCallback fptr) { mTickCallback = fptr; }
204 inline void setHandleContinue(ContinueCallback fptr) { mContinueCallback = fptr; }
205 inline void setHandleStop(StopCallback fptr) { mStopCallback = fptr; }
206 inline void setHandleActiveSensing(ActiveSensingCallback fptr) { mActiveSensingCallback = fptr; }
207 inline void setHandleSystemReset(SystemResetCallback fptr) { mSystemResetCallback = fptr; }
212 void launchCallback();
214 void (*mMessageCallback)(
const MidiMessage& message) =
nullptr;
215 ErrorCallback mErrorCallback =
nullptr;
216 NoteOffCallback mNoteOffCallback =
nullptr;
217 NoteOnCallback mNoteOnCallback =
nullptr;
218 AfterTouchPolyCallback mAfterTouchPolyCallback =
nullptr;
219 ControlChangeCallback mControlChangeCallback =
nullptr;
220 ProgramChangeCallback mProgramChangeCallback =
nullptr;
221 AfterTouchChannelCallback mAfterTouchChannelCallback =
nullptr;
222 PitchBendCallback mPitchBendCallback =
nullptr;
223 SystemExclusiveCallback mSystemExclusiveCallback =
nullptr;
224 TimeCodeQuarterFrameCallback mTimeCodeQuarterFrameCallback =
nullptr;
225 SongPositionCallback mSongPositionCallback =
nullptr;
226 SongSelectCallback mSongSelectCallback =
nullptr;
227 TuneRequestCallback mTuneRequestCallback =
nullptr;
228 ClockCallback mClockCallback =
nullptr;
229 StartCallback mStartCallback =
nullptr;
230 TickCallback mTickCallback =
nullptr;
231 ContinueCallback mContinueCallback =
nullptr;
232 StopCallback mStopCallback =
nullptr;
233 ActiveSensingCallback mActiveSensingCallback =
nullptr;
234 SystemResetCallback mSystemResetCallback =
nullptr;
241 inline bool getThruState()
const;
244 inline void turnThruOff();
248 void thruFilter(
byte inChannel);
255 inline void handleNullVelocityNoteOnAsNoteOff();
256 inline bool inputFilter(Channel inChannel);
257 inline void resetInput();
258 inline void UpdateLastSentTime();
264 Transport* getTransport() {
return &mTransport; };
267 Transport& mTransport;
273 Channel mInputChannel;
274 StatusByte mRunningStatus_RX;
275 StatusByte mRunningStatus_TX;
276 byte mPendingMessage[3];
277 unsigned mPendingMessageExpectedLength;
278 unsigned mPendingMessageIndex;
279 unsigned mCurrentRpnNumber;
280 unsigned mCurrentNrpnNumber;
281 bool mThruActivated : 1;
284 unsigned long mLastMessageSentTime;
285 unsigned long mLastMessageReceivedTime;
286 unsigned long mSenderActiveSensingPeriodicity;
287 bool mReceiverActiveSensingActivated;
291 inline StatusByte getStatus(
MidiType inType,
292 Channel inChannel)
const;
300 bool inFlipHeaderBits =
false);
304 bool inFlipHeaderBits =
false);
unsigned encodeSysEx(const byte *inData, byte *outSysEx, unsigned inLength, bool inFlipHeaderBits=false)
Encode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes ...
unsigned decodeSysEx(const byte *inSysEx, byte *outData, unsigned inLength, bool inFlipHeaderBits=false)
Decode System Exclusive messages. SysEx messages are encoded to guarantee transmission of data bytes ...
MIDI Library for the Arduino - Inline implementations.
The main class for MIDI handling. It is templated over the type of serial port to provide abstraction...
~MidiInterface()
Destructor for MidiInterface.
MidiInterface(Transport &)
Constructor for MidiInterface.
void begin(Channel inChannel=1)
Call the begin method in the setup() function of the Arduino.
void sendAfterTouch(DataByte inPressure, Channel inChannel)
Send a MonoPhonic AfterTouch message (applies to all notes)
void endRpn(Channel inChannel)
Terminate an RPN frame. This will send a Null Function to deselect the currently selected RPN.
void sendPitchBend(int inPitchValue, Channel inChannel)
Send a Pitch Bend message using a signed integer value.
void sendTimeCodeQuarterFrame(DataByte inTypeNibble, DataByte inValuesNibble)
Send a MIDI Time Code Quarter Frame.
void endNrpn(Channel inChannel)
Terminate an NRPN frame. This will send a Null Function to deselect the currently selected NRPN.
void sendNoteOn(DataByte inNoteNumber, DataByte inVelocity, Channel inChannel)
Send a Note On message.
void sendTuneRequest()
Send a Tune Request message.
void sendControlChange(DataByte inControlNumber, DataByte inControlValue, Channel inChannel)
Send a Control Change message.
void send(const MidiMessage &)
Send a MIDI message.
void sendProgramChange(DataByte inProgramNumber, Channel inChannel)
Send a Program Change message.
void beginNrpn(unsigned inNumber, Channel inChannel)
Start a Non-Registered Parameter Number frame.
void beginRpn(unsigned inNumber, Channel inChannel)
Start a Registered Parameter Number frame.
void sendSongPosition(unsigned inBeats)
Send a Song Position Pointer message.
void sendPolyPressure(DataByte inNoteNumber, DataByte inPressure, Channel inChannel)
Send a Polyphonic AfterTouch message (applies to a specified note)
void sendSongSelect(DataByte inSongNumber)
Send a Song Select message.
void sendCommon(MidiType inType, unsigned=0)
Send a Common message. Common messages reset the running status.
void sendRpnValue(unsigned inValue, Channel inChannel)
Send a 14-bit value for the currently selected RPN number.
void sendRealTime(MidiType inType)
Send a Real Time (one byte) message.
void sendSysEx(unsigned inLength, const byte *inArray, bool inArrayContainsBoundaries=false)
Generate and send a System Exclusive frame.
void sendNoteOff(DataByte inNoteNumber, DataByte inVelocity, Channel inChannel)
Send a Note Off message.
void sendNrpnValue(unsigned inValue, Channel inChannel)
Send a 14-bit value for the currently selected NRPN number.
void setThruFilterMode(Thru::Mode inThruFilterMode)
Set the filter for thru mirroring.
MIDI Library for the Arduino - Definitions.
@ Continue
System Real Time - Continue.
@ Clock
System Real Time - Timing Clock.
@ ActiveSensing
System Real Time - Active Sensing.
@ SystemReset
System Real Time - System Reset.
@ Tick
System Real Time - Timing Tick (1 tick = 10 milliseconds)
@ Start
System Real Time - Start.
@ Stop
System Real Time - Stop.
MIDI Library for the Arduino - Message struct definition.
MIDI Library for the Arduino - Settings.
MIDI Library for the Arduino - Platform @license MIT - Copyright (c) 2015 Francois Best.
@ Full
Fully enabled Thru (every incoming message is sent back).