II.3.9. Adding MIDI Interface

Before writing Blackstomp sketch with MIDI support, we have to be aware that Blacktomp library doesn’t provide direct support for MIDI functions. As the consequence, we have to use third party library if we don’t want to write our own MIDI low level functions.

Installing MIDI Library

Before we can compile the example code “midipedal.ino”, we have to install the required library: “MIDI Library” (by Francois Best, Lathoub). Use the menu Tools > Manage Libraries, type “midi” in the search box and scroll the result to find the library and install it (See Figure 16).

Figure 16. MIDI Library Installaton

Writing MIDI-Controlled and MIDI Controller Sketch with Blackstomp

To write a Blackstomp sketch with MIDI support using MIDI Library, we can follow these guidelines:

  • Include <MIDI.h> on the top of codes.
  • Call the function MIDI_CREATE_DEFAULT_INSTANCE() before defining the effectModule descendant class, so the MIDI variable will be accessible from all sketch sections.
  • Create all the needed MIDI message handlers to handle the incoming MIDI messages.
  • Create a MIDI task for setting up the MIDI, installing its handler, and listening the incoming messages. Run the task at core 0.

The following codes is the sketch example on how to write Blackstomp sketch with MIDI support. This sketch is available in the example folder of the Blackstomp library as “midipedal.ino”

As shown in the example codes, the class definition is done after calling the macro function MIDI_CREATE_DEFAULT_INSTANCE() at line #4. The MIDI handler handleControlChange is implemented at line #128, and it should be done after the declaration of the effectModule instance (midiPedal myPedal; at line #126). This is important since the handler implementation should access the effectModule instance (myPedal). Note that unlike the usual intermediate variable, we have declared the member function gain in the public section (at line #8), not in private section. By placing it in public section, the gain variable is now accessible from outside the class, by the MIDI handler.

The MIDI task is implemented at line #143, doing the MIDI setup by calling the MIDI.begin() method, installing the MIDI handler handleControlChange, and run MIDI.read() indefinitely to read and process the incoming MIDI messages. The MIDI task is started to run on core 0 by calling the FreeRTOS API xTaskCreatePinnedToCore inside the Arduino’s setup function at line #160.

To run the sketch on the development mode pedal, don’t forget to turn the S.TTL/MIDI switcher to MIDI position after uploading the sketch to the pedal. The first knob would set the MIDI channel channel (1-16), the second knob controls the gain, and the third knob would set the MIDI control function (0-11). Use the auxiliary LED’s blinking to count the indicated position when turning the knob from all the way down position.

The pedal will function as both MIDI controller and MIDI-controlled device. As a MIDI controller, it send a continuous control command when we turn the gain knob. It becomes a converter of analog expression pedal to MIDI pedal when we plug an analog expression pedal into the EXP/CV input port. As a MIDI-controlled device, it will be a simple volume pedal that receive the MIDI signal from a MIDI expression pedal controller.

Back to Table of ContentsBuy Blackstomp PCBBuy Blackstomp ModuleBuy Blackstomp Pedal