Arduino MIDI Library  Version 5.0.1
MidiInterface< Transport, _Settings, _Platform > Class Template Reference

The main class for MIDI handling. It is templated over the type of serial port to provide abstraction from the hardware interface, meaning you can use HardwareSerial, SoftwareSerial or ak47's Uart classes. The only requirement is that the class implements the begin, read, write and available methods. More...

#include <MIDI.h>

Public Types

typedef _Settings Settings
 
typedef _Platform Platform
 
typedef Message< Settings::SysExMaxSize > MidiMessage
 

Public Member Functions

 MidiInterface (Transport &)
 Constructor for MidiInterface. More...
 
 ~MidiInterface ()
 Destructor for MidiInterface. More...
 
void begin (Channel inChannel=1)
 Call the begin method in the setup() function of the Arduino. More...
 
void sendNoteOn (DataByte inNoteNumber, DataByte inVelocity, Channel inChannel)
 Send a Note On message. More...
 
void sendNoteOff (DataByte inNoteNumber, DataByte inVelocity, Channel inChannel)
 Send a Note Off message. More...
 
void sendProgramChange (DataByte inProgramNumber, Channel inChannel)
 Send a Program Change message. More...
 
void sendControlChange (DataByte inControlNumber, DataByte inControlValue, Channel inChannel)
 Send a Control Change message. More...
 
void sendPitchBend (int inPitchValue, Channel inChannel)
 Send a Pitch Bend message using a signed integer value. More...
 
void sendPitchBend (double inPitchValue, Channel inChannel)
 Send a Pitch Bend message using a floating point value. More...
 
void sendPolyPressure (DataByte inNoteNumber, DataByte inPressure, Channel inChannel) __attribute__((deprecated))
 Send a Polyphonic AfterTouch message (applies to a specified note) More...
 
void sendAfterTouch (DataByte inPressure, Channel inChannel)
 Send a MonoPhonic AfterTouch message (applies to all notes) More...
 
void sendAfterTouch (DataByte inNoteNumber, DataByte inPressure, Channel inChannel)
 Send a Polyphonic AfterTouch message (applies to a specified note) More...
 
void sendSysEx (unsigned inLength, const byte *inArray, bool inArrayContainsBoundaries=false)
 Generate and send a System Exclusive frame. More...
 
void sendTimeCodeQuarterFrame (DataByte inTypeNibble, DataByte inValuesNibble)
 Send a MIDI Time Code Quarter Frame. More...
 
void sendTimeCodeQuarterFrame (DataByte inData)
 Send a MIDI Time Code Quarter Frame. More...
 
void sendSongPosition (unsigned inBeats)
 Send a Song Position Pointer message. More...
 
void sendSongSelect (DataByte inSongNumber)
 Send a Song Select message. More...
 
void sendTuneRequest ()
 Send a Tune Request message. More...
 
void sendCommon (MidiType inType, unsigned=0)
 Send a Common message. Common messages reset the running status. More...
 
void sendClock ()
 
void sendStart ()
 
void sendStop ()
 
void sendTick ()
 
void sendContinue ()
 
void sendActiveSensing ()
 
void sendSystemReset ()
 
void sendRealTime (MidiType inType)
 Send a Real Time (one byte) message. More...
 
void beginRpn (unsigned inNumber, Channel inChannel)
 Start a Registered Parameter Number frame. More...
 
void sendRpnValue (unsigned inValue, Channel inChannel)
 Send a 14-bit value for the currently selected RPN number. More...
 
void sendRpnValue (byte inMsb, byte inLsb, Channel inChannel)
 Send separate MSB/LSB values for the currently selected RPN number. More...
 
void sendRpnIncrement (byte inAmount, Channel inChannel)
 
void sendRpnDecrement (byte inAmount, Channel inChannel)
 
void endRpn (Channel inChannel)
 Terminate an RPN frame. This will send a Null Function to deselect the currently selected RPN. More...
 
void beginNrpn (unsigned inNumber, Channel inChannel)
 Start a Non-Registered Parameter Number frame. More...
 
void sendNrpnValue (unsigned inValue, Channel inChannel)
 Send a 14-bit value for the currently selected NRPN number. More...
 
void sendNrpnValue (byte inMsb, byte inLsb, Channel inChannel)
 Send separate MSB/LSB values for the currently selected NRPN number. More...
 
void sendNrpnIncrement (byte inAmount, Channel inChannel)
 
void sendNrpnDecrement (byte inAmount, Channel inChannel)
 
