Max 5 API Reference
00001 /** 00002 @file 00003 delay2 - an ITM-based delay 00004 00005 @ingroup examples 00006 */ 00007 00008 #include "ext.h" 00009 #include "ext_common.h" 00010 #include "ext_obex.h" 00011 #include "ext_time.h" 00012 #include "ext_itm.h" 00013 00014 typedef struct delay2 00015 { 00016 t_object d_obj; 00017 void *d_outlet; 00018 void *d_proxy; 00019 long d_inletnum; 00020 t_object *d_timeobj; 00021 void *d_outlet2; 00022 t_object *d_quantize; 00023 void *d_clock; 00024 } t_delay2; 00025 00026 void *delay2_new(t_symbol *s, long argc, t_atom *argv); 00027 void delay2_free(t_delay2 *x); 00028 void delay2_assist(t_delay2 *x, void *b, long m, long a, char *s); 00029 void delay2_inletinfo(t_delay2 *x, void *b, long a, char *t); 00030 void delay2_int(t_delay2 *x, long n); 00031 void delay2_float(t_delay2 *x, double f); 00032 void delay2_list(t_delay2 *x, t_symbol *s, long argc, t_atom *argv); 00033 void delay2_anything(t_delay2 *x, t_symbol *msg, long argc, t_atom *argv); 00034 void delay2_tick(t_delay2 *x); 00035 void delay2_bang(t_delay2 *x); 00036 void delay2_stop(t_delay2 *x); 00037 void delay2_clocktick(t_delay2 *x); 00038 00039 static t_class *s_delay2_class = NULL; 00040 00041 int main(void) 00042 { 00043 t_class *c = class_new( "delay2", (method)delay2_new, (method)delay2_free, sizeof(t_delay2), (method)0L, A_GIMME, 0); 00044 00045 class_addmethod(c, (method)delay2_bang, "bang", 0); 00046 class_addmethod(c, (method)delay2_stop, "stop", 0); 00047 class_addmethod(c, (method)delay2_int, "int", A_LONG, 0); 00048 class_addmethod(c, (method)delay2_float, "float", A_FLOAT, 0); 00049 class_addmethod(c, (method)delay2_list, "list", A_GIMME, 0); 00050 class_addmethod(c, (method)delay2_anything, "anything", A_GIMME, 0); 00051 00052 class_addmethod(c, (method)delay2_assist, "assist", A_CANT, 0); 00053 class_addmethod(c, (method)delay2_inletinfo, "inletinfo", A_CANT, 0); 00054 00055 class_time_addattr(c, "delaytime", "Delay Time", TIME_FLAGS_TICKSONLY | TIME_FLAGS_USECLOCK | TIME_FLAGS_TRANSPORT); 00056 class_time_addattr(c, "quantize", "Quantization", TIME_FLAGS_TICKSONLY); 00057 00058 class_register(CLASS_BOX, c); 00059 00060 s_delay2_class = c; 00061 return 0; 00062 } 00063 00064 // initial optional arg is delay time 00065 00066 void *delay2_new(t_symbol *s, long argc, t_atom *argv) 00067 { 00068 t_delay2 *x = (t_delay2 *)object_alloc(s_delay2_class); 00069 long attrstart = attr_args_offset(argc, argv); 00070 t_atom a; 00071 00072 x->d_inletnum = 0; 00073 x->d_proxy = proxy_new(x, 1, &x->d_inletnum); 00074 x->d_outlet2 = bangout(x); 00075 x->d_outlet = bangout(x); 00076 00077 x->d_timeobj = (t_object*) time_new((t_object *)x, gensym("delaytime"), (method)delay2_tick, TIME_FLAGS_TICKSONLY | TIME_FLAGS_USECLOCK); 00078 x->d_quantize = (t_object*) time_new((t_object *)x, gensym("quantize"), NULL, TIME_FLAGS_TICKSONLY); 00079 x->d_clock = clock_new((t_object *)x, (method)delay2_clocktick); 00080 00081 if (attrstart && argv) 00082 time_setvalue(x->d_timeobj, NULL, 1, argv); 00083 else { 00084 atom_setfloat(&a, 0.); 00085 time_setvalue(x->d_timeobj, NULL, 1, &a); 00086 } 00087 atom_setfloat(&a,0); 00088 time_setvalue(x->d_quantize, NULL, 1, &a); 00089 00090 attr_args_process(x, argc, argv); 00091 return x; 00092 } 00093 00094 00095 void delay2_free(t_delay2 *x) 00096 { 00097 freeobject(x->d_timeobj); 00098 freeobject(x->d_quantize); 00099 freeobject((t_object *) x->d_proxy); 00100 freeobject((t_object *)x->d_clock); 00101 } 00102 00103 void delay2_assist(t_delay2 *x, void *b, long m, long a, char *s) 00104 { 00105 if (m == ASSIST_INLET) { // Inlets 00106 switch (a) { 00107 case 0: sprintf(s, "bang Gets Delayed, stop Cancels"); break; 00108 case 1: sprintf(s, "Set Delay Time"); break; 00109 } 00110 } 00111 else { // Outlets 00112 switch (a) { 00113 case 0: sprintf(s, "Delayed bang"); break; 00114 case 1: sprintf(s, "Another Delayed bang"); break; 00115 } 00116 } 00117 } 00118 00119 void delay2_inletinfo(t_delay2 *x, void *b, long a, char *t) 00120 { 00121 if (a) 00122 *t = 1; 00123 } 00124 00125 void delay2_int(t_delay2 *x, long n) 00126 { 00127 delay2_float(x, n); 00128 } 00129 00130 void delay2_float(t_delay2 *x, double f) 00131 { 00132 t_atom a; 00133 00134 atom_setfloat(&a, f); 00135 time_setvalue(x->d_timeobj, NULL, 1, &a); 00136 00137 if (proxy_getinlet((t_object *)x) == 0) 00138 delay2_bang(x); 00139 } 00140 00141 void delay2_list(t_delay2 *x, t_symbol *s, long argc, t_atom *argv) 00142 { 00143 delay2_anything(x, NULL, argc, argv); 00144 } 00145 00146 void delay2_anything(t_delay2 *x, t_symbol *msg, long argc, t_atom *argv) 00147 { 00148 time_setvalue(x->d_timeobj, msg, argc, argv); 00149 00150 if (proxy_getinlet((t_object *)x) == 0) 00151 delay2_bang(x); 00152 } 00153 00154 void delay2_tick(t_delay2 *x) 00155 { 00156 outlet_bang(x->d_outlet); 00157 } 00158 00159 void delay2_bang(t_delay2 *x) 00160 { 00161 double ms, tix; 00162 00163 time_schedule(x->d_timeobj, x->d_quantize); 00164 00165 tix = time_getticks(x->d_timeobj); 00166 ms = itm_tickstoms(time_getitm(x->d_timeobj), tix); 00167 clock_fdelay(x->d_clock, ms); 00168 } 00169 00170 void delay2_clocktick(t_delay2 *x) 00171 { 00172 outlet_bang(x->d_outlet2); 00173 } 00174 00175 void delay2_stop(t_delay2 *x) 00176 { 00177 time_stop(x->d_timeobj); 00178 clock_unset(x->d_clock); 00179 } 00180 00181
Copyright © 2008, Cycling '74