Arduino MIDI Library  Version 5.0.1
MIDI Input

Modules

 Callbacks
 

Functions

bool MidiInterface< Transport, _Settings, _Platform >::read ()
 Read messages from the serial port using the main input channel. More...
 
bool MidiInterface< Transport, _Settings, _Platform >::read (Channel inChannel)
 Read messages on a specified channel. More...
 
MidiType MidiInterface< Transport, _Settings, _Platform >::getType () const
 Get the last received message's type. More...
 
Channel MidiInterface< Transport, _Settings, _Platform >::getChannel () const
 Get the channel of the message stored in the structure. More...
 
DataByte MidiInterface< Transport, _Settings, _Platform >::getData1 () const
 Get the first data byte of the last received message. More...
 
DataByte MidiInterface< Transport, _Settings, _Platform >::getData2 () const
 Get the second data byte of the last received message. More...
 
const byteMidiInterface< Transport, _Settings, _Platform >::getSysExArray () const
 Get the System Exclusive byte array. More...
 
unsigned MidiInterface< Transport, _Settings, _Platform >::getSysExArrayLength () const
 Get the length of the System Exclusive array. More...
 
bool MidiInterface< Transport, _Settings, _Platform >::check () const
 Check if a valid message is stored in the structure. More...
 
Channel MidiInterface< Transport, _Settings, _Platform >::getInputChannel () const
 
void MidiInterface< Transport, _Settings, _Platform >::setInputChannel (Channel inChannel)
 Set the value for the input MIDI channel. More...
 
static MidiType MidiInterface< Transport, _Settings, _Platform >::getTypeFromStatusByte (byte inStatus)
 Extract an enumerated MIDI type from a status byte. More...
 
static Channel MidiInterface< Transport, _Settings, _Platform >::getChannelFromStatusByte (byte inStatus)
 Returns channel in the range 1-16. More...
 
static bool MidiInterface< Transport, _Settings, _Platform >::isChannelMessage (MidiType inType)
 
void MidiInterface< Transport, _Settings, _Platform >::disconnectCallbackFromType (MidiType inType)
 Detach an external function from the given type. More...
 

Detailed Description

Function Documentation

◆ check()

template<class Transport , class Settings , class Platform >
bool MidiInterface< Transport, Settings, Platform >::check
inline

Check if a valid message is stored in the structure.

Definition at line 1187 of file MIDI.hpp.

1188 {
1189  return mMessage.valid;
1190 }

◆ disconnectCallbackFromType()

template<class Transport , class Settings , class Platform >
void MidiInterface< Transport, Settings, Platform >::disconnectCallbackFromType ( MidiType  inType)
inline

Detach an external function from the given type.

Use this method to cancel the effects of setHandle********.

Parameters
inTypeThe type of message to unbind. When a message of this type is received, no function will be called.

Definition at line 1262 of file MIDI.hpp.

1263 {
1264  switch (inType)
1265  {
1266  case NoteOff: mNoteOffCallback = nullptr; break;
1267  case NoteOn: mNoteOnCallback = nullptr; break;
1268  case AfterTouchPoly: mAfterTouchPolyCallback = nullptr; break;
1269  case ControlChange: mControlChangeCallback = nullptr; break;
1270  case ProgramChange: mProgramChangeCallback = nullptr; break;
1271  case AfterTouchChannel: mAfterTouchChannelCallback = nullptr; break;
1272  case PitchBend: mPitchBendCallback = nullptr; break;
1273  case SystemExclusive: mSystemExclusiveCallback = nullptr; break;
1274  case TimeCodeQuarterFrame: mTimeCodeQuarterFrameCallback = nullptr; break;
1275  case SongPosition: mSongPositionCallback = nullptr; break;
1276  case SongSelect: mSongSelectCallback = nullptr; break;
1277  case TuneRequest: mTuneRequestCallback = nullptr; break;
1278  case Clock: mClockCallback = nullptr; break;
1279  case Start: mStartCallback = nullptr; break;
1280  case Tick: mTickCallback = nullptr; break;
1281  case Continue: mContinueCallback = nullptr; break;
1282  case Stop: mStopCallback = nullptr; break;
1283  case ActiveSensing: mActiveSensingCallback = nullptr; break;
1284  case SystemReset: mSystemResetCallback = nullptr; break;
1285  default:
1286  break;
1287  }
1288 }

