changeset 573:503e0d091d5e

Reindent pd bindings file. I don't really mind one consistent indentation style, but two or maybe three within the same file is a bit much.
author mas01cr
date Mon, 06 Jul 2009 11:52:23 +0000
parents e6dab5ed471c
children a082d2babb3d
files bindings/pd/adbpd.c
diffstat 1 files changed, 113 insertions(+), 117 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/pd/adbpd.c	Mon Jul 06 11:52:21 2009 +0000
+++ b/bindings/pd/adbpd.c	Mon Jul 06 11:52:23 2009 +0000
@@ -24,14 +24,13 @@
 adb_ptr dbpointer={0};/*This is the audioDB pointer*/
 
 typedef struct _adbpd {
-	t_object x_obj;
-	t_outlet *x_key;
-	t_outlet *x_dist;
-	t_outlet *x_qpos;
-	t_outlet *x_spos;
-
+  t_object x_obj;
+  t_outlet *x_key;
+  t_outlet *x_dist;
+  t_outlet *x_qpos;
+  t_outlet *x_spos;
   t_symbol *x_dbname; //database name
-
+  
   t_int x_dbquerytype; //sequence, track, etc.
   t_symbol *x_dbfeature; 
 //    t_symbol *x_dbpower;
@@ -67,24 +66,24 @@
 /* input arguments are only used for startup vals */
 static void *adbpd_new(t_symbol *s) {
 
-	/* some sort of standard declaration line */
-	t_adbpd *x = (t_adbpd *)pd_new(adbpd_class);
-	
-	/* setup some inlets */
-	floatinlet_new(&x->x_obj,&x->x_dbqpoint); /* second inlet */
-	floatinlet_new(&x->x_obj,&x->x_dbnumpoints); /* third inlet */
-	floatinlet_new(&x->x_obj,&x->x_dbradius); /* fourth inlet */
-	floatinlet_new(&x->x_obj,&x->x_dbresultlength); /* fifth inlet */
-	floatinlet_new(&x->x_obj,&x->x_dbsequencelength); /* sixth inlet */
-
-
-	/* outlets */
-	outlet_new(&x->x_obj, &s_float);
-
-	x->x_key = outlet_new(&x->x_obj, &s_symbol);
-	x->x_dist = outlet_new(&x->x_obj, &s_float);
-	x->x_qpos = outlet_new(&x->x_obj, &s_float);
-	x->x_spos = outlet_new(&x->x_obj, &s_float);
+  /* some sort of standard declaration line */
+  t_adbpd *x = (t_adbpd *)pd_new(adbpd_class);
+  
+  /* setup some inlets */
+  floatinlet_new(&x->x_obj,&x->x_dbqpoint); /* second inlet */
+  floatinlet_new(&x->x_obj,&x->x_dbnumpoints); /* third inlet */
+  floatinlet_new(&x->x_obj,&x->x_dbradius); /* fourth inlet */
+  floatinlet_new(&x->x_obj,&x->x_dbresultlength); /* fifth inlet */
+  floatinlet_new(&x->x_obj,&x->x_dbsequencelength); /* sixth inlet */
+  
+  
+  /* outlets */
+  outlet_new(&x->x_obj, &s_float);
+  
+  x->x_key = outlet_new(&x->x_obj, &s_symbol);
+  x->x_dist = outlet_new(&x->x_obj, &s_float);
+  x->x_qpos = outlet_new(&x->x_obj, &s_float);
+  x->x_spos = outlet_new(&x->x_obj, &s_float);
 
   /* adb defaults. These are the same but we need to init them */
   x->x_dbname=gensym("no db has been specified yet");
@@ -95,14 +94,12 @@
   x->x_dbradius=1;
   x->x_dbresultlength=10;
   x->x_dbsequencelength=12;
-	return(x);
-  
+  return(x);
 }
 
 /* bang just gets the status of the db */
 static void adbpd_bang(t_adbpd *x) {
   adbpd_doquery(x);
-
 }
 
 /* create a database */
@@ -112,48 +109,23 @@
   dbpointer=audiodb_create(x->x_dbname->s_name,0,0,0);
 
   if (dbpointer){
-      post("Created");
-      x->db=dbpointer;
+    post("Created");
+    x->db=dbpointer;
   } else {
-      error("Could not create db. May already exist");
-      x->db=NULL;
+    error("Could not create db. May already exist");
+    x->db=NULL;
   }
-	
 }
 
