teaching machines

The Monodrone, Part II

June 13, 2019 by . Filed under electronics, music, public.

This post is part of a series of notes and exercises for a summer camp on making musical instruments with Arduino and Pure Data.

Now we’ll use Pure Data to generate some MIDI notes when the button is pressed. Start by assembling this patch that reads from the serial port:

Test that you can get numbers from the Arduino by pressing the button and inspecting the result in the number box.

When we see a 1 on the serial port, we want to start sounding a MIDI note. When we see a 0, we want to stop the note. The noteout object will handle both of these actions for us. Add a single noteout object at the bottom of your patch. It has these three inlets:

  1. The note’s MIDI number.
  2. The velocity, which quantifies the note’s “force.”
  3. The channel, which can be used to channel the note to different MIDI instruments. We only have one instrument (VMPK), so we can ignore this inlet.

Add three number boxes right above the noteout. The first will be the note number. Set it to the MIDI number of your favorite note. The second will be the velocity of a played note. Set it to some audible level. 127 is the loudest possible velocity. The third will be a velocity of 0. When Pure Data sees a velocity of 0, it stops playing a note.

Connect the note number to the first inlet of noteout. Connect both the velocities to the second inlet.

To choose which of the two velocities will get pushed to noteout, we’ll use a select object. We pass select a space-separated list of numbers to listen for. To respond to numbers 10, 11, and 12, we’d write select 10 11 12. The select box will have an outlet for each number we include in the list. When a float comes into the inlet of the select, it sends a bng out along the outlet that corresponds to the matching number found in the list.

In our case, our list of numbers is just 0 and 1. We wire up the outlets so that when a 0 is seen, we issue a bng to the stop velocity. When a 1 is seen, we issue a bng to the new note velocity.

All told, our patch looks something like this:

Number2 boxes are used here because their values can be saved. Regular number boxes reset to 0 when a file is opened.

Note how we wire up the the bng outlet of the trigger to force an update to the note number. Without that, a button press will not trigger a new note—as the velocities are only connected to cold inlets.

Test your circuit. Don’t forget to open VMPK and set Pure Data’s MIDI output to IAC Driver Bus 1 via Media / MIDI Settings. You should be able to drone monotonously by pressing the button. But it probably sounds pretty echo-y. We’ll fix that in the next exercise.

Challenges

After you get your monodrone working, answer the following questions on a piece of scratch paper.

  1. Experiment with different instruments in VMPK. What differences do you notice in how velocity affects different instruments?
  2. For what do you suppose the third outlet is on the select? After making a hypothesis, control-click on it and choose Help to see its documentation and validate your hypothesis.