# teaching machines

## Music Mouse, Part V

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 start issuing MIDI numbers. When the musician goes up or down in the Music Mouse interface, a single note of the melody is played. When the music goes left or right, however, multiple notes are played. That is the harmony.

### Echo X and Y

If you aren’t already printing x and y when they change, do so now. Also, we will need to distinguish between melody and harmony commands in Pure Data. Let’s support this by sending a message type as the first byte in each message we send. Print 0 before x and 1 before y.

### Echo Horizontal Chords

When the horizontal position changes, we want to print more than x. We also want to print its partner notes in the chord. Let’s figure out what these partner notes are using Tero Parviainen’s Music Mouse implementation.

Move the mouse so that the bottom note of the chord is on a C, which is any white key immediately to the left of a pair of black keys.

How many halfsteps above the C is the middle note of the chord?
7

Okay. Next question.

How many halfsteps above the middle note is the third note of the chord starting on C?
9

Are they all like this? 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.

How many halfsteps above the D is the middle note of the chord?
7. This looks promising!

Next question.

How many halfsteps above the middle note is the third note of the chord starting on D?
8

Ugh. The partner notes aren’t at fixed, absolute intervals from the root. Let’s create two arrays to record the offsets:

int middle_offsets[] = {7, 7, ?, ?, ?, ?, ?};
int final_offsets[] = {9, 8, ?, ?, ?, ?, ?};


Use Music Mouse and determine the rest of the offsets.

What did you come up with?
int middle_offsets[] = {7, 7, 7, 7, 7, 7, 6};
int final_offsets[] = {9, 8, 8, 9, 9, 8, 9};


After you print x, also print the middle note’s MIDI number. Calculate the number using x and an appropriate middle offset. Look up the middle offset using scale_index_x.

Then print the final note’s MIDI number.

Upload your code. Horizontal motion should show 0, x, and the two partner notes. Vertical motion should show 1 and y.

### Preparing For Pure Data

We’re mostly done with the Arduino side of this instrument. To make the Pure Data work a bit easier, it’d be helpful if both horizontal and vertical motion produced messages of the same length. Horizontal motion generates messages with four numbers, so add two print statements for vertical motion. Just print 0s. This probably feels silly, and there are probably cleaner ways to solve this. But sometimes our time is more important than the product.

Also, change all your println calls to write calls.