teaching machines

Music Mouse, Part V

June 16, 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.

In this exercise, we prepare our Music Mouse to send messages to a Pure Data patch. When the musician goes up or down in the Music Mouse interface, we issue a message containing a single note to be played. This will be the melody. When the joystick goes left or right, however, we issue a message containing several notes to be played. This will be the harmony.

In this exercise, we design a protocol, a language for describing how two systems communicate with each other.

Melody Message

We need to distinguish between melody and harmony messages in Pure Data. Let’s support this on the Arduino side by sending a message type as the first byte in each message we send. We’ll use a 1 to denote a melody message. The melody, which is controlled by vertical motion, plays a single note at a time, so we technically need only send one MIDI number across the serial port. However, we will need four numbers in our harmony messages.

To make our work in Pure Data easier, let’s make both messages take up four bytes. Melody messages will have this form:

1 y 0 0

You should already have code that prints y. Precede it with code to print 1. Print two meaningless zeros after y.

Harmony Message

We’ll use 0 to denote a harmony message. When the horizontal position changes, we want to print more than x. We also want to print the partner notes of the chord. A harmony message will have this form:

0 x (x + offset to middle) (x + offset to middle + offset to final)

Let’s figure out what these partner notes are using Tero Parviainen’s Music Mouse implementation.

Move the mouse so that the leftmost note of the chord is on a C, which is any white key immediately to the left of a pair of black keys. Observe the other two keys that are played above or to the right of the C. Count the number of keys or halfsteps it takes to jump up to these higher notes.

Do all the chords have the same offsets? Let’s check. Move the mouse so that the bottom note of the chord is on a D, which is any white key between a pair of black keys.

Now we are ready to send a complete message for the harmony. You should already be printing x. Precede it with a 0. After printing x, print the MIDI numbers of the middle and final notes. Which offset we use depends on our current position in the scale. What do we have that can tell us our current position in the scale?

Upload your code. You should see both message types. When you see the messages following the protocol, change all your println calls to write calls. We’re heading to Pure Data next.