The first program you encounter when learning a programming language is usually “Hello, world!”. The “Hello, world!” program makes the text “Hello, world!” appear on the screen. We also start out with “Hello, world!”. However, we do not have to write code to achieve this. In Max, we add objects to the canvas and connect them in order to create programs, which we call patches.
Let’s begin from scratch and start out with a empty patch.
Start Max and open a new Patcher (use the menu bar: File -> new Patcher). You should see this:
Now, we want to print a message to the screen. To do this, we need two objects: a message box which holds our message and an object which can print to the screen. In order to be able to edit our patch, it has to be in edit mode. This means it has to be unlocked. You can lock and unlock your patch by clicking on the little lock in the left down corner, or by pressing cmd+e. Make sure your patch is in edit mode. Let’s first create a message box. You can do that by double clicking and then selecting the message box or by pressing m on the keyboard (make sure the Patcher is the active window).
This is our message box:
We now have a message box and only have to type our message (Hello world) inside the box.
In order to print this message to the screen, we need a print object. You can do that by double clicking and selecting an object box (the first option!) or by pressing n for creating a new object box.
This is the new object box:
In order to turn the object box into a print object, we have to type the word ‘print’ inside the object box:
Now we want to send the message to the print object, which will then print the message to the screen. In order to send our message to the print object, we first have to connect the two. We connect them using a patchcord from the message box’s outlet to the inlet of the print-object box (the inlets and outlets are the little dark ports which are highlighted with a red circle if you mouse over them). In order to connect them, first click on the outlet of the message box (bottom left corner) and draw a line (patchcord) to the inlet of the print object (upper left corner).
Our first patch looks like this:
Now that the two are connected, we can send the message to the print object by clicking on the message. However, if you still are in edit mode, clicking on the message will select the message. Lock your patch. Now, clicking on the message will print the message. Probably, you still won’t see it. That’s because the message is printed to the Max Window. Open the Max Window by pressing cmd+m or choose Window –> Max Window from the menu bar.
Now you should see this:
Congratulations, your first patch is working!
Now that we have a first working patch, let’s modify it it. First, let’s try out some new messages. If you read my post carefully, you might have noticed that our patch is not outputting “Hello, World!” as I originally intended but “Hello World”. That’s because commas change everything. Change the message to “Hello, World” and have a look at the output in the Max Window:
The message has been separated by the comma into two discrete messages. If you want to display the comma, rather than use it as a message separator, you need a backslash (“\”) character preceding the comma. The backslash tells the message box to to treat the proceeding comma as a normal text character: we use the backslash to “escape” a character that has special meaning.
In order to print “Hello, world!” our patch looks like this:
It is good practice to comment your patch in order to explain your patch. You also have to do this in the homework assignments. Just like the other objects, a comment can be created by double-clicking and then selecting the comment. Alternatively, you can press c on the keyboard. By default, a comment box has no border. Add a comment to explain that the message has to be clicked in order to print it to the max window.
Our final first patch is finished:
Don’t forget to save it using the menu bar (File>Save as…) or by pressing cmd+s on the keyboard.
The End.
What you should be able to do by now:
- Create a new patch.
- Create object boxes, message boxes and comments.
- Connect objects.
- Lock and unlock your patch.
- Open the Max Window.
- Print messages to the Max Window.
- Save your patch.
What you should know by now:
Object boxes contain functions that perform tasks. The print object is such an object box which contains a print-function. It prints received messages to the Max Window. Object boxes have a round borders. You can create a new object box by pressing n on the keyboard or by double-clicking on a free spot in your patch and choosing the object box.
Message boxes allow us to create messages that can be sent to objects. By default, they have gray backgrounds. They have two inlets and one outlet. When the patcher is locked, clicking on the message sends the message. When the patcher is unlocked, double-clicking on the message allows you to change it. You can create a new message box by pressing m on the keyboard or by double-clicking on a free spot in your patch and choosing the message box.
Comment boxes are used to document and explain the patch. By default, they have no borders. You can create a new comment by pressing c on the keyboard or by double-clicking on a free spot in your patch and choosing the comment.
You can view printed messages in the Max Window. It also displays error messages. It is opened with the key combination cmd+m or by choosing Window>Max Window in the menu bar.
Depending on their functionality, objects have one or more inlets and/or outlets. Messages can be passed on between objects by using patchcords to connect their outlets and inlets.
In order to modify the patch, the patcher needs to be in edit mode. In other words, the patch needs to be unlocked. In order to use the patch, you have to lock the patch (and thereby exit the edit mode). There are several options to lock and unlock the patch. For example, you can do this using the little lock in the left bottom corner or by pressing cmd+e.
Using commas in a message, separates the message. The backslash can be used to escape characters which have special meaning.