Arduino MIDI Library  Version 4.3.1
MidiInterface< SerialPort, _Settings > 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
 

Public Member Functions

 MidiInterface (SerialPort &inSerial)
 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 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 (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 lenght 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 setHandleNoteOff (void(*fptr)(byte channel, byte note, byte velocity))
 
void setHandleNoteOn (void(*fptr)(byte channel, byte note, byte velocity))
 
void setHandleAfterTouchPoly (void(*fptr)(byte channel, byte note, byte pressure))
 
void setHandleControlChange (void(*fptr)(byte channel, byte number, byte value))
 
void setHandleProgramChange (void(*fptr)(byte channel, byte number))
 
void setHandleAfterTouchChannel (void(*fptr)(byte channel, byte pressure))
 
void setHandlePitchBend (void(*fptr)(byte channel, int bend))
 
void setHandleSystemExclusive (void(*fptr)(byte *array, unsigned size))
 
void setHandleTimeCodeQuarterFrame (void(*fptr)(byte data))
 
void setHandleSongPosition (void(*fptr)(unsigned beats))
 
void setHandleSongSelect (void(*fptr)(byte songnumber))
 
void setHandleTuneRequest (void(*fptr)(void))
 
void setHandleClock (void(*fptr)(void))
 
void setHandleStart (void(*fptr)(void))
 
void setHandleContinue (void(*fptr)(void))
 
void setHandleStop (void(*fptr)(void))
 
void setHandleActiveSensing (void(*fptr)(void))
 
void setHandleSystemReset (void(*fptr)(void))
 
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...
 

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 SerialPort, class _Settings = DefaultSettings>
class MidiInterface< SerialPort, _Settings >

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 45 of file MIDI.h.

Member Typedef Documentation

§ Settings

template<class SerialPort , class _Settings = DefaultSettings>
typedef _Settings MidiInterface< SerialPort, _Settings >::Settings

Definition at line 48 of file MIDI.h.

Constructor & Destructor Documentation

§ MidiInterface()

template<class SerialPort , class Settings >
BEGIN_MIDI_NAMESPACE MidiInterface< SerialPort, Settings >::MidiInterface ( SerialPort &  inSerial)
inline

Constructor for MidiInterface.

Definition at line 34 of file MIDI.hpp.

35  : mSerial(inSerial)
36  , mInputChannel(0)
37  , mRunningStatus_RX(InvalidType)
38  , mRunningStatus_TX(InvalidType)
39  , mPendingMessageExpectedLenght(0)
40  , mPendingMessageIndex(0)
41  , mCurrentRpnNumber(0xffff)
42  , mCurrentNrpnNumber(0xffff)
43  , mThruActivated(true)
44  , mThruFilterMode(Thru::Full)
45 {
46  mNoteOffCallback = 0;
47  mNoteOnCallback = 0;
48  mAfterTouchPolyCallback = 0;
49  mControlChangeCallback = 0;
50  mProgramChangeCallback = 0;
51  mAfterTouchChannelCallback = 0;
52  mPitchBendCallback = 0;
53  mSystemExclusiveCallback = 0;
54  mTimeCodeQuarterFrameCallback = 0;
55  mSongPositionCallback = 0;
56  mSongSelectCallback = 0;
57  mTuneRequestCallback = 0;
58  mClockCallback = 0;
59  mStartCallback = 0;
60  mContinueCallback = 0;
61  mStopCallback = 0;
62  mActiveSensingCallback = 0;
63  mSystemResetCallback = 0;
64 }
For notifying errors.
Definition: midi_Defs.h:67
Fully enabled Thru (every incoming message is sent back).
Definition: midi_Defs.h:96

§ ~MidiInterface()

template<class SerialPort , class Settings >
MidiInterface< SerialPort, Settings >::~MidiInterface ( )
inline

Destructor for MidiInterface.

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

Definition at line 71 of file MIDI.hpp.

72 {
73 }

Member Function Documentation

§ begin()

template<class SerialPort , class Settings >
void MidiInterface< SerialPort, Settings >::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 84 of file MIDI.hpp.

85 {
86  // Initialise the Serial port
87 #if defined(FSE_AVR)
88  mSerial. template open<Settings::BaudRate>();
89 #else
90  mSerial.begin(Settings::BaudRate);
91 #endif
92 
93  mInputChannel = inChannel;
94  mRunningStatus_TX = InvalidType;
95  mRunningStatus_RX = InvalidType;
96 
97  mPendingMessageIndex = 0;
98  mPendingMessageExpectedLenght = 0;
99 
100  mCurrentRpnNumber = 0xffff;
101  mCurrentNrpnNumber = 0xffff;
102 
103  mMessage.valid = false;
104  mMessage.type = InvalidType;
105  mMessage.channel = 0;
106  mMessage.data1 = 0;
107  mMessage.data2 = 0;
108 
109  mThruFilterMode = Thru::Full;
110  mThruActivated = true;
111 }
DataByte data1
Definition: midi_Message.h:71
DataByte data2
Definition: midi_Message.h:77
MidiType type
Definition: midi_Message.h:66
For notifying errors.
Definition: midi_Defs.h:67
bool valid
Definition: midi_Message.h:89
Fully enabled Thru (every incoming message is sent back).
Definition: midi_Defs.h:96
Channel channel
Definition: midi_Message.h:61

The documentation for this class was generated from the following files: