Max 5 and Attributes
Sometimes when you are programming, you need to be able to configure some information about how your computer will do its job. Over the years, programmers have come up with a number of different terms for these little pieces of information — parameters, properties, fields, etc. In Max, we call them attributes. Attributes were first introduced in Jitter, where they make it convenient to manage the state of complex objects such as jit.qt.movie. In Max 4.5, a few Max objects such as pattr (which is short for “patcher attributes” by the way) and js began to make use of attributes.
Jitter users will be familiar with the fact that the initial value of an attribute can be set when typing arguments into an object box. Here’s an example:
jit.qt.movie @loop 2 @highquality 1
This sets the initial value of the loop attribute to the number 2 (for palindrome looping) and the initial value of the highquality attribute to 1. Subsequent messages to the object can just say loop 2 or highquality 1. The @ serves to delineate the arguments setting the initial value of each attribute. Setting multiple arguments for an object that uses attributes is typically easier to read due to the @ syntax. (For example, would you know what 2 and 1 meant if you saw an object that had jit.qt.movie 2 1 as arguments? You’d probably have to look it up in the manual.)
In Max 5, we’re beginning the process of converting the basic Max and MSP objects to use attributes. At the same time, we’re adding user interface features to make your interaction with attributes more fun and useful. However, there are hundreds of Max objects and we probably won’t complete the task of “attributizing” all of them with the first Max 5 release. For the most part, we’ve concentrated on user interface objects, because we’ve used attributes as the basis of our new UI object design, including the way you edit the settings of UI objects with inspectors. Unlike the inspectors in Max 4, which were patches created laboriously by hand, these new inspectors are automatically generated based on an object’s attributes. We moved to this system because we wanted to offer a rich set of attribute-based editing features that would be consistent across all objects including:
- undo (and multiple undo at that)
- reverting an attribute
- setting an attribute to its default value
- dragging any attribute out of an inspector to create a message box
- freezing attributes (I’ll explain this in a minute)
- consistent editing for attributes based on their type
- classifying attributes into categories
- attribute documentation available when you need it
Attributes and the Inspector
Let’s take a closer look at a simple UI object, the toggle, to see how some of these new attribute features work. We’re going to use color attributes to demonstrate some of the features mentioned above, because they’re, well, colorful and obvious. But the same principles apply to any attribute.
The Max 5 toggle object offers the customization of the color used for the X, the background, and the frame. All of these colors are now defined as attributes, so you can edit them in the toggle inspector window. The programmer of the toggle object has identified these attributes as colors, so the inspector displays a color editor, which features a set of presets you can modify and store in collections right from within the editor. In addition, due to the new compositing graphics engine we’re using, you can set alpha — or transparency — values for any color. Colors with an alpha value less than 1 are transparent to some extent; the closer the alpha value is to 0, the more transparent they are. The movie below shows the inspector for toggle and the color editor in action.
Now let’s look at some other tricks we can do with attributes. As in Jitter, Max UI object attributes can be modified programmatically by sending messages to the object. So let’s write a patch to do this. The first thing to notice is that while we see polite descriptions of our toggle colors such as “Frame Color”, these are not the real attribute names. To work with the real names, we have a number of options. First, the real attribute name shows up in the new Clue Window when we move the mouse over an attribute in the inspector, along with a description of what the attribute does.
Alternatively, if you want to control the attribute via a message to the object you’re inspecting, you can just drag the attribute out of the inspector into your patch. If you drag it near the object it will make a message box where you release the mouse with attributename $1. If you drag it onto the object, a message box will be created that is automatically connected.
Finally, there is a column called Attribute in the inspector that is initially hidden. You can show it by clicking the Show Attribute Names button in the inspector toolbar. Now all the official attribute names are displayed.
Below is a patch that manipulates the color of the toggle border. It’s not the most useful thing in the world, but it will allow us to demonstrate a new feature of Max 5 called attribute freezing. First, let me give you a little background on the problem we are trying to address with this feature. When you type counter 128 into an object box, you are setting the maximum value of the counter, and every time the patcher file is loaded, the counter has the same maximum value of 128, regardless of what its maximum value was when you saved the patch. However, there are many settings of an object you can’t set by typing in arguments, so Max programmers are often forced to set them manually using a loadbang object connected to a message box. And even when you can set initial values for object settings, such as by using attributes in Jitter, the number of arguments you have to type into an object box can quickly get out of hand.
But here’s the real issue: when we animate the border color of our toggle, the value of this color attribute is left at its last animated value when we save the patch, because UI objects don’t have any concept of “typed-in arguments.” However, we’d like it to be set to a specific fixed value when the patch is opened to provide a good impression. Before Max 5, the only way to do this would be to add a message box connected to a loadbang to set the color of the toggle’s border attribute when the patch is opened. But now, we can use the inspector window to set the border color and then freeze the attribute so that the value saved in the patcher will not be affected by our color animation.
This movie shows the process of freezing the attribute. First, you’ll see that the color value shown in the inspector actually animates as the patch manipulates the background color value. Next, we’ll stop the animation and set a value that we really like as a starting point, then freeze the background color. Note how the attribute name turns (ice) blue when the attribute is in a frozen state. Finally, you’ll see the toggle object duplicated, which is the same as saving the object and reloading it. Even though the original toggle has a gray background color from our animation patch, the newly created toggle has a background color equivalent to the frozen value.
Any attribute can be frozen in this way, whether it’s in a UI object such as a toggle or lives inside an object in an object box such as jit.qt.movie. Dynamic attribute manipulation is used by a lot of Jitter patches, and the ability to freeze attribute values will make it easier to work from a known starting point.
Now that we’ve taken a look at editing and freezing attributes in the inspector, let’s look at one more thing — a faster way to view the state of an object. I want to show you an enhanced version of the somewhat obscure quick reference menu that existed in previous versions of Max. In Max 4.x, you could shift-control-click (or was it option-command-click? I can never remember) on an object to see a list of messages the object responds to as well as a list of its attributes and their current values. In Max 5, this menu has a few new features. First of all, it is much easier to access. Just click on the left inlet of any object. Second, the quick reference menu is linked to the on-line documentation, so as you mouse over any message or attribute name, you’ll get a description of what it does in the clue window. And finally, you can actually select any item from the menu, and Max will create a message box with the message or attribute name, connect it to the object, and even let you start typing any arguments immediately.
Finally, note also that when we show the quick reference menu on our toggle, you even see which attributes are frozen.
I hope you’ve enjoyed this brief look at some of the new attribute features of Max 5. In the next Max 5 article, I’ll show you some of the new Max 5 debugging features, including wiretaps, the debug window, and the signal and matrix probes. You’ll see that attributes are as useful to have around when you are debugging your patches as when you are decorating them.