### Visual Studio Project Setup for Max SDK Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_appendix_e.html Guidance for setting up Visual Studio projects for Max SDK development, particularly for x64 builds. It recommends creating new projects based on examples and performing find/replace operations for project renaming. ```bash 1. choose a relevant starting point, e.g., the "dummy" example project 2. copy it to the folder your old project was in, rename it 3. open it in a text editor such as "sublime text 2" 4. do a find/replace for all instances of the text "dummy" changing it to your object's name 5. open the Visual Studio project and build you can choose either "Win32" or "x64" from the platform drop-down menu in the IDE ``` -------------------------------- ### Initialize Max Class with setup() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__class__old.html The setup() function initializes your class by informing Max of its size, creation/destruction functions, and argument types. Pass NULL for the menufun parameter. ```c BEGIN_USING_C_LINKAGE void setup(t_messlist **_ident_, method _makefun_, method _freefun_, t_getbytes_size _size_, method _menufun_, short _type_, ...); ``` -------------------------------- ### Start File Watcher Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Starts the filewatcher to begin monitoring. Ensure you have initialized it using filewatcher_new() first. ```c filewatcher_start(); ``` -------------------------------- ### Write Matrix to JXF File Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_jxf.html Example demonstrating how to create a file, write a header and matrix data, and then update the header with the correct file size. Includes error handling and file closing. ```c if (err=path_createsysfile(filename, path, type, &fh)) { error("jit.matrix: could not create file %s",name->s_name); goto out; } if (jit_bin_write_header(fh,0)) { error("jit.matrix: could not write header %s", matrixName->s_name); sysfile_close(fh); goto out; } if (jit_bin_write_matrix(fh,pointerToMatrix)) { error("jit.matrix: could not write matrix %s", matrixName->s_name); sysfile_close(fh); goto out; } sysfile_getpos(fh, &position); sysfile_seteof(fh, position); if (jit_bin_write_header(fh,position)) { error("jit.matrix: could not write header %s", matrixName->s_name); sysfile_close(fh); goto out; } sysfile_close(fh); ``` -------------------------------- ### Example using binbuf_insert() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__presets.html An example showing how to use `binbuf_insert()` to store preset data, assuming the object's state can be restored with a 'set' message. This method is preferred for storing large amounts of data. ```APIDOC 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); } } ``` -------------------------------- ### Read Matrix from JXF File Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_jxf.html Example demonstrating how to open a file, read its header, and import matrix data using the Jitter binary API. Includes error handling and file closing. ```c if (!(err=path_opensysfile(filename, path, &fh, READ_PERM))) { //all is well } else { error("jit.matrix: can't open file %s",name->s_name); goto out; } if (jit_bin_read_header(fh,&version,&filesize)) { error("jit.matrix: improper file format %s",name->s_name); sysfile_close(fh); goto out; } if (jit_bin_read_matrix(fh,matrix)) { error("jit.matrix: improper file format %s",name->s_name); sysfile_close(fh); goto out; } sysfile_close(fh); ``` -------------------------------- ### Max Class Constructor with `max_jit_mop_setup_simple` Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopqs.html Constructor for a Max class that utilizes `max_jit_mop_setup_simple` for standard MOP wrapper setup. Handles object instantiation, MOP setup, and attribute argument processing. ```c void *max_jit_scalebias_new(t_symbol *s, long argc, t_atom *argv) { t_max_jit_scalebias *x; void *o; if (x = (t_max_jit_scalebias *) max_jit_obex_new( max_jit_scalebias_class, gensym("jit_scalebias"))) { // instantiate Jitter object if (o=jit_object_new(gensym("jit_scalebias"))) { // handle standard MOP max wrapper setup tasks max_jit_mop_setup_simple(x,o,argc,argv); // process attribute arguments max_jit_attr_args(x,argc,argv); } else { error("jit.scalebias: could not allocate object"); freeobject(x); } } return (x); } ``` -------------------------------- ### setup() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__class__old.html Initializes a Max class by informing Max of its size, creation/destruction functions, and argument types. ```APIDOC ## setup() ### Description Use the setup() function to initialize your class by informing Max of its size, the name of your functions that create and destroy instances, and the types of arguments passed to the instance creation function. ### Parameters - **ident** (t_messlist **) - Max class identifier. - **makefun** (method) - Function to create instances. - **freefun** (method) - Function to destroy instances. - **size** (t_getbytes_size) - Size of the object instance. - **menufun** (method) - Function for menu actions. - **type** (short) - Type of arguments for instance creation. - **...** - Additional arguments. ``` -------------------------------- ### setup() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__class__old.html Initializes a Max class by informing Max of its size, creation/destruction functions, and argument types. ```APIDOC ## setup() ### Description Use the setup() function to initialize your class by informing Max of its size, the name of your functions that create and destroy instances, and the types of arguments passed to the instance creation function. ### Parameters * **ident** (t_messlist **) - A global variable in your code that points to the initialized class. * **makefun** (method) - Your instance creation function. * **freefun** (method) - Your instance free function. * **size** (t_getbytes_size) - The size of your objects data structure in bytes. Usually you use the C sizeof operator here. * **menufun** (method) - No longer used. You should pass NULL for this parameter. * **type** (short) - The first of a list of arguments passed to makefun when an object is created. * **...** - Any additional arguments passed to makefun when an object is created. Together with the type parameter, this creates a standard Max type list as enumerated in e_max_atomtypes. The final argument of the type list should be a 0. ### See also Anatomy of a Max Object ``` -------------------------------- ### Declare UI Object with jit.gl.handle Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_ob3ddetails.html Use JIT_OB3D_DOES_UI flag and define an ob3d_ui method for user interface OB3D objects. The prototype should match this example from jit.gl.handle. ```c t_jit_err jit_gl_handle_ui(t_jit_gl_handle *x, t_line_3d *p_line, t_wind_mouse_info *p_mouse); ``` -------------------------------- ### Example of Sticky Methods Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__attr.html This example shows how to use CLASS_STICKY_METHOD to mark methods as undocumented and then clear this sticky attribute. ```c CLASS_STICKY_METHOD(c, "undocumented", 0, "1"); // add some methods here with class_addmethod() // the undocumented attribute for methods means that the ref-page // generator will ignore these methods. CLASS_STICKY_METHOD_CLEAR(c, "undocumented"); ``` -------------------------------- ### Example: Managing Buffer References Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__misc.html This example demonstrates how to use globalsymbol_reference and globalsymbol_dereference to manage references to a buffer~ object based on a symbol name. It ensures that old references are released when a new one is established. ```c // the struct of our object typedef struct _myobject { t_object obj; t_symbol *buffer_name; t_buffer *buffer_object; } t_myobject; void myobject_setbuffer(t_myobject *x, t_symbol *s, long argc, t_atom *argv) { if(s != x->buffer_name){ // Reference the buffer associated with the incoming name x->buffer_object = (t_buffer *)globalsymbol_reference((t_object *)x, s->s_name, "buffer~"); // If we were previously referencing another buffer, we should not longer reference it. globalsymbol_dereference((t_object *)x, x->buffer_name->s_name, "buffer~"); x->buffer_name = s; } } ``` -------------------------------- ### Example: Ensuring Exit with Multiple Control Paths Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__critical.html This example shows how to ensure `critical_exit()` is called even when returning from within the protected code block. ```APIDOC ```c critical_enter(0); for (p = head; p; p = p->next) { if (p->value == val) { critical_exit(0); return p; } } critical_exit(0); return NULL; ``` ``` -------------------------------- ### path_setdefault Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Install a path as the default search path. ```APIDOC ## path_setdefault ### Description Install a path as the default search path. ### Signature void path_setdefault(short path, short recursive) ``` -------------------------------- ### Write Surface Image Data to File Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jsurface.html Get surface data ready for manually writing to a file. The data will be allocated and filled, and must be freed using sysmem_freeptr(). A good example of this is to embed the surface as a PNG in a patcher file. ```c void jgraphics_write_image_surface_to_filedata(t_jsurface *surf, long fmt, void **data, long *size) ``` ```c long size = 0; void *data = NULL; jgraphics_write_image_surface_to_filedata(x->j_surface, JGRAPHICS_FILEFORMAT_PNG, &data, &size); if (size) { x->j_format = gensym("png"); binarydata_appendtodictionary(data, size, gensym("data"), x->j_format, d); x->j_imagedata = data; x->j_imagedatasize = size; } ``` -------------------------------- ### Detailed `max_jit_mop_setup_simple` Implementation Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopqs.html Provides a detailed breakdown of the `max_jit_mop_setup_simple` function, showing its internal calls for setting up MOP Max wrapper resources. ```c t_jit_err max_jit_mop_setup_simple(void *x, void *o, long argc, t_atom *argv) { max_jit_obex_jitob_set(x,o); max_jit_obex_dumpout_set(x,outlet_new(x,NULL)); max_jit_mop_setup(x); max_jit_mop_inputs(x); max_jit_mop_outputs(x); max_jit_mop_matrix_args(x,argc,argv); return JIT_ERR_NONE; } ``` -------------------------------- ### Custom Setter Method Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_objectmodel.html Example of a custom setter method for an attribute. ```APIDOC ## Custom Setter Method ### Description Defines a custom accessor method to set an attribute's value. ### Prototype `t_jit_err jit_foo_myval_set(t_jit_foo *x, void *attr, long ac, t_atom *av)` ### Parameters - **x** (t_jit_foo *) - Pointer to the Jitter object. - **attr** (void *) - The attribute object. - **ac** (long) - The count of atoms in the `av` array. - **av** (t_atom *) - An array of atoms containing the new value. ### Notes - If `ac` and `av` are provided, the attribute value is updated using `jit_atom_getfloat`. - If no arguments are provided (`ac` is 0 or `av` is NULL), the attribute is set to zero. - Returns `JIT_ERR_NONE` on success. ``` -------------------------------- ### Custom Getter Method Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_objectmodel.html Example of a custom getter method for an attribute. ```APIDOC ## Custom Getter Method ### Description Defines a custom accessor method to query an attribute's value. ### Prototype `t_jit_err jit_foo_myval_get(t_jit_foo *x, void *attr, long *ac, t_atom **av)` ### Parameters - **x** (t_jit_foo *) - Pointer to the Jitter object. - **attr** (void *) - The attribute object. - **ac** (long *) - Pointer to the count of atoms to be returned. - **av** (t_atom **) - Pointer to an array of atoms to store the attribute value. ### Notes - If `ac` and `av` are not provided (NULL), memory must be allocated for the atoms. - The `jit_atom_setfloat` function can be used to set the atom value. - Returns `JIT_ERR_NONE` on success or `JIT_ERR_OUT_OF_MEM` if memory allocation fails. ``` -------------------------------- ### max_jit_mop_setup_simple Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__maxmopmod.html Initializes default state and resources for MOP Max wrapper class. ```APIDOC ## max_jit_mop_setup_simple ### Description Initializes default state and resources for MOP Max wrapper class. ### Signature t_jit_err max_jit_mop_setup_simple (void *x, void *o, long argc, t_atom *argv) ``` -------------------------------- ### max_jit_mop_setup_simple Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__maxmopmod.html Initializes default state and resources for MOP Max wrapper class. ```APIDOC ## max_jit_mop_setup_simple() ### Description Initializes default state and resources for MOP Max wrapper class. ### Parameters - **_x** (void *) - Max object pointer - **_o_** (void *) - Jitter object pointer - **_argc_** (long) - argument count - **_argv_** (t_atom *) - argument vector ### Returns - **t_jit_err** - error code ### Example ```c max_jit_obex_jitob_set(x,o); max_jit_obex_dumpout_set(x,outlet_new(x,NULL)); max_jit_mop_setup(x); max_jit_mop_inputs(x); max_jit_mop_outputs(x); max_jit_mop_matrix_args(x,argc,argv); return JIT_ERR_NONE; ``` ``` -------------------------------- ### Example of Sticky Attributes Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__attr.html This example demonstrates using CLASS_STICKY_ATTR to group attributes under the 'category' and then clearing it. Other attributes like CLASS_ATTR_DOUBLE and CLASS_ATTR_CHAR are shown. ```c CLASS_STICKY_ATTR(c, "category", 0, "Foo"); CLASS_ATTR_DOUBLE(c, "bar", 0, t_myobject, x_bar); CLASS_ATTR_LABEL(c, "bar", 0, "A Bar"); CLASS_ATTR_CHAR(c, "switch", 0, t_myobject, x_switch); CLASS_ATTR_STYLE_LABEL(c, "switch", 0, "onoff", "Bar Switch"); CLASS_ATTR_DOUBLE(c, "flow", 0, t_myobject, x_flow); CLASS_ATTR_LABEL(c, "flow", 0, "Flow Amount"); CLASS_STICKY_ATTR_CLEAR(c, "category"); ``` -------------------------------- ### Create and Set a Qelem Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_scheduler.html In your new instance routine, create the qelem using qelem_new() and store the pointer. Then, set the qelem using qelem_set() to schedule its execution. ```c x->m_qelem = qelem_new((t_object *)x, (method)myobject_qtask); qelem_set(x->m_qelem); ``` -------------------------------- ### Custom Attribute Setter Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__attr.html Example of a custom setter function for an attribute. This function takes a t_atom structure and sets the attribute's value. ```APIDOC ## Writing a custom Attribute Setter If you need to define a custom accessor, it should have a prototype and form comparable to the following custom setter: t_max_err foo_myval_set(t_foo *x, void *attr, long ac, t_atom *av) { if (ac&&av) { x->myval = atom_getfloat(av); } else { // no args, set to zero x->myval = 0; } return MAX_ERR_NONE; } ### Helper Functions: - **atom_getfloat** `t_atom_float atom_getfloat(const t_atom *a)` Retrieves a floating point value from a t_atom. - **t_max_err** `t_atom_long t_max_err` An integer value suitable to be returned as an error code. - **MAX_ERR_NONE**: No error. ``` -------------------------------- ### Custom Attribute Getter Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__attr.html Example of a custom getter function for an attribute. This function retrieves the attribute's value and populates a t_atom structure. ```APIDOC ## Writing a custom Attribute Getter If you need to define a custom accessor, it should have a prototype and form comparable to the following custom getter: t_max_err foo_myval_get(t_foo *x, void *attr, long *ac, t_atom **av) { if ((*ac)&&(*av)) { //memory passed in, use it } else { //otherwise allocate memory *ac = 1; if (!(*av = getbytes(sizeof(t_atom)*(*ac)))) { *ac = 0; return MAX_ERR_OUT_OF_MEM; } } atom_setfloat(*av,x->myval); return MAX_ERR_NONE; } ### Helper Functions: - **atom_setfloat** `t_max_err atom_setfloat(t_atom *a, double b)` Inserts a floating point number into a t_atom and change the t_atom's type to A_FLOAT. - **getbytes** `char * getbytes(t_getbytes_size size)` Allocate small amounts of non-relocatable memory. - **t_max_err** `t_atom_long t_max_err` An integer value suitable to be returned as an error code. - **MAX_ERR_OUT_OF_MEM**: Out of memory. - **MAX_ERR_NONE**: No error. - **t_atom** An atom is a typed datum. ``` -------------------------------- ### max_jit_mop_setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__maxmopmod.html Sets up necessary resources for MOP Max wrapper object. ```APIDOC ## max_jit_mop_setup ### Description Sets up necessary resources for MOP Max wrapper object. ### Signature t_jit_err max_jit_mop_setup (void *x) ``` -------------------------------- ### max_jit_mop_setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__maxmopmod.html Sets up necessary resources for MOP Max wrapper object. ```APIDOC ## max_jit_mop_setup() ### Description Sets up necessary resources for MOP Max wrapper object. ### Parameters - **_x** (void *) - Max object pointer ### Returns - **t_jit_err** - error code ``` -------------------------------- ### Retrieve Long from Atom Argument with Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__atom.html Use atom_arg_getlong to retrieve an integer value as a t_atom_long from a t_atom. The example shows how to check if the value was successfully retrieved. ```c t_max_err atom_arg_getlong(t_atom_long *_c_, long _idx_, long _ac_, const t_atom *_av_) ``` ```c void myobject_mymessage(t_myobject *x, t_symbol *s, long ac, t_atom *av) { t_atom_long var = -1; // here, we are expecting a value of 0 or greater atom_arg_getlong(&var, 0, ac, av); if (val == -1) // i.e. unchanged post("it is likely that the user did not provide a valid argument"); else { ... } } ``` -------------------------------- ### Initialize MSP Object with DSP Setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_msp_anatomy.html Call dsp_setup() in the new instance routine, passing the object pointer and the number of signal inlets. This function automatically creates signal inlets as proxies. ```c dsp_setup((t_pxobject *)x, 1); ``` -------------------------------- ### Custom Setter Method Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_objectmodel.html Example of a custom setter method for a Jitter attribute. It retrieves a floating-point value from the atom and updates the object's internal state. ```c t_jit_err jit_foo_myval_set(t_jit_foo *x, void *attr, long ac, t_atom *av) { if (ac&&av) { x->myval = jit_atom_getfloat(av); } else { // no args, set to zero x->myval = 0; } return JIT_ERR_NONE; } ``` -------------------------------- ### Create, Store, Lookup, and Delete Hashtab Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__hashtab.html This example demonstrates the basic workflow of using a hash table: creating it, storing a value with a symbol key, looking up that value, and finally freeing the hash table. Ensure keys are unique symbols for optimal performance. ```c t_hashtab *tab = (t_hashtab *)hashtab_new(0); long result, value; hashtab_store(tab, gensym("a great number"), (t_object *)74); result = hashtab_lookup(tab, gensym("a great number"), (t_object **)value); if (!result) post("found the value and it is %ld",value); else post("did not find the value"); hashtab_chuck(tab); post ``` -------------------------------- ### Custom Getter Method Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_objectmodel.html Example of a custom getter method for a Jitter attribute. It handles memory allocation if needed and sets the atom value using jit_atom_setfloat. ```c t_jit_err jit_foo_myval_get(t_jit_foo *x, void *attr, long *ac, t_atom **av) { if ((*ac)&&(*av)) { //memory passed in, use it } else { //otherwise allocate memory *ac = 1; if (!(*av = jit_getbytes(sizeof(t_atom)*(*ac)))) { *ac = 0; return JIT_ERR_OUT_OF_MEM; } } jit_atom_setfloat(*av,x->myval); return JIT_ERR_NONE; } ``` -------------------------------- ### Setup OB3D Max Wrapper Class Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_ob3ddetails.html To define a standard OB3D Max wrapper class, include calls to max_ob3d_setup() for drawing methods and max_jit_ob3d_assist() for the assist method, unless a custom assist method is required. ```c max_ob3d_setup(); max_jit_ob3d_assist(); ``` -------------------------------- ### Example: Protecting Linked List Traversal Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__critical.html This example demonstrates how to protect a linked list traversal using `critical_enter()` and `critical_exit()` to prevent race conditions with other threads modifying the list. ```APIDOC ```c critical_enter(0); for (p = head; p; p = p->next) { if (p->value == val) break; } critical_exit(0); return p; ``` ``` -------------------------------- ### z_dsp_setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__msp.html Initializes MSP object fields and allocates necessary proxies. This routine should be called after object creation using object_alloc() and before creating non-signal inlets. ```APIDOC ## z_dsp_setup() ### Description Call this routine after creating your object in the new instance routine with object_alloc(). Cast your object to t_pxobject as the first argument, then specify the number of signal inputs your object will have. dsp_setup() initializes fields of the t_pxobject header and allocates any proxies needed (if num_signal_inputs is greater than 1). Some signal objects have no inputs; you should pass 0 for num_signal_inputs in this case. After calling dsp_setup(), you can create additional non-signal inlets using intin(), floatin(), or inlet_new(). ### Parameters - **x** (t_pxobject *) - Your object's pointer. - **nsignals** (long) - The number of signal/proxy inlets to create for the object. ### See also - dsp_setup ``` -------------------------------- ### Clock Task Function Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_scheduler.html Write a task function that accepts a pointer to your object and performs an action when the clock is executed. This example retrieves and posts the current scheduler time. ```c void myobject_task(t_myobject *x) { double time; sched_getftime(&time); post("instance %lx is executing at time %.2f", x, time); } ``` -------------------------------- ### Create and Configure jit_mop Instance Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopqs.html Instantiate a `jit_mop` object with specified inputs and outputs, then enforce single type and plane count for all inputs and outputs. ```c // create a new instance of jit_mop with 1 input, and 1 output mop = jit_object_new(_jit_sym_jit_mop,1,1); // enforce a single type for all inputs and outputs jit_mop_single_type(mop,_jit_sym_char); // enforce a single plane count for all inputs and outputs jit_mop_single_planecount(mop,4); // add the jit_mop object as an adornment to the class jit_class_addadornment(_jit_scalebias_class,mop); ``` -------------------------------- ### Max JIT MOP Outputs Setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopdetails.html Creates output resources for a MOP Max wrapper object, including outlets and internal matrices. It iterates through outputs, creates matrix outlets, and sets up internal matrices with unique names. ```c t_jit_err max_jit_mop_outputs(void *x) { void *mop,*p,*m; long i,outcount; t_jit_matrix_info info; t_symbol *name; if (x&&(mop=max_jit_obex_adornment_get(x,_jit_sym_jit_mop))) { outcount = jit_attr_getlong(mop,_jit_sym_outputcount); // add outlet and internal matrix for all outputs for (i=1;i<=outcount;i++) { max_jit_mop_matrixout_new(x,(outcount)-i);// right to left if (p=jit_object_method(mop,_jit_sym_getoutput,i)) { jit_matrix_info_default(&info); max_jit_mop_restrict_info(x,p,&info); name = jit_symbol_unique(); m = jit_object_new(_jit_sym_jit_matrix,&info); m = jit_object_register(m,name); jit_attr_setsym(p,_jit_sym_matrixname,name); jit_object_method(p,_jit_sym_matrix,m); jit_object_attach(name, x); } } return JIT_ERR_NONE; } return JIT_ERR_INVALID_PTR; } ``` -------------------------------- ### max_jit_classex_setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__maxwrapmod.html Allocates and initializes special t_max_jit_classex data used by the Max wrapper class. ```APIDOC ## max_jit_classex_setup() ### Description Allocates and initializes special t_max_jit_classex data, used by the Max wrapper class. ### Parameters - **oboffset** (long) - object struct byte offset to obex pointer ### Returns - (void *) - pointer to t_max_jit_classex data (opaque) ``` -------------------------------- ### jgraphics_reference Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jgraphics.html Get a reference to a graphics context. ```APIDOC ## jgraphics_reference ### Description Get a reference to a graphics context. ### Signature t_jgraphics * jgraphics_reference(t_jgraphics *g) ``` -------------------------------- ### Max JIT MOP Inputs Setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopdetails.html Defines necessary proxy inlets and internal matrices for MOP inputs, excluding the leftmost inlet. It iterates through inputs, creates proxy inlets, and sets up internal matrices with unique names. ```c t_jit_err max_jit_mop_inputs(void *x) { void *mop,*p,*m; long i,incount; t_jit_matrix_info info; t_symbol *name; // look up object's MOP adornment if (x&&(mop=max_jit_obex_adornment_get(x,_jit_sym_jit_mop))) { incount = jit_attr_getlong(mop,_jit_sym_inputcount); // add proxy inlet and internal matrix for // all inputs except leftmost inlet for (i=2;i<=incount;i++) { max_jit_obex_proxy_new(x,(incount+1)-i); // right to left if (p=jit_object_method(mop,_jit_sym_getinput,i)) { jit_matrix_info_default(&info); max_jit_mop_restrict_info(x,p,&info); name = jit_symbol_unique(); m = jit_object_new(_jit_sym_jit_matrix,&info); m = jit_object_register(m,name); jit_attr_setsym(p,_jit_sym_matrixname,name); jit_object_method(p,_jit_sym_matrix,m); jit_object_attach(name, x); } } return JIT_ERR_NONE; } return JIT_ERR_INVALID_PTR; } ``` -------------------------------- ### Include Basic Max API Headers Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_anatomy.html Include ext.h and ext_obex.h for basic Max API functionality. These should typically be included first. ```c #include "ext.h" // should always be first, followed by ext_obex.h and any other files. ``` -------------------------------- ### jpatchline_get_color Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatchline.html Get the color of a patch line. ```APIDOC ## jpatchline_get_color ### Description Get the color of a patch line. ### Method `t_max_err jpatchline_get_color (t_object *l, t_jrgba *prgba)` ### Parameters - **l** (t_object *) - A pointer to the patchline's instance. - **prgba** (t_jrgba *) - Pointer to a t_jrgba structure to store the color. ### Returns - **t_max_err** - Error code indicating success or failure. ``` -------------------------------- ### Qelem Task Function Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_scheduler.html Write a task function that accepts a pointer to your object. This function will be executed when the qelem is serviced by the low-priority queue. ```c void myobject_qtask(t_myobject *x) { post("I am being executed a low priority!" } ``` -------------------------------- ### C++ Class Definitions for Doxygen Graph Example Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/graph_legend.html These C++ class definitions are used as an example to demonstrate how doxygen generates inheritance and usage graphs. They showcase various inheritance types (public, protected, private) and template usage. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### path_closefolder() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Completes a directory iteration started by path_openfolder(). ```APIDOC ## path_closefolder() ### Description Complete a directory iteration. ### Parameters - **x** (void *) - The "folder state" value originally returned by path_openfolder(). ``` -------------------------------- ### db_open_ext() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__database.html Opens or creates a database instance with extended options, including flags for controlling the opening behavior. ```APIDOC ## db_open_ext() ### Description Create an instance of a database. ### Method `db_open_ext(t_symbol *_dbname_, const char *_fullpath_, t_database **_db_, long _flags_)` ### Parameters #### Path Parameters - **dbname** (t_symbol *) - The name of the database. - **fullpath** (const char *) - If a database with this dbname is not already open, this will specify a full path to the location where the database is stored on disk. If NULL is passed for this argument, the database will reside in memory only. The path should be formatted as a Max style path. - **db** (t_database **) - The address of a t_database pointer that will be set to point to the new database instance. If the pointer is not NULL, then it will be treated as a pre-existing database instance and thus will be freed. - **flags** (long) - Any flags to be passed to the database backend while opening the db. At this time, DB_OPEN_FLAGS_READONLY (0x01) is the only flag available. ### Returns - An error code. ``` -------------------------------- ### ext_main - Initialization Routine Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_anatomy.html The entry point for a Max external object. This function is called when the object is loaded and is responsible for defining and registering the object's class. ```APIDOC ## ext_main ### Description This function is the entry point for an extern to be loaded. All externs must implement this shared function. It is called when Max loads your object for the first time, and it's where you define one or more classes for your object. ### Signature ```c void ext_main(void *r) ``` ### Usage Example ```c static t_class *s_simp_class; // global pointer to our class definition that is setup in ext_main() void ext_main(void *r) { t_class *c; c = class_new("simp", (method)simp_new, (method)NULL, sizeof(t_simp), 0L, 0); class_addmethod(c, (method)simp_int, "int", A_LONG, 0); class_addmethod(c, (method)simp_bang, "bang", 0); class_register(CLASS_BOX, c); s_simp_class = c; } ``` ``` -------------------------------- ### path_foldernextfile Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Get the next file in the directory during iteration. ```APIDOC ## path_foldernextfile ### Description Get the next file in the directory during iteration. ### Signature short path_foldernextfile(void *xx, t_fourcc *filetype, char *name, short descend) ``` -------------------------------- ### Instantiate and Add jit_mop Object Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_mopdetails.html Example of creating a `jit_mop` instance with specified inputs and outputs, and adding it as an adornment to a Jitter class. This is a required step for defining MOPs. ```c // create a new instance of jit_mop with 1 input, and 1 output mop = jit_object_new(_jit_sym_jit_mop,1,1); // add jit_mop object as an adornment to the class jit_class_addadornment(_jit_your_class,mop); ``` -------------------------------- ### jpatcher_get_firstview Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatcher.html Get the first view for a given patcher. ```APIDOC ## jpatcher_get_firstview ### Description Get the first view (jpatcherview) for a given patcher. ### Signature t_object * jpatcher_get_firstview (t_object *p) ### Parameters * **p** (t_object *) - A pointer to the patcher object. ### Return Value A pointer to the first jpatcherview associated with the patcher, or NULL if none exists. ``` -------------------------------- ### jpatcher_get_firstline Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatcher.html Get the first line (patch-cord) in a patcher. ```APIDOC ## jpatcher_get_firstline ### Description Get the first line (patch-cord) in a patcher. ### Signature t_object * jpatcher_get_firstline (t_object *p) ### Parameters * **p** (t_object *) - A pointer to the patcher object. ### Return Value A pointer to the first line object in the patcher, or NULL if there are no lines. ``` -------------------------------- ### Initializing and Opening a Text Editor Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_enhancements.html Initialize the editor pointer to NULL and implement the dblclick method to either create a new 'jed' object or bring an existing one to the front. ```c if (!x->m_editor) x->m_editor = object_new(CLASS_NOBOX, gensym("jed"), (t_object *)x, 0); else object_attr_setchar(x->m_editor, gensym("visible"), 1); ``` -------------------------------- ### jpatcher_get_lastobject Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatcher.html Get the last box within a patcher. ```APIDOC ## jpatcher_get_lastobject ### Description Get the last box in a patcher. ### Signature t_object * jpatcher_get_lastobject (t_object *p) ### Parameters * **p** (t_object *) - A pointer to the patcher object. ### Return Value A pointer to the last t_jbox object in the patcher, or NULL if the patcher is empty. ``` -------------------------------- ### jbox_start_layer Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__boxlayer.html Creates a layer and prepares it for drawing commands. Subsequent calls to jbox_start_layer for the same layer will return NULL. ```APIDOC ## ◆ jbox_start_layer() t_jgraphics* jbox_start_layer | ( | t_object * | _b_ , ---|---|---|--- | | t_object * | _view_ , | | t_symbol * | _name_ , | | double | _width_ , | | double | _height_ | ) | | Create a layer, and ready it for drawing commands. The layer drawing commands must be wrapped with a matching call to jbox_end_layer() prior to calling jbox_paint_layer(). Parameters b| The object/box to which the layer is attached. ---|--- view| The patcherview for the object to which the layer is attached. name| A name for this layer. width| The width of the layer. height| The height of the layer. Returns A t_jgraphics context for drawing into the layer. ``` -------------------------------- ### ext_main() Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__class.html The entry point for an extern to be loaded. All externs must implement this shared/common prototype to ensure correct export on all platforms. ```APIDOC ## ext_main() ### Description `ext_main()` is the entry point for an extern to be loaded, which all externs must implement this shared/common prototype ensures that it will be exported correctly on all platforms. ### Parameters * **r** (void *) - Pointer to resources for the external, if applicable. ### See also * Anatomy of a Max Object ### Version * Introduced in Max 6.1.9 ``` -------------------------------- ### jpatcher_get_firstobject Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatcher.html Get the first box within a patcher. ```APIDOC ## jpatcher_get_firstobject ### Description Get the first box in a patcher. ### Signature t_object * jpatcher_get_firstobject (t_object *p) ### Parameters * **p** (t_object *) - A pointer to the patcher object. ### Return Value A pointer to the first t_jbox object in the patcher, or NULL if the patcher is empty. ``` -------------------------------- ### Create and Initialize New Binbuf Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__binbuf.html Use binbuf_new to create and initialize a new Binbuf. Returns a pointer to the new binbuf or NULL if unsuccessful. ```c void* binbuf_new(void) ``` -------------------------------- ### jgraphics_copy_path Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jgraphics.html Get a copy of the current path from a context. ```APIDOC ## jgraphics_copy_path ### Description Get a copy of the current path from a context. ### Signature t_jpath * jgraphics_copy_path(t_jgraphics *g) ``` -------------------------------- ### path_openfolder Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Prepares a directory for iteration. ```APIDOC ## path_openfolder() ### Description Prepare a directory for iteration. ### Parameters * **path** (short) - The directory Path ID to open. ### Returns The return value of this routine is an internal "folder state" structure used for further folder manipulation. It should be saved and used for calls to path_foldernextfile() and path_closefolder(). If the folder cannot be found or accessed, path_openfolder() returns 0. ``` -------------------------------- ### hashtab_getflags Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__hashtab.html Gets the hashtab's datastore flags. ```APIDOC ## hashtab_getflags ### Description Get the hashtab's datastore flags. ### Signature t_atom_long hashtab_getflags (t_hashtab *x) ``` -------------------------------- ### patcherview_get_rect Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatcherview.html Get the value of the rect attribute for a patcherview. ```APIDOC ## patcherview_get_rect ### Description Get the value of the rect attribute for a patcherview. ### Method `t_max_err patcherview_get_rect (t_object *pv, t_rect *pr)` ### Parameters #### Path Parameters - **pv** (t_object *) - A pointer to the patcherview object. - **pr** (t_rect *) - A pointer to a t_rect structure to store the rectangle information. ### Return Value `t_max_err` indicating success or failure. ``` -------------------------------- ### OB3D Max Wrapper Class Setup Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_jit_ob3dqs.html Defines the entry point for an OB3D Max extern, initializing Jitter and Max classes, wrapping the Jitter class, and adding standard OB3D methods. ```c void ext_main(void *r) { void *classex, *jitclass; // initialize Jitter class jit_gl_simple_init(); // create Max class setup((t_messlist **)&max_jit_gl_simple_class, (method)max_jit_gl_simple_new, (method)max_jit_gl_simple_free, (short)sizeof(t_max_jit_gl_simple), 0L, A_GIMME, 0); // specify a byte offset to keep additional information about our object classex = max_jit_classex_setup(calcoffset(t_max_jit_gl_simple, obex)); // look up Jitter class in the class registry jitclass = jit_class_findbyname(gensym("jit_gl_simple")); // wrap Jitter class with the standard methods for Jitter objects max_jit_classex_standard_wrap(classex, jitclass, 0); // use standard ob3d assist method addmess((method)max_jit_ob3d_assist, "assist", A_CANT,0); // add methods for 3d drawing max_ob3d_setup(); } ``` -------------------------------- ### path_openfolder Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Prepare a directory for iteration. ```APIDOC ## path_openfolder ### Description Prepare a directory for iteration. ### Signature void * path_openfolder(short path) ``` -------------------------------- ### path_setdefault Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__files.html Installs a path as the default search path. ```APIDOC ## path_setdefault() ### Description Install a path as the default search path. The default path is searched before the Max search path. For instance, when loading a patcher from a directory outside the search path, the patcher's directory is searched for files before the search path. path_setdefault() allows you to set a path as the default. ### Parameters * **path** (short) - The path to use as the search path. If path is already part of the Max Search path, it will not be added (since, by default, it will be searched during file searches). * **recursive** (short) - If non-zero, all subdirectories will be installed in the default search list. Be very careful with the use of the recursive argument. It has the capacity to slow down file searches dramatically as the list of folders is being built. Max itself never creates a hierarchical default search path. ``` -------------------------------- ### Initialize Max External Object Class Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_anatomy.html The ext_main function is the entry point for Max to load your external. It defines the object's class, registers methods, and registers the class in a namespace. Use this for the primary setup of your object. ```c static t_class *s_simp_class; // global pointer to our class definition that is setup in ext_main() void ext_main(void *r) { t_class *c; c = class_new("simp", (method)simp_new, (method)NULL, sizeof(t_simp), 0L, 0); class_addmethod(c, (method)simp_int, "int", A_LONG, 0); class_addmethod(c, (method)simp_bang, "bang", 0); class_register(CLASS_BOX, c); s_simp_class = c; } ``` -------------------------------- ### jpatchline_get_startpoint Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatchline.html Retrieves the starting coordinates (x, y) of a patch line. ```APIDOC ## jpatchline_get_startpoint() ### Description Retrieve a patchline's starting point. ### Parameters - **l** (t_object *) - A pointer to the patchline's instance. - **x** (double *) - The address of a variable to hold the x-coordinate of the starting point's position upon return. - **y** (double *) - The address of a variable to hold the y-coordinate of the starting point's position upon return. ### Returns - A Max error code. ``` -------------------------------- ### jpatchline_get_startpoint Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jpatchline.html Retrieve a patchline's starting point coordinates. ```APIDOC ## jpatchline_get_startpoint ### Description Retrieve a patchline's starting point. ### Method `t_max_err jpatchline_get_startpoint (t_object *l, double *x, double *y)` ### Parameters - **l** (t_object *) - A pointer to the patchline's instance. - **x** (double *) - Pointer to store the x-coordinate. - **y** (double *) - Pointer to store the y-coordinate. ### Returns - **t_max_err** - Error code indicating success or failure. ``` -------------------------------- ### Construct MOP I/O Instance with Copy Settings Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__mopmod.html Constructs a new t_jit_mop_io instance, copying the settings from an existing one. This function is not exported and is intended for internal use or direct method calls. ```c t_jit_object * jit_mop_io_newcopy | ( | t_jit_mop_io * | _x_| ) | ``` -------------------------------- ### Get Object Class Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__obj.html Determines the class of a given object. ```APIDOC ## object_class ### Description Determines the class of a given object. ### Signature t_class * object_class (void *x) ### Parameters - **x** (void *) - Pointer to the object. ``` -------------------------------- ### jgraphics_get_current_point Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/group__jgraphics.html Get the current location of the cursor in a graphics context. ```APIDOC ## jgraphics_get_current_point ### Description Get the current location of the cursor in a graphics context. ### Signature void jgraphics_get_current_point(t_jgraphics *g, double *x, double *y) ``` -------------------------------- ### Create and Schedule a Clock Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_scheduler.html In your new instance routine, create a clock by passing a pointer to your object and the task function. Then, schedule the clock using clock_fdelay() to execute after a specified delay. ```c x->m_clock = clock_new((t_object *)x, (method)myobject_task); clock_fdelay(x->m_clock, 100.); ``` -------------------------------- ### MSP Class Initialization with dsp_free Source: https://sdk.cdn.cycling74.com/max-sdk-8.2.0/chapter_msp_anatomy.html When creating a class with class_new(), use dsp_free() as the free function for MSP objects. Ensure it's called first in any custom free function. ```c c = class_new("mydspobject", (method)mydspobject_new, (method)dsp_free, sizeof(t_mydspobject), NULL, 0); ```