Skip to content

Commit

Permalink
Merge branch 'release/4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Best committed Jun 11, 2014
2 parents bde05f4 + cfa634f commit 67f6b00
Show file tree
Hide file tree
Showing 18 changed files with 2,208 additions and 1,608 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Arduino MIDI Library v4.1
#Arduino MIDI Library v4.2

This library enables MIDI I/O communications on the Arduino serial ports.
The purpose of this library is not to make a big synthetizer out of an Arduino board, the application remains yours. However, it will help you interfacing it with other MIDI devices.

Download the latest version [here](https://github.com/FortySevenEffects/arduino_midi_library/releases/download/4.1/Arduino_MIDI_Library_v4.1.zip).
Download the latest version [here](https://github.com/FortySevenEffects/arduino_midi_library/releases/latest).

### Features
* Compatible with all Arduino boards (and clones with an AVR processor)
Expand All @@ -18,6 +18,7 @@ Download the latest version [here](https://github.com/FortySevenEffects/arduino_


#### Changelog
* 11/06/2014 : Version 4.2 released. Bug fix for SysEx, overridable template settings.
* 16/04/2014 : Version 4.1 released. Bug fixes regarding running status.
* 13/02/2014 : Version 4.0 released. Moved to GitHub, added multiple instances & software serial support, and a few bug fixes.
* 29/01/2012 : Version 3.2 released. Release notes are [here](http://sourceforge.net/news/?group_id=265194)
Expand All @@ -26,7 +27,7 @@ Download the latest version [here](https://github.com/FortySevenEffects/arduino_
* 14/12/2009 : Version 2.5 released.
* 28/07/2009 : Version 2.0 released.
* 28/03/2009 : Simplified version of MIDI.begin, Fast mode is now on by default.
* 08/03/2009 : Thru method operationnal. Added some features to enable thru.
* 08/03/2009 : Thru method operational. Added some features to enable thru.



Expand All @@ -35,9 +36,10 @@ Download the latest version [here](https://github.com/FortySevenEffects/arduino_

### What do I need to do?

* Download the library ([link](https://github.com/FortySevenEffects/arduino_midi_library/releases/download/4.1/Arduino_MIDI_Library_v4.1.zip))
* Download the library ([link](https://github.com/FortySevenEffects/arduino_midi_library/releases/latest))
* Follow the installation instructions there: http://arduino.cc/en/Guide/Libraries
* Include the library in your sketch using the menu in the IDE, or type `#include <MIDI.h>`
* Create the MIDI instance using `MIDI_CREATE_DEFAULT_INSTANCE();` or take a look at the documentation for custom serial port, settings etc..

You are now ready to use the library. Look at the reference page to learn how to use it, or the examples given. Just don't forget to enable the I/O communications with MIDI.begin...

Expand All @@ -46,9 +48,6 @@ You are now ready to use the library. Look at the reference page to learn how to

See the extended reference [here](http://arduinomidilib.fortyseveneffects.com) ([Mirror](http://fortyseveneffects.github.io/arduino_midi_library/)).

To know how to use the callback feature, see the dedicated page [here](http://playground.arduino.cc/Main/MIDILibraryCallbacks).


### Using MIDI.begin

In the `setup()` function of the Arduino, you must call the `MIDI.begin()` method. If you don't give any argument to this method, the input channel for MIDI in will be set to 1 (channels are going from 1 to 16, plus `MIDI_CHANNEL_OMNI to listen to all channels at the same time).
Expand Down Expand Up @@ -78,4 +77,3 @@ Take a look at [the MIDI.org schematic](http://www.midi.org/techspecs/electrispe
if you have any comment or support request to make, feel free to contact me: francois.best@fortyseveneffects.com

You can also get informations about bug fixes and updates on my twitter account: [@fortysevenfx](http://twitter.com/fortysevenfx).

2,680 changes: 1,603 additions & 1,077 deletions doc/Doxyfile

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/midi_DoxygenMainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
\example MIDI_Bench.ino
\example MIDI_DualMerger.ino
\example MIDI_Input.ino
\example MIDI_SimpleSynth.ino
*/

// -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion res/Examples/MIDI_Basic_IO/MIDI_Basic_IO.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <MIDI.h>

// Simple tutorial on how to receive and send MIDI messages.
// Here, when receiving any message on channel 4, the Arduino
// Here, when receiving any message on channel 4, the Arduino
// will blink a led and play back a note for 1 second.

MIDI_CREATE_DEFAULT_INSTANCE();

#define LED 13 // LED pin on Arduino Uno

void setup()
Expand Down
28 changes: 17 additions & 11 deletions res/Examples/MIDI_Callbacks/MIDI_Callbacks.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

// -----------------------------------------------------------------------------

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here:
// http://arduinomidilib.fortyseveneffects.com/a00022.html

void HandleNoteOn(byte channel, byte pitch, byte velocity)
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
// Do whatever you want when you receive a Note On.

if (velocity == 0)
{
// This acts like a NoteOff. You can ask the library to call the NoteOff
// callback when receiving null-velocity NoteOn messages.
// See MIDI_HANDLE_NULL_VELOCITY_NOTE_ON_AS_NOTE_OFF in midi_Settings.h
}
// Do whatever you want when a note is pressed.

// Try to keep your callbacks short (no delays ect)
// otherwise it would slow down the loop() and have a bad impact
// on real-time performance.
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
// Do something when the note is released.
// Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
}

// -----------------------------------------------------------------------------

void setup()
{
// Connect the HandleNoteOn function to the library,
// Connect the handleNoteOn function to the library,
// so it is called upon reception of a NoteOn.
MIDI.setHandleNoteOn(HandleNoteOn); // Put only the name of the function
MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function

// Do the same for NoteOffs
MIDI.setHandleNoteOff(handleNoteOff);

// Initiate MIDI communications, listen to all channels
MIDI.begin(MIDI_CHANNEL_OMNI);
Expand Down
14 changes: 9 additions & 5 deletions res/Examples/MIDI_Input/MIDI_Input.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

// -----------------------------------------------------------------------------

// This example shows the old way of checking for input messages.
// It's simpler to use the callbacks now, check out the dedicated example.

Expand All @@ -8,7 +12,7 @@
// -----------------------------------------------------------------------------

void BlinkLed(byte num) // Basic blink function
{
{
for (byte i=0;i<num;i++)
{
digitalWrite(LED,HIGH);
Expand All @@ -29,12 +33,12 @@ void setup()
void loop()
{
if (MIDI.read()) // Is there a MIDI message incoming ?
{
{
switch(MIDI.getType()) // Get the type of the message we caught
{
{
case midi::ProgramChange: // If it is a Program Change,
BlinkLed(MIDI.getData1()); // blink the LED a number of times
// correponding to the program number
BlinkLed(MIDI.getData1()); // blink the LED a number of times
// correponding to the program number
// (0 to 127, it can last a while..)
break;
// See the online reference for other message types
Expand Down
30 changes: 23 additions & 7 deletions res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "noteList.h"
#include "pitches.h"

MIDI_CREATE_DEFAULT_INSTANCE();

#ifdef ARDUINO_SAM_DUE // Due has no tone function (yet), overriden to prevent build errors.
#define tone(...)
#define noTone(...)
Expand All @@ -18,12 +20,12 @@ MidiNoteList<sMaxNumNotes> midiNotes;

// -----------------------------------------------------------------------------

void handleGateChanged(bool inGateActive)
inline void handleGateChanged(bool inGateActive)
{
digitalWrite(sGatePin, inGateActive ? HIGH : LOW);
}

void pulseGate()
inline void pulseGate()
{
handleGateChanged(false);
delay(1);
Expand All @@ -32,7 +34,7 @@ void pulseGate()

// -----------------------------------------------------------------------------

void handleNotesChanged()
void handleNotesChanged(bool isFirstNote = false)
{
if (midiNotes.empty())
{
Expand All @@ -41,11 +43,24 @@ void handleNotesChanged()
}
else
{
// Possible playing modes:
// Mono Low: use midiNotes.getLow
// Mono High: use midiNotes.getHigh
// Mono Last: use midiNotes.getLast

byte currentNote = 0;
if (midiNotes.getTail(currentNote))
if (midiNotes.getLast(currentNote))
{
tone(sAudioOutPin, sNotePitches[currentNote]);
pulseGate(); // Retrigger envelopes. Remove for legato effect.

if (isFirstNote)
{
handleGateChanged(true);
}
else
{
pulseGate(); // Retrigger envelopes. Remove for legato effect.
}
}
}
}
Expand All @@ -54,8 +69,9 @@ void handleNotesChanged()

void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
{
const bool firstNote = midiNotes.empty();
midiNotes.add(MidiNote(inNote, inVelocity));
handleNotesChanged();
handleNotesChanged(firstNote);
}

void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
Expand All @@ -67,7 +83,7 @@ void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
// -----------------------------------------------------------------------------

void setup()
{
{
pinMode(sGatePin, OUTPUT);
pinMode(sAudioOutPin, OUTPUT);
MIDI.setHandleNoteOn(handleNoteOn);
Expand Down
Loading

0 comments on commit 67f6b00

Please sign in to comment.