4.3 HIDs

4.3.1 Theory

It's possible to play a patch live, just like you might play an instrument live on stage. While something is running in the patch, you can click on GUI objects, though using the mouse is fairly impractical if you want be precise with respect to time. For this reason, there are Human Interface Devices (HIDs), interfaces between man and machine. The mouse and keyboard are technically HIDs, but there are also many others, some of which are specially designed for use in music, for example to control a Pd patch. Keyboard and mouse

If you click in a number box, you can enter a value with the keyboard. You could also use the keyboard to transmit other information directly:

The keys are numbered (with some exceptions, the F1 and F12 keys, for example). "key" registers that a key has been pressed, "keyup" that it has been released. Each time, the key's number is sent. "keyname" shows a key's normal name.

Using the "MouseState" (case-sensitive!) external from Pd-extended, you can also use data from the mouse:

With "poll" and "unpoll" you can start/stop the display (in my version you have to click "unpoll" first and then "poll" for it to work). This displays absolute x/y-coordinates, delta values, and also whether the left mouse button is held.

Normally the coordinates 0/0 appear in the monitor's upper left; with "zero" you can select another point as a reference: MIDI

At the beginning of the 80s, large electronic instrument manufacturers established a standard data transfer protocol for use with an array of input devices called Musical Instrument Digital Interface (MIDI). Now there are MIDI keyboards, MIDI mixers, MIDI gloves, etc. In Pd, there are objects for receiving and sending MIDI data. You can send this input to a device or patch where it is converted into sound. However, most computer soundcards contain MIDI sounds as well, so MIDI data can also be converted into sound there.

MIDI protocol itself doesn't contain any sounds, but comprises commands for controlling the patch or other instruments, e.g., "note-on", "velocity", and "note-off". In addition to these basic commands MIDI uses other more specialized commands that could be used to, say, load other sounds or to modify loaded sounds using control data produced using switches, buttons, or tuning knobs.

Every standard MIDI command (except for system-exclusive data, SysEx for short) carries a channel number in addition to its command ID and command data. The channel number is 4 bits long, which means 24=16 channels can be controlled. Depending on the software, the channels are numbered either 0 to 15 or 1 to 16, though the latter is more common.

Since MIDI is a serialized protocol and the data rate of MIDI interfaces is fairly small by today's standards, there can often be timing problems when many notes are played at once, especially in conjunction with a sequencer program. Even just striking a chord comprising several notes can lead to an audible delay, because MIDI can never send notes simultaneously, only one at a time.

For the following examples, MIDI hardware is necessary. You can set these devices in Pd under Media MIDI settings.

The most basic object is "midiin". Every MIDI input is displayed there, the value on the left and the channel number on the right.

If you have a MIDI keyboard or other input device with definite pitches, with "notein" you get the following values:

The MIDI number for the pitch appears on the left, the velocity (strength of the attack) in the middle, and the channel number on the right.

Conversely, you could send this information to an instrument. If only one instrument is connected, you don't have to enter a channel number. You'll need to use "noteout" and then "makenote", the latter of which combines the entries in a manner similar to the "pack" object:

There are also control values, which are entered with "ctlin" and "ctlout". Let's take a look at "ctlin":

The left output is the value, the middle the number of the controller, and the channel on the right. You could also enter the middle value as an argument directly in the object to select the controller.

All other MIDI senders and receivers function like this as well. Among them are "pgmin", "bendin", "touchin", and "sysexin". Using signals to control sound

Sound input received through a microphone can not only be used purely as sound, but also as control data. As you learned in, you can use "fiddle~" to determine information regarding amplitude and frequency:

These numbers – again, Pure Data works only with numbers – can be used in conjunction with parameters in a patch.

One problem here is that data that comes from the "fiddle~" object is very chaotic. There is a trick you can use to filter it:

A low-pass filter can also receive control data input. In this case, only relatively slow changes are allowed to pass.

4.3.2 Applications Playing patches live

Using the input devices/methods described above, parameters in a patch can be changed externally:


It's clear that different devices have different functions: a button stands for on/off, a knob for gradual changes.

For controllers that have a row of numbers, like knobs or sliders, it is recommended that you use interpolation (especially because they have only 128 values in MIDI).

In Pd-extended (but only if GEM isn't loaded), there is a very useful external you can use for this: "scale". For example, if you change frequencies between 69 and 81 (MIDI numbers) and want to use a MIDI controller for this (which generates numbers from 0 to 127), you could write:

The last argument stands for linear (0) or exponential (1). More exercises

a) Use external MIDI sounds instead of oscillators for the algorithms in

b) Use parameters from any of the patches in Chapter 3 with input devices.

4.3.3 Appendix Other HIDs

In addition to the normal keyboard, mouse, and MIDI devices, the number of other input devices continues to rise: anything from joysticks for computer games, to tablets for drawing, to motion sensors. Though there is at present (June 2008) no single object in Pd that will work with all of these devices, the following externals should be mentioned:

"joystick", which can receive information from joysticks; "wintablet" for Wacom tablets in Windows; and "hid" in Linux and MacOSX, which works with many different input devices. A device called an Arduino Board has also been around for awhile; this device digitizes information it receives from analog instruments that are connected to it. With additional software, this information can also be received by Pd. Video input

There is also a video component in Pd called GEM that can be used to extract numbers from a video signal - either previously recorded or live - that could, of course, then be used to control sound parameters.

4.3.4 For those especially interested Instrument design

I have also given a presentation (in German) in the Lagerhaus Lecture Series in Freiburg, Germany on the art of using external input devices in a composition. It can be viewed online at this address: