Max 5 API Reference
00001 /** 00002 @file 00003 jit.simple - simple example of a Jitter external 00004 multiplies an incoming matrix by a constant 00005 00006 @ingroup examples 00007 00008 Copyright 2009 - Cycling '74 00009 Timothy Place, tim@cycling74.com 00010 */ 00011 00012 #include "jit.common.h" 00013 #include "max.jit.mop.h" 00014 #include "z_dsp.h" 00015 #include "ext_obex.h" 00016 00017 00018 // Max object instance data 00019 // Note: most instance data is in the Jitter object which we will wrap 00020 typedef struct _max_jit_simple { 00021 t_pxobject ob; 00022 void *obex; 00023 t_object *simple; 00024 } t_max_jit_simple; 00025 00026 00027 // prototypes 00028 BEGIN_USING_C_LINKAGE 00029 t_jit_err jit_simple_init(void); 00030 void *max_jit_simple_new(t_symbol *s, long argc, t_atom *argv); 00031 void max_jit_simple_free(t_max_jit_simple *x); 00032 t_int *max_jit_simple_perform(t_int *w); 00033 void max_jit_simple_dsp(t_max_jit_simple *x, t_signal **sp, short *count); 00034 END_USING_C_LINKAGE 00035 00036 // globals 00037 static void *s_max_jit_simple_class = NULL; 00038 static t_symbol *ps_gain = NULL; 00039 00040 00041 /************************************************************************************/ 00042 00043 int main(void) 00044 { 00045 void *p, *q; 00046 00047 jit_simple_init(); 00048 setup((t_messlist**)&s_max_jit_simple_class, (method)max_jit_simple_new, (method)max_jit_simple_free, sizeof(t_max_jit_simple), 0, A_GIMME, 0); 00049 00050 p = max_jit_classex_setup(calcoffset(t_max_jit_simple, obex)); 00051 q = jit_class_findbyname(gensym("jit_simple~")); 00052 max_jit_classex_mop_wrap(p, q, 0); // attrs & methods for name, type, dim, planecount, bang, outputmatrix, etc 00053 max_jit_classex_standard_wrap(p, q, 0); // attrs & methods for getattributes, dumpout, maxjitclassaddmethods, etc 00054 addmess((method)max_jit_mop_assist, "assist", A_CANT, 0); // standard matrix-operator (mop) assist fn 00055 00056 addmess((method)max_jit_simple_dsp, "dsp", A_CANT, 0); 00057 dsp_initclass(); 00058 00059 ps_gain = gensym("gain"); 00060 return 0; 00061 } 00062 00063 00064 /************************************************************************************/ 00065 // Object Life Cycle 00066 00067 void *max_jit_simple_new(t_symbol *s, long argc, t_atom *argv) 00068 { 00069 t_max_jit_simple *x; 00070 00071 x = (t_max_jit_simple*)max_jit_obex_new(s_max_jit_simple_class, gensym("jit_simple~")); 00072 if (x) { 00073 x->simple = (t_object*)jit_object_new(gensym("jit_simple~")); 00074 if (x->simple) { 00075 max_jit_mop_setup_simple(x, x->simple, argc, argv); 00076 max_jit_attr_args(x, argc, argv); 00077 } 00078 else { 00079 jit_object_error((t_object*)x, "jit.simple~: could not allocate object"); 00080 freeobject((t_object*)x); 00081 x = NULL; 00082 } 00083 dsp_setup((t_pxobject*)x, 1); 00084 } 00085 return (x); 00086 } 00087 00088 00089 void max_jit_simple_free(t_max_jit_simple *x) 00090 { 00091 dsp_free((t_pxobject*)x); 00092 max_jit_mop_free(x); 00093 jit_object_free(max_jit_obex_jitob_get(x)); 00094 max_jit_obex_free(x); 00095 } 00096 00097 00098 t_int *max_jit_simple_perform(t_int *w) 00099 { 00100 t_max_jit_simple *x = (t_max_jit_simple*)(w[1]); 00101 float *in = (float*)w[2]; 00102 long n = (int)(w[3]); 00103 00104 if (x->ob.z_disabled) 00105 goto out; 00106 00107 while (n--) { 00108 object_method_float(x->simple, ps_gain, *in++, NULL); 00109 } 00110 out: 00111 return w+4; 00112 } 00113 00114 00115 void max_jit_simple_dsp(t_max_jit_simple *x, t_signal **sp, short *count) 00116 { 00117 dsp_add(max_jit_simple_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); 00118 }
Copyright © 2008, Cycling '74