changeset 578:dabbde72e331

Make the initialization of adbpd objects useful Provide a single argument, naming the database, and actually use that argument. Also provide a destructor method which closes an open database, and a useful create method (now with 100% fewer 2GB files).
author mas01cr
date Mon, 06 Jul 2009 16:44:59 +0000
parents a3d62f2f864f
children 81053b8bdb51
files bindings/pd/adbpd.c bindings/pd/pdtest.pd
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/pd/adbpd.c	Mon Jul 06 15:26:24 2009 +0000
+++ b/bindings/pd/adbpd.c	Mon Jul 06 16:44:59 2009 +0000
@@ -43,7 +43,7 @@
 } t_adbpd;
 
 
-static void adbpd_create(t_adbpd *x);
+static void adbpd_create(t_adbpd *, t_floatarg, t_floatarg, t_floatarg);
 static void adbpd_open(t_adbpd *x);
 static void adbpd_setname(t_adbpd *x, t_symbol *s, int argc, t_atom *argv);
 static void adbpd_status(t_adbpd *x);
@@ -66,7 +66,8 @@
 static void *adbpd_new(t_symbol *s) {
 
   /* some sort of standard declaration line */
-  t_adbpd *x = (t_adbpd *)pd_new(adbpd_class);
+  t_adbpd *x = (t_adbpd *) pd_new(adbpd_class);
+  x->x_dbname = s;
   
   /* setup some inlets */
   floatinlet_new(&x->x_obj,&x->x_dbqpoint); /* second inlet */
@@ -75,7 +76,6 @@
   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);
   
@@ -85,7 +85,6 @@
   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");
   x->x_dbquerytype=O2_POINT_QUERY;
   x->x_dbfeature=gensym("No feature file yet specified");
   x->x_dbqpoint=1;
@@ -96,18 +95,25 @@
   return(x);
 }
 
+static void adbpd_free(t_adbpd *x) {
+  if(x->db) {
+    audiodb_close(x->db);
+    x->db = NULL;
+  }
+}
+
 /* bang executes the defined query */
 static void adbpd_bang(t_adbpd *x) {
   adbpd_doquery(x);
 }
 
 /* create a database */
-static void adbpd_create(t_adbpd *x) {
+static void adbpd_create(t_adbpd *x, t_floatarg datasize, t_floatarg ntracks, t_floatarg dim) {
   post("creating db '%s'", x->x_dbname->s_name);
-  x->db = audiodb_create(x->x_dbname->s_name, 0, 0, 0);
+  x->db = audiodb_create(x->x_dbname->s_name, datasize, ntracks, dim);
 
   if (x->db) {
-    post("Created");
+    post("Created and opened");
   } else {
     error("Could not create db '%s'.");
   }
@@ -395,7 +401,9 @@
 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);
+  adbpd_class = 
+    class_new(gensym("adbpd"), (t_newmethod) adbpd_new, (t_method) adbpd_free,
+	      sizeof(t_adbpd), CLASS_DEFAULT, A_DEFSYMBOL, 0);
 
   /* all methods that respond to input must be defined here */
   class_addbang(adbpd_class, adbpd_bang);
@@ -406,7 +414,7 @@
   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_create, gensym("create"), A_NULL);
+  class_addmethod(adbpd_class, (t_method)adbpd_create, gensym("create"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
   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);
--- a/bindings/pd/pdtest.pd	Mon Jul 06 15:26:24 2009 +0000
+++ b/bindings/pd/pdtest.pd	Mon Jul 06 16:44:59 2009 +0000
@@ -9,7 +9,8 @@
 #X floatatom 366 253 5 0 0 0 - - -;
 #X floatatom 420 259 5 0 0 0 - - -;
 #X floatatom 477 264 5 0 0 0 - - -;
-#X obj 303 336 adbpd 100 1 1 5 20;
+#X obj 303 336 adbpd pdtest.adb;
+#X msg 204 180 create 50 1000 12;
 #X connect 0 0 8 0;
 #X connect 1 0 8 0;
 #X connect 2 0 8 0;
@@ -18,4 +19,5 @@
 #X connect 5 0 8 3;
 #X connect 6 0 8 4;
 #X connect 7 0 8 5;
+#X connect 9 0 8 0;
 #X coords 0 0 1 1 85 60 0;