So far, we have looked at messages made of text (e.g. “Hello world”) and at the special bang message, which means something like “do that thing you do!“. While we humans are good at communicating with words, computers usually are better with numbers. Also in the control of interactive media and sound, numbers play a decisive role: MIDI notes are for example represented by the numbers 0-127 and the color pixels on the screen are defined by numbers as well (see Max Tutorial 3) When using Max, you will therefor need to be able to send numeric messages as well. And to make it even more complicated, those numeric messages are often combined with other messages such as text. This exercise is about numeric messages and about combining several messages into a list.
Numbers
As usually, Max has some built in objects which makes dealing with numbers easy for us. First in line is the number box. Actually, there is a number box for integers and one for floating point numbers. Let’s open a new patch and add an integer number box which accepts many different messages but only outputs “whole numbers”. You add a number box by pressing i (i like integer) on the keyboard or by double-clicking and selecting the number box. Let’s also connect it to a print object, so we can monitor its output:
Lock the patch and click on the box. Keep the mouse in clicked state and move up and down. You should see the integer contained in the number box increasing when moving up and decreasing when moving down. That’s one way you might want to control a value live. However, looking at the max window we see that scrolling triggers a lot of events. Sometimes, you might just jumpt to a specific number right away instead. One way to go to a desired value directly is by clicking inside the number box and typing in the number. Also, we can send it a messages just like we did send messages to the print object in other assignments. Let’s try some:
Try out sending different messages and print the number boxes output to the Max window.
- When a whole number is send to the number box the number is displayed by the box and also send from its outlet to the print object.
- When a floating point number is send, it takes the integer before the comma, displays it and sends it from its outlet. When a non-numeric message is send (“Let’s have a break”), the number box does not understand it and complains about it in the max window.
- When you send it a bang, the current value is send without changing the value. When a longer message is send which starts with a number, the ongoing number is displaid and send, however, if the message does not start with a number, the number box does not understand the message and complains.
- An exception from the latter observation is a message in which a number is preceded by the word “set”. For example “set 0″. In that case, the value changes, but is not outputted. We call this a “silently” changing the content fo the number box. (The method of using “set” as a way to change the state of an object without triggering an additional messages is also common in other Max objects).
Let’s repeat the experiment with a floating point number box. Therefore, we first add a floating point number box at a free spot in our patch. We do so by pressing f (f like float) or by double-clicking and selecting the floating point number box.
You can distinguish the floating point number box from the integer number box by the little point in the bottom right corner. Now, we copy the floating point number box and delete it. Afterwards we right click on the integer number box. Here, we select “Paste Replace“. We now have replaced the integer number box by the floating point number box (you can delete the original floating point number box which still is placed in your patch but not connected to anything):
Trying out the different messages, many produce results similar to those we have seen using the integer number box. However, when a floating point value is send to the box, the entire value is registered and send by this number box. Bang, text and set messages all behave as one would expect. Also, our trick of locking the patch and changing the value by typing them or by dragging the mouse works. The only difference is, that now, it is important where exactly you click with the mouse. If you click on the integer part (before the point) you will increase the value in integer steps. However, the same works also for the displayed digits behind the point. Entering very high numbers the number box might be too small to display them. We can change the size of the number boxes by clicking on it and dragging the little handle.
To illustrate the biggest difference between integer and floating point number boxes, let’s have a simple patch which uses the output of a floating point number box and feeds it into a integer number box:
Lists
We have already sent messages like “8.254 6″and “max 4 life”. Messages which combine several numbers or even numbers and text are called a list. A list is useful for keeping data together in a single message. So far, we have only send lists to the number boxes, which usually did not deal with them too well. Let’s send some lists to the print object instead:
The first two examples behave as expected. Interesting are especially the two examples on the right. In our “it’s $1 minutes”-example, we have a number box connected to a message box. The text in the message box contains “$1“. This is called a replaceable argument. Use the mouse to change the value of the number box; the result is that the Max window displays the our message, but replaces the $1 text with the incoming number.
The example to the right accepts two values (the message contains $1 and $2 replaceable arguments). It uses the incoming list values to create our final message. A message can have up to 9 replaceable arguments (numbered $1 – $9). The arguments can be put in any order. Also, you can put the same replaceable argument in your message several times (E.g. “It’s $1 minutes until class ends. I don’t know if I can wait another $1 minutes!”). Let’s try an experiment with the arguments and switch $1 and $2 in our last message. Now you should have more euro than cent in your pocket.
What you should be able to do by now:
- Use integer and floating point number boxes
- Change the values in integer and floating point numbers by:
- sending a message
- typing in numbers
- using the mouse
- Create and send lists
- Use replaceable arguments
What you should know by now:
Numbers: you can send numerical data just like text. Integer number boxes are useful when dealing with “whole numbers”. They cut the part after the point when receiving floating-point numbers. For floating-point numbers use the floating point number box. Know, that you create number boxes by pressing i for integer number boxes and f for floating-point number boxes. You distinguish them visually by the point. The values of number boxes can be changed by sending a message, typing in numbers or by using the mouse. If you want to change the value without outputting it, you can change it silently using the “set” message.
Lists: A lists combines groups of numbers (e.g. (“60 12.34 -14 110″) or number(s) and text (“1 2 polizei”) in a single message. Message boxes can be used to create lists and complex messages with replaceable arguments.
Replaceable arguments: You can put up to 9 replaceable arguments in a message using $1-$9. You can use them in any order and you also can use several instances of the replaceable argument in the same message.