get back to the main page

The reference has been moved to an external page, this one is no more supported.

HTML reference - PDF reference

void MIDI.begin(Opto,Mode)

Description

You must launch this method in the setup() function of the Arduino, it enables I/O communications on the serial port, which means you don't need to use Serial.begin(31250). You can also define the pin number for powering the input optocoupler, and set the fast transmission mode.

Parameters

The parameters are described on the library main page.

void MIDI.send(Type,Data1,Data2,Channel)

Description

This method generates and sends a MIDI message described by the parameters.

Parameters

  • Correct values for Type are:
    • NoteOn
    • NoteOff
    • PC (Program Change)
    • CC (Control Change)
    • ATPoly (Aftertouch Polyphonic)
    • ATCanal (Channel Aftertouch)
    • PitchBend
    • System

  • Data1 & Data2: the 2 bytes you want to send within your message. If the type is PC or ATCanal, then the Data2 parameter is useless, you can use any value you want (0 is good), but use one!

  • Channel: the MIDI channel you want your message to be emitted on (1 to 16). If this parameter is out of range (meaning lower than 1 or higher than 16, the message won't be sent. Using the special value OFF in your code will have the same effect.

eg. MIDI.send(NoteOn,12,42,1) will send a NoteOn message on channel 1, for the note #12 with a velocity of 42.

bool MIDI.read(Filter)

Description

This method reads the serial input of the Arduino to check if there are some MIDI messages matching the Filter condition. When a valid MIDI message is detected, it is stocked into a structure, so you can access it outside the library for your applications.

It reads only one message at the time, if you expect more than one message, multiple calling of MIDI.read and saved messages stocking is advised.

When you call this method, it will erase the previously saved message in the structure, even if there are no new message to save.

If you plan to use an external powering (not a pin) for the optocoupler, be sure to use the MIDI.useExternalPowerPin method before calling MIDI.read, to enable MIDI input communications.

Parameters

  • Filter: the channel number (1-16) you want to listen to. If a MIDI message is detected in the serial input buffer and if its channel matches the Filter condition, it is saved. Other messages won't be. You can use the special value OMNI to get every MIDI message on the line (for debugging purpose only, using this option could be dangerous if you have some MIDI devices online).

  • The method returns true if a valid MIDI message has been detected and saved in the method, false if not.

bool MIDI.thru(Filter)

This is a combination of MIDI.read and MIDI.send.

Description

This method first looks for a MIDI message wih MIDI.read, then if one is found AND thru mode enabled, sends it back on the MIDI out with MIDI.send. The message remains in the memory structure if you want to use it.

If the thru mode is active, every message (on every channel, filtering comes later) is mirrored to the output. Then the channel filtering is processed, and if a valid message is found, it returns true.

Parameters

  • Filter: the same as for the MIDI.read method.
  • Returns true if a valid message is saved in the structure.

bool MIDI.check(void)

Description

Checks whether a valid MIDI message is saved in the structure.

Parameters

Returns true if the message is valid, false if it's not.

byte MIDI.getType(void)

Returns the type of the MIDI message. You can use the types defined above for comparison in your sketch.

byte MIDI.getChannel(void)

Returns the channel of the MIDI message.

byte MIDI.getData1(void)

Returns the first byte of data embedded in the message.

byte MIDI.getData2(void)

Returns the second byte of data. If the message is a PC or a ATCanal (a 1 data byte message), the returned value is 0.

void MIDI.setFastMode(Mode)

Description

Sets the fast transmission mode on or off (default on).

Parameters

  • Mode is a boolean: true means that the fast mode is enabled.

void MIDI.turnOnOpto()

Sets the optocoupler power pin high to enable hardware MIDI input.

void MIDI.turnOffOpto()

Sets the optocoupler power pin low to disable hardware MIDI input.

void MIDI.setOptoPin(pin)

Description

Defines the pin handling the optocoupler power for hardware MIDI input.

Parameters

  • pin is the number of the pin assigned to power the optocoupler.

void MIDI.useExternalPowerPin()

Use this method if you want to power the optocoupler externally (without an Arduino pin), you may not have control on hardware MIDI input, but you save yourself a pin.. Remember that MIDI.read is disabled if no optocoupler pin has been declared (with MIDI.begin(Opto,..) or this method).

void MIDI.turnThruOn()

Set the thru mode on.

void MIDI.turnThruOff()

Set the thru mode off.

void MIDI.turnThru(bool mode)

Set the thru mode to the indicated value.

get back to the main page

Share