changeset 574:a082d2babb3d

Remove global adbpointer from PD external It wasn't doing anything useful. Also change some comments to tell the truth, and remove some copy-and-paste code in favour of this exciting new "function call" abstraction.
author mas01cr
date Mon, 06 Jul 2009 15:09:53 +0000
parents 503e0d091d5e
children 7293a11b0fec
files bindings/pd/adbpd.c
diffstat 1 files changed, 19 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/pd/adbpd.c	Mon Jul 06 11:52:23 2009 +0000
+++ b/bindings/pd/adbpd.c	Mon Jul 06 15:09:53 2009 +0000
@@ -21,7 +21,6 @@
 #define O2_ONE_TO_ONE_N_SEQUENCE_QUERY (0x40U)
 
 static t_class *adbpd_class; /* so this bit is different */
-adb_ptr dbpointer={0};/*This is the audioDB pointer*/
 
 typedef struct _adbpd {
   t_object x_obj;
@@ -97,70 +96,51 @@
   return(x);
 }
 
-/* bang just gets the status of the db */
+/* 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){
-	
-  post("creating db '%s'",x->x_dbname->s_name);
-  dbpointer=audiodb_create(x->x_dbname->s_name,0,0,0);
+static void adbpd_create(t_adbpd *x) {
+  post("creating db '%s'", x->x_dbname->s_name);
+  x->db = audiodb_create(x->x_dbname->s_name, 0, 0, 0);
 
-  if (dbpointer){
+  if (x->db) {
     post("Created");
-    x->db=dbpointer;
   } else {
-    error("Could not create db. May already exist");
-    x->db=NULL;
+    error("Could not create db '%s'.");
   }
 }
 
 /* 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){
+static void adbpd_open(t_adbpd *x) {
+  post("Opening db '%s'", x->x_dbname->s_name);
+  x->db = audiodb_open(x->x_dbname->s_name, O_RDWR);
   
-  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;
+  if (x->db) {
+    post("Opened");
   } else {
-    error("failed ! Check '%s' exists, or create a new db",x->x_dbname->s_name);
-    x->db=NULL;
+    error("Could not open db '%s'.", x->x_dbname->s_name);
   }
 }
 
 /* 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){
-  
+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);
+    x->x_dbname = gensym(argv->a_w.w_symbol->s_name); 
+    post("Name set to '%s'.", 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;
-  }
+  /* now we can open the database as we did with the audiodb_open call
+     above */
+  /* FIXME: well, we _can_, but why is that a good idea? */
+  adbpd_open(x);
 }