Skip to content

Commit 67f6b00

Browse files
author
Francois Best
committed
Merge branch 'release/4.2'
2 parents bde05f4 + cfa634f commit 67f6b00

File tree

18 files changed

+2208
-1608
lines changed

18 files changed

+2208
-1608
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#Arduino MIDI Library v4.1
1+
#Arduino MIDI Library v4.2
22

33
This library enables MIDI I/O communications on the Arduino serial ports.
44
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.
55

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

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

1919

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

3132

3233

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

3637
### What do I need to do?
3738

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

4244
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...
4345

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

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

49-
To know how to use the callback feature, see the dedicated page [here](http://playground.arduino.cc/Main/MIDILibraryCallbacks).
50-
51-
5251
### Using MIDI.begin
5352

5453
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).
@@ -78,4 +77,3 @@ Take a look at [the MIDI.org schematic](http://www.midi.org/techspecs/electrispe
7877
if you have any comment or support request to make, feel free to contact me: [email protected]
7978

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

doc/Doxyfile

Lines changed: 1603 additions & 1077 deletions
Large diffs are not rendered by default.

doc/midi_DoxygenMainPage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
\example MIDI_Bench.ino
3838
\example MIDI_DualMerger.ino
3939
\example MIDI_Input.ino
40+
\example MIDI_SimpleSynth.ino
4041
*/
4142

4243
// -----------------------------------------------------------------------------

res/Examples/MIDI_Basic_IO/MIDI_Basic_IO.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <MIDI.h>
22

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

7+
MIDI_CREATE_DEFAULT_INSTANCE();
8+
79
#define LED 13 // LED pin on Arduino Uno
810

911
void setup()

res/Examples/MIDI_Callbacks/MIDI_Callbacks.ino

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
#include <MIDI.h>
22

3+
MIDI_CREATE_DEFAULT_INSTANCE();
4+
5+
// -----------------------------------------------------------------------------
6+
37
// This function will be automatically called when a NoteOn is received.
48
// It must be a void-returning function with the correct parameters,
59
// see documentation here:
610
// http://arduinomidilib.fortyseveneffects.com/a00022.html
711

8-
void HandleNoteOn(byte channel, byte pitch, byte velocity)
12+
void handleNoteOn(byte channel, byte pitch, byte velocity)
913
{
10-
// Do whatever you want when you receive a Note On.
11-
12-
if (velocity == 0)
13-
{
14-
// This acts like a NoteOff. You can ask the library to call the NoteOff
15-
// callback when receiving null-velocity NoteOn messages.
16-
// See MIDI_HANDLE_NULL_VELOCITY_NOTE_ON_AS_NOTE_OFF in midi_Settings.h
17-
}
14+
// Do whatever you want when a note is pressed.
1815

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

21+
void handleNoteOff(byte channel, byte pitch, byte velocity)
22+
{
23+
// Do something when the note is released.
24+
// Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
25+
}
26+
2427
// -----------------------------------------------------------------------------
2528

2629
void setup()
2730
{
28-
// Connect the HandleNoteOn function to the library,
31+
// Connect the handleNoteOn function to the library,
2932
// so it is called upon reception of a NoteOn.
30-
MIDI.setHandleNoteOn(HandleNoteOn); // Put only the name of the function
33+
MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
34+
35+
// Do the same for NoteOffs
36+
MIDI.setHandleNoteOff(handleNoteOff);
3137

3238
// Initiate MIDI communications, listen to all channels
3339
MIDI.begin(MIDI_CHANNEL_OMNI);

res/Examples/MIDI_Input/MIDI_Input.ino

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include <MIDI.h>
22

3+
MIDI_CREATE_DEFAULT_INSTANCE();
4+
5+
// -----------------------------------------------------------------------------
6+
37
// This example shows the old way of checking for input messages.
48
// It's simpler to use the callbacks now, check out the dedicated example.
59

@@ -8,7 +12,7 @@
812
// -----------------------------------------------------------------------------
913

1014
void BlinkLed(byte num) // Basic blink function
11-
{
15+
{
1216
for (byte i=0;i<num;i++)
1317
{
1418
digitalWrite(LED,HIGH);
@@ -29,12 +33,12 @@ void setup()
2933
void loop()
3034
{
3135
if (MIDI.read()) // Is there a MIDI message incoming ?
32-
{
36+
{
3337
switch(MIDI.getType()) // Get the type of the message we caught
34-
{
38+
{
3539
case midi::ProgramChange: // If it is a Program Change,
36-
BlinkLed(MIDI.getData1()); // blink the LED a number of times
37-
// correponding to the program number
40+
BlinkLed(MIDI.getData1()); // blink the LED a number of times
41+
// correponding to the program number
3842
// (0 to 127, it can last a while..)
3943
break;
4044
// See the online reference for other message types

res/Examples/MIDI_SimpleSynth/MIDI_SimpleSynth.ino

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "noteList.h"
33
#include "pitches.h"
44

5+
MIDI_CREATE_DEFAULT_INSTANCE();
6+
57
#ifdef ARDUINO_SAM_DUE // Due has no tone function (yet), overriden to prevent build errors.
68
#define tone(...)
79
#define noTone(...)
@@ -18,12 +20,12 @@ MidiNoteList<sMaxNumNotes> midiNotes;
1820

1921
// -----------------------------------------------------------------------------
2022

21-
void handleGateChanged(bool inGateActive)
23+
inline void handleGateChanged(bool inGateActive)
2224
{
2325
digitalWrite(sGatePin, inGateActive ? HIGH : LOW);
2426
}
2527

26-
void pulseGate()
28+
inline void pulseGate()
2729
{
2830
handleGateChanged(false);
2931
delay(1);
@@ -32,7 +34,7 @@ void pulseGate()
3234

3335
// -----------------------------------------------------------------------------
3436

35-
void handleNotesChanged()
37+
void handleNotesChanged(bool isFirstNote = false)
3638
{
3739
if (midiNotes.empty())
3840
{
@@ -41,11 +43,24 @@ void handleNotesChanged()
4143
}
4244
else
4345
{
46+
// Possible playing modes:
47+
// Mono Low: use midiNotes.getLow
48+
// Mono High: use midiNotes.getHigh
49+
// Mono Last: use midiNotes.getLast
50+
4451
byte currentNote = 0;
45-
if (midiNotes.getTail(currentNote))
52+
if (midiNotes.getLast(currentNote))
4653
{
4754
tone(sAudioOutPin, sNotePitches[currentNote]);
48-
pulseGate(); // Retrigger envelopes. Remove for legato effect.
55+
56+
if (isFirstNote)
57+
{
58+
handleGateChanged(true);
59+
}
60+
else
61+
{
62+
pulseGate(); // Retrigger envelopes. Remove for legato effect.
63+
}
4964
}
5065
}
5166
}
@@ -54,8 +69,9 @@ void handleNotesChanged()
5469

5570
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
5671
{
72+
const bool firstNote = midiNotes.empty();
5773
midiNotes.add(MidiNote(inNote, inVelocity));
58-
handleNotesChanged();
74+
handleNotesChanged(firstNote);
5975
}
6076

6177
void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
@@ -67,7 +83,7 @@ void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
6783
// -----------------------------------------------------------------------------
6884

6985
void setup()
70-
{
86+
{
7187
pinMode(sGatePin, OUTPUT);
7288
pinMode(sAudioOutPin, OUTPUT);
7389
MIDI.setHandleNoteOn(handleNoteOn);

0 commit comments

Comments
 (0)