Max pattr Tutorial 2: Automatic Bindings and Storage
Open Tutorial

pattr Tutorial 2: Automatic Bindings and Storage


The Max pattr object can be used to help you manage data, either by binding to an object and referencing its data or by storing the data itself. The pattrhub object allows you to remotely query and set the data stored in pattr objects throughout a patcher hierarchy. In this tutorial, we’ll look at two powerful extensions to the pattr family: autopattr, which simplifies the binding of large groups of objects to the pattr system, and pattrstorage, which provides an extensive system for storing and recalling ‘states’ of data stored in multiple pattr objects.

To open the tutorial patch, click on the green Open Tutorial button in the upper right-hand corner of the documentation window.

Automatic Binding

Take a look at the tutorial patcher. Start the patch by clicking the toggle box attached to the metro object in the upper-left corner of the patch. The patch creates an algorithmic drawing based on the parameters stored in the rslider object and number box objects attached to the patcher named drawing. The message box that sends a bang to the receive object named reset allows you to clear the lcd display and reset the counter objects in the drawing subpatch.

The object called autopattr in the lower-right corner has a number of message box objects connected to it that contain different example settings for the drawing controls. The autopattr object has much of the same functionality as pattrhub, allowing you to send and query values from objects bound to the pattr system within a patch.

Unlock the patch and select one of the drawing interface controls other than the toggle object (i.e. the rslider or number box objects at the top). Under the Object menu, select Name….

Note that our four ‘control’ objects in the patch have names (range, angle, offset, and desynch). If you create a group of user-interface objects and give them names, an autopattr object will automatically bring those objects into the pattr system, exactly as if they had pattr objects all bound to them individually. In this sense, autopattr also functions as a set of pattr objects, allowing you to include multiple objects for patcher storage with one object.

The default behavior of the autopattr object is to bind only named user interface objects in a patcher when the object is created. The autoname attribute to autopattr, when set to 1, will automatically name all user interface objects in the patcher and bind them to the pattr system. Like the Max preset object, the autopattr object will exclude any objects connected to its second inlet or, if objects are connected to its left inlet, allow you to only specify a few objects explicitly for naming and binding into the pattr system.

Because the autopattr object combines many of the features of the pattr and pattrhub objects, it allows you to rapidly include large numbers of Max objects with a single object, while allowing you to query and set their data through the same object.

Storing States

Click on the message box labeled clientwindow attached to the pattrstorage object. The window that appears gives you a tabulated list of all the pattr associated objects in the patch, as well as some information about them. Change the settings in some of the control objects for the drawing machine and watch the window update to reflect the new settings.

The pattrstorage object provides a number of features for high-level parameter management. The client window shows the names of all the objects bound to pattr in the patch (including those controlled by pattr objects or autopattr objects). It shows their current values in the last column. The middle two columns show the recall priority and interpolation mode for the objects, which can be changed to fine-tune the order in which the objects are recalled to a saved state, and how objects respond to an in-between state (see below).

Click on the message box labeled storagewindow attached to the pattrstorage. A window with a list of the control objects should appear. Create a setting you like with the four objects that control the drawing machine. Once you have a setting you’re happy with, click the button object labeled "store a preset" attached to the int object above the pattrstorage. This will send the message store 1 to pattrstorage.

Sending a store message, followed by an integer value, tells pattrstorage to capture the current state of all bound objects and save them as a preset (or state) in a numbered slot inside the object. The slot will then receive a column in the storage window, showing us the number of the slot as a column header, with all the appropriate values tabulated below it. State 0 is a special slot that allows you to save a state temporarily without having it save in a file (see below).

Now that you’ve saved a preset, change one of the pattr-bound objects. Watch how the storage window responds. When you make a change to an object that deviates from the most recently saved or recalled preset slot, the value for the appropriate object becomes italicized in the storage window.

Create some more preset states by making changes to the control objects, then storing their settings in pattrstorage by incrementing the number box attached to the int object and clicking the button. Note that if you re-use a slot number (e.g. you save a state under slot 2, then save again) the old settings are overwritten. Also note that the most current state (stored or recalled) is shown with a colored highlight, while non-current states appear unhighlighted.

Click on the number box labeled ‘recall a preset’. Set it to one of the values you’ve stored. The user interface objects should recall to their saved values, and the slot column representing that state in the storage window should go to boldface.

Sending an integer to pattrstorage will recall the slot corresponding to that integer. Attempting to recall a slot that has never been saved is harmless, and pattrstorage will ignore you.


Click on the floating-point number box labeled ‘interpolate between presets’. Type in a value between two adjacent slots you’ve saved (e.g. if you’ve saved a state under 1 and a state under 2, type 1.5). The pattr-bound objects will go to an interpolated value between those two states. Drag with the mouse in the number box so that you effect a smooth transition from one state to another. The controlled objects will smoothly interpolate as well.

Floating-point values sent to pattrstorage will interpolate values between saved states. Non-adjacent states can be interpolated as well, using the message fade a b n, where a and b are the slot numbers and n is a value from 0.0 (100% a) to 1.0 (100% b). Note that interpolated values will italicize both of the participating slots in the storage window (the highlight color will fade from the a to the b slot, as well).

Saving and Loading Files

After you’ve saved a couple of states into preset slots, click on the message box labeled write attached to the pattrstorage object. A file save dialog will appear, asking you to save a file with the suffix .xml. Save the file somewhere and open it in any application that can read text files (Max, for example). Look over the file.

The pattrstorage object reads and writes collections of preset states as XML (extended markup language) files, a format which uses nested tags as identifiers for different types of data in a file.

An example XML file from our tutorial patch could look something like this:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<pattrstorage name = "u518000001">
<slot number = "1">
<pattr name = "angle" value = “60.” />
<pattr name = “desynch” value = “7” />
<pattr name = “offset” value = “0.” />
<pattr name = “range” value = “50 100" />
<slot number = “2”>
<pattr name = “angle” value = “33.5” />
<pattr name = “desynch” value = “39” />
<pattr name = “offset” value = “8.8” />
<pattr name = “range” value = “50 147" />

The first relevant tag that encompasses all our data defines the information as belonging the a pattrstorage object. The <pattrstorage> tag also tells us the name of the pattrstorage argument, which is randomly generated unless we set it explicitly with an argument to the object.

Between the <pattrstorage> tags, we have <slot> tags defining the saved states. Note that slot 0 is not saved in the file. Within each <slot>, we have <pattr> tags that list the bound objects by name and list their preset value for that state.

Make a change to the numerical data in one of the slots and save the XML file. Be careful to preserve the quotation marks around the values. Read it back into the patch by clicking the read message box and selecting the file. The storage window will update to the new preset value, which you can then recall.

Because XML is a straightforward, human-readable format, it’s quite simple to edit preset files saved using pattrstorage. We could even use a piece of software (e.g. Max) to automatically generate preset files for our patches once they’ve been set up to use pattrstorage!


The autopattr object functions as a hybrid of the pattr and pattrhub objects, allowing you to automatically bind multiple user interface objects to the pattr system in one easy step. The object allows you to automatically name objects for inclusion (through the autoname attribute), as well as explicitly include or exclude objects through the first two outlets, respectively. The pattrstorage object allows you to view the current settings of pattr-bound objects, as well as save states of settings into numerical slots (through the store message) and recall them (by sending an integer to the object). Furthermore, you can interpolate between preset slots, as well as save and recall your saved states in an easy-to-read XML format.

See Also

Name Description
autopattr Expose multiple objects to the pattr system
pattrstorage Save and recall pattr presets