WoMax Documentation OMax Logo

OMax.SLT.c

Go to the documentation of this file.
00001 /*--------------------------------------
00002  * OMax.SLT - OMax.SLT.c
00003  * Created on 12/04/09 by BenCello
00004  *--------------------------------------*/
00005 
00007 
00009 
00010 
00011 #ifndef __OMax_SLT_MAX_API_
00012 #define __OMAX_SLT_MAX_API_
00013 
00014 #include "Oracle_classes.hpp"
00015 #include "OMax.oracle.h"
00016 
00017 extern "C"
00018 {
00019         
00020 #include "ext.h"                                // standard Max include, always required
00021 #include "ext_obex.h"                   // required for new style Max object
00022 #include "jpatcher_api.h"               // required for the color
00023 #include "jgraphics.h"                  // required for the color
00024         
00029         typedef struct _OMax_SLT 
00030         {
00031                 t_object        ob;                     
00032                 t_symbol*       oname;          
00033                 bool            obound;         
00034                 O_oracle*       oracle;         
00035                 long            context;        
00036                 void*           out_root;       
00037                 void*           out_SLT;        
00038                 void*           out_path;       
00039         } t_OMax_SLT;
00040         
00042         
00044         // Prototypes //
00046         
00047         // Standard Max5 methodes
00048         void *OMax_SLT_new(t_symbol *s, long argc, t_atom *argv);
00049         void OMax_SLT_free(t_OMax_SLT *x);
00050         void OMax_SLT_assist(t_OMax_SLT *x, void *b, long io, long index, char *s);
00051         
00052         // Input/ouput routines
00053         void OMax_SLT(t_OMax_SLT *x, long statnb);
00054         void OMax_path(t_OMax_SLT *x, long statnb);
00055         void OMax_fullpath(t_OMax_SLT *x, long statnb);
00056         void OMax_sortedSLT(t_OMax_SLT *x, long statnb);
00057         void OMax_ctxt(t_OMax_SLT *x, long ctxt);
00058         
00059         // Internal routines
00060         bool OMax_SLT_bind(t_OMax_SLT *x);
00061         
00062         // Global class pointer variable
00063         t_class *OMax_SLT_class;
00064         
00066         // Functions //
00068         
00069         int main(void)
00070         {       
00071                 t_class *c;
00072                 
00073                 c = class_new("OMax.SLT", (method)OMax_SLT_new, (method)OMax_SLT_free, (long)sizeof(t_OMax_SLT), 
00074                                           0L /* leave NULL!! */, A_GIMME, 0);
00075                 // assistance
00076                 class_addmethod(c, (method)OMax_SLT_assist,"assist",A_CANT, 0); 
00077                 class_addmethod(c, (method)stdinletinfo, "inletinfo", A_CANT, 0);
00078                 
00079                 // input methods
00080                 class_addmethod(c, (method)OMax_SLT, "int", 0);
00081                 class_addmethod(c, (method)OMax_path, "path", A_LONG, 0);
00082                 class_addmethod(c, (method)OMax_fullpath, "fullpath", A_LONG, 0);
00083                 class_addmethod(c, (method)OMax_sortedSLT, "sorted", A_LONG, 0);
00084                 class_addmethod(c, (method)OMax_ctxt, "in1", A_LONG, 0);                
00085                 
00086                 class_register(CLASS_BOX, c); /* CLASS_NOBOX */
00087                 OMax_SLT_class = c;
00088                 
00089                 return 0;
00090         }
00091         
00093 
00094         
00097         void *OMax_SLT_new(t_symbol *s, long argc, t_atom *argv)
00098         {
00099                 t_OMax_SLT *x = NULL;
00100                 
00101                 if (x = (t_OMax_SLT *)object_alloc(OMax_SLT_class))
00102                 {
00103                         // inlets
00104                         intin(x, 1); // right inlet
00105                         
00106                         // outlets
00107                         x->out_path = listout(x); // rightmost
00108                         x->out_SLT = listout(x);
00109                         x->out_root = intout(x);
00110                         
00112                         x->obound = FALSE;
00113                         if (argc == 0)
00114                                 object_error((t_object *)x,"Missing name of the Oracle to read");
00115                         else
00116                         {
00117                                 if (argv->a_type != A_SYM)
00118                                         object_error((t_object *)x,"First argument must be a symbol (name of an existing Oracle)");
00119                                 else
00120                                 {
00121                                         x->oname = atom_getsym(argv);
00122                                         
00124                                         if ((argv+1)->a_type == A_LONG)
00125                                                 x->context = atom_getlong(argv+1);
00126                                         else
00127                                                 x->context = 1;
00128                                 }
00129                         }
00130                         
00131                         // color
00132                         t_object *box;
00133                         t_jrgba colorvals;
00134                         jrgba_set(&colorvals, 0.30, 1.0, 0.15, 1.0);
00135                         object_obex_lookup((t_object *)x, gensym("#B"), &box);
00136                         jbox_set_color(box, &colorvals);                        
00137                 }
00138                 return (x);
00139         }
00140         
00143         void OMax_SLT_free(t_OMax_SLT *x)
00144         {
00145                 ;
00146         }
00147         
00150         void OMax_SLT_assist(t_OMax_SLT *x, void *b, long io, long index, char *s)
00151         {
00152                 switch (io)
00153                 {
00154             case 1: // inlets
00155                                 switch (index)
00156                         {
00157                                 case 0: // leftmost
00158                                         sprintf(s, "int: get path & SLT of this state\n path int: get suffix path\n fullpath int: get whole suffix path (to 0)");
00159                                         break;
00160                                 case 1:
00161                                         sprintf(s, "minimal context of path & SLT");
00162                         }
00163                 break;
00164             case 2: // outlets
00165                                 switch (index)
00166                         {
00167                                 case 0:
00168                                         sprintf(s, "root of the SLT");
00169                                         break;
00170                                 case 1:
00171                                         sprintf(s, "states & lrs in the SLT");
00172                                         break;
00173                                 case 2:
00174                                         sprintf(s, "path to the root");
00175                                         break;
00176                         }
00177                                 break;
00178                 }
00179         }
00180         
00182         
00184 
00185         
00188         bool OMax_SLT_bind(t_OMax_SLT *x)
00189         {
00191                 if (x->obound == FALSE)
00192                 {
00194                         if ((x->oname->s_thing) && (ob_sym(x->oname->s_thing) == gensym("OMax.oracle")))
00195                         {
00196                                 x->oracle = &(((t_OMax_oracle*)(x->oname->s_thing))->oracle);
00197                                 // If binding is ok, then don't do it next time.
00198                                 x->obound = TRUE;
00199                         }
00200                         else
00201                         {
00202                                 object_error((t_object *)x,"No oracle %s declared", x->oname->s_name);
00203                         }
00204                 }
00205                 return x->obound;
00206         }
00207         
00209         
00211 
00212         
00216         void OMax_SLT(t_OMax_SLT *x, long statnb)
00217         {
00218                 if (OMax_SLT_bind(x))
00219                 {
00220                         ATOMIC_INCREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00221                         if(!(((t_OMax_oracle *)(x->oname->s_thing))->wflag))
00222                         {
00223                                 if ((statnb>=0) && (statnb<(long)(x->oracle->get_size())))
00224                                 {
00225                                         O_state * state = (*x->oracle)[statnb];
00226                                         
00228                                         char err;
00229                                         long i = 0;
00230                                         list<O_state*> path;
00231                                         list<O_state*>::iterator pathit;
00232                                         
00233                                         O_state * root = state->rec_upSLT(&path, x->context);
00234                                         
00235                                         long pathvals[path.size()];
00236                                         t_atom * pathout = NULL;
00237                                         for (pathit = path.begin(); pathit!=path.end(); pathit++)
00238                                         {
00239                                                 pathvals[i]=(*pathit)->get_statenb();
00240                                                 i++;
00241                                         }
00242                                         atom_alloc_array((long)path.size(), &i, &pathout, &err);
00243                                         if(err)
00244                                         {
00245                                                 atom_setlong_array((long)path.size(),pathout, (long)path.size(),pathvals);
00247                                                 outlet_list(x->out_path, NULL, (short)path.size(), pathout);
00248                                         }
00249                                         
00250                                         
00252                                         list<pair<O_state*,int> > SLT;
00253                                         list<pair<O_state*,int> >::iterator it;
00254                                         
00255                                         root->rec_downSLT(&SLT, x->context);
00256 
00257                                         long vals[2];
00258                                         t_atom * SLTout = NULL;
00259                                         atom_alloc_array(2, &i, &SLTout, &err);
00260                                         if(err && i==2)
00261                                         {
00262                                                 for (it = SLT.begin(); it!=SLT.end(); it++)
00263                                                 {
00264                                                         vals[0]=(*it).first->get_statenb();
00265                                                         vals[1]=(*it).second;
00266                                                         atom_setlong_array(2,SLTout,2,vals);
00267                                                         outlet_list(x->out_SLT, NULL, 2, SLTout); // output
00268                                                 }
00269                                         }
00270                                         
00272                                         outlet_int(x->out_root, root->get_statenb());
00273                                 }
00274                         }
00275                         ATOMIC_DECREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00276                 }
00277         }
00278         
00282         void OMax_path(t_OMax_SLT *x, long statnb)
00283         {
00284                 if (OMax_SLT_bind(x))
00285                 {
00286                         ATOMIC_INCREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00287                         if(!(((t_OMax_oracle *)(x->oname->s_thing))->wflag))
00288                         {
00289                                 if ((statnb>=0) && (statnb<(long)(x->oracle->get_size())))
00290                                 {
00291                                         O_state * state = (*x->oracle)[statnb];
00292                                         
00293                                         char err;
00294                                         long i = 0;
00295                                         list<O_state*> path;
00296                                         list<O_state*>::iterator pathit;
00297                                         
00299                                         O_state * root = state->rec_upSLT(&path, x->context);
00300                                         
00301                                         long pathvals[path.size()];
00302                                         t_atom * pathout = NULL;
00303                                         for (pathit = path.begin(); pathit!=path.end(); pathit++)
00304                                         {
00305                                                 pathvals[i]=(*pathit)->get_statenb();
00306                                                 i++;
00307                                         }
00308                                         atom_alloc_array((long)path.size(), &i, &pathout, &err);
00309                                         if(err)
00310                                         {
00311                                                 atom_setlong_array((long)path.size(),pathout, (long)path.size(),pathvals);
00313                                                 outlet_list(x->out_path, NULL, (short)path.size(), pathout);
00314                                         }
00315                                         
00317                                         outlet_int(x->out_root, root->get_statenb());
00318                                 }
00319                         }
00320                         ATOMIC_DECREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00321                 }
00322         }
00323         
00327         void OMax_fullpath(t_OMax_SLT *x, long statnb)
00328         {
00329                 if (OMax_SLT_bind(x))
00330                 {
00331                         ATOMIC_INCREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00332                         if(!(((t_OMax_oracle *)(x->oname->s_thing))->wflag))
00333                         {
00334                                 if ((statnb>=0) && (statnb<(long)(x->oracle->get_size())))
00335                                 {
00336                                         O_state * state = (*x->oracle)[statnb];
00337                                         
00338                                         char err;
00339                                         long i = 0;
00340                                         list<O_state*> path;
00341                                         list<O_state*>::iterator pathit;
00342                                         
00344                                         O_state * root = state->rec_upSLT(&path, 0);
00345                                         
00346                                         long pathvals[path.size()];
00347                                         t_atom * pathout = NULL;
00348                                         for (pathit = path.begin(); pathit!=path.end(); pathit++)
00349                                         {
00350                                                 pathvals[i]=(*pathit)->get_statenb();
00351                                                 i++;
00352                                         }
00353                                         atom_alloc_array((long)path.size(), &i, &pathout, &err);
00354                                         if(err)
00355                                         {
00356                                                 atom_setlong_array((long)path.size(),pathout, (long)path.size(),pathvals);
00358                                                 outlet_list(x->out_path, NULL, (short)path.size(), pathout);
00359                                         }
00360                                         
00362                                         outlet_int(x->out_root, root->get_statenb());
00363                                 }
00364                         }
00365                         ATOMIC_DECREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00366                 }
00367         }
00368         
00372         void OMax_sortedSLT(t_OMax_SLT *x, long statnb)
00373         {
00374                 if (OMax_SLT_bind(x))
00375                 {
00376                         ATOMIC_INCREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00377                         if(!(((t_OMax_oracle *)(x->oname->s_thing))->wflag))
00378                         {
00379                                 if ((statnb>=0) && (statnb<(long)(x->oracle->get_size())))
00380                                 {
00381                                         O_state * state = (*x->oracle)[statnb];
00382                                         
00383                                         char err;
00384                                         long i = 0;
00385                                         list<pair<O_state*,int> > SLT;
00386                                         list<pair<O_state*,int> >::iterator it;
00387                                         
00388                                         SLT = *state->sortedSLT(x->context);
00389                                         
00390                                         long vals[2];
00391                                         t_atom * SLTout = NULL;
00392                                         atom_alloc_array(2, &i, &SLTout, &err);
00393                                         if(err && i==2)
00394                                         {
00395                                                 for (it = SLT.begin(); it!=SLT.end(); it++)
00396                                                 {
00397                                                         vals[0]=(*it).first->get_statenb();
00398                                                         vals[1]=(*it).second;
00399                                                         atom_setlong_array(2,SLTout,2,vals);
00400                                                         outlet_list(x->out_SLT, NULL, 2, SLTout); // output
00401                                                 }
00402                                         }
00403                                         
00404                                         list<O_state*> path;
00405                                         O_state * root = state->rec_upSLT(&path, x->context);
00407                                         outlet_int(x->out_root, root->get_statenb());
00408                                 }
00409                         }
00410                         ATOMIC_DECREMENT(&(((t_OMax_oracle *)(x->oname->s_thing))->readcount));
00411                 }
00412         }
00413         
00417         void OMax_ctxt(t_OMax_SLT* x, long ctxtin)
00418         {
00419                 x->context = ctxtin;
00420         }
00421         
00423 }
00424 
00425 #endif

Generated on 16 Mar 2010 for Benjamin Lévy by  doxygen 1.6.1