00001
00002
00003
00004
00005
00007
00009
00010
00011 #ifndef __OMax_state2date_MAX_API_
00012 #define __OMax_state2date_MAX_API_
00013
00014 #include "Oracle_data.hpp"
00015
00016 extern "C"
00017 {
00018
00019 #include "ext.h"
00020 #include "ext_obex.h"
00021 #include "jpatcher_api.h"
00022 #include "jgraphics.h"
00023
00024 #include "OMax.data.h"
00025
00030 typedef struct _OMax_state2date
00031 {
00032 t_object ob;
00033 t_symbol* oname;
00034 t_symbol* dataname;
00035 bool obound;
00036 O_DataType datatype;
00037 O_data* data;
00038 void* out_enddate;
00039 void* out_begindate;
00040 } t_OMax_state2date;
00041
00043
00045
00047
00048
00049 void *OMax_state2date_new(t_symbol *s, long argc, t_atom *argv);
00050 void OMax_state2date_free(t_OMax_state2date *x);
00051 void OMax_state2date_assist(t_OMax_state2date *x, void *b, long io, long index, char *s);
00052
00053
00054 void OMax_state2date_do(t_OMax_state2date *x, long statnb);
00055 void OMax_state2date_setname(t_OMax_state2date *x, t_symbol *newname);
00056
00057
00058 t_symbol * OMax_state2date_name(t_symbol * oname);
00059 bool OMax_state2date_bind(t_OMax_state2date *x);
00060
00061
00062 t_class* OMax_state2date_class;
00063
00065
00067
00068 int main(void)
00069 {
00070
00071 t_class *c;
00072
00073 c = class_new("OMax.state2date", (method)OMax_state2date_new, (method)OMax_state2date_free, (long)sizeof(t_OMax_state2date),
00074 0L , A_GIMME, 0);
00075
00076
00077 class_addmethod(c, (method)OMax_state2date_assist,"assist",A_CANT, 0);
00078
00079
00080 class_addmethod(c, (method)OMax_state2date_do, "int", 0);
00081 class_addmethod(c, (method)OMax_state2date_setname, "set", A_DEFSYM, 0);
00082
00083 class_register(CLASS_BOX, c);
00084 OMax_state2date_class = c;
00085
00086 return 0;
00087 }
00088
00090
00091
00094 void *OMax_state2date_new(t_symbol *s, long argc, t_atom *argv)
00095 {
00096 t_OMax_state2date *x = NULL;
00097
00098
00099 if (x = (t_OMax_state2date *)object_alloc(OMax_state2date_class))
00100 {
00101
00102 x->out_begindate = intout(x);
00103 x->out_enddate = intout(x);
00104
00106 x->obound = FALSE;
00107 if (argc == 0)
00108 object_error((t_object *)x,"Missing name of the Oracle data to read");
00109 else
00110 {
00111 if (argv->a_type != A_SYM)
00112 object_error((t_object *)x,"First argument must be a symbol (name of an existing Oracle)");
00113 else
00114 x->oname = atom_getsym(argv);
00115 }
00116
00117
00118 t_object *box;
00119 t_jrgba colorvals;
00120 jrgba_set(&colorvals, 0.30, 1.0, 0.15, 1.0);
00121 object_obex_lookup((t_object *)x, gensym("#B"), &box);
00122 jbox_set_color(box, &colorvals);
00123 }
00124 return (x);
00125 }
00126
00129 void OMax_state2date_free(t_OMax_state2date *x)
00130 {
00131 ;
00132 }
00133
00136 void OMax_state2date_assist(t_OMax_state2date *x, void *b, long io, long index, char *s)
00137 {
00138 switch (io)
00139 {
00140 case 1:
00141 sprintf(s, "state number, set [symbol] changes sequence to read");
00142 break;
00143 case 2:
00144 switch(index)
00145 {
00146 case 0:
00147 sprintf(s, "end date");
00148 break;
00149 case 1:
00150 sprintf(s, "begin date");
00151 break;
00152 }
00153 }
00154 }
00155
00157
00159
00160
00163 t_symbol * OMax_state2date_name(t_symbol * oname)
00164 {
00165 char dataname[128];
00166 strcpy(dataname,oname->s_name);
00168 strcat(dataname,"_data");
00169 return gensym(dataname);
00170 }
00171
00174 bool OMax_state2date_bind(t_OMax_state2date *x)
00175 {
00177 if (x->obound == FALSE)
00178 {
00180 x->dataname = OMax_state2date_name(x->oname);
00181 if ((x->dataname->s_thing) && (ob_sym(x->dataname->s_thing) == gensym("OMax.data")))
00182 {
00183 x->data = &(((t_OMax_data*)(x->dataname->s_thing))->data);
00184
00185 x->obound = TRUE;
00187 x->datatype = ((t_OMax_data*)(x->dataname->s_thing))->datatype;
00188 }
00189 else
00190 {
00191 object_error((t_object *)x,"No data for Oracle %s declared", x->oname->s_name);
00192 }
00193 }
00194 return x->obound;
00195 }
00196
00198
00200
00201
00205 void OMax_state2date_do(t_OMax_state2date *x, long statnb)
00206 {
00207 if (OMax_state2date_bind(x))
00208 {
00209 ATOMIC_INCREMENT(&(((t_OMax_data *)(x->dataname->s_thing))->readcount));
00210 if(((t_OMax_data *)(x->dataname->s_thing))->wflag == FALSE)
00211 {
00212 if ((statnb>=0) && (statnb<(long)(x->data->get_size())))
00213 {
00214 switch(x->datatype)
00215 {
00216 case LETTERS:
00217 outlet_int(x->out_begindate,statnb-1);
00218 outlet_int(x->out_enddate,statnb);
00219 break;
00220 default:
00221 int date = (*x->data).get_date(statnb);
00222 outlet_int(x->out_begindate,date);
00223 outlet_int(x->out_enddate,date+(*x->data)[statnb]->get_duration());
00224 break;
00225 }
00226 }
00227 }
00228 else
00229 object_error((t_object *)x,"Data of Oracle %s busy",x->oname->s_name);
00230 ATOMIC_DECREMENT(&(((t_OMax_data *)(x->dataname->s_thing))->readcount));
00231 }
00232 }
00233
00237 void OMax_state2date_setname(t_OMax_state2date *x, t_symbol *s)
00238 {
00239 x->oname = s;
00240 x->obound = FALSE;
00241 OMax_state2date_bind(x);
00242 }
00243
00245 }
00246
00247 #endif