#include <MIDI.h>
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 () |
byte * | getSysExArray () |
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) |
Definition at line 117 of file MIDI.h.
MIDI_Class::MIDI_Class | ( | ) |
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.
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:
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 | ( | ) |
byte MIDI_Class::getChannel | ( | ) |
byte MIDI_Class::getData1 | ( | ) |
byte MIDI_Class::getData2 | ( | ) |
kThruFilterMode MIDI_Class::getFilterMode | ( | ) | [inline] |
byte MIDI_Class::getInputChannel | ( | ) | [inline] |
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] |
kMIDIType MIDI_Class::getType | ( | ) |
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 }
Send a MonoPhonic AfterTouch message (applies to all notes)
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); }
Send a Control Change message
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); }
Send a Note Off message (a real Note Off, not a Note On with null velocity)
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); }
Send a Note On message
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.
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.
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 }
Send a Polyphonic AfterTouch message (applies to only one specified note)
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); }
Send a Program Change message
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.
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.
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 }
Generate and send a System Exclusive frame.
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.
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 }
Send a MIDI Time Code Quarter Frame. See MIDI Specification for more information.
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.
00228 { sendRealTime(TuneRequest); }
void MIDI_Class::setInputChannel | ( | const byte | Channel | ) |
void MIDI_Class::setThruFilterMode | ( | const kThruFilterMode | inThruFilterMode | ) |
Set the filter for thru mirroring
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
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 | ( | ) |
void MIDI_Class::turnThruOn | ( | kThruFilterMode | inThruFilterMode = Full |
) |