-/* open a database. Need to work out the path stuff here. At present databases need to be in the root directory. Not good. */
+/* open a database. Need to work out the path stuff here. At present
+   databases need to be in the root directory. Not good. */
 static void adbpd_open(t_adbpd *x){
-	
+  
   post("Opening db '%s'",x->x_dbname->s_name);
   dbpointer=audiodb_open(x->x_dbname->s_name,O_RDWR);
-
+  
   if (dbpointer){
-	post("Opened db");
-    x->db=dbpointer;
-  } else {
-    error("failed ! Check '%s' exists, or create a new db",x->x_dbname->s_name);
-    x->db=NULL;
-  }
-	
-}
-
-/* This is accessed via the 'set' message. It sets the name and opens the database. */
-static void adbpd_setname(t_adbpd *x, t_symbol *s, int argc, t_atom *argv){
-	
-	/* if we have a properly formed instruction */
-  if (argc == 1 && argv->a_type == A_SYMBOL){
-    x->x_dbname=gensym(argv->a_w.w_symbol->s_name); /* make the internal database reference name the same as the name of the database we want.
-	 This is stupid. There must be a better way of doing this. */
-    post("Name has been set to '%s', and can now be opened.",x->x_dbname->s_name);
-  }
-	
-	/* now we can open the database as we did with the audiodb_open call above*/
-	
-	post("Opening db '%s'",x->x_dbname->s_name);
-  dbpointer=audiodb_open(x->x_dbname->s_name,O_RDWR); /* opened in read and write mode for when I get round to doing the insert code */
-	
-  if (dbpointer){ /* yes we have a database*/
-	post("Opened db");
+    post("Opened db");
     x->db=dbpointer;
   } else {
     error("failed ! Check '%s' exists, or create a new db",x->x_dbname->s_name);
@@ -161,6 +133,36 @@
   }
 }
 
