MIDI_Class Class Reference

#include <MIDI.h>

List of all members.

Public Member Functions

 MIDI_Class ()
 ~MIDI_Class ()
void begin (const byte inChannel=1)
void sendNoteOn (byte NoteNumber, byte Velocity, byte Channel)
void sendNoteOff (byte NoteNumber, byte Velocity, byte Channel)
void sendProgramChange (byte ProgramNumber, byte Channel)
void sendControlChange (byte ControlNumber, byte ControlValue, byte Channel)
void sendPitchBend (unsigned int PitchValue, byte Channel)
void sendPitchBend (double PitchValue, byte Channel)
void sendPolyPressure (byte NoteNumber, byte Pressure, byte Channel)
void sendAfterTouch (byte Pressure, byte Channel)
void sendSysEx (byte length, byte *array, bool ArrayContainsBoundaries=false)
void sendTimeCodeQuarterFrame (byte TypeNibble, byte ValuesNibble)
void sendTimeCodeQuarterFrame (byte data)
void sendSongPosition (unsigned int Beats)
void sendSongSelect (byte SongNumber)
void sendTuneRequest ()
void sendRealTime (kMIDIType Type)
bool read ()
bool read (const byte Channel)
kMIDIType getType ()
byte getChannel ()
byte getData1 ()
byte getData2 ()
bytegetSysExArray ()
bool check ()
byte getInputChannel ()
void setInputChannel (const byte Channel)
kThruFilterMode getFilterMode ()
bool getThruState ()
void turnThruOn (kThruFilterMode inThruFilterMode=Full)
void turnThruOff ()
void setThruFilterMode (const byte inThruFilterMode)
void setThruFilterMode (const kThruFilterMode inThruFilterMode)


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


Constructor & Destructor Documentation

MIDI_Class::MIDI_Class (  ) 

Default constructor for MIDI_Class.

Definition at line 22 of file MIDI.cpp.

00022 { }

MIDI_Class::~MIDI_Class (  ) 

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

Definition at line 26 of file MIDI.cpp.

00026 { }


Member Function Documentation

void MIDI_Class::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 34 of file MIDI.cpp.

00034                                            {
00035         
00036         // Initialise the Serial port
00037         USE_SERIAL_PORT.begin(MIDI_BAUDRATE);
00038         
00039         
00040 #if COMPFLAG_MIDI_OUT
00041         
00042 #if USE_RUNNING_STATUS
00043         mRunningStatus_TX = InvalidType;
00044 #endif // USE_RUNNING_STATUS
00045         
00046 #endif // COMPFLAG_MIDI_OUT
00047         
00048         
00049 #if COMPFLAG_MIDI_IN
00050         
00051         mInputChannel = inChannel;
00052         mRunningStatus_RX = InvalidType;
00053         mPendingMessageIndex = 0;
00054         mPendingMessageExpectedLenght = 0;
00055         
00056         mMessage.valid = false;
00057         mMessage.type = InvalidType;
00058         mMessage.channel = 0;
00059         mMessage.data1 = 0;
00060         mMessage.data2 = 0;
00061         
00062 #endif // COMPFLAG_MIDI_IN
00063         
00064         
00065 #if (COMPFLAG_MIDI_IN && COMPFLAG_MIDI_OUT) // Thru
00066         
00067         mThruFilterMode = Full;
00068         
00069 #endif // Thru
00070         
00071 }

bool MIDI_Class::check (  ) 

Check if a valid message is stored in the structure.

Definition at line 587 of file MIDI.cpp.

00587 { return mMessage.valid; }

byte MIDI_Class::getChannel (  ) 

Getter method: access to the channel of the message stored in the structure.

Definition at line 579 of file MIDI.cpp.

00579 { return mMessage.channel; }

byte MIDI_Class::getData1 (  ) 

Getter method: access to the first data byte of the message stored in the structure.
If the message is SysEx, the length of the array is stocked there.

Definition at line 581 of file MIDI.cpp.

00581 { return mMessage.data1; }

byte MIDI_Class::getData2 (  ) 

Getter method: access to the second data byte of the message stored in the structure.

Definition at line 583 of file MIDI.cpp.

00583 { return mMessage.data2; }

kThruFilterMode MIDI_Class::getFilterMode (  )  [inline]

Definition at line 223 of file MIDI.h.

00223 { return mThruFilterMode; }

