Mauro Graziani

A Max/MSP primer

Lesson 01
Starting with Max/MSP


This materials are part of the lecture notes from my lessons about Max/MSP
at the E.F. Dall'Abaco Conservatorium, Verona (Italy)

email me: mg AT maurograziani DOT org


Chapter Codes

Chapter topics are coded using title colors:

Black Title: normal chapter you must read.
Blue Title: tips or tricks maybe useful but not essential.
Maroon Title: advanced topic for advanced users. More information but not essential for current lesson. Try to read; skip if you don't understand.

English is not my first language. I apologize for errors. This material is in english to be worthwhile to more people and to give my students a little thrust.


Starting with Max/Msp: Prerequisites

Starting to learn Max/Msp from scratch could be a little difficult. In my opinion a student should have at least the following background knowledge:
Here "basic knowledge" means the student must understand the concepts. A deep or mathematical skill is good but not required. Knowledge of the way a filter or an FFT works is not required. But the student must know what a filter or an FFT does.
Max/Msp is a virtual synthesizer on which you must build your own instruments and effects connecting basic modules, so the knowledge of other synthesis system (e.g. CSound) is very helpful.
A general skill on using and connecting mixers, effects box and studio equipment is very useful.
Last but not least, the user must be acquainted with the windows/mac editing modes (edit box, menus, copy, paste, etc).

Starting with Max/Msp: Install & Configure

Audiotester boxInstalling and configuring Max/Msp on Windoze/Mac is easy if your system already play sounds. I never found problems to install Max and get sounds on a properly configured system.
Max don't install special drivers, It connects to the ones it find on your system. So BE SURE that your computer can play the system sounds and other sound material BEFORE the Max/Msp install.
Remember: if your system can't play sounds by itself (not through Cubase or other software) you'll have to tell Max to use another sound driver.
The same is for MIDI: if you plan to use MIDI, test your MIDI in/out before installing Max.
To test Max:
  1. Start the program. Note that if you don't have QuickTime installed, Max complains about the QuickTime lack writing some messages on the little Max Window on the left. This window is the one on which the error an system messages appear. QuickTime is optional (used to handle movies and images). All audio and MIDI works normally without it, so you can install it later.
  2. Now click the menu Extras -> Audiotester and the audiotester box will appear. On the box, click the button labelled "start" (see image). Now look at the right half and click one of the little square boxes labelled "on". The box becomes checked and in spaces above you should see a little green wave (a sort of oscilloscope) and a level meter horizontal line. Also you should hear a 440 Hz sine wave on a channel.
    Note: the sound starts at low level; to increase volume click and drag the 0.2 number at the left of the "on" box (max level is 1). To change the frequency click and drag the 440 box.
    Ok, done. To stop the sound 'uncheck' the "on" box. To end test and turn off the box click the "stop" button.
    To test the Input you must connect a microphone to your board. We'll make it later.
  3. If you can't hear anything, before considering harakiri/seppuku, do the following:
    1. If you have one sound board only, generally Max start using the default sound driver, so check the system sounds. Exit Max and be sure to hear the system sounds. Then reboot  the system (windoze is a rebooting system: in this case the proper italian translation is "ributtante"). Re-check the system sounds. If the system sounds works, restart Max. Retry Audiotester.
    2. If you see the audiotester running (i.e. the oscilloscope and the level meter works) but you don't hear any sound, check the volume. If you have 2 or more sound boards, be sure you can hear all their outputs: maybe Max is playing on a channel or board that is not connected to the PA. If a good sound board is installed it is common to connect this last one and leave the motherboard sound output unconnected.
    3. With the Audiotester box open, click the menu Options -> DSP Status and open the sound configuration box. Don't worry if you see Audio Off. Audio goes on only when you click the Start button on a patch. In this box you can check the following:
    4. First check the "Output Devices" and select a device that is connected to the PA. Try stop and start the audiotester.
    5. Try to change the sound driver. In XP, the default driver is "ad_mme" (standard multimedia driver). If you have directx you can find the "ad_directsound". Other software can install different drivers, as the Asio drivers. Try all.
    6. Check the output channel 1 & 2 assignment (down on the box)
  4. If nothing works consider harakiri/seppuku.