◆ getChannel()

template<class Transport , class Settings , class Platform >
Channel MidiInterface< Transport, Settings, Platform >::getChannel
inline

Get the channel of the message stored in the structure.

Returns
Channel range is 1 to 16. For non-channel messages, this will return 0.

Definition at line 1145 of file MIDI.hpp.

1146 {
1147  return mMessage.channel;
1148 }

◆ getChannelFromStatusByte()

template<class Transport , class Settings , class Platform >
Channel MidiInterface< Transport, Settings, Platform >::getChannelFromStatusByte ( byte  inStatus)
inlinestatic

Returns channel in the range 1-16.

Definition at line 1236 of file MIDI.hpp.

1237 {
1238  return Channel((inStatus & 0x0f) + 1);
1239 }

◆ getData1()

template<class Transport , class Settings , class Platform >
DataByte MidiInterface< Transport, Settings, Platform >::getData1
inline

Get the first data byte of the last received message.

Definition at line 1152 of file MIDI.hpp.

1153 {
1154  return mMessage.data1;
1155 }

◆ getData2()

template<class Transport , class Settings , class Platform >
DataByte MidiInterface< Transport, Settings, Platform >::getData2
inline

Get the second data byte of the last received message.

Definition at line 1159 of file MIDI.hpp.

1160 {
1161  return mMessage.data2;
1162 }

◆ getInputChannel()

template<class Transport , class Settings , class Platform >
Channel MidiInterface< Transport, Settings, Platform >::getInputChannel
inline

Definition at line 1195 of file MIDI.hpp.

1196 {
1197  return mInputChannel;
1198 }

◆ getSysExArray()

template<class Transport , class Settings , class Platform >
const byte * MidiInterface< Transport, Settings, Platform >::getSysExArray
inline

Get the System Exclusive byte array.

See also
getSysExArrayLength to get the array's length in bytes.

Definition at line 1169 of file MIDI.hpp.

1170 {
1171  return mMessage.sysexArray;
1172 }

◆ getSysExArrayLength()

template<class Transport , class Settings , class Platform >
unsigned MidiInterface< Transport, Settings, Platform >::getSysExArrayLength
inline

Get the length of the System Exclusive array.

It is coded using data1 as LSB and data2 as MSB.

Returns
The array's length, in bytes.

Definition at line 1180 of file MIDI.hpp.

1181 {
1182  return mMessage.getSysExSize();
1183 }

◆ getType()

template<class Transport , class Settings , class Platform >
MidiType MidiInterface< Transport, Settings, Platform >::getType
inline

Get the last received message's type.

Returns an enumerated type.

See also
MidiType

Definition at line 1134 of file MIDI.hpp.

1135 {
1136  return mMessage.type;
1137 }

◆ getTypeFromStatusByte()

template<class Transport , class Settings , class Platform >
MidiType MidiInterface< Transport, Settings, Platform >::getTypeFromStatusByte ( byte  inStatus)
inlinestatic

Extract an enumerated MIDI type from a status byte.

This is a utility static method, used internally, made public so you can handle MidiTypes more easily.

Definition at line 1218 of file MIDI.hpp.

1219 {
1220  if ((inStatus < 0x80) ||
1221  (inStatus == Undefined_F4) ||
1222  (inStatus == Undefined_F5) ||
1223  (inStatus == Undefined_FD))
1224  return InvalidType; // Data bytes and undefined.
1225 
1226  if (inStatus < 0xf0)
1227  // Channel message, remove channel nibble.
1228  return MidiType(inStatus & 0xf0);
1229 
1230  return MidiType(inStatus);
1231 }

