Max contains a preset object that has the ability to send preset messages to some or all of the objects (clients) in a Patcher window. More...

+ Collaboration diagram for Presets:

Functions

void preset_store (char *fmt,...)
 Give the preset object a general message to restore the current state of your object. More...
 
void preset_set (t_object *obj, t_atom_long val)
 Restore the state of your object with a set message. More...
 
void preset_int (t_object *x, t_atom_long n)
 Restore the state of your object with an int message. More...
 

Detailed Description

Max contains a preset object that has the ability to send preset messages to some or all of the objects (clients) in a Patcher window.

The preset message, sent when the user is storing a preset, is just a request for your object to tell the preset object how to restore your internal state to what it is now. Later, when the user executes a preset, the preset object will send you back the message you had previously said you wanted.

The dialog goes something like this:

The client object won’t know the difference between receiving int 34 from a preset object and receiving a 34 in its leftmost inlet.

It’s not mandatory for your object to respond to the preset message, but it is something that will make users happy. All Max user interface objects currently respond to preset messages. Note that if your object is not a user interface object and implements a preset method, the user will need to connect the outlet of the preset object to its leftmost inlet in order for it to be sent a preset message when the user stores a preset.

Here’s an example of using preset_store() that specifies that the object would like to receive a set message. We assume it has one field, myvalue, which it would like to save and restore.

void myobject_preset(myobject *x)
{
preset_store("ossl",x,ob_sym(x),gensym("set"),x->myvalue);
}

When this preset is executed, the object will receive a set message whose argument will be the value of myvalue. Note that the same thing can be accomplished more easily with preset_set() and preset_int().

Don’t pass more than 12 items to preset_store(). If you want to store a huge amount of data in a preset, use binbuf_insert().

The following example locates the Binbuf into which the preset data is being collected, then calls binbuf_insert() on a previously prepared array of Atoms. It assumes that the state of your object can be restored with a set message.

void myobject_preset(myObject *x)
{
void *preset_buf;// Binbuf that stores the preset
short atomCount; // number of atoms you’re storing
t_atom atomArray[SOMESIZE];// array of atoms to be stored
// 1. prepare the preset "header" information
atom_setobj(atomArray,x);
atom_setsym(atomArray+1,ob_sym(x));
atom_setsym(atomArray+2,gensym("set"));
// fill atomArray+3 with object's state here and set atomCount
// 2. find the Binbuf
preset_buf = gensym("_preset")->s_thing;
// 3. store the data
if (preset_buf) {
binbuf_insert(preset_buf,NIL,atomCount,atomArray);
}
}

Function Documentation

void preset_int ( t_object x,
t_atom_long  n 
)

Restore the state of your object with an int message.

This function causes an int message with the argument value to be sent to your object from the preset object when the user executes a preset. All of the existing user interface objects use the int message for restoring their state when a preset is executed.

Parameters
xYour object.
nCurrent value of your object.
void preset_set ( t_object obj,
t_atom_long  val 
)

Restore the state of your object with a set message.

This function causes a set message with the argument value to be sent to your object from the preset object when the user executes a preset.

Parameters
objYour object.
valCurrent value of your object.
void preset_store ( char *  fmt,
  ... 
)

Give the preset object a general message to restore the current state of your object.

This is a general preset function for use when your object's state cannot be restored with a simple int or set message. The example below shows the expected format for specifying what your current state is to a preset object. The first thing you supply is your object itself, followed by the symbol that is the name of your object's class (which you can retrieve from your object using the macro ob_sym, declared in ext_mess.h). Next, supply the symbol that specifies the message you want receive (a method for which had better be defined in your class), followed by the arguments to this message—the current values of your object's fields.

Parameters
fmtC string containing one or more letters corresponding to the types of each element of the message. s for Symbol, l for long, or f for float.
...Elements of the message used to restore the state of your object, passed directly to the function as Symbols, longs, or floats. See below for an example that conforms to what the preset object expects.
  Copyright © 2015, Cycling '74