Updated: 08/10/26


This page is on using the MIDI library for Arduino(Download)
Hopefully in the near future, the following which is a copy of the attached README will be replaced with an article full of examples and photos.
MIDI IN library
MIDI OUT library

Gyokimae MIDI in library
(Document revised 08/10/29)




**** ATTENTION ****

This library utilizes the ISR vector "USART_RX_vect".
Since this conflicts with the Arduino Serial library which also uses
this vector, you cannot uses them together.

Also, this library is distributed as a combination of 2 libraries,
"GMidiin" and "GMidiout." In order to save program memory, include
only the libraries necessary for your project.



*********************
Overview
*********************

MIDI messages are transfered in the form of a byte series.
This library allows you to set callback functions which are called
when ever a series of bytes forms some sense.

The current version allows you to set callbacks for the following
type of MIDI messages.

- Note On
- Note Off
- CC
- Program change
- Pitch bend
- Sysex



*********************
Reference
*********************

+---------------------+
| void Midiin.begin() |
+---------------------+
  Begin receiving MIDI messages.
  To be specifics, this sets the bits to enable USART RX interrupts.


+--------------------+
| void Midiin.stop() |
+--------------------+
  Stop receiving MIDI messages.
  To be specifics, this clears the bits to enable USART RX interrupts.


+----------------------------------------------------------------------------+
|void                                                                        |
|Midiin.setNoteOnFunc(void (*funcPtr)(int channel, int noteNo, int velocity))|
+----------------------------------------------------------------------------+

  Set the function to be called when a "note on" message is received.

  This is actually a lot simpler than it sounds.
  First, create a function with the specified arguments.

   void myNoteOnFunc(int channel, int noteNo, int velocity)
   {
        // Do something
   }

   Then call the method,

   Midiin.setNoteOnFunc(myNoteOnFunc);

   What is named "myNoteOnFunc" can be any function name of your choice,
   only as long as it has the 3 necessary arguments.

   After setting your function, it will be called whenever a "note on"
   message is received.


+---------------------------------------------------------------------------+
|void setNoteOffFunc(void (*funcPtr)(int channel, int noteNo, int velocity))|
|void setCcFunc(void (*funcPtr)(int channel, int ccNo, int value))          |
|void setPrgChangeFunc(void (*funcPtr)(int channel, int prgNo))             |
|void setPitchBendFunc(void (*funcPtr)(int channel, int value))             |
+---------------------------------------------------------------------------+

Refer to Midiin.setNoteOnFunc().
They all work almost in the same way.


+-----------------------------------------------------------------------+
| void                                                                  |
| setSysexFunc(void (*funcPtr)(volatile unsigned char *sysex,           |
|                               int len,                                |
|                               int overflow ))                         |
+-----------------------------------------------------------------------+

  int overflow = SYSEX_NO_OVERFLOW | SYSEX_OVERFLOW


  Set function to be called when a Sysex message is received.

  This function only returns a pointer to an array of bytes so how
  the message is handled is up to the user.

  To determine the length of the message, you can either refer to
  argument variable "len" or find the Sysex end byte of 0xF0.
  What data the array contains after the Sysex end byte is undefined.


  The buffer size is initially fixed to 8 bytes.
  The current behavior of the library when recieved Sysex message
  buffer is, the 9th byte is written to the second byte and on.

  i.e.
  When receiving the following bytes,

  {0xF7, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xF0}

  The callback function will receive the following.

  {0xF7, 0x08, 0x09, 0xF0} (len = 4);

  Also, you can test wether or not such overflows had occured by

  testing the argument "overflow."


  If you need to receive Sysex messages longer than this, you can
  open the file "GMidiin.h" and modify the line below.

    #define MESSAGE_BUFFER_SIZE 8

  You may have to enter your library directory and delete GMidi.o
  once before the changes take effect.


+--------------------------------------+
| Midiin.sendByte(const unsigned char) |
+--------------------------------------+
  Send a byte to the message buffer.
  Generally this is no need to access this method directly. However,
  it is left open in case you want to manually send bytes during
  debug, etc..


**** Todo

- Add functions to make MIDI OUT convenient.
- Test Sysex callback feature (Not done yet due to lack of tools).
- Support for pitch wheel data.


Gyokimae MIDI out library (Document revised 08/10/29) **** ATTENTION **** This library utilizes the ISR vector "USART_TX_vect". Since this conflicts with the Arduino Serial library which also uses this vector, you cannot uses them together. Also, this library is distributed as a combination of 2 libraries, "GMidiin" and "GMidiout." In order to save program memory, include only the libraries necessary for your project. ********************* Overview ********************* A collection of functions to ease sending MIDI messages. ********************* Reference ********************* +----------------------+ | void Midiout.begin() | +----------------------+ Begin receiving MIDI data. This sets the TX enable and TX interrupt enable bits. +--------------------------------------------------------------------------+ | void Midiout.noteOn( | | unsigned char channel, unsigned char noteNo, unsigned char velocity) | +--------------------------------------------------------------------------+ Send a NOTE ON message. The following work in the same way as Midiout.noteOn() +----------------------------------------------------------------------+ | void Midiout.noteOff | | (unsigned char , unsigned char noteNo, unsigned char velocity) | | | | void Midiout.cc | | (unsigned char channel, unsigned char ccNo, unsigned char value) | | | | void Midiout.prgChange | | (unsigned char channel, unsigned char prgNo) | +----------------------------------------------------------------------+ +----------------------------------------------------------+ | void Midiout.pitchBend(unsigned char channel, int value) | +----------------------------------------------------------+ Send a pitch bend message. "value" must be between 0 and 16,384. 8192 indicates the pitch bend wheel is centered. +-------------------------------------------------------------+ | void Midiout.sysex(unsigned char *sysex, unsigned char len) | +-------------------------------------------------------------+ Send a Sysex message. It is the programmers responsibility to specify the correct message length using the "len" argument. +-----------------------------------------------------+ | unsigned char Midiout.setSendByte( | | unsigned char setSendByte, unsigned char onFull) | +-----------------------------------------------------+ onFull = ON_FULL_WAIT | ON_FULL_RETURN return = MIDIOUT_SEND_FULL | MIDIOUT_SEND_OK Send a byte directly to buffer. This remains for debugging purposes or when you want to send commands not supported by functions in this library. The onFull argument specifies how to behave when the send buffer is full. When specifying ON_FULL_RETURN, the function will give up sending the requested byte and return instantly, in which case, returns MIDI_SEND_FULL. Otherwise, the functions always returns MIDIOUT_SEND_OK.