github.com/256dpi/max-go@v0.7.0/lib/max/ext_globalsymbol.h (about)

     1  #ifndef __EXT_GLOBALSYMBOL_H__
     2  #define __EXT_GLOBALSYMBOL_H__
     3  
     4  #include "ext_prefix.h"
     5  #include "ext_mess.h"
     6  
     7  BEGIN_USING_C_LINKAGE
     8  
     9  /**	Get a reference to an object that is bound to a #t_symbol.
    10  	@ingroup misc
    11  	@param	x			The object that is getting the reference to the symbol.
    12  	@param	name		The name of the symbol to reference.
    13  	@param	classname	The name of the class of which the object we are referencing should be an instance.
    14  	@return				The s_thing of the #t_symbol.
    15  	
    16  	@remark				An example of real-world use is to get the buffer~ object associated with a symbol.
    17  	@code
    18  	// the struct of our object
    19  	typedef struct _myobject {
    20  		t_object	obj;
    21  		t_symbol	*buffer_name;
    22  		t_buffer	*buffer_object;
    23  	} t_myobject;
    24  	
    25  	void myobject_setbuffer(t_myobject *x, t_symbol *s, long argc, t_atom *argv)
    26  	{		
    27  		if(s != x->buffer_name){
    28  			// Reference the buffer associated with the incoming name
    29  			x->buffer_object = (t_buffer *)globalsymbol_reference((t_object *)x, s->s_name, "buffer~");
    30  			
    31  			// If we were previously referencing another buffer, we should not longer reference it.
    32  			globalsymbol_dereference((t_object *)x, x->buffer_name->s_name, "buffer~");
    33  			
    34  			x->buffer_name = s;
    35  		}		
    36  	}
    37  	@endcode
    38  */
    39  void *globalsymbol_reference(t_object *x, C74_CONST char *name, C74_CONST char *classname);
    40  
    41  
    42  /**	Stop referencing an object that is bound to a #t_symbol, previously referenced using globalsymbol_reference().
    43  	@ingroup misc
    44  	@param	x			The object that is getting the reference to the symbol.
    45  	@param	name		The name of the symbol to reference.
    46  	@param	classname	The name of the class of which the object we are referencing should be an instance.
    47  	@see	globalsymbol_reference()
    48  */
    49  void globalsymbol_dereference(t_object *x, C74_CONST char *name, C74_CONST char *classname);
    50  
    51  
    52  /**	Bind an object to a #t_symbol.
    53  	@ingroup misc
    54  	@param	x		The object to bind to the #t_symbol.
    55  	@param	name	The name of the #t_symbol to which the object will be bound.
    56  	@param	flags	Pass 0.
    57  	@return		A Max error code.
    58  */
    59  t_max_err globalsymbol_bind(t_object *x, C74_CONST char *name, long flags);
    60  
    61  
    62  /** Remove an object from being bound to a #t_symbol.
    63  	@ingroup misc
    64  	@param	x		The object from which to unbind the #t_symbol.
    65  	@param	name	The name of the #t_symbol from which the object will be unbound.
    66  	@param	flags	Pass 0.
    67  */
    68  void globalsymbol_unbind(t_object *x, C74_CONST char *name, long flags);
    69  
    70  
    71  // private
    72  void globalsymbol_notify(t_object *x, C74_CONST char *name, t_symbol *msg, void *data);
    73  
    74  
    75  END_USING_C_LINKAGE
    76  
    77  #endif // __EXT_GLOBALSYMBOL_H__
    78