+/* This is accessed via the 'set' message. It sets the name and opens
+   the database. */
+static void adbpd_setname(t_adbpd *x, t_symbol *s, int argc, t_atom *argv){
+  
+  /* if we have a properly formed instruction */
+  if (argc == 1 && argv->a_type == A_SYMBOL) {
+
+    /* make the internal database reference name the same as the name
+       of the database we want.  This is stupid. There must be a
+       better way of doing this. */
+    x->x_dbname=gensym(argv->a_w.w_symbol->s_name); 
+    post("Name has been set to '%s', and can now be opened.",x->x_dbname->s_name);
+  }
+	
+  /* now we can open the database as we did with the audiodb_open call above*/
+  
+  post("Opening db '%s'",x->x_dbname->s_name);
+  /* opened in read and write mode for when I get round to doing the
+     insert code */
+  dbpointer=audiodb_open(x->x_dbname->s_name,O_RDWR);
+  
+  if (dbpointer) { /* yes we have a database*/
+    post("Opened db");
+    x->db=dbpointer;
+  } else {
+    error("failed ! Check '%s' exists, or create a new db",x->x_dbname->s_name);
+    x->db=NULL;
+  }
+}
+
 
 /* this is a status call to the audioDB API */
 static void adbpd_status(t_adbpd *x){
@@ -168,7 +170,7 @@
   adb_status_t mystatus; 
 
   post("Getting Status");
-
+  
   if (x->db && !(audiodb_status(x->db,&mystatus))){
     post("numFiles %d",mystatus.numFiles);
     post("dim %d",mystatus.dim);
@@ -226,7 +228,7 @@
   
   // Set up query spec params depending on the query type.
   switch(x->x_dbquerytype)
-  {
+    {
     case O2_POINT_QUERY:
       spec.qid.sequence_length = 1;
       spec.params.accumulation = ADB_ACCUMULATION_DB;
@@ -244,7 +246,9 @@
     case O2_N_SEQUENCE_QUERY:
       spec.params.accumulation = ADB_ACCUMULATION_PER_TRACK;
       // TODO : Add unit norming param. Defaults to false.
-      // spec.params.distance = no_unit_norming ? ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
+      //
+      // spec.params.distance = no_unit_norming ?
+      // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
       spec.params.distance = ADB_DISTANCE_EUCLIDEAN_NORMED;
       spec.params.npoints = x->x_dbnumpoints;
       spec.params.ntracks = x->x_dbresultlength;
@@ -252,7 +256,9 @@
     case O2_ONE_TO_ONE_N_SEQUENCE_QUERY:
       spec.params.accumulation = ADB_ACCUMULATION_ONE_TO_ONE;
       // TODO : Add unit norming param. Defaults to false.
-      // spec.params.distance = no_unit_norming ? ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
+      //
+      // spec.params.distance = no_unit_norming ?
+      // ADB_DISTANCE_EUCLIDEAN : ADB_DISTANCE_EUCLIDEAN_NORMED;
       spec.params.distance =ADB_DISTANCE_EUCLIDEAN_NORMED;
       spec.params.npoints = 0;
       spec.params.ntracks = 0;
@@ -264,16 +270,16 @@
   adb_query_results_t *rs = audiodb_query_spec(x->db, &spec);
   
   if(datum.data) {
-      free(datum.data);
-      datum.data = NULL;
+    free(datum.data);
+    datum.data = NULL;
   }
   if(datum.power) {
-      free(datum.data);
-      datum.data = NULL;
+    free(datum.data);
+    datum.data = NULL;
   }
   if(datum.times) {
-      free(datum.data);
-      datum.data = NULL;
+    free(datum.data);
+    datum.data = NULL;
   }
   
   if(rs == NULL)
@@ -300,8 +306,8 @@
     
 }
 
-/* Do I need to set a the power file for this flag to work ? Hmmm. Dunno. Also, should be on/off*/
-
+/* Do I need to set a the power file for this flag to work ?
+   Hmmm. Dunno. Also, should be on/off*/
 static void adbpd_power(t_adbpd *x){
   post("power");
 
@@ -312,8 +318,8 @@
   }   
 }
 
-/* works fine but would be better if it took an argument to switch it on and off */
-
+/* works fine but would be better if it took an argument to switch it
+   on and off */
 static void adbpd_l2norm(t_adbpd *x){
   post("l2norm");
 
@@ -330,43 +336,36 @@
 }
 
 /* this sets the qpoint for the current query*/
-
 static void adbpd_setqpoint(t_adbpd *x,t_floatarg f){
-	post("qpoint %.3f",f);
-    
+  post("qpoint %.3f",f);
   x->x_dbqpoint=f; 
 } 
 
 /* This sets the number of points for current query */
-
 static void adbpd_setnumpoints(t_adbpd *x,t_floatarg f){
-	post("numpoints %.3f",f);
-    x->x_dbnumpoints=(int)f;
+  post("numpoints %.3f",f);
+  x->x_dbnumpoints=(int)f;
 }
 
 /* This sets the radius */
-
 static void adbpd_setradius(t_adbpd *x,t_floatarg f){
-	post("radius %.3f",f);
-    x->x_dbradius=f;
+  post("radius %.3f",f);
+  x->x_dbradius=f;
 } 
 
 /* This sets the result length */ 
-
 static void adbpd_setresultlength(t_adbpd *x,t_floatarg f){
-	post("resultlength %.3f",f);
-    x->x_dbresultlength=(int)f;
+  post("resultlength %.3f",f);
+  x->x_dbresultlength=(int)f;
 }
 
 /* This sets the sequence length */
-
 static void adbpd_setsequencelength(t_adbpd *x,t_floatarg f){
-	post("sequencelength %.3f",f);
-    x->x_dbsequencelength=(int)f;
+  post("sequencelength %.3f",f);
+  x->x_dbsequencelength=(int)f;
 } 
 
 /* This sets the feature file to use for the query */
-
 static void adbpd_setfeatures(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){
 
   if (argc == 1 && argv->a_type == A_SYMBOL){
@@ -376,13 +375,10 @@
 }
 
 /* This sets the query type */
-
 static void adbpd_setquerytype(t_adbpd *x,t_symbol *s,int argc, t_atom *argv){ 
-    
-	if (argc == 1 && argv->a_type == A_SYMBOL){
+  if (argc == 1 && argv->a_type == A_SYMBOL) {
   
     // Determine which constant to use based on the string passed.
-    
     if(strncmp(argv->a_w.w_symbol->s_name, "track", MAXSTR)==0)
       x->x_dbquerytype=O2_TRACK_QUERY;
     else if(strncmp(argv->a_w.w_symbol->s_name, "point", MAXSTR)==0)
@@ -414,29 +410,29 @@
   post("sequencelength %.3f",x->x_dbsequencelength);
 }
 
-/* THAR SHE BLOWS. This sets up the object, takes the messages with args and maps them to methods. */
-
+/* THAR SHE BLOWS. This sets up the object, takes the messages with
+   args and maps them to methods. */
 void adbpd_setup(void) {
-	/* the arguments in this line refer to INPUT ARGUMENTS and not OUTPUTS */
-	adbpd_class = class_new(gensym("adbpd"),(t_newmethod)adbpd_new,0,sizeof(t_adbpd),0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
-
-	/* all methods that respond to input must be defined here */
-	class_addbang(adbpd_class, adbpd_bang);
-	class_addfloat(adbpd_class, adbpd_setqpoint);
-	class_addfloat(adbpd_class, adbpd_setnumpoints);
-	class_addfloat(adbpd_class, adbpd_setradius);
-	class_addfloat(adbpd_class, adbpd_setresultlength);
-	class_addfloat(adbpd_class, adbpd_setsequencelength);
-	class_addmethod(adbpd_class, (t_method)adbpd_setname, gensym("set"), A_GIMME, 0);
-	class_addmethod(adbpd_class, (t_method)adbpd_getname, gensym("get"), A_NULL);
-	class_addmethod(adbpd_class, (t_method)adbpd_open, gensym("open"), A_NULL);
-	class_addmethod(adbpd_class, (t_method)adbpd_status, gensym("status"), A_NULL);
-	class_addmethod(adbpd_class, (t_method)adbpd_l2norm, gensym("l2norm"), A_NULL);
-	class_addmethod(adbpd_class, (t_method)adbpd_power, gensym("power"), A_NULL);
-	class_addmethod(adbpd_class, (t_method)adbpd_doquery, gensym("doquery"), A_NULL);
+  /* the arguments in this line refer to INPUT ARGUMENTS and not
+     OUTPUTS */
+  adbpd_class = class_new(gensym("adbpd"),(t_newmethod)adbpd_new,0,sizeof(t_adbpd),0, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+  
+  /* all methods that respond to input must be defined here */
+  class_addbang(adbpd_class, adbpd_bang);
+  class_addfloat(adbpd_class, adbpd_setqpoint);
+  class_addfloat(adbpd_class, adbpd_setnumpoints);
+  class_addfloat(adbpd_class, adbpd_setradius);
+  class_addfloat(adbpd_class, adbpd_setresultlength);
+  class_addfloat(adbpd_class, adbpd_setsequencelength);
+  class_addmethod(adbpd_class, (t_method)adbpd_setname, gensym("set"), A_GIMME, 0);
+  class_addmethod(adbpd_class, (t_method)adbpd_getname, gensym("get"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_open, gensym("open"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_status, gensym("status"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_l2norm, gensym("l2norm"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_power, gensym("power"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_doquery, gensym("doquery"), A_NULL);
   class_addmethod(adbpd_class, (t_method)adbpd_setquerytype, gensym("querytype"), A_GIMME, 0);
   class_addmethod(adbpd_class, (t_method)adbpd_setfeatures, gensym("features"), A_GIMME, 0);
-	class_addmethod(adbpd_class, (t_method)adbpd_parameters, gensym("parameters"), A_NULL);
-
+  class_addmethod(adbpd_class, (t_method)adbpd_parameters, gensym("parameters"), A_NULL);
 }