byte MIDI_Class::getInputChannel (  )  [inline]

Definition at line 183 of file MIDI.h.

00183 { return mInputChannel; }

byte * MIDI_Class::getSysExArray (  ) 

Getter method: access to the System Exclusive byte array. Array length is stocked in Data1.

Definition at line 585 of file MIDI.cpp.

00585 { return mMessage.sysex_array; }

bool MIDI_Class::getThruState (  )  [inline]

Definition at line 224 of file MIDI.h.

00224 { return mThruActivated; }

kMIDIType MIDI_Class::getType (  ) 

Getter method: access to the message type stored in the structure.
Returns an enumerated type.

Definition at line 577 of file MIDI.cpp.

00577 { return mMessage.type; }

bool MIDI_Class::read ( const byte  inChannel  ) 

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

Definition at line 306 of file MIDI.cpp.

00306                                           {
00307         
00308         if (inChannel >= MIDI_CHANNEL_OFF) return false; // MIDI Input disabled.
00309         
00310         if (parse(inChannel)) return filter(inChannel);
00311         else return false;
00312         
00313 }

bool MIDI_Class::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 301 of file MIDI.cpp.

00301                       {
00302         return read(mInputChannel);
00303 }

void MIDI_Class::sendAfterTouch ( byte  Pressure,
byte  Channel 
)

Send a MonoPhonic AfterTouch message (applies to all notes)

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

Definition at line 192 of file MIDI.cpp.

00192 { send(AfterTouchChannel,Pressure,0,Channel); }

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

Send a Control Change message

Parameters:
ControlNumber The controller number (0 to 127). See the detailed description here: 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).

Definition at line 179 of file MIDI.cpp.

00179 { send(ControlChange,ControlNumber,ControlValue,Channel); }

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
Velocity Release velocity (0 to 127).
Channel The channel on which the message will be sent (1 to 16).

Definition at line 166 of file MIDI.cpp.

00166 { send(NoteOff,NoteNumber,Velocity,Channel); }

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

Send a Note On message

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
Velocity Note attack velocity (0 to 127). A NoteOn with 0 velocity is considered as a NoteOff.
Channel The channel on which the message will be sent (1 to 16).

Definition at line 159 of file MIDI.cpp.

00159 { send(NoteOn,NoteNumber,Velocity,Channel); }

void MIDI_Class::sendPitchBend ( double  PitchValue,
byte  Channel 
)

Send a Pitch Bend message using a floating point value.

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

Definition at line 207 of file MIDI.cpp.

00207                                                              {
00208 
00209         unsigned int pitchval = (PitchValue+1.f)*8192;
00210         if (pitchval > 16383) pitchval = 16383;         // overflow protection
00211         sendPitchBend(pitchval,Channel);
00212         
00213 }

void MIDI_Class::sendPitchBend ( unsigned int  PitchValue,
byte  Channel 
)

Send a Pitch Bend message using an integer value.

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

Definition at line 198 of file MIDI.cpp.

00198                                                                    {
00199 
00200         send(PitchBend,(PitchValue & 0x7F),(PitchValue >> 7) & 0x7F,Channel);
00201         
00202 }

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

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

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).

Definition at line 186 of file MIDI.cpp.

00186 { send(AfterTouchPoly,NoteNumber,Pressure,Channel); }

void MIDI_Class::sendProgramChange ( byte  ProgramNumber,
byte  Channel 
)

Send a Program Change message

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

Definition at line 172 of file MIDI.cpp.

00172 { send(ProgramChange,ProgramNumber,0,Channel); }

void MIDI_Class::sendRealTime ( kMIDIType  Type  ) 

Send a Real Time (one byte) message.
You can also send a Tune Request with this method.

Parameters:
Type The available Real Time types are: Start, Stop, Continue, Clock, ActiveSensing and SystemReset.

Definition at line 273 of file MIDI.cpp.

00273                                             {
00274         switch (Type) {
00275                 case TuneRequest: // Not really real-time, but one byte anyway.
00276                 case Clock:
00277                 case Start:
00278                 case Stop:      
00279                 case Continue:
00280                 case ActiveSensing:
00281                 case SystemReset:
00282                         USE_SERIAL_PORT.write((byte)Type);
00283                         break;
00284                 default:
00285                         // Invalid Real Time marker
00286                         break;
00287         }
00288 }

void MIDI_Class::sendSongPosition ( unsigned int  Beats  ) 

