Just one object in a patcher ?

Jan 7, 2011 at 5:19pm

Just one object in a patcher ?

Hello maxers,

I want to let the user create just ONE object from a class in a patcher …

void *flop_new (t_symbol *s, long argc, t_atom *argv)
t_flop *x = NULL ;

if (x = (t_flop *)object_alloc (flop_class))
	t_object *jp = NULL ;

	if (jp = (t_object *)gensym ("#P")->s_thing)
		  t_atomarray *optr = NULL ;

		  object_obex_lookup (jp, gensym ("toto"), (t_object **)&optr) ;

		  if (!optr)
				optr = atomarray_new (0, NULL) ;
				object_obex_store (jp, gensym ("toto"), (t_object *)optr) ;
				x->m_out = bangout ((t_object *)x) ;
				object_free (x) ;
				x = NULL ;

return x ;

1. Is there something best than my ugly atomarray i can store in the obex ?
2. Is there a best strategy ?


Jan 8, 2011 at 9:02am

IMHO, the simple way would be to declare a global variable to your object, and just play with it when you instantiate/free an instance.

Jan 8, 2011 at 3:24pm

Hello Emmanuel,

yes, probably …

But i want to avoid the user to create more than one instance of the class in the _same_ patcher, while it can be in another patcher. That’s not something very important ; just for fun / cosmetic ; i think i’ll just go across the jpatcher looking for classname.

Thanks for reply ;-)

Jan 8, 2011 at 6:13pm

Sorry I miss read. Then your code seems appropriate.

Jan 9, 2011 at 6:51am


I tried to store a NULL pointer in the Obex and it didn’t work well ; That’s why i used the empty atomarray ; I suppose i must store a valid object as it will be free with object_free ? But is it possible without this atomarray trick ?


You must be logged in to reply to this topic.