27.11.2012 Views

programming with max/msp - Virtual Sound

programming with max/msp - Virtual Sound

programming with max/msp - Virtual Sound

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Interlude A - Programming <strong>with</strong> Max/MSP IA<br />

In this style of patch, the “cold” inlet of the addition object behaves as though<br />

it were a “hot” inlet. Try building it, and verifying that the number box on the<br />

right triggers a result every time that its value is changed.<br />

It is essential that the positions of the objects in your patch are absolutely the<br />

same as the positions in the figure. Placing the button to the right of the<br />

+ object, for example, will produce undesired results, since the bang will fire<br />

before the new value is stored, causing the addition object to use the old value<br />

that had been copied into the internal variable previously in its calculation rather<br />

than the new value (as shown in Figure IA.4).<br />

Fig. IA.4 Buggy results produced by an error in the order of execution<br />

Delete the two number boxes above the + object and connect a message box to<br />

its left inlet. After this is done, type two numbers (separated by a space) inside<br />

the message box, as in Figure IA.5:<br />

Fig. IA.5 Summing a list<br />

If you now click on the message box in performance mode, the + object will<br />

sum its values; the operator behaves as though it had received the second<br />

number on the right inlet (and, as usual, the argument 5 inside the object box<br />

is replaced by that new value). This behavior (the ability to accept lists of two or<br />

more elements on their left inlet and then route the individual list items to the<br />

other inlets) is also a common feature of many Max objects, and works not only<br />

<strong>with</strong> binary operators, but often <strong>with</strong> objects that have three or more inlets.<br />

To see a simple musical application of Max’s addition object, open the file<br />

IA_01_transposition.<strong>max</strong>pat (seen in Figure IA.6). Every time a key is pressed<br />

on the kslider object in this patch, two notes are generated, the second of<br />

which is 7 semitones above the first – the musical distance of a fifth. Every time<br />

that we press a key on the kslider, the value of the corresponding MIDI note<br />

number (a C in Figure IA.6, for example) is sent to the mtof object on the left,<br />

which converts it into a frequency value. At the same time, the note number<br />

is also sent to a + object that adds 7 (producing the MIDI note number for a G<br />

from “Electronic Music and <strong>Sound</strong> Design” Vol. 1 by Alessandro Cipriani and Maurizio Giri<br />

© ConTempoNet 2010 - All rights reserved<br />

133

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!