Max and Msp

As the name suggest, Max and Msp are two different packages that work together.
Max handles the MIDI and control data only. It don't make sound. Max was originally written to process MIDI data and send to an external MIDI synthesizer.
Msp creates and process audio data.
The difference between Max and Msp modules and connections is made visible in the patches because:
Max was conceived and developed for the Macintosh in 1986 at IRCAM by Miller S. Puckette. Further development by David Zicarelli. Max is named after Max Mathews, a pioneer in the world of computer music, the man who wrote MUSIC, the first widely-used program for sound generation, in 1957.
In 1996 Puckette released an entirely re-designed Free Software program running on Linux and called Pd (short for "Pure Data"). PD includes the audio processing and remains an attractive substitute for those who don't want to spend hundreds of dollars on Max/MSP.
Reusing the PD audio part, David Zicarelli released late 1997 the MSP package. MSP is said to be tha acronym of Max Signal Processing but could be seen also as the acronym of original developer's name Miller S. Puckette.
The package was first commercialized by Opcode and is now distributed by by Zicarelli's company Cycling'74. A free java version also exists, called jMax.

Operating difference between Max and Msp

The real, operating difference between Max and Msp modules is that the former work in asynchronous way (i.e. the computation is made only when a message comes) and the latter work in synchronous way at the SR speed (i.e. if the SR is 44100, then a new value is computed 44100 times each second).
For instance, with a SR = 44100 (the standard), the Msp multiplier operator (*~) computes its result 44100 times each second. The aim of this module is multiplying two signals or a signal and a number. The result is another signal with 44100 samples per second.
On the contrary, the Max multiplier operator (*) computes its result once and outputs a single number. If you need to multiply a frequency value by 2 (to calculate the 8ve) and pass the result to a cycle~ object, computing 44100 times the same number is stupid and CPU consuming, so it's better to use the Max multiplier instead of the Msp multiplier.

The First Patch

Ok, I hope the audiotester works on your system. We can start patching.
The first patch is very simple. It's only a single oscillator connected to output, but you will learn some interesting things about the way Msp handles the connections with your sound board via dac~ object. Now open a new patcher windows (File -> New -> Patcher).

The modes

The patcher opens in Edit mode. In this mode you can add new objects to the patch dragging from the palette that appears on the upper part of the window. You can also connecting, move and edit objects already placed in the window.
The other is the Play mode. In Play mode the patch is locked: you can't edit. The palette disappear. You can only play and act on the objects that allow a real time interaction.
You can switch between the Edit <-> Play modes with
  1. the Edit menu
  2. the key Ctrl-E
  3. Ctrl- left click in the patcher windows

The palette

Now stay in Edit mode and look at the Max/Msp palette:
The palette
New Object boxAs you can see, there are many different object icons in the palette. The ones on the left are the most commons. To put an object in the patcher window, first click the icon on the palette, the click everywhere in the window.
Now click the Object icon (the first on the left) and place it into the patcher window. The module list will open (see it on the right).
On the left you find the object category, on the right the objects name. If you don't remember the category where an object belong, select the first (All Objects) and go through the very long alphabetical list on the right.

Suggestion

You can use this box to begin exploring the category list. It's a good idea to get acquainted with the categories contents because by this way you can understand how many objects exist and guess their meaning.
For instance, looking at the "MSP Synthesis" category, you see objects that make basic waves for sound synthesis. Depending on your skill in electronic music, you could guess that click~ could be a single pulse generator, cycle~ could cycle a stored wave, noise~ is a noise generator, oscbank~ is for sure an oscillator bank and so on...
You can then search the MSP and Max Reference manuals to see how each object works.

Patching step-by-step

