Max5 GUI - psave

Toshiro Yamada's icon

I'm writing a gui object and trying to save the state of object in the clipboard (by copying the object) or in the maxpat file. (i.e. points of function object is saved when copied, duplicated, and save in a file.) I found that this can be implemented using psave and pstate in Max 4, but I read in this forum that psave is implemented differently in Max 5. I couldn't find any resource that shows how to do it in Max 5 and was wondering if anyone can point me to the right direction. I also tried putting psave shown in Writing External Objects for Max 4.0 and MSP 2.0 document, but I had no luck.

I'm new to max external development and I'd much appreciate your help!

Thanks,
Toshiro

Emmanuel Jourdan's icon

On 14 janv. 09, at 00:22, Toshiro Yamada wrote:

> I'm writing a gui object and trying to save the state of object in
> the clipboard (by copying the object) or in the maxpat file. (i.e.
> points of function object is saved when copied, duplicated, and save
> in a file.) I found that this can be implemented using psave and
> pstate in Max 4, but I read in this forum that psave is implemented
> differently in Max 5. I couldn't find any resource that shows how to
> do it in Max 5 and was wondering if anyone can point me to the right
> direction. I also tried putting psave shown in Writing External
> Objects for Max 4.0 and MSP 2.0 document, but I had no luck.
>
> I'm new to max external development and I'd much appreciate your help!

you just need to add a save function. The save function receive a
pointer to the object dictionary, and you just have to add things to
the dictionary. The save function will be automatically called when
needed (copy, save).

in your class initialization method:

    class_addmethod(c, (method)yourobject_jsave, "jsave", A_CANT, 0);

and then:

void yourobject_save(t_yourobject *x, t_object *bd)
{
    t_atom a[2];

    if (x && bd) {
        atom_setlong(&a[0], 1);
        atom_setlong(&a[1], 2);
        dictionary_appendatoms((t_dictionary *)bd, gensym("toto"), 1,
&a);        // add an atom array
        dictionary_appendlong((t_dictionary *)bd, gensym("titi"), 74);            //
add a simple int
    }
}

Note that attribute declared with the SAVE macro are automatically
saved for you and you don't have to declare any save method for them.

HTH,
ej

Toshiro Yamada's icon

Thanks Emmanuel! This is exactly what I was looking for.

Best,
Toshiro