void endNrpn (Channel inChannel)
 Terminate an NRPN frame. This will send a Null Function to deselect the currently selected NRPN. More...
 
void send (const MidiMessage &)
 Send a MIDI message. More...
 
void send (MidiType inType, DataByte inData1, DataByte inData2, Channel inChannel)
 Generate and send a MIDI message from the values given. More...
 
bool read ()
 Read messages from the serial port using the main input channel. More...
 
bool read (Channel inChannel)
 Read messages on a specified channel. More...
 
MidiType getType () const
 Get the last received message's type. More...
 
Channel getChannel () const
 Get the channel of the message stored in the structure. More...
 
DataByte getData1 () const
 Get the first data byte of the last received message. More...
 
DataByte getData2 () const
 Get the second data byte of the last received message. More...
 
const bytegetSysExArray () const
 Get the System Exclusive byte array. More...
 
unsigned getSysExArrayLength () const
 Get the length of the System Exclusive array. More...
 
bool check () const
 Check if a valid message is stored in the structure. More...
 
Channel getInputChannel () const
 
void setInputChannel (Channel inChannel)
 Set the value for the input MIDI channel. More...
 
void setHandleMessage (void(*fptr)(const MidiMessage &))
 
void setHandleError (ErrorCallback fptr)
 
void setHandleNoteOff (NoteOffCallback fptr)
 
void setHandleNoteOn (NoteOnCallback fptr)
 
void setHandleAfterTouchPoly (AfterTouchPolyCallback fptr)
 
void setHandleControlChange (ControlChangeCallback fptr)
 
void setHandleProgramChange (ProgramChangeCallback fptr)
 
void setHandleAfterTouchChannel (AfterTouchChannelCallback fptr)
 
void setHandlePitchBend (PitchBendCallback fptr)
 
void setHandleSystemExclusive (SystemExclusiveCallback fptr)
 
void setHandleTimeCodeQuarterFrame (TimeCodeQuarterFrameCallback fptr)
 
void setHandleSongPosition (SongPositionCallback fptr)
 
void setHandleSongSelect (SongSelectCallback fptr)
 
void setHandleTuneRequest (TuneRequestCallback fptr)
 
void setHandleClock (ClockCallback fptr)
 
void setHandleStart (StartCallback fptr)
 
void setHandleTick (TickCallback fptr)
 
void setHandleContinue (ContinueCallback fptr)
 
void setHandleStop (StopCallback fptr)
 
void setHandleActiveSensing (ActiveSensingCallback fptr)
 
void setHandleSystemReset (SystemResetCallback fptr)
 
void disconnectCallbackFromType (MidiType inType)
 Detach an external function from the given type. More...
 
Thru::Mode getFilterMode () const
 
bool getThruState () const
 
void turnThruOn (Thru::Mode inThruFilterMode=Thru::Full)
 
void turnThruOff ()
 
void setThruFilterMode (Thru::Mode inThruFilterMode)
 Set the filter for thru mirroring. More...
 
Transport * getTransport ()
 

Static Public Member Functions

static MidiType getTypeFromStatusByte (byte inStatus)
 Extract an enumerated MIDI type from a status byte. More...
 
static Channel getChannelFromStatusByte (byte inStatus)
 Returns channel in the range 1-16. More...
 
static bool isChannelMessage (MidiType inType)
 

Detailed Description

template<class Transport, class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
class MidiInterface< Transport, _Settings, _Platform >

The main class for MIDI handling. It is templated over the type of serial port to provide abstraction from the hardware interface, meaning you can use HardwareSerial, SoftwareSerial or ak47's Uart classes. The only requirement is that the class implements the begin, read, write and available methods.

Definition at line 53 of file MIDI.h.

Member Typedef Documentation

◆ MidiMessage

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
typedef Message<Settings::SysExMaxSize> MidiInterface< Transport, _Settings, _Platform >::MidiMessage

Definition at line 58 of file MIDI.h.

◆ Platform

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
typedef _Platform MidiInterface< Transport, _Settings, _Platform >::Platform

Definition at line 57 of file MIDI.h.

◆ Settings

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
typedef _Settings MidiInterface< Transport, _Settings, _Platform >::Settings

Definition at line 56 of file MIDI.h.

Constructor & Destructor Documentation

◆ MidiInterface()

template<class Transport , class Settings , class Platform >
BEGIN_MIDI_NAMESPACE MidiInterface< Transport, Settings, Platform >::MidiInterface ( Transport &  inTransport)
inline

Constructor for MidiInterface.

Definition at line 34 of file MIDI.hpp.

