Pages: [1]   Go Down
Author Topic: New: Extended MIDI Library  (Read 461 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I've been working on a project involving MIDI and discovered that the existing library doesn't have any support for system real-time messages.
So I wrote a new extended library with support for real-time messages.

Real-time messages are messages like:
- Timing Clock. (24ppqn)
- Start.
- Stop.
- Continue.
- Active Sensing.
- Reset.

I plan on supporting System Exclusive in the future.
Further more I managed to reduce the size of the library.

Of course I haven't been able to test everything to it's full extend, so please let me know if you happen to encounter any bugs while using this lib.

After including the library you need to declare an object of type MIDI before you are able to use it.

Putting the following line outside of your setup() and loop() will suffice:
Code:
MIDI midi;

 Also make sure you include WProgram.h in your sketch before this library.
Code:
#include <WProgram.h>
#include <MIDI.h>

I think all the names of variables, parameters, functions are logical descriptions of their purpose, but in short:

You first have to call MIDI.begin(). After this you can either use MIDI.read() or MIDI.read(int channel, bool sys) to check if there is an incoming message. It will return true if a message was read, otherwise it will return false.
Ones a message is read it is available until you either call read(), read(channel, sys).
The sys parameter allows you to read for messages on the given channel and still receive System real-time messages (which are not channel bound) if true or ignore them if false.
A MIDI message can be three different sizes: 1, 2 or 3 bytes. So it is advised to check the message size with getSize() before retrieving the data1 en data2 parts of the message.
The default value for data1 and data2 is 0 which can also be a value received from a MIDI device.
getType() Allows you to check what kind of MIDI message is received very much like in the old library.
Retrieving the data from the message is possible with: getStatus(), getData1(), getData2().

I also added a method to retrieve the channel from the status byte, which can come in handy.

Sending MIDI messages is possible by using one of the three send() methods.
send(status), send(status, data1), send(status, data1, data2).

I will add a send method that allows you to specify message type, channel and (optionally) data soon.

http://webserv.nhl.nl/~weste608/Arduino_MIDI/MIDI(extended).zip
« Last Edit: April 08, 2009, 10:37:50 am by tetracon » Logged

Pages: [1]   Go Up
Jump to: