patch #1: black keys

In this patch, we turn the computer keyboard into a musical keyboard. If you press a keyboard-key, you will hear a piano (a badly synthesized piano) play. For this patch, we will map the keys 1-9 of the computer keyboard to some black keys of the piano-keyboard. We will also use some built in MIDI-functionality. Note that MIDI is no sound, it is ‘only’ a protocol which tells digital instruments which sounds they should make.

The parts we need for that:

1. Detecting key presses

2. Mapping them to notes

3. Play back the notes

Let’s start with with detecting key presses 1-9.

We can do this with the [key] object like this.

Now we map them to the notes of the black keys. We will use the MIDI protocol. Max has some powerful MIDI functionalities built in. MIDI uses the numbers 0-127 to address the different notes. The C (or C4 to be precise) in the middle of a piano is adressed with number 60. We can see which number corresponds to which note, when we open the help of the [kslider] object:

When we press on the [kslider]-keys with the mouse, we can see which MIDI note number corresponds to that specific piano-key. Inside the [kslider] help, we also find all the other components we need to continue. The [makenote] object produces the MIDI note messages we need to start and stop a note. (Besides the information which key has been pressed, it also includes the duration and the velocity of the note). The MIDI note messages is then send to the [noteout] object which in turn sends it to the build-in synthesizer.  (Double click on the [noteout] object to select the  built-in synthesizer. Alternative you can send the MIDI messages from Max to other programs such as Ableton Live).

We can use the [kslider] as a visual feedback in our patch. We also copy the [makenote] and [noteout] objects. Furthermore, we note down the numbers that correspond to the black keys we want to play with our computer-keyboard. The numbers are: 54,56,58,61, 63, 66, 68, 70, 73,75. Let’s trigger those numbers with the computer-keyboard.

This is the resulting patch. (All notes have a duration of 1 sec and a velocity of 80). Try out other durations and velocities: