Arduino MIDI Library v3.1.1 - Reference Manual
Arduino MIDI Library v3.1.1 - Reference Manual
Version 3.1.1
Class Index
Here are the classes, structs, unions and interfaces with brief descriptions:
See member descriptions to know how to use it, or check out the examples supplied
with the library )??
midimsg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ??
2 Class Index
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
Chapter 2
File Index
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
Chapter 3
Class Documentation
• MIDI_Class ()
Default constructor for MIDI_Class.
• ∼MIDI_Class ()
Default destructor for MIDI_Class.
• void begin (const byte inChannel=1)
Call the begin method in the setup() function of the Arduino.
• void sendNoteOn (byte NoteNumber, byte Velocity, byte Channel)
Send a Note On message.
• void sendNoteOff (byte NoteNumber, byte Velocity, byte Channel)
Send a Note Off message (a real Note Off, not a Note On with null velocity)
• void sendProgramChange (byte ProgramNumber, byte Channel)
Send a Program Change message.
• void sendControlChange (byte ControlNumber, byte ControlValue, byte Chan-
nel)
Send a Control Change message.
• void sendPitchBend (int PitchValue, byte Channel)
Send a Pitch Bend message using a signed integer value.
• void sendPitchBend (unsigned int PitchValue, byte Channel)
Send a Pitch Bend message using an unsigned integer value.
6 Class Documentation
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 7
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
8 Class Documentation
{
#if USE_CALLBACKS
// Initialise callbacks to NULL pointer
mNoteOffCallback = NULL;
mNoteOnCallback = NULL;
mAfterTouchPolyCallback = NULL;
mControlChangeCallback = NULL;
mProgramChangeCallback = NULL;
mAfterTouchChannelCallback = NULL;
mPitchBendCallback = NULL;
mSystemExclusiveCallback = NULL;
mTimeCodeQuarterFrameCallback = NULL;
mSongPositionCallback = NULL;
mSongSelectCallback = NULL;
mTuneRequestCallback = NULL;
mClockCallback = NULL;
mStartCallback = NULL;
mContinueCallback = NULL;
mStopCallback = NULL;
mActiveSensingCallback = NULL;
mSystemResetCallback = NULL;
#endif
}
{ }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 9
#if COMPILE_MIDI_OUT
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif // USE_RUNNING_STATUS
#endif // COMPILE_MIDI_OUT
#if COMPILE_MIDI_IN
mInputChannel = inChannel;
mRunningStatus_RX = InvalidType;
mPendingMessageIndex = 0;
mPendingMessageExpectedLenght = 0;
mMessage.valid = false;
mMessage.type = InvalidType;
mMessage.channel = 0;
mMessage.data1 = 0;
mMessage.data2 = 0;
#endif // COMPILE_MIDI_IN
mThruFilterMode = Full;
mThruActivated = true;
#endif // Thru
{ return mMessage.valid; }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
10 Class Documentation
Parameters
Type The type of message to unbind. When a message of this type is received,
no function will be called.
switch (Type) {
case NoteOff: mNoteOffCallback = NULL; break
;
case NoteOn: mNoteOnCallback = NULL; break
;
case AfterTouchPoly: mAfterTouchPolyCallback = NULL; break
;
case ControlChange: mControlChangeCallback = NULL; break
;
case ProgramChange: mProgramChangeCallback = NULL; break
;
case AfterTouchChannel: mAfterTouchChannelCallback = NULL; break
;
case PitchBend: mPitchBendCallback = NULL; break
;
case SystemExclusive: mSystemExclusiveCallback = NULL; break
;
case TimeCodeQuarterFrame: mTimeCodeQuarterFrameCallback = NULL; break
;
case SongPosition: mSongPositionCallback = NULL; break
;
case SongSelect: mSongSelectCallback = NULL; break
;
case TuneRequest: mTuneRequestCallback = NULL; break
;
case Clock: mClockCallback = NULL; break
;
case Start: mStartCallback = NULL; break
;
case Continue: mContinueCallback = NULL; break
;
case Stop: mStopCallback = NULL; break
;
case ActiveSensing: mActiveSensingCallback = NULL; break
;
case SystemReset: mSystemResetCallback = NULL; break
;
default:
break;
}
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 11
{ return mMessage.channel; }
{ return mMessage.data1; }
{ return mMessage.data2; }
{ return mThruFilterMode; }
{ return mInputChannel; }
{ return mMessage.sysex_array; }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
12 Class Documentation
{ return mThruActivated; }
See also
kMIDIType
{ return mMessage.type; }
{
if ((inStatus < 0x80)
|| (inStatus == 0xF4)
|| (inStatus == 0xF5)
|| (inStatus == 0xF9)
|| (inStatus == 0xFD)) return InvalidType; // data bytes and undefine
d.
if (inStatus < 0xF0) return (kMIDIType)(inStatus & 0xF0); // Channel me
ssage, remove channel nibble.
else return (kMIDIType)inStatus;
}
Reading/thru-ing method, the same as read() with a given input channel to read on.
Definition at line 350 of file MIDI.cpp.
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 13
if (parse(inChannel)) {
if (input_filter(inChannel)) {
#if USE_CALLBACKS
launchCallback();
#endif
return true;
}
}
return false;
}
Read a MIDI message from the serial port using the main input channel (see set-
InputChannel() for reference).
Returned value: true if any 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 messages matches the filter, it is sent back on the MIDI
output.
Definition at line 345 of file MIDI.cpp.
{
return read(mInputChannel);
}
3.1.3.15 void MIDI Class::send ( kMIDIType type, byte data1, byte data2, byte channel )
Parameters
type The message type (see type defines for reference)
data1 The first data byte.
data2 The second data byte (if the message contains only 1 data byte, set this one
to 0).
channel The output channel on which the message will be sent (values from 1 to 16).
Note: you cannot send to OMNI.
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
14 Class Documentation
This is an internal method, use it only if you need to send raw data from your code, at
your own risks.
Definition at line 114 of file MIDI.cpp.
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
#if USE_RUNNING_STATUS
// Check Running Status
if (mRunningStatus_TX != statusbyte) {
// New message, memorise and send header
mRunningStatus_TX = statusbyte;
USE_SERIAL_PORT.write(mRunningStatus_TX);
}
#else
// Don’t care about running status, send the Control byte.
USE_SERIAL_PORT.write(statusbyte);
#endif
Parameters
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 15
{ send(AfterTouchChannel,Pressure,0,Channel); }
Parameters
ControlNum- The controller number (0 to 127). See the detailed description here:
ber http://www.somascape.org/midi/tech/spec.html#ctrlnums
ControlValue The value for the specified controller (0 to 127).
Channel The channel on which the message will be sent (1 to 16).
{ send(ControlChange,ControlNumber,ControlValue,Channel); }
3.1.3.18 void MIDI Class::sendNoteOff ( byte NoteNumber, byte Velocity, byte Channel )
Send a Note Off message (a real Note Off, not a Note On with null velocity)
Parameters
NoteNumber Pitch value in the MIDI format (0 to 127). Take a look
at the values, names and frequencies of notes here:
http://www.phys.unsw.edu.au/jw/notes.html
{ send(NoteOff,NoteNumber,Velocity,Channel); }
3.1.3.19 void MIDI Class::sendNoteOn ( byte NoteNumber, byte Velocity, byte Channel )
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
16 Class Documentation
Parameters
NoteNumber Pitch value in the MIDI format (0 to 127). Take a look
at the values, names and frequencies of notes here:
http://www.phys.unsw.edu.au/jw/notes.html
{ send(NoteOn,NoteNumber,Velocity,Channel); }
Parameters
PitchValue The amount of bend to send (in a floating point format), between -1.0f (max-
imum downwards bend) and +1.0f (max upwards bend), center value is 0.0f.
Channel The channel on which the message will be sent (1 to 16).
Parameters
PitchValue The amount of bend to send (in a signed integer format), between -8192
(maximum downwards bend) and 8191 (max upwards bend), center value is
0.
Channel The channel on which the message will be sent (1 to 16).
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 17
Parameters
PitchValue The amount of bend to send (in a signed integer format), between 0 (max-
imum downwards bend) and 16383 (max upwards bend), center value is
8192.
Channel The channel on which the message will be sent (1 to 16).
Parameters
NoteNumber The note to apply AfterTouch to (0 to 127).
Pressure The amount of AfterTouch to apply (0 to 127).
Channel The channel on which the message will be sent (1 to 16).
{ send(AfterTouchPoly,NoteNumber,Pressure,Channel); }
Parameters
Program- The Program to select (0 to 127).
Number
Channel The channel on which the message will be sent (1 to 16).
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
18 Class Documentation
{ send(ProgramChange,ProgramNumber,0,Channel); }
Parameters
Type The available Real Time types are: Start, Stop, Continue, Clock, ActiveSens-
ing and SystemReset. You can also send a Tune Request with this method.
See also
kMIDIType
{
switch (Type) {
case TuneRequest: // Not really real-time, but one byte anyway.
case Clock:
case Start:
case Stop:
case Continue:
case ActiveSensing:
case SystemReset:
USE_SERIAL_PORT.write((byte)Type);
break;
default:
// Invalid Real Time marker
break;
}
// Do not cancel Running Status for real-time messages as they can be interle
aved within any message.
// Though, TuneRequest can be sent here, and as it is a System Common message
, it must reset Running Status.
#if USE_RUNNING_STATUS
if (Type == TuneRequest) mRunningStatus_TX = InvalidType;
#endif
Parameters
Beats The number of beats since the start of the song.
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 19
USE_SERIAL_PORT.write((byte)SongPosition);
USE_SERIAL_PORT.write(Beats & 0x7F);
USE_SERIAL_PORT.write((Beats >> 7) & 0x7F);
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
}
USE_SERIAL_PORT.write((byte)SongSelect);
USE_SERIAL_PORT.write(SongNumber & 0x7F);
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
}
Parameters
length The size of the array to send
array The byte array containing the data to send
ArrayCon- When set to ’true’, 0xF0 & 0xF7 bytes (start & stop SysEx) will NOT be sent
tainsBound- (and therefore must be included in the array). default value is set to ’false’
aries for compatibility with previous versions of the library.
{
if (!ArrayContainsBoundaries) USE_SERIAL_PORT.write(0xF0);
for (byte i=0;i<length;i++) USE_SERIAL_PORT.write(array[i]);
if (!ArrayContainsBoundaries) USE_SERIAL_PORT.write(0xF7);
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
}
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
20 Class Documentation
Parameters
TypeNibble MTC type
ValuesNib- MTC data
ble
Parameters
data if you want to encode directly the nibbles in your program, you can send the
byte here.
USE_SERIAL_PORT.write((byte)TimeCodeQuarterFrame);
USE_SERIAL_PORT.write(data);
#if USE_RUNNING_STATUS
mRunningStatus_TX = InvalidType;
#endif
}
{ sendRealTime(TuneRequest); }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 21
{ mActiveSensingCallback = fptr; }
{ mAfterTouchChannelCallback = fptr; }
{ mAfterTouchPolyCallback = fptr; }
{ mClockCallback = fptr; }
{ mContinueCallback = fptr; }
{ mControlChangeCallback = fptr; }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
22 Class Documentation
3.1.3.38 void MIDI Class::setHandleNoteOff ( void(∗)(byte channel, byte note, byte velocity)
fptr )
{ mNoteOffCallback = fptr; }
3.1.3.39 void MIDI Class::setHandleNoteOn ( void(∗)(byte channel, byte note, byte velocity)
fptr )
{ mNoteOnCallback = fptr; }
{ mPitchBendCallback = fptr; }
{ mProgramChangeCallback = fptr; }
{ mSongPositionCallback = fptr; }
{ mSongSelectCallback = fptr; }
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.1 MIDI_Class Class Reference 23
{ mStartCallback = fptr; }
{ mStopCallback = fptr; }
{ mSystemExclusiveCallback = fptr; }
{ mSystemResetCallback = fptr; }
{ mTimeCodeQuarterFrameCallback = fptr; }
{ mTuneRequestCallback = fptr; }
Parameters
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
24 Class Documentation
Channel the 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 MIDI
input.
{ mInputChannel = Channel; }
Parameters
inThruFilter- a filter mode
Mode
See also
kThruFilterMode
{
mThruFilterMode = inThruFilterMode;
if (mThruFilterMode != Off) mThruActivated = true;
else mThruActivated = false;
}
{
mThruActivated = false;
mThruFilterMode = Off;
}
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
3.2 midimsg Struct Reference 25
{
mThruActivated = true;
mThruFilterMode = inThruFilterMode;
}
The documentation for this class was generated from the following files:
• /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/libraries/MIDILib/trunk/Arduino/MIDI.h
• /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/libraries/MIDILib/trunk/Arduino/MIDI.cpp
#include <MIDI.h>
Public Attributes
• byte channel
• kMIDIType type
• byte data1
• byte data2
• byte sysex_array [MIDI_SYSEX_ARRAY_SIZE]
• bool valid
The midimsg structure contains decoded data of a MIDI message read from the serial
port with read() or thru().
Definition at line 98 of file MIDI.h.
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
26 Class Documentation
The second data byte. If the message is only 2 bytes long, this one is null.
Value goes from 0 to 127.
Definition at line 106 of file MIDI.h.
The type of the message (see the define section for types reference)
Definition at line 102 of file MIDI.h.
This boolean indicates if the message is valid or not. There is no channel consideration
here, validity means the message respects the MIDI norm.
Definition at line 110 of file MIDI.h.
The documentation for this struct was generated from the following file:
• /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/libraries/MIDILib/trunk/Arduino/MIDI.h
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
Chapter 4
File Documentation
4.1 /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/libraries/MIDILib/trunk/Arduino/MID
File Reference
Variables
• MIDI_Class MIDI
Main instance (the class comes pre-instantiated).
Version
3.1
Author
Francois Best
Date
4.2 /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/libraries/MIDILib/trunk/A
File Reference
Classes
• struct midimsg
• class MIDI_Class
The main class for MIDI handling.
See member descriptions to know how to use it, or check out the examples supplied
with the library.
Defines
• #define COMPILE_MIDI_IN 1
• #define COMPILE_MIDI_OUT 1
• #define COMPILE_MIDI_THRU 1
• #define USE_SERIAL_PORT Serial
• #define USE_RUNNING_STATUS 1
• #define USE_CALLBACKS 1
• #define MIDI_BAUDRATE 31250
• #define MIDI_CHANNEL_OMNI 0
• #define MIDI_CHANNEL_OFF 17
• #define MIDI_SYSEX_ARRAY_SIZE 255
Typedefs
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
4.2 /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/li-
braries/MIDILib/trunk/Arduino/MIDI.h File
Reference 29
Enumerations
• enum kMIDIType {
NoteOff = 0x80, NoteOn = 0x90, AfterTouchPoly = 0xA0, ControlChange = 0xB0,
ProgramChange = 0xC0, AfterTouchChannel = 0xD0, PitchBend = 0xE0, Syste-
mExclusive = 0xF0,
TimeCodeQuarterFrame = 0xF1, SongPosition = 0xF2, SongSelect = 0xF3, TuneRequest
= 0xF6,
Clock = 0xF8, Start = 0xFA, Continue = 0xFB, Stop = 0xFC,
ActiveSensing = 0xFE, SystemReset = 0xFF, InvalidType = 0x00 }
• enum kThruFilterMode { Off = 0, Full = 1, SameChannel = 2, DifferentChannel =
3}
Variables
• MIDI_Class MIDI
Main instance (the class comes pre-instantiated).
MIDI Library for the Arduino Version 3.1. Project MIDI Library
Author
Francois Best
Date
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
30 File Documentation
Type definition for practical use (because "unsigned char" is a bit long to write.. )
Definition at line 62 of file MIDI.h.
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
4.2 /Users/franky/Documents/Dropbox/SVN/embedded/toolbox/li-
braries/MIDILib/trunk/Arduino/MIDI.h File
Reference 31
4.2.4 Enumeration Type Documentation
Enumerator:
{
NoteOff = 0x80,
NoteOn = 0x90,
AfterTouchPoly = 0xA0,
ControlChange = 0xB0,
ProgramChange = 0xC0,
AfterTouchChannel = 0xD0,
PitchBend = 0xE0,
SystemExclusive = 0xF0,
TimeCodeQuarterFrame = 0xF1,
SongPosition = 0xF2,
SongSelect = 0xF3,
TuneRequest = 0xF6,
Clock = 0xF8,
Start = 0xFA,
Continue = 0xFB,
Stop = 0xFC,
ActiveSensing = 0xFE,
SystemReset = 0xFF,
InvalidType = 0x00
};
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen
32 File Documentation
Enumerator:
{
Off = 0,
Full = 1,
SameChannel = 2,
DifferentChannel = 3
};
Generated on Fri May 20 2011 19:49:48 for Arduino MIDI Library by Doxygen