◆ isChannelMessage()

template<class Transport , class Settings , class Platform >
bool MidiInterface< Transport, Settings, Platform >::isChannelMessage ( MidiType  inType)
inlinestatic

Definition at line 1242 of file MIDI.hpp.

1243 {
1244  return (inType == NoteOff ||
1245  inType == NoteOn ||
1246  inType == ControlChange ||
1247  inType == AfterTouchPoly ||
1248  inType == AfterTouchChannel ||
1249  inType == PitchBend ||
1250  inType == ProgramChange);
1251 }

◆ read() [1/2]

template<class Transport , class Settings , class Platform >
bool MidiInterface< Transport, Settings, Platform >::read
inline

Read messages from the serial port using the main input channel.

Returns
True if a valid message has been stored in the structure, false if not. A valid message is a message that matches the input channel.

If the Thru is enabled and the message matches the filter, it is sent back on the MIDI output.
See also
see setInputChannel()

Definition at line 704 of file MIDI.hpp.

705 {
706  return read(mInputChannel);
707 }

◆ read() [2/2]

template<class Transport , class Settings , class Platform >
bool MidiInterface< Transport, Settings, Platform >::read ( Channel  inChannel)
inline

Read messages on a specified channel.

Definition at line 712 of file MIDI.hpp.

713 {
714  #ifndef RegionActiveSending
715  // Active Sensing. This message is intended to be sent
716  // repeatedly to tell the receiver that a connection is alive. Use
717  // of this message is optional. When initially received, the
718  // receiver will expect to receive another Active Sensing
719  // message each 300ms (max), and if it does not then it will
720  // assume that the connection has been terminated. At
721  // termination, the receiver will turn off all voices and return to
722  // normal (non- active sensing) operation.
723  if (Settings::UseSenderActiveSensing && (mSenderActiveSensingPeriodicity > 0) && (Platform::now() - mLastMessageSentTime) > mSenderActiveSensingPeriodicity)
724  {
726  mLastMessageSentTime = Platform::now();
727  }
728 
729  if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActivated && (mLastMessageReceivedTime + ActiveSensingTimeout < Platform::now()))
730  {
731  mReceiverActiveSensingActivated = false;
732 
733  mLastError |= 1UL << ErrorActiveSensingTimeout; // set the ErrorActiveSensingTimeout bit
734  if (mErrorCallback)
735  mErrorCallback(mLastError);
736  }
737  #endif
738 
739  if (inChannel >= MIDI_CHANNEL_OFF)
740  return false; // MIDI Input disabled.
741 
742  if (!parse())
743  return false;
744 
745  #ifndef RegionActiveSending
746 
747  if (Settings::UseReceiverActiveSensing && mMessage.type == ActiveSensing)
748  {
749  // When an ActiveSensing message is received, the time keeping is activated.
750  // When a timeout occurs, an error message is send and time keeping ends.
751  mReceiverActiveSensingActivated = true;
752 
753  // is ErrorActiveSensingTimeout bit in mLastError on
754  if (mLastError & (1 << (ErrorActiveSensingTimeout - 1)))
755  {
756  mLastError &= ~(1UL << ErrorActiveSensingTimeout); // clear the ErrorActiveSensingTimeout bit
757  if (mErrorCallback)
758  mErrorCallback(mLastError);
759  }
760  }
761 
762  // Keep the time of the last received message, so we can check for the timeout
763  if (Settings::UseReceiverActiveSensing && mReceiverActiveSensingActivated)
764  mLastMessageReceivedTime = Platform::now();
765 
766  #endif
767 
768  handleNullVelocityNoteOnAsNoteOff();
769 
770  const bool channelMatch = inputFilter(inChannel);
771  if (channelMatch)
772  launchCallback();
773 
774  thruFilter(inChannel);
775 
776  return channelMatch;
777 }

◆ setInputChannel()