35  : mTransport(inTransport)
36  , mInputChannel(0)
37  , mRunningStatus_RX(InvalidType)
38  , mRunningStatus_TX(InvalidType)
39  , mPendingMessageExpectedLength(0)
40  , mPendingMessageIndex(0)
41  , mCurrentRpnNumber(0xffff)
42  , mCurrentNrpnNumber(0xffff)
43  , mThruActivated(true)
44  , mThruFilterMode(Thru::Full)
45  , mLastMessageSentTime(0)
46  , mLastMessageReceivedTime(0)
47  , mSenderActiveSensingPeriodicity(0)
48  , mReceiverActiveSensingActivated(false)
49  , mLastError(0)
50 {
51  mSenderActiveSensingPeriodicity = Settings::SenderActiveSensingPeriodicity;
52 }

◆ ~MidiInterface()

template<class Transport , class Settings , class Platform >
MidiInterface< Transport, Settings, Platform >::~MidiInterface
inline

Destructor for MidiInterface.

This is not really useful for the Arduino, as it is never called...

Definition at line 59 of file MIDI.hpp.

60 {
61 }

Member Function Documentation

◆ begin()

template<class Transport , class Settings , class Platform >
void MidiInterface< Transport, Settings, Platform >::begin ( Channel  inChannel = 1)

Call the begin method in the setup() function of the Arduino.

All parameters are set to their default values:

  • Input channel set to 1 if no value is specified
  • Full thru mirroring

Definition at line 72 of file MIDI.hpp.

73 {
74  // Initialise the Transport layer
75  mTransport.begin();
76 
77  mInputChannel = inChannel;
78  mRunningStatus_TX = InvalidType;
79  mRunningStatus_RX = InvalidType;
80 
81  mPendingMessageIndex = 0;
82  mPendingMessageExpectedLength = 0;
83 
84  mCurrentRpnNumber = 0xffff;
85  mCurrentNrpnNumber = 0xffff;
86 
87  mLastMessageSentTime = Platform::now();
88 
89  mMessage.valid = false;
90  mMessage.type = InvalidType;
91  mMessage.channel = 0;
92  mMessage.data1 = 0;
93  mMessage.data2 = 0;
94  mMessage.length = 0;
95 
96  mThruFilterMode = Thru::Full;
97  mThruActivated = mTransport.thruActivated;
98 }

◆ getTransport()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
Transport* MidiInterface< Transport, _Settings, _Platform >::getTransport ( )
inline

Definition at line 263 of file MIDI.h.

263 { return &mTransport; };

◆ sendActiveSensing()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendActiveSensing ( )
inline

Definition at line 118 of file MIDI.h.

◆ sendClock()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendClock ( )
inline

Definition at line 113 of file MIDI.h.

113 { sendRealTime(Clock); };

◆ sendContinue()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendContinue ( )
inline

Definition at line 117 of file MIDI.h.

117 { sendRealTime(Continue); };

◆ sendStart()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendStart ( )
inline

Definition at line 114 of file MIDI.h.

114 { sendRealTime(Start); };

◆ sendStop()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendStop ( )
inline

Definition at line 115 of file MIDI.h.

115 { sendRealTime(Stop); };

◆ sendSystemReset()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendSystemReset ( )
inline

Definition at line 119 of file MIDI.h.

◆ sendTick()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::sendTick ( )
inline

Definition at line 116 of file MIDI.h.

116 { sendRealTime(Tick); };

◆ setHandleActiveSensing()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleActiveSensing ( ActiveSensingCallback  fptr)
inline

Definition at line 205 of file MIDI.h.

205 { mActiveSensingCallback = fptr; }

◆ setHandleAfterTouchChannel()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleAfterTouchChannel ( AfterTouchChannelCallback  fptr)
inline

Definition at line 193 of file MIDI.h.

193 { mAfterTouchChannelCallback = fptr; }

◆ setHandleAfterTouchPoly()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleAfterTouchPoly ( AfterTouchPolyCallback  fptr)
inline

Definition at line 190 of file MIDI.h.

190 { mAfterTouchPolyCallback = fptr; }

◆ setHandleClock()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleClock ( ClockCallback  fptr)
inline

Definition at line 200 of file MIDI.h.

200 { mClockCallback = fptr; }

◆ setHandleContinue()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleContinue ( ContinueCallback  fptr)
inline

Definition at line 203 of file MIDI.h.

203 { mContinueCallback = fptr; }

◆ setHandleControlChange()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleControlChange ( ControlChangeCallback  fptr)
inline

Definition at line 191 of file MIDI.h.

191 { mControlChangeCallback = fptr; }

