Max msp notes 1 PDF

Title Max msp notes 1
Course Operating Systems and Object Oriented Programming
Institution University of Hertfordshire
Pages 7
File Size 391.4 KB
File Type PDF
Total Downloads 40
Total Views 145

Summary

max/msp first of the notes...


Description

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999

Programming 1 – Max5 Selection and Routing

Please note – in this handout, some of the screen grabs are from Max4 meaning they look a little different graphically. The function and name of these objects is exactly the same as Max5 (i.e. the version you are using).

Many pieces of code are based upon a simple premise of saying ‘if a value equals something then do something’. The [select] object that has been spoken about in class at length does the exact same thing and can be demonstrated as a piece of text based code. [select 34] could be written in C (or Max for that matter, see the section on comparisons below) as: if the input equals 34 then send a bang out of the LH outlet else send the input out of the RH outlet or… (in Max5 and excluding the ‘else send the input out of the RH outlet’) [if $i1 == 34 then bang]

The [if] object and [sel] object are doing, pretty much, the same thing. Below, we will see how this can be done with the slect object using multipal arguments. As we attempt to carry out more complicated tasks with Max, we often want to pick out particular information and route information to different places accordingly. One useful tool is the select object. This can pick out particular values and indicate that they have been received:

1

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999 In this example we give select an argument of 10, which means select for 10. This means that if it receives 10 (from the slider in this case) it will send a bang from the left output. If any other number arrives it passes that number on through its right output. This means we could chain several select objects to pick out different numbers:

Here, each select picks out a different number from the original slider, and bangs if it finds it. If not, it passes on to the next one. However, we don’t have to do this since we can pick out more than one value using a single select, giving an argument for each value we want to pick:

Select can also be used with floats and symbols. In this example, select picks out particular symbols from a popup menu and bangs different outputs accordingly. Note that we use the right-hand outlet of the menu to give us the symbols themselves and not their index (of course having checked ‘evaluate item text’ in the ‘inspector’ options for the menu).

While select is a useful object for picking out particular values (e.g. when a maximum velocity note event occurs) there are other objects that can route information. These are switches and gates. A switch takes several possible inputs and directs only one of them to its output. Gates take one input and route it to one of several possible outputs. Two basic versions are Gswitch and Ggate. They both only have two possible routings and can be switched by clicking on them as well as by control through their left inputs. They also graphically indicate which route is currently selected:

2

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999

More general objects are gate and switch, which can have many routings rather than just two, but don’t show graphically which routing is currently active. They also have an off state where no routing is active at all:

Here both the gate and switch are given 5 routings (+ off). The left-hand input chooses which routing is active, so here the switch is selected to pass input 4, and the gate is set to route its input to output 2.

3

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999

Comparisons and further mathematics Having seen how we can route items and pick out specific items we now take a look at how we can make decisions based on comparing values rather than simply on the basis of picking out when a particular value occurs. The most common objects are ones for comparing two numbers. These exist in pretty much all programming languages and usually use the same symbols:

The comparisons are less than (). Again the result is calculated only when the left input changes, and the result is 0 for false and 1 for true. A useful object to use alongside these operators is togedge. This object indicates (using a bang) when transitions from 0-1 (false-true) occur - at the left outlet - and when 1-0 (true to false) occur – at the right outlet. Here we use select and comparison operators to detect different event characteristics of a note:

So here we get different triggers depending on whether the message is a noteoff, a noteon at max velocity, or whether the note is loud or soft. In the next example we use togedge to look for transitions. The togedge only registers changes from false-true or vice versa so will only indicate if the transition was from a loud to a soft, or soft to a loud note – if you keep playing soft notes, it will only indicate the first soft note, and the same for loud ones.

4

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999 Another group of operators are logical operators. These again are common across different programming languages. These are AND (&&) and OR (||) for comparing two states that are either true or false. If both are true && will output true, anything else false. If both are false, || will output false, anything else true. We often use these to combine the results of comparisons in order to make more sophisticated tests. In the next example we combine an OR (||) with two comparison operators to detect when either very quiet or very loud notes occur, but not those in between.

Using these objects we can pick out very specific events, or broad bands of events. For example, here we pick out whenever middle C is played at velocity 64, and also whenever notes below middle C are played with velocity greater than 90. Again we use stripnote to ignore noteoffs.

5

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999

Communication without Patch Cords Often we want to send messages from one place to another without using patch cords. For example between two Max patches in different windows – it would be impossible to connect one to another. The objects we use are send and receive, which can be abbreviated as s and r. In this example they are going to different patcher windows. If you have many [receive somewhere] objects the send will go to all of them at the same time (regardless of where they are).

To send you make a send object (or s) and give a symbol (an argument) to use to identify it. You then make a receive (or r) object with same symbol, which then receives any messages put into the corresponding send object. You can receive the same information at as many different places as you which. IMPORTANT – the argument or identifier must consist of a single word or symbol. A space will indicate two arguments meaning that receive and send will see the first argument only (hence, [send somewhereesle] is a one word argument, with and not [send somewhere esle] which would be a two word argument). Another way of sharing information in different places is to use value or v. This object is similar in that you give it an identifying symbol. Then any value object you make with the same symbol has shared access to the value stored in it. To change the value you send a number into the input of any of the value objects with the same symbol. Sending a bang into a value object outputs its value:

6

Programming 1 – Rob Godman 2009 Notes: prog 1: Programming techniques with Max R.Polfreman, 1999

Again the value boxes can be in different patcher windows. You can use send, receive and value objects both to communicate between patches, which helps you to use modular design approaches (since each patch can be a standalone program, but can be send information from other programs) and also to help keep individual patches organised by reducing the number of long and inconvenient patch cords you need to use.

Revision – Rob Godman March 2009

7...


Similar Free PDFs