This tutorial shows how ho use the 'Native USB port of an Arduino or Genuino Zero, DUE or 101 board as a MIDI device using the Arduino MIDI USB library. The library can be installed using the arduino library manager
If you use a Linux machine as the sound generating device, the test procedure described in the main page of the library on Github must be followed to make this example work in the right way. In particular it is necessary to load the correct drivers and soundbank as described in the first part of the explanation. Free soundbanks can be easily found on the web searching for free soundbanks .sf2 .
The Windows Operating System has a software synth that works with General Standard MIDI commands since the early versions. It needs to be used by the proper MIDI software so that it gets the MIDI messages. This may be achieved with a variety of applications that route, connect or generate the streams between OUT and IN devices. The MIDI sound generator is therefore not directly driven by a MIDI device, like ours. As the routing software we suggest an open source application that allows us to route our MIDI OUT device to the MIDI IN of a software synth . Virtual MIDI Piano Keyboard allows us to configure properly the connections and it is also useful on OSX and Linux to manage the software sound generators.
Virtual MIDI Piano Keyboard is a MIDI events generator and receiver. It doesn't produce any sound by itself, but can be used to drive a MIDI synthesizer. It allows to use the computer's mouse and keyboard to play MIDI notes. Virtual MIDI Piano Keyboard can be also used to display the played MIDI notes from an instrument MIDI OUT stream or MIDI file player.
The stream of notes and commands routed by VMPK may drive the built-in "Microsoft GS Wavetable Synth", but the soundbanks are not too cool. We suggest that you download and use this CoolSoft Virtual MIDI Synth that supports soundfonts and also sounds great.
Here is the full procedure to set up your Windows machine:
- Download and install CoolSoft Virtual MIDI Synth;
- Launch Configure Virtual MIDI Synth;
- In the MIDI mapper tab select CoolSoft VirtualMIDISynth as Windows Media Player Default Peripheral ;
- In the Options tab select your preferred Audio Output;
- Download and install Virtual Piano MIDI Keyboard;
- Launch VPMK and click on Edit->MIDI connections;
- In the MDI In Driver list select Windows MM;
- In the Input MIDI Connection list select Arduino Zero;
- In the MIDI Out Driver list select FluidSynth;
- Enjoy playing your Arduio/Genuino board to generate music on your computer!
In this example basically two MIDI messages are sent:
The noteOff message is important because the MIDI protocol is event based and the pressure of a key triggers a sound generator that stays on with the specified note until another event is sent, as note off, signaling that the same key has been released and the generator should stop. Each noteOn requires a noteOff or a "all Notes Off" message.
In the prototype of the used functions, a parameter called velocity is present. This name can be interpreted as a false friend since it indicates how loud is the note and not for how long the note is on. This is part of MIDI specs. Some musical keyboards are velocity sensitive and use the speed of the note press as a measure of the loudness that the player wants to use for that note. A piano works in this way. The velocity parameter is controlled by means of the linear potentiometer attached to the A0 input.
In the code the various pitches associated to the notes are defined in a separate header files included at the very beginning of the sketch. We suggest to go the the GitHub repository to follow this example.
The keys and the linear potentiometer are associated to the pins by means of the following numeric constants.
Please note that the intensityPot is defined equal to 0 because the define A0 is associated to the respective note in this particular example.
The notes to be played (from left to right in the breadboard related image) can be changed modifying the values of the following vector:
void readButtons() is used to make a mask of the buttons that has been pressed and so be able to play the associated notes by means of the function
Here the whole sketch:
Last revision 12/22/2015 by AG