Ported from Arduino MIDI library Orignal: http://www.arduino.cc/playground/Main/MIDILibrary use Serial (UART)

Dependents:   MIDI_sample MIDI_usb_bridge MIDI_Interpreter midi-timer ... more

Embed: (wiki syntax)

« Back to documentation index

MIDI Class Reference

The main class for MIDI handling.
See member descriptions to know how to use it, or check out the examples supplied with the library. More...

#include <MIDI.h>

Public Member Functions

 MIDI (PinName p_tx, PinName p_rx)
 Default constructor for MIDI.
 ~MIDI ()
 Default destructor for MIDI.
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 Channel)
 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.
void sendPitchBend (double PitchValue, byte Channel)
 Send a Pitch Bend message using a floating point value.
void sendPolyPressure (byte NoteNumber, byte Pressure, byte Channel)
 Send a Polyphonic AfterTouch message (applies to only one specified note)
void sendAfterTouch (byte Pressure, byte Channel)
 Send a MonoPhonic AfterTouch message (applies to all notes)
void sendSysEx (int length, const byte *const array, bool ArrayContainsBoundaries=false)
 Generate and send a System Exclusive frame.
void sendTimeCodeQuarterFrame (byte TypeNibble, byte ValuesNibble)
 Send a MIDI Time Code Quarter Frame.
void sendTimeCodeQuarterFrame (byte data)
 Send a MIDI Time Code Quarter Frame.
void sendSongPosition (unsigned int Beats)
 Send a Song Position Pointer message.
void sendSongSelect (byte SongNumber)
 Send a Song Select message.
void sendTuneRequest ()
 Send a Tune Request message.
void sendRealTime (kMIDIType Type)
 Send a Real Time (one byte) message.
void send (kMIDIType type, byte param1, byte param2, byte channel)
 Generate and send a MIDI message from the values given.
bool read ()
 Read a MIDI message from the serial port using the main input channel (see setInputChannel() for reference).
bool read (const byte Channel)
 Reading/thru-ing method, the same as read() with a given input channel to read on.
kMIDIType getType () const
 Get the last received message's type.
byte getChannel () const
 Get the channel of the message stored in the structure.
byte getData1 () const
 Get the first data byte of the last received message.
byte getData2 () const
 Get the second data byte of the last received message.
const bytegetSysExArray () const
 Get the System Exclusive byte array.
unsigned int getSysExArrayLength () const
 Get the lenght of the System Exclusive array.
bool check () const
 Check if a valid message is stored in the structure.
void setInputChannel (const byte Channel)
 Set the value for the input MIDI channel.
void disconnectCallbackFromType (kMIDIType Type)
 Detach an external function from the given type.
void turnThruOn (kThruFilterMode inThruFilterMode=Full)
 Setter method: turn message mirroring on.
void turnThruOff ()
 Setter method: turn message mirroring off.
void setThruFilterMode (const kThruFilterMode inThruFilterMode)
 Set the filter for thru mirroring.

Static Public Member Functions

static kMIDIType getTypeFromStatusByte (const byte inStatus)
 Extract an enumerated MIDI type from a status byte.

Detailed Description

The main class for MIDI handling.
See member descriptions to know how to use it, or check out the examples supplied with the library.

Definition at line 126 of file MIDI.h.


Constructor & Destructor Documentation

MIDI ( PinName  p_tx,
PinName  p_rx 
)

Default constructor for MIDI.

Definition at line 21 of file MIDI.cpp.

~MIDI (  )

Default destructor for MIDI.

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

Definition at line 55 of file MIDI.cpp.


Member Function Documentation

