This post is part of a series of notes and exercises for a summer camp on making musical instruments with Arduino and Pure Data.
When we generate sound by altering the frequencies of waves, we are operating at a pretty low level. Most musicians don’t think about physical laws like we have been doing. They think about notes and timing and volume. So that we can operate at a higher level, we will abandon the wave representation of sound. Instead, we will consider the MIDI representation.
MIDI was designed in the early 1980s by several companies that made electronic musical instruments. They wanted to agree on a standard for representing music. Before MIDI, each instrument had its own way of representing music that was incompatible with the other instruments. Trying to connect instruments into a single system was painful. Music’s supposed to bring people together, right? MIDI defined a universal language that all instruments could “speak,” making it much simpler for one device to communicate with another.
Each note in a MIDI representation is by two numbers. First is the note number. The note numbers for the musical notes across several octaves are shown in the following table:
Check that you can interpret this table with these questions:
The second number in the MIDI representation of a note is the velocity, which determines how loud the note is. If the MIDI instrument is a piano keyboard, velocity refers to the force applied to a key. 0 means silent, and 127 is as loud as can be.
That’s all the background we need to start generating MIDI notes. Now we’re going to rework our tiangle to use MIDI instead of physical waves.Are you ready?
To produce this new instrument, which we’ll call the midiometer, start by copying your Pure Data patch for the tiangle instrument into a new patch. Tweak it to look like this:
makenote object wants three pieces of information:
It sends the note along to the
noteout object, which sends a message to whatever MIDI instrument is listening. Pure Data itself doesn’t play MIDI sounds; we need a MIDI instrument. For that, we will use a program called Virtual MIDI Piano Keyboard (VMPK). Follow these steps to get the programs talking to each other:
Command-Spaceand open Audio MIDI Setup.
Command-Spaceand open VMPK.
Ideally, you’ll hear something that sounds like a piano. But something probably went wrong. Feel free to ask for help!
Recall that our Arduino spits out numbers in [0, 255]. But the MIDI note numbers are limited to [21, 107]. Let’s remap the potentiometer readings to the note number range. Hit
close 1 in Pure Data. In your Arduino sketch, you probably have some code that looks like this:
int reading = analogRead(A0); reading = reading / 4;
Map the potentiometer’s raw [0, 1023] range to [21, 107] with the
int reading = analogRead(A0); reading = map(reading, 0, 1023, 21, 107);
Verify and upload your sketch. Test your changes. Every note should be audible.
After you get your midiometer working, answer the following questions on a piece of scratch paper.
makenote. Leave Edit Mode, drag on it, and play more notes on the midiometer. What does it do? After you’ve determined your answer, two-finger or right-finger click on
makenoteand check your answer against the documentation under Help.