template<class Transport , class Settings , class Platform >
void MidiInterface< Transport, Settings, Platform >::setInputChannel ( Channel  inChannel)
inline

Set the value for the input MIDI channel.

Parameters
inChannelthe channel value. Valid values are 1 to 16, MIDI_CHANNEL_OMNI if you want to listen to all channels, and MIDI_CHANNEL_OFF to disable input.

Definition at line 1205 of file MIDI.hpp.

1206 {
1207  mInputChannel = inChannel;
1208 }
Undefined_F4
@ Undefined_F4
Definition: midi_Defs.h:109
Clock
@ Clock
System Real Time - Timing Clock.
Definition: midi_Defs.h:113
Message::getSysExSize
unsigned getSysExSize() const
Definition: midi_Message.h:98
SystemReset
@ SystemReset
System Real Time - System Reset.
Definition: midi_Defs.h:121
SystemExclusive
@ SystemExclusive
System Exclusive.
Definition: midi_Defs.h:104
TuneRequest
@ TuneRequest
System Common - Tune Request.
Definition: midi_Defs.h:111
ErrorActiveSensingTimeout
static const uint8_t ErrorActiveSensingTimeout
Definition: midi_Defs.h:64
ActiveSensingTimeout
static const uint16_t ActiveSensingTimeout
Definition: midi_Defs.h:51
Undefined_F5
@ Undefined_F5
Definition: midi_Defs.h:110
Message::sysexArray
DataByte sysexArray[sSysExMaxSize]
Definition: midi_Message.h:86
MIDI_CHANNEL_OFF
#define MIDI_CHANNEL_OFF
Definition: midi_Defs.h:44
ProgramChange
@ ProgramChange
Channel Message - Program Change.
Definition: midi_Defs.h:101
Start
@ Start
System Real Time - Start.
Definition: midi_Defs.h:116
InvalidType
@ InvalidType
For notifying errors.
Definition: midi_Defs.h:96
AfterTouchPoly
@ AfterTouchPoly
Channel Message - Polyphonic AfterTouch.
Definition: midi_Defs.h:99
Message::valid
bool valid
Definition: midi_Message.h:92
TimeCodeQuarterFrame
@ TimeCodeQuarterFrame
System Common - MIDI Time Code Quarter Frame.
Definition: midi_Defs.h:106
Undefined_FD
@ Undefined_FD
Definition: midi_Defs.h:119
NoteOn
@ NoteOn
Channel Message - Note On.
Definition: midi_Defs.h:98
Continue
@ Continue
System Real Time - Continue.
Definition: midi_Defs.h:117
NoteOff
@ NoteOff
Channel Message - Note Off.
Definition: midi_Defs.h:97
Message::data2
DataByte data2
Definition: midi_Message.h:80
SongSelect
@ SongSelect
System Common - Song Select.
Definition: midi_Defs.h:108
ActiveSensing
@ ActiveSensing
System Real Time - Active Sensing.
Definition: midi_Defs.h:120
Message::type
MidiType type
Definition: midi_Message.h:69
MidiType
MidiType
Definition: midi_Defs.h:95
PitchBend
@ PitchBend
Channel Message - Pitch Bend.
Definition: midi_Defs.h:103
Message::channel
Channel channel
Definition: midi_Message.h:64
Channel
byte Channel
Definition: midi_Defs.h:58
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
ControlChange
@ ControlChange
Channel Message - Control Change / Channel Mode.
Definition: midi_Defs.h:100
Message::data1
DataByte data1
Definition: midi_Message.h:74
SongPosition
@ SongPosition
System Common - Song Position Pointer.
Definition: midi_Defs.h:107
MidiInterface::read
bool read()
Read messages from the serial port using the main input channel.
Definition: MIDI.hpp:704
AfterTouchChannel
@ AfterTouchChannel
Channel Message - Channel (monophonic) AfterTouch.
Definition: midi_Defs.h:102
MidiInterface::sendActiveSensing
void sendActiveSensing()
Definition: MIDI.h:118