void begin ( const byte  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 67 of file MIDI.cpp.

bool check (  ) const

Check if a valid message is stored in the structure.

Definition at line 895 of file MIDI.cpp.

void disconnectCallbackFromType ( kMIDIType  Type )

Detach an external function from the given type.

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

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

Definition at line 943 of file MIDI.cpp.

byte getChannel (  ) const

Get the channel of the message stored in the structure.

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

Definition at line 842 of file MIDI.cpp.

byte getData1 (  ) const

Get the first data byte of the last received message.

Definition at line 851 of file MIDI.cpp.

byte getData2 (  ) const

Get the second data byte of the last received message.

Definition at line 860 of file MIDI.cpp.

const byte * getSysExArray (  ) const

Get the System Exclusive byte array.

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

Definition at line 872 of file MIDI.cpp.

unsigned int getSysExArrayLength (  ) const

Get the lenght 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 884 of file MIDI.cpp.

kMIDIType getType (  ) const

Get the last received message's type.

Returns an enumerated type.

See also:
kMIDIType

Definition at line 830 of file MIDI.cpp.

static kMIDIType getTypeFromStatusByte ( const byte  inStatus ) [static]

Extract an enumerated MIDI type from a status byte.

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

Definition at line 208 of file MIDI.h.

bool read ( const byte  Channel )

Reading/thru-ing method, the same as read() with a given input channel to read on.

Definition at line 480 of file MIDI.cpp.

bool read (  )

Read a MIDI message from the serial port using the main input channel (see setInputChannel() 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 471 of file MIDI.cpp.

void send ( kMIDIType  type,
byte  data1,
byte  data2,
byte  channel 
)

Generate and send a MIDI message from the values given.

Parameters:
typeThe message type (see type defines for reference)
data1The first data byte.
data2The second data byte (if the message contains only 1 data byte, set this one to 0).
channelThe output channel on which the message will be sent (values from 1 to 16). Note: you cannot send to OMNI.

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 131 of file MIDI.cpp.

void sendAfterTouch ( byte  Pressure,
byte  Channel 
)

Send a MonoPhonic AfterTouch message (applies to all notes)

Parameters:
PressureThe amount of AfterTouch to apply to all notes.
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 260 of file MIDI.cpp.

void sendControlChange ( byte  ControlNumber,
byte  ControlValue,
byte  Channel 
)

Send a Control Change message.

Parameters:
ControlNumberThe controller number (0 to 127). See the detailed description here: http://www.somascape.org/midi/tech/spec.html#ctrlnums
ControlValueThe value for the specified controller (0 to 127).
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 231 of file MIDI.cpp.

void sendNoteOff ( byte  NoteNumber,
byte  Velocity,
byte  Channel 
)

Send a Note Off message (a real Note Off, not a Note On with null velocity)

Parameters:
NoteNumberPitch 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
VelocityRelease velocity (0 to 127).
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 203 of file MIDI.cpp.

void sendNoteOn ( byte  NoteNumber,
byte  Velocity,
byte  Channel 
)

Send a Note On message.

Parameters:
NoteNumberPitch 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
VelocityNote attack velocity (0 to 127). A NoteOn with 0 velocity is considered as a NoteOff.
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 188 of file MIDI.cpp.

void sendPitchBend ( double  PitchValue,
byte  Channel 
)

Send a Pitch Bend message using a floating point value.

Parameters:
PitchValueThe amount of bend to send (in a floating point format), between -1.0f (maximum downwards bend) and +1.0f (max upwards bend), center value is 0.0f.
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 300 of file MIDI.cpp.

void sendPitchBend ( int  PitchValue,
byte  Channel 
)

Send a Pitch Bend message using a signed integer value.

Parameters:
PitchValueThe amount of bend to send (in a signed integer format), between -8192 (maximum downwards bend) and 8191 (max upwards bend), center value is 0.
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 273 of file MIDI.cpp.

void sendPitchBend ( unsigned int  PitchValue,
byte  Channel 
)

Send a Pitch Bend message using an unsigned integer value.

Parameters:
PitchValueThe amount of bend to send (in a signed integer format), between 0 (maximum downwards bend) and 16383 (max upwards bend), center value is 8192.
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 287 of file MIDI.cpp.

void sendPolyPressure ( byte  NoteNumber,
byte  Pressure,
byte  Channel 
)

Send a Polyphonic AfterTouch message (applies to only one specified note)

Parameters:
NoteNumberThe note to apply AfterTouch to (0 to 127).
PressureThe amount of AfterTouch to apply (0 to 127).
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 246 of file MIDI.cpp.

void sendProgramChange ( byte  ProgramNumber,
byte  Channel 
)

Send a Program Change message.

Parameters:
ProgramNumberThe Program to select (0 to 127).
ChannelThe channel on which the message will be sent (1 to 16).

Definition at line 217 of file MIDI.cpp.

void sendRealTime ( kMIDIType  Type )

Send a Real Time (one byte) message.

Parameters:
TypeThe available Real Time types are: Start, Stop, Continue, Clock, ActiveSensing and SystemReset. You can also send a Tune Request with this method.
See also:
kMIDIType

Definition at line 434 of file MIDI.cpp.

void sendSongPosition ( unsigned int  Beats )

Send a Song Position Pointer message.

Parameters:
BeatsThe number of beats since the start of the song.

Definition at line 400 of file MIDI.cpp.

void sendSongSelect ( byte  SongNumber )

Send a Song Select message.

Definition at line 415 of file MIDI.cpp.

void sendSysEx ( int  length,
const byte *const   array,
bool  ArrayContainsBoundaries = false 
)

Generate and send a System Exclusive frame.

Parameters:
lengthThe size of the array to send
arrayThe byte array containing the data to send
ArrayContainsBoundariesWhen set to 'true', 0xF0 & 0xF7 bytes (start & stop SysEx) will NOT be sent (and therefore must be included in the array). default value is set to 'false' for compatibility with previous versions of the library.

Definition at line 317 of file MIDI.cpp.

void sendTimeCodeQuarterFrame ( byte  data )

Send a MIDI Time Code Quarter Frame.

See MIDI Specification for more information.

Parameters:
dataif you want to encode directly the nibbles in your program, you can send the byte here.

Definition at line 384 of file MIDI.cpp.

void sendTimeCodeQuarterFrame ( byte  TypeNibble,
byte  ValuesNibble 
)

Send a MIDI Time Code Quarter Frame.

See MIDI Specification for more information.

Parameters:
TypeNibbleMTC type
ValuesNibbleMTC data

Definition at line 370 of file MIDI.cpp.

void sendTuneRequest (  )

Send a Tune Request message.

When a MIDI unit receives this message, it should tune its oscillators (if equipped with any)

Definition at line 356 of file MIDI.cpp.

void setInputChannel ( const byte  Channel )

Set the value for the input MIDI channel.

Parameters:
Channelthe 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.

Definition at line 908 of file MIDI.cpp.

void setThruFilterMode ( const kThruFilterMode  inThruFilterMode )

Set the filter for thru mirroring.

Parameters:
inThruFilterModea filter mode
See also:
kThruFilterMode

Definition at line 1029 of file MIDI.cpp.

void turnThruOff (  )

Setter method: turn message mirroring off.

Definition at line 1050 of file MIDI.cpp.

void turnThruOn ( kThruFilterMode  inThruFilterMode = Full )

Setter method: turn message mirroring on.

Definition at line 1040 of file MIDI.cpp.