Author |
Message |
marvkaye
Joined: Mar 14, 2011 Posts: 225 Location: Fla
|
Posted: Thu Sep 06, 2012 7:42 am Post subject:
MIDI w/ Arduino primer |
|
|
Spotted this Send-and-Receive-MIDI-with-Arduino primer in my latest "what's new" announcement from Instructables. Thought some folks here might enjoy seeing it.
<marv> |
|
Back to top
|
|
|
elmegil
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
|
Posted: Thu Sep 06, 2012 8:19 am Post subject:
|
|
|
Suffers from an issue I've seen with many Arduino MIDI tutorials, in that it omits "running mode" which is going to lead any newb into trouble when trying to take MIDI input from a "real world" keyboard or controller.
It does appear to be well written and nice clear diagrams, however |
|
Back to top
|
|
|
marvkaye
Joined: Mar 14, 2011 Posts: 225 Location: Fla
|
Posted: Thu Sep 06, 2012 8:25 am Post subject:
|
|
|
Interesting... so what's the "running mode" cure? Or have you found another tutorial that you could point us to that does a better job to keep newbs (like me) from terminal hair loss trying to implement something like this?
<m> |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24085 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Thu Sep 06, 2012 8:56 am Post subject:
|
|
|
MIDI messages consist of a command byte and possible parameter / data bytes; like for NoteOn you will have a key parameter and a velocity parameter.
MIDI command and parameter bytes are distinguished by the most significant bit, when that bit is a 1 the byte is a command and otherwise it is parameter data.
This distinction makes it possible to omit command repetition if it would be the same as one that was sent before. So when you send a series of note on commands and all those commands are on the same channel you only need specify that command once; then the two data bytes for the first command follow, then two data bytes for the 2nd note on, etc.
When a command is not seen by the MIDI interpreter it uses the previous command, and that one is called the running status.
This also is the rationale for using a note on message with velocity 0 as a note off. A note off command after a note on would break the running status, whereas a note on with a velocity of zero would not.
This compacts the MIDI stream, and also make reaction times on commands shorter.
So, to keep running status all you would have to do is remember the last command seen, and combine that with orphaned data bytes you received to reassemble a complete MIDI message.
For sending MIDI you could omit running status, the MIDI stream will not be optimal, but all connected devices will understand it.
For receiving MIDI you should implement running status as lots of sending gear will use it.
When implementing running status keep in mind that certain MIDI messages do not break running status .. IIRC such holds for MIDI clock .. but better Google for the details there ... _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
elmegil
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
|
Posted: Thu Sep 06, 2012 9:39 am Post subject:
|
|
|
Great Summary
This bit me when I was using "roll your own" and copied code to do MIDI, as I was adapting Thomas Henry's MTS-100 to use an Arduino.
I switched to using the "official" Arduino MIDI Library (http://arduino.cc/playground/Main/MIDILibrary), and it was all handled already.
I would strongly recommend that anyone using Arduino for MIDI use the library rather than the home grown code such as that from the Instructable.
To be clear, I don't mean to be disrespecting the Instructable--there's a lot of good information there, I just know that I was originally working from something similar and was, as you say, tearing my hair out over why my keyboard didn't work right until I understood what Blue Hell has explained. |
|
Back to top
|
|
|
Cynosure
Site Admin
Joined: Dec 11, 2010 Posts: 966 Location: Toronto, Ontario - Canada
Audio files: 82
|
Posted: Wed Sep 12, 2012 7:18 am Post subject:
|
|
|
Great explanation Jan.
I am also using the MIDI Library and it has been working great so far. There was one minor thing with this though - the note off being a note on with 0 velocity worked for my hardware synths, but I had to add the regular noteoff message for use with Ableton Live. Make sure you use both methods for compatibility. _________________ JacobWatters.com |
|
Back to top
|
|
|
|