WoMax Documentation

# OMax.data.c

Go to the documentation of this file.

    00001 /*--------------------------------------
    00002  * OMax.data - OMax.data.c
    00003  * Created on 17/03/09 by BenCello
    00004  *--------------------------------------*/
    00005
    00007
    00008 #ifndef __OMAX_DATA_MAX_API__
    00009 #define __OMAX_DATA_MAX_API__
    00010
    00011 #include "Oracle_label.hpp"
    00012 #include "Oracle_data.hpp"
    00013
    00014 #include <string.h>
    00015
    00016 extern "C"
    00017 {
    00018         #include "OMax.data.h"          // object structure
    00019
    00021         // Prototypes //
    00023
    00024         // Standard Max5 methodes
    00025         void *OMax_data_new(t_symbol *s, long argc, t_atom *argv);
    00026         void OMax_data_free(t_OMax_data *x);
    00027         void OMax_data_assist(t_OMax_data *x, void *b, long io, long index, char *s);
    00028
    00029         // Input/ouput routines
    00030         void OMax_data_size(t_OMax_data *x);
    00031         void OMax_data_init(t_OMax_data *x);
    00032         void OMax_data_reset(t_OMax_data *x);
    00033         void OMax_data_type(t_OMax_data *x);
    00034
    00035         // Internal routines
    00036         t_symbol * OMax_data_name(t_symbol * oname);
    00037
    00038         // Global class pointer variable
    00039         t_class *OMax_data_class;
    00040
    00042         // Functions //
    00044
    00045         int main(void)
    00046         {
    00047                 t_class *c;
    00048
    00049                 c = class_new("OMax.data", (method)OMax_data_new, (method)OMax_data_free, (long)sizeof(t_OMax_data),
    00050                                           0L /* leave NULL!! */, A_GIMME, 0);
    00051
    00052                 // assistance
    00053                 class_addmethod(c, (method)OMax_data_assist,"assist",A_CANT, 0);
    00054
    00055                 // input methods
    00056                 class_addmethod(c, (method)OMax_data_size, "size", 0);
    00057                 class_addmethod(c, (method)OMax_data_init, "init", 0);
    00058                 class_addmethod(c, (method)OMax_data_reset, "reset", 0);
    00059                 class_addmethod(c, (method)OMax_data_type, "type", 0);
    00060
    00061
    00062                 class_register(CLASS_BOX, c); /* CLASS_NOBOX */
    00063                 OMax_data_class = c;
    00064
    00065                 return 0;
    00066         }
    00067
    00069
    00070
    00073         void *OMax_data_new(t_symbol *s, long argc, t_atom *argv)
    00074         {
    00075                 t_OMax_data *x = NULL;
    00076
    00077                 if (x = (t_OMax_data *)object_alloc(OMax_data_class))
    00078                 {
    00079                         // outlets
    00080                         x->out0 = outlet_new(x, NULL);
    00081
    00082                         if (argc == 0)
    00083                                 object_error((t_object *)x,"Missing arguments");
    00084                         else
    00085                         {
    00086                                 if (argv->a_type!= A_SYM)
    00087                                         object_error((t_object *)x,"First argument must be a symbol (name of the data)");
    00088                                 else
    00089                                 {
    00091
    00092                                         // get oracle name
    00093                                         x->oname = atom_getsym(argv);
    00094
    00095                                         // set data name
    00096                                         x->dataname = OMax_data_name(x->oname);
    00097                                         x->dataname->s_thing = (t_object*)x;
    00098
    00100                                         x->datatype = LETTERS;
    00101                                         string datatype = "LETTERS";
    00102                                         if (argc < 2 || (argv+1)->a_type!=A_SYM)
    00103                                                 object_post((t_object *)x,"No data type, using LETTERS");
    00104                                         else
    00105                                         {
    00106                                                 if (atom_getsym(argv+1) == gensym("MIDI_MONO"))
    00107                                                 {
    00108                                                         x->datatype = MIDI_MONO;
    00109                                                         datatype = "MIDI_MONO";
    00110                                                 }
    00111                                                 else {
    00112                                                         if (atom_getsym(argv+1) == gensym("SPECTRAL"))
    00113                                                         {
    00114                                                                 x->datatype = SPECTRAL;
    00115                                                                 datatype = "SPECTRAL";
    00116                                                                 if (atom_getlong(argv+2))
    00117                                                                         x->nbcoeffs = atom_getlong(argv+2);
    00118                                                                 else
    00119                                                                 {
    00120                                                                         x->nbcoeffs = 7;
    00121                                                                         object_post((t_object *)x, "Missing number of coefficients for %s, assuming 7",x->oname->s_name);
    00122                                                                 }
    00123                                                         }
    00124                                                         else {
    00125                                                                 if (atom_getsym(argv+1) == gensym("LETTERS")){}
    00126                                                                 else
    00127                                                                         object_error((t_object *)x,"Type %s undefined, using LETTERS",atom_getsym(argv+1)->s_name);
    00128                                                         }
    00129                                                 }
    00130                                         }
    00131                                 if (datatype == "SPECTRAL")
    00132                                         object_post((t_object *)x,"Data %s of type %s declared with %ld coefficients",x->oname->s_name, datatype.c_str(),x->nbcoeffs);
    00133                                 else
    00134                                         object_post((t_object *)x,"Data %s of type %s declared",x->oname->s_name, datatype.c_str());
    00135
    00136                                 }
    00137                         }
    00138                         // write flags
    00139                         x->wflag = 0;
    00140                         x->readcount = 0;
    00141                         x->noDelete = TRUE;
    00142
    00143                         // color
    00144                         t_object *box;
    00145                         t_jrgba colorvals;
    00146                         jrgba_set(&colorvals, 0.30, 1.0, 0.15, 1.0);
    00147                         object_obex_lookup((t_object *)x, gensym("#B"), &box);
    00148                         jbox_set_color(box, &colorvals);
    00149                 }
    00150                 return (x);
    00151         }
    00152
    00155         void OMax_data_free(t_OMax_data *x)
    00156         {
    00158                 if (!(x->noDelete))
    00159                 {
    00160                         switch (x->datatype)
    00161                         {
    00162                                 case SPECTRAL:
    00163                                         x->data.freestates<O_spectral>();
    00164                                 case MIDI_MONO:
    00165                                         x->data.freestates<O_MIDI_mono>();
    00166                                 default:
    00167                                         x->data.freestates<O_char>();
    00168                         }
    00169                 }
    00170         }
    00171
    00175         void OMax_data_assist(t_OMax_data *x, void *b, long io, long index, char *s)
    00176         {
    00177                 switch (io)
    00178                 {
    00179             case 1: // inlets
    00180                                 switch (index)
    00181                         {
    00182                                 case 0: // leftmost
    00183                                         sprintf(s, "messages (init, reset, size)");
    00184                                         break;
    00185                         }
    00186                 break;
    00187             case 2: // outlets
    00188                                 switch (index)
    00189                         {
    00190                                 case 0:
    00191                                         sprintf(s, "Anything you asked");
    00192                                         break;
    00193                         }
    00194                                 break;
    00195                 }
    00196         }
    00197
    00199
    00201
    00202
    00206         void OMax_data_size(t_OMax_data *x)
    00207         {
    00208                 outlet_int(x->out0,(long)x->data.get_size());
    00209         }
    00210
    00214         void OMax_data_init(t_OMax_data *x)
    00215         {
    00216                 switch (x->datatype)
    00217                 {
    00218                         case SPECTRAL:
    00219                                 x->data.start<O_spectral>();
    00220                         case MIDI_MONO:
    00221                                 x->data.start<O_MIDI_mono>();
    00222                         default:
    00223                                 x->data.start<O_char>();
    00224                 }
    00225         }
    00226
    00230         void OMax_data_reset(t_OMax_data *x)
    00231         {
    00233                 if (x->noDelete)
    00234                 {
    00235                         x->data.clear_vect();
    00236                 }
    00237                 else
    00238                 {
    00239                         switch (x->datatype)
    00240                         {
    00241                                 case SPECTRAL:
    00242                                         x->data.freestates<O_spectral>();
    00243                                 case MIDI_MONO:
    00244                                         x->data.freestates<O_MIDI_mono>();
    00245                                 default:
    00246                                         x->data.freestates<O_char>();
    00247                         }
    00248                 }
    00249                 x->data.reset_D2S();
    00250                 x->data.reset_S2D();
    00251                 outlet_int(x->out0,(long)x->data.get_size());
    00252         }
    00253
    00257         void OMax_data_type(t_OMax_data *x)
    00258         {
    00259                 outlet_int(x->out0, (long)x->datatype);
    00260         }
    00261
    00263
    00265
    00266
    00269         t_symbol * OMax_data_name(t_symbol * oname)
    00270         {
    00271                 char dataname[128];
    00272                 strcpy(dataname,oname->s_name);
    00274                 strcat(dataname,"_data");
    00275                 return gensym(dataname);
    00276         }
    00277
    00279
    00280 }
    00281
    00282 #endif