Now select the "MSP Synthesis" category and double-click the cycle~ object. Place the cycle~ into the patcher window and insert a space followed by frequency value in Hz (e.g. cycle~ 220 or 440). Click on the window outside the object and see the cycle~ automatically resizing.
Then place another object under the last one: select the dac~ from MSP I/O category. This is the output object, the real connection between  the software and the sound board outputs. Write nothing in and click outside the object box.
inlets/outlets
Now take a closer look at cycle~ object. You'll see 2 black lines on the left and right of upper border and one black line on the left of lower border.
The uppers are called "inlets" and are input connections for signals and control messages. Each module can have a different number of inlets with different meaning. For instance, in the cycle~,
so, connecting something to left inlet we can change the frequency in real time (we'll do later).
The lowers are the "outlets" and are the outputs from the module. The cycle~ has only one outlet carrying the audio signal.
If you move the mouse near each inlet/outlet, Max makes the inlet/outlet thicker and its function is displayed on the lower left of the Max window.
Connection
Now connect the cycle~ to the left inlet of the dac~. To create the connection, move the mouse near the cycle~ outlet (it becomes thicker) then click and drag the wire to the dac~ inlet. You'll see that, when the mouse approach the dac~'s inlet, this one becomes thicker and attracts the connection wire.
Ok, you've made it! Now the cycle~ is connected to the left output. The default dac~ (with no arguments) has 2 inlets that are internally connected with output 1 & 2 (normally left & right) of your soundboard.
The very simple patch is done, but you can't hear any sound until you turn on the dac~.
Now save this patch (File -> Save as) giving it a name.

MessagesThe messages

Messages are the way you send commands to Max/Msp objects. Each  object understands his own messages only. If you send the wrong (not understood) message to an object, an error message appears on Max window.
A message can be
In Edit mode, a message is displayed as a box with the message text inside. In Play mode, the box becomes a button: when you click the button, the message runs through the connection wire reaching its destination.
To insert a message, select the 2nd icon on the palette and click on the patcher window. This time no list appears: you must know the message text you have to insert. You can find a list of messages that each module understand on the Reference manuals.
Now we'll set up the messages to turn on/off the sound. Create 2 messages labelled "start" and "stop" and connect to the left inlet of dac~ (see image). Now switch to Play mode (menu-> edit or Ctrl-E) and click start. You will ear a sine tone at 220 Hz. Clicking stop you turn off the sound.
As you see the same inlet can receive signals and/or messages.

messagesSending messages to the cycle~

In the same way you can send messages to any object. Of course you must know what kind of messages are meaningful for the object.
It's easy to think about each message as a command. When an object receive a command it performs the associated action, if any.
For instance, in the dac~ object there are actions associated with the "start" and "stop" messages (turning on/off the dac itself), but there is no action associated with the message "foo". If a dac~ receive the "foo" message it does nothing and an error message is written on the Max window (try it).
The cycle~ object has no action associated with messages like "start" or "stop" because, as the oscillators in a synthesizer, the cycle~ is always playing.
Instead in the cycle~ an action is associated with numbers (integers or floats). The cycle~ understands each number as a frequency in Hz, so sending a cycle~ a message like "440" trigger the action "setting frequency to 440 Hz".
Now you can try sending numbers to the cycle~, as in figure, and hear the cycle~ changing frequency. You must note that the messages override the value written in the cycle~ itself (220).

I don't want to go blind

In Max the font dimension can be very little with an high resolution screen.
To change the font dimensions and/or type open a new patcher windows. Before inserting any object choose a new dimension on the Font menu. The dimension you selected affects the new objects only.
If you already have some object in the window, first select all (Edit → Select all), then click an object with the right mouse key and select "Fix width".

A useful patch: comparing scales

Cycle~ and dac~ are only a few objects to work with, but we can also try to create an interesting patch.
First we will build a little musical keyboard. This chart shows the frequencies in Hz for the notes in the temperate system (the piano extension is in brown).


-1

1

2

3

4

5

6

7

8

9

C

16.35

32.70

65.41

130.81

261.63

523.25

1046.50

2093.00

4186.01

8372.02

C#/Db

17.32

34.65

69.30

138.59

277.18

554.37

1108.73

2217.46

4434.92

8869.84

D

18.35

36.71

73.42

146.83

293.66

587.33

1174.66

2349.32

4698.64

9397.27

D#/Eb

19.45

38.89

77.78

155.56

311.13

622.25

1244.51

2489.02

4978.03

9956.06

E

20.60

41.20

82.41

164.81

329.63

659.26

1318.51

2637.02

5274.04

10548.08

F

21.83

43.65

87.31

174.61

349.23

698.46

1396.91

2793.83

5587.65

11175.30

F#/Gb

23.12

46.25

92.50

185.00

369.99

739.99

1479.98

2959.96

5919.91

11839.82

G

24.50

49.00

98.00

196.00

392.00

783.99

1567.98

3135.96

6271.93

12543.85

G#/Ab

25.96

51.91

103.83

207.65

415.30

830.61

1661.22

3322.44

6644.88

13289.75

A

27.50

55.00

110.00

220.00

440.00

880.00

1760.00

3520.00

7040.00

14080.00

A#/Bb

29.14

58.27

116.54

233.08

466.16

932.33

1864.66

3729.31

7458.62

14917.24

B

30.87

61.74

123.47

246.94

493.88

987.77

1975.53

3951.07

7902.13

15804.27


Now we can build a patch to play a major scale from C4 to C5. It's easy. Simply place a message that send the frequency for each note to build your personal keyboard (see image below).
Diatonic keyboard
You can select the message boxes and align with the right-click menu.
This is a very simple patch without envelope (push start and stop to turn the sound on/off), but we can make it more interesting comparing two scales: the equal temperament and the just scale (sometimes referred to as "harmonic tuning" or "Helmholtz's scale") more strictly related to the harmonics (click here to read more about the Just Scale).
The table below shows the differences between the intervals in the just and tempered scales.

Interval Just Scale
ratio
Equal Temperament
ratio
Unison 1.0000 1.0000
Minor Second 25/24 = 1.0417 1.05946
Major Second 9/8 = 1.1250 1.12246
Minor Third 6/5 = 1.2000 1.18921
Major Third 5/4 = 1.2500 1.25992
Fourth 4/3 = 1.3333 1.33483
Diminished Fifth 45/32 = 1.4063 1.41421
Fifth 3/2 = 1.5000 1.49831
Minor Sixth 8/5 = 1.6000 1.58740
Major Sixth 5/3 = 1.6667 1.68179
Minor Seventh 9/5 = 1.8000 1.78180
Major Seventh 15/8 = 1.8750 1.88775
Octave 2.0000 2.0000

From this table we can easily compute the frequencies of the notes in the equally tempered and just scales.

Note Just Scale Equal
Temperament
Difference
Hz
C4 261.63 261.63 0
C4# 272.54 277.18 +4.64
D4 294.33 293.66 -0.67
E4b 313.96 311.13 -2.84
E4 327.03 329.63 +2.60
F4 348.83 349.23 +0.40
F4# 367.92 369.99 +2.07
G4 392.44 392.00 -0.44
A4b 418.60 415.30 -3.30
A4 436.05 440.00 +3.94
B4b 470.93 466.16 -4.77
B4 490.55 493.88 +3.33
C5 523.25 523.25 0

Now we can add a second line of messages above the existing one with the frequencies of just scale and connect to the cycle~ in the same way. You can seect the line, copy, paste and move in the right place. Adding some labels using the comment box (the 3rd in the palette) we will make the patch more clear.
Comparing Scales

Beautifying

Some beautifying operation can make this patch more pretty. We can change colours and fonts. Moreover, the stuff the user don't need to interact with, can disappear while playing. Select the objects and wires (press the Alt while draggging) and click Hide-on-Lock on pop-up menu.
Start and stop boxes can be repositioned. Finally, a panel on the back can be positioned to enclose all controls, so we can build a coherent and simple user interface for this patch. We'll see more about it later.
In this version a second cycle~ playing a C drone has been added with a check box to turn the drone on/off (Base C check box).
Beautifying

Download the patches for this lesson

Click here to download

Some practice

  1. Compute frequencies and add to this patch a new buttons line to hear the Pitagorean scale also. The Pitagorean major intervals are like the Just, but the following: major third = 81/64, major sixth = 27/16, major seventh = 243/128.
  2. Add to this patch a second cycle~. Put each cycle~ on a different output channel (left/right) and assign the just scale to the left cycle~ and the tempered scale to the right. Note that you need two buttons for unison and octave to do it.


Index
Back Next