◆ setHandleError()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleError ( ErrorCallback  fptr)
inline

Definition at line 187 of file MIDI.h.

187 { mErrorCallback = fptr; }

◆ setHandleMessage()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleMessage ( void(*)(const MidiMessage &)  fptr)
inline

Definition at line 186 of file MIDI.h.

186 { mMessageCallback = fptr; };

◆ setHandleNoteOff()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleNoteOff ( NoteOffCallback  fptr)
inline

Definition at line 188 of file MIDI.h.

188 { mNoteOffCallback = fptr; }

◆ setHandleNoteOn()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleNoteOn ( NoteOnCallback  fptr)
inline

Definition at line 189 of file MIDI.h.

189 { mNoteOnCallback = fptr; }

◆ setHandlePitchBend()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandlePitchBend ( PitchBendCallback  fptr)
inline

Definition at line 194 of file MIDI.h.

194 { mPitchBendCallback = fptr; }

◆ setHandleProgramChange()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleProgramChange ( ProgramChangeCallback  fptr)
inline

Definition at line 192 of file MIDI.h.

192 { mProgramChangeCallback = fptr; }

◆ setHandleSongPosition()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleSongPosition ( SongPositionCallback  fptr)
inline

Definition at line 197 of file MIDI.h.

197 { mSongPositionCallback = fptr; }

◆ setHandleSongSelect()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleSongSelect ( SongSelectCallback  fptr)
inline

Definition at line 198 of file MIDI.h.

198 { mSongSelectCallback = fptr; }

◆ setHandleStart()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleStart ( StartCallback  fptr)
inline

Definition at line 201 of file MIDI.h.

201 { mStartCallback = fptr; }

◆ setHandleStop()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleStop ( StopCallback  fptr)
inline

Definition at line 204 of file MIDI.h.

204 { mStopCallback = fptr; }

◆ setHandleSystemExclusive()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleSystemExclusive ( SystemExclusiveCallback  fptr)
inline

Definition at line 195 of file MIDI.h.

195 { mSystemExclusiveCallback = fptr; }

◆ setHandleSystemReset()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleSystemReset ( SystemResetCallback  fptr)
inline

Definition at line 206 of file MIDI.h.

206 { mSystemResetCallback = fptr; }

◆ setHandleTick()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleTick ( TickCallback  fptr)
inline

Definition at line 202 of file MIDI.h.

202 { mTickCallback = fptr; }

◆ setHandleTimeCodeQuarterFrame()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleTimeCodeQuarterFrame ( TimeCodeQuarterFrameCallback  fptr)
inline

Definition at line 196 of file MIDI.h.

196 { mTimeCodeQuarterFrameCallback = fptr; }

◆ setHandleTuneRequest()

template<class Transport , class _Settings = DefaultSettings, class _Platform = DefaultPlatform>
void MidiInterface< Transport, _Settings, _Platform >::setHandleTuneRequest ( TuneRequestCallback  fptr)
inline

Definition at line 199 of file MIDI.h.

199 { mTuneRequestCallback = fptr; }

The documentation for this class was generated from the following files:
Clock
@ Clock
System Real Time - Timing Clock.
Definition: midi_Defs.h:113
SystemReset
@ SystemReset
System Real Time - System Reset.
Definition: midi_Defs.h:121
Start
@ Start
System Real Time - Start.
Definition: midi_Defs.h:116
InvalidType
@ InvalidType
For notifying errors.
Definition: midi_Defs.h:96
MidiInterface::sendRealTime
void sendRealTime(MidiType inType)
Send a Real Time (one byte) message.
Definition: MIDI.hpp:492
Message::valid
bool valid
Definition: midi_Message.h:92
Message::length
unsigned length
Definition: midi_Message.h:96
Continue
@ Continue
System Real Time - Continue.
Definition: midi_Defs.h:117
Message::data2
DataByte data2
Definition: midi_Message.h:80
ActiveSensing
@ ActiveSensing
System Real Time - Active Sensing.
Definition: midi_Defs.h:120
Message::type
MidiType type
Definition: midi_Message.h:69
Message::channel
Channel channel
Definition: midi_Message.h:64
Thru::Full
@ Full
Fully enabled Thru (every incoming message is sent back).
Definition: midi_Defs.h:132
Stop
@ Stop
System Real Time - Stop.
Definition: midi_Defs.h:118
Tick
@ Tick
System Real Time - Timing Tick (1 tick = 10 milliseconds)
Definition: midi_Defs.h:115
Message::data1
DataByte data1
Definition: midi_Message.h:74