Send a Song Position Pointer message.

Parameters:
Beats The number of beats since the start of the song.

Definition at line 254 of file MIDI.cpp.

00254                                                     {
00255         
00256         USE_SERIAL_PORT.write((byte)SongPosition);
00257         USE_SERIAL_PORT.write(Beats & 0x7F);
00258         USE_SERIAL_PORT.write((Beats >> 7) & 0x7F);
00259         
00260 }

void MIDI_Class::sendSongSelect ( byte  SongNumber  ) 

Send a Song Select message

Definition at line 263 of file MIDI.cpp.

00263                                                {
00264         
00265         USE_SERIAL_PORT.write((byte)SongSelect);
00266         USE_SERIAL_PORT.write(SongNumber & 0x7F);
00267         
00268 }

void MIDI_Class::sendSysEx ( byte  length,
byte array,
bool  ArrayContainsBoundaries = false 
)

Generate and send a System Exclusive frame.

Parameters:
length The size of the array to send
array The byte array containing the data to send
ArrayContainsBoundaries When 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 221 of file MIDI.cpp.

00221                                                                                   {
00222         if (!ArrayContainsBoundaries) USE_SERIAL_PORT.write(0xF0);
00223         for (byte i=0;i<length;i++) USE_SERIAL_PORT.write(array[i]);
00224         if (!ArrayContainsBoundaries) USE_SERIAL_PORT.write(0xF7);
00225 }

void MIDI_Class::sendTimeCodeQuarterFrame ( byte  data  ) 

Send a MIDI Time Code Quarter Frame. See MIDI Specification for more information.

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

Definition at line 244 of file MIDI.cpp.

00244                                                    {
00245         
00246         USE_SERIAL_PORT.write((byte)TimeCodeQuarterFrame);
00247         USE_SERIAL_PORT.write(data);
00248         
00249 }

void MIDI_Class::sendTimeCodeQuarterFrame ( byte  TypeNibble,
byte  ValuesNibble 
)

Send a MIDI Time Code Quarter Frame. See MIDI Specification for more information.

Parameters:
TypeNibble MTC type
ValuesNibble MTC data

Definition at line 234 of file MIDI.cpp.

00234                                                                             {
00235         
00236         byte data = ( ((TypeNibble & 0x07) << 4) | (ValuesNibble & 0x0F) );
00237         sendTimeCodeQuarterFrame(data);
00238         
00239 }

void MIDI_Class::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 228 of file MIDI.cpp.

void MIDI_Class::setInputChannel ( const byte  Channel  ) 

Set the value for the input MIDI channel

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

Definition at line 594 of file MIDI.cpp.

00594 { mInputChannel = Channel; }

void MIDI_Class::setThruFilterMode ( const kThruFilterMode  inThruFilterMode  ) 

Set the filter for thru mirroring

Parameters:
inThruFilterMode a filter mode See kThruFilterMode for detailed description.

Definition at line 608 of file MIDI.cpp.

00608                                                                    { 
00609         mThruFilterMode = inThruFilterMode;
00610         if (mThruFilterMode != Off) mThruActivated = true;
00611         else mThruActivated = false;
00612 }

void MIDI_Class::setThruFilterMode ( const byte  inThruFilterMode  ) 

Set the filter for thru mirroring

Parameters:
inThruFilterMode a filter mode See kThruFilterMode for detailed description.
This method uses a byte parameter and is for compatibility only, please use kThruFilterMode for future programs.

Definition at line 618 of file MIDI.cpp.

00618                                                         { 
00619         mThruFilterMode = (kThruFilterMode)inThruFilterMode;
00620         if (mThruFilterMode != Off) mThruActivated = true;
00621         else mThruActivated = false;
00622 }

void MIDI_Class::turnThruOff (  ) 

Setter method: turn message mirroring off.

Definition at line 631 of file MIDI.cpp.

00631                              {
00632         mThruActivated = false; 
00633         mThruFilterMode = Off;
00634 }

void MIDI_Class::turnThruOn ( kThruFilterMode  inThruFilterMode = Full  ) 

Setter method: turn message mirroring on.

Definition at line 626 of file MIDI.cpp.

00626                                                             { 
00627         mThruActivated = true;
00628         mThruFilterMode = inThruFilterMode;
00629 }


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

Generated on Mon Mar 7 23:44:19 2011 for Arduino MIDI Library by  doxygen 1.5.8