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. We’ll use the
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. We can use the
noteout object to both start and end the note.
Add a single
noteout object at the bottom of your patch. It has these three inlets:
Add three number boxes right above the
noteout. The first will be the note number. The second will be the velocity of a new note. The third will be 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 list of numbers. It will have an outlet for each number we include in the list. When a float comes from the
trigger through its inlet, 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:
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.
After you get your monodrone working, answer the following questions on a piece of scratch paper.
select? After making a hypothesis, control-click on it and choose Help to see its documentation and validate your hypothesis.