[xiph-commits] r13550 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Aug 15 14:37:15 PDT 2007


Author: xiphmont
Date: 2007-08-15 14:37:14 -0700 (Wed, 15 Aug 2007)
New Revision: 13550

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/dimension.h
   trunk/sushivision/example_fractal.c
   trunk/sushivision/internal.h
   trunk/sushivision/main.c
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-xy.c
   trunk/sushivision/sushivision.h
   trunk/sushivision/undo.c
Log:
Continue rework of API: dimension addressing



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/dimension.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -374,7 +374,7 @@
 }
 
 /* undo/redo have to frob widgets; this is indirected here too */
-int _sv_dim_set_value(_sv_dim_widget_t *dw, int thumb, double val){
+int _sv_dim_widget_set_thumb(_sv_dim_widget_t *dw, int thumb, double val){
   sv_dim_t *d = dw->dl->d;
 
   switch(d->type){
@@ -419,10 +419,7 @@
   return 0;
 }
 
-/* external version with externalish API */
-int sv_dim_set_value(sv_dim_t *in, int thumb, double val){
-  sv_dim_t *d = (sv_dim_t *)in; // unwrap
-
+int _sv_dim_set_thumb(sv_dim_t *d, int thumb, double val){
   if(!d->private->widgets){
     switch(thumb){
     case 0:
@@ -441,12 +438,25 @@
 
     if(d->private->value_callback) 
       d->private->value_callback(d,d->private->value_callback_data);
-
+    
   }else
-    return _sv_dim_set_value(d->private->widget_list[0],thumb,val);
+    return _sv_dim_widget_set_thumb(d->private->widget_list[0],thumb,val);
   return 0;
 }
 
+/* external version with externalish API */
+int sv_dim_set_value(double val){
+  sv_dim_t *d = sv_dim(0);
+  return _sv_dim_set_thumb(d,1,val);
+}
+
+int sv_dim_set_bracket(double lo, double hi){
+  sv_dim_t *d = sv_dim(0);
+  int ret = _sv_dim_widget_set_thumb(d->private->widget_list[0],0,lo);
+  if(!ret) ret = _sv_dim_widget_set_thumb(d->private->widget_list[0],2,hi);
+  return ret;
+}
+
 void _sv_dim_widget_set_thumb_active(_sv_dim_widget_t *dw, int thumb, int active){
   if(dw->scale)
     _sv_slider_set_thumb_active(dw->scale,thumb,active);
@@ -637,7 +647,7 @@
       
       gtk_table_attach(GTK_TABLE(dw->t),dw->menu,0,1,0,1,
 		       GTK_EXPAND|GTK_FILL,GTK_SHRINK,0,2);
-      _sv_dim_set_value(dw,1,d->val);
+      _sv_dim_widget_set_thumb(dw,1,d->val);
       //gtk_combo_box_set_active(GTK_COMBO_BOX(dw->menu),0);
     }
     break;
@@ -694,14 +704,16 @@
   d->type = SV_DIM_CONTINUOUS;
   d->private = calloc(1, sizeof(*d->private));
 
+  pthread_setspecific(_sv_dim_key, (void *)d);
+
   return d;
 }
 
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
-int sv_dim_set_scale(sv_dim_t *in,
-		     sv_scale_t *scale){
-  sv_dim_t *d = (sv_dim_t *)in; // unwrap
+int sv_dim_set_scale(sv_scale_t *scale){
+  sv_dim_t *d = sv_dim(0);
+  if(!d) return -EINVAL;
 
   if(d->scale)
     sv_scale_free(d->scale); // always a deep copy we own
@@ -720,27 +732,26 @@
 
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
-int sv_dim_make_scale(sv_dim_t *in,
-		      unsigned scalevals, 
+int sv_dim_make_scale(unsigned scalevals, 
 		      double *scaleval_list,
 		      char **scalelabel_list,
 		      unsigned flags){
-  sv_dim_t *d = (sv_dim_t *)in; //unwrap
+  sv_dim_t *d = sv_dim(0);
+  if(!d) return -EINVAL;
 
   sv_scale_t *scale = sv_scale_new(d->name,scalevals,scaleval_list,scalelabel_list,0);
   if(!scale)return errno;
 
-  int ret = sv_dim_set_scale(d,scale);
+  int ret = sv_dim_set_scale(scale);
   sv_scale_free(scale);
   return ret;
 }
 
 // XXXX need to recompute after
-int sv_dim_set_discrete(sv_dim_t *in,
-			long quant_numerator,
+int sv_dim_set_discrete(long quant_numerator,
 			long quant_denominator){
   
-  sv_dim_t *d = (sv_dim_t *)in; //unwrap
+  sv_dim_t *d = sv_dim(0);
   if(!d) return -EINVAL;
 
   d->private->discrete_numerator = quant_numerator;
@@ -750,9 +761,9 @@
   return 0;
 }
 
-int sv_dim_set_picklist(sv_dim_t *in){
+int sv_dim_set_picklist(){
   
-  sv_dim_t *d = (sv_dim_t *)in; //unwrap  
+  sv_dim_t *d = sv_dim(0);
   if(!d) return -EINVAL;
 
   d->type = SV_DIM_PICKLIST;
@@ -810,8 +821,28 @@
   return ret;
 }
 
-int sv_dim_callback_value (sv_dim_t *d, int (*callback)(sv_dim_t *, void *), void *data){
+int sv_dim_callback_value (int (*callback)(sv_dim_t *, void *), void *data){
+  sv_dim_t *d = sv_dim(0);
+  if(!d) return -EINVAL;
+  
   d->private->value_callback = callback;
   d->private->value_callback_data = data;
   return 0;
 }
+
+sv_dim_t *sv_dim(char *name){
+  int i;
+  
+  if(name == NULL || name == 0 || !strcmp(name,"")){
+    return (sv_dim_t *)pthread_getspecific(_sv_dim_key);
+    
+  }
+  for(i=0;i<_sv_dimensions;i++){
+    sv_dim_t *d=_sv_dimension_list[i];
+    if(d && d->name && !strcmp(name,d->name)){
+      pthread_setspecific(_sv_dim_key, (void *)d);
+      return d;
+    }
+  }
+  return NULL;
+}

Modified: trunk/sushivision/dimension.h
===================================================================
--- trunk/sushivision/dimension.h	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/dimension.h	2007-08-15 21:37:14 UTC (rev 13550)
@@ -65,7 +65,8 @@
 				     _sv_scalespace_t *data, 
 				     _sv_scalespace_t *iter);
 
-extern int _sv_dim_set_value(_sv_dim_widget_t *d, int thumb, double val);
+extern int _sv_dim_set_thumb(sv_dim_t *d, int thumb, double val);
+extern int _sv_dim_widget_set_thumb(_sv_dim_widget_t *d, int thumb, double val);
 extern void _sv_dim_widget_set_thumb_active(_sv_dim_widget_t *dw, int thumb, int active);
 extern _sv_dim_widget_t *_sv_dim_widget_new(sv_dim_list_t *dl,   
 					   void (*center_callback)(sv_dim_list_t *),

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/example_fractal.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -59,26 +59,27 @@
 
 
   sv_dim_t *d0 = sv_dim_new(0, "Re(c)", 0);
-  sv_dim_make_scale(d0, 5, (double []){-2.25,-0.75,0,0.25,0.75}, NULL, 0);
+  sv_dim_make_scale(5, (double []){-2.25,-0.75,0,0.25,0.75}, NULL, 0);
   
   sv_dim_t *d1 = sv_dim_new(1, "Im(c)", 0);
-  sv_dim_make_scale(d1, 5, (double []){-2,-1,0,1,2}, NULL, 0);
+  sv_dim_make_scale(5, (double []){-2,-1,0,1,2}, NULL, 0);
 
   sv_dim_t *d2 = sv_dim_new(2, "Re(z0)", 0);
-  sv_dim_make_scale(d2, 5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
+  sv_dim_make_scale(5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
 
   sv_dim_t *d3 = sv_dim_new(3, "Im(z0)", 0);
-  sv_dim_make_scale(d3, 5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
+  sv_dim_make_scale(5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
 
   sv_dim_t *d4 = sv_dim_new(4, "Max Iterations", 0);
-  sv_dim_make_scale(d4, 4, (double []){100,1000,10000,100000},
+  sv_dim_make_scale(4, (double []){100,1000,10000,100000},
 		    (char *[]){"one hundred",
-				 "one thousand",
-				 "ten thousand",
-				 "one hundred thousand"}, 0);
-  sv_dim_set_picklist(d4);
-  sv_dim_set_value(d4,1,100);
+			"one thousand",
+			"ten thousand",
+			"one hundred thousand"}, 0);
 
+  sv_dim_set_picklist();
+  sv_dim_set_value(100);
+
   sv_func_t *f = sv_func_new(0, 2, fractal_objective, 0);
   
   sv_obj_t *o0 = sv_obj_new(0,"outer",

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/internal.h	2007-08-15 21:37:14 UTC (rev 13550)
@@ -23,6 +23,7 @@
 
 #include <time.h>
 #include <signal.h>
+#include <pthread.h>
 #include <gtk/gtk.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
@@ -211,3 +212,5 @@
 extern int _sv_undo_suspended;
 extern _sv_undo_t **_sv_undo_stack;
 
+extern pthread_key_t _sv_dim_key;
+

Modified: trunk/sushivision/main.c
===================================================================
--- trunk/sushivision/main.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/main.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -57,6 +57,8 @@
 int _sv_undo_suspended=0;
 _sv_undo_t **_sv_undo_stack=NULL;
 
+pthread_key_t   _sv_dim_key;
+
 void _sv_wake_workers(){
   pthread_mutex_lock(&m);
   wake_pending = num_threads;
@@ -67,9 +69,13 @@
 void _sv_clean_exit(){
   _sv_exiting = 1;
   _sv_wake_workers();
+
+  gdk_threads_enter();
   if(!gtk_main_iteration_do(FALSE)) // side effect: returns true if
 				    // there are no main loops active
     gtk_main_quit();
+  gdk_threads_leave();
+
 }
 
 static int num_proccies(){
@@ -196,7 +202,10 @@
 
 /* externally visible interface */
 int sv_init(){
-  
+  int ret=0;
+  if((ret=pthread_key_create(&_sv_dim_key,NULL)))
+     return ret;
+
   num_threads = num_proccies();
   _gtk_mutex_fixup();
   gtk_init (NULL,NULL);

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/panel-1d.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -955,7 +955,7 @@
     for(i=0;i<p->dimensions;i++){
       sv_dim_t *d = p->dimension_list[i].d;
       if(d == p->private->x_d)
-	_sv_dim_set_value(p->private->dim_scales[i],1,x);
+	_sv_dim_widget_set_thumb(p->private->dim_scales[i],1,x);
 	            
       p->private->oldbox_active = 0;
     }
@@ -980,8 +980,8 @@
 
     _sv_panel1d_crosshair_callback(p);
     
-    _sv_dim_set_value(p1->x_scale,0,p1->oldbox[0]);
-    _sv_dim_set_value(p1->x_scale,2,p1->oldbox[1]);
+    _sv_dim_widget_set_thumb(p1->x_scale,0,p1->oldbox[0]);
+    _sv_dim_widget_set_thumb(p1->x_scale,2,p1->oldbox[1]);
     p->private->oldbox_active = 0;
     _sv_undo_resume();
     break;

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/panel-2d.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -1289,11 +1289,11 @@
   for(i=0;i<p->dimensions;i++){
     sv_dim_t *d = p->dimension_list[i].d;
     if(d == p->private->x_d){
-      _sv_dim_set_value(p->private->dim_scales[i],1,x);
+      _sv_dim_widget_set_thumb(p->private->dim_scales[i],1,x);
     }
 
     if(d == p->private->y_d){
-      _sv_dim_set_value(p->private->dim_scales[i],1,y);
+      _sv_dim_widget_set_thumb(p->private->dim_scales[i],1,y);
     }
     
     p->private->oldbox_active = 0;
@@ -1327,10 +1327,10 @@
 
     _sv_panel2d_crosshairs_callback(p);
 
-    _sv_dim_set_value(p2->x_scale,0,p2->oldbox[0]);
-    _sv_dim_set_value(p2->x_scale,2,p2->oldbox[1]);
-    _sv_dim_set_value(p2->y_scale,0,p2->oldbox[2]);
-    _sv_dim_set_value(p2->y_scale,2,p2->oldbox[3]);
+    _sv_dim_widget_set_thumb(p2->x_scale,0,p2->oldbox[0]);
+    _sv_dim_widget_set_thumb(p2->x_scale,2,p2->oldbox[1]);
+    _sv_dim_widget_set_thumb(p2->y_scale,0,p2->oldbox[2]);
+    _sv_dim_widget_set_thumb(p2->y_scale,2,p2->oldbox[3]);
     p->private->oldbox_active = 0;
     _sv_undo_resume();
     break;

Modified: trunk/sushivision/panel-xy.c
===================================================================
--- trunk/sushivision/panel-xy.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/panel-xy.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -781,7 +781,7 @@
   double y = xy->y_vec[xy->cross_objnum][x_bin];
 
   _sv_plot_set_crosshairs(plot,x,y);
-  sv_dim_set_value(p->private->x_d,1,_sv_scalespace_value(&xy->data_v, x_bin));
+  _sv_dim_set_thumb(p->private->x_d,1,_sv_scalespace_value(&xy->data_v, x_bin));
 
   _sv_panel_dirty_legend(p);
 }
@@ -876,7 +876,7 @@
     xy->cross_objnum = besto;
     
     double dimval = _sv_scalespace_value(&xy->data_v, bestbin);
-    sv_dim_set_value(p->private->x_d,1,dimval);  
+    _sv_dim_set_thumb(p->private->x_d,1,dimval);  
   }
   
 

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/sushivision.h	2007-08-15 21:37:14 UTC (rev 13550)
@@ -100,27 +100,26 @@
 				 char *name,
 				 unsigned flags);
 
-int            sv_dim_set_scale (sv_dim_t *d,
-				 sv_scale_t *scale);
+sv_dim_t                *sv_dim (char *name);
 
-int           sv_dim_make_scale (sv_dim_t *d,
-				 unsigned scalevals, 
+int            sv_dim_set_scale (sv_scale_t *scale);
+
+int           sv_dim_make_scale (unsigned scalevals, 
 				 double *scaleval_list, 
 				 char **scalelabel_list,
 				 unsigned flags);
 
-int         sv_dim_set_discrete (sv_dim_t *d,
-				 long quant_numerator,
+int         sv_dim_set_discrete (long quant_numerator,
 				 long quant_denominator);
 
-int         sv_dim_set_picklist (sv_dim_t *d);
+int         sv_dim_set_picklist ();
 
-int            sv_dim_set_value (sv_dim_t *d,
-				 int thumb, 
-				 double val);
+int            sv_dim_set_value (double val);
 
-int       sv_dim_callback_value (sv_dim_t *d,
-				 int (*callback)(sv_dim_t *, void*),
+int          sv_dim_set_bracket (double lo,
+				 double hi);
+
+int       sv_dim_callback_value (int (*callback)(sv_dim_t *, void*),
 				 void *callback_data);
 
 /* functions *****************************************************/

Modified: trunk/sushivision/undo.c
===================================================================
--- trunk/sushivision/undo.c	2007-08-15 19:44:39 UTC (rev 13549)
+++ trunk/sushivision/undo.c	2007-08-15 21:37:14 UTC (rev 13550)
@@ -121,9 +121,9 @@
   for(i=0;i<_sv_dimensions;i++){
     sv_dim_t *d = _sv_dimension_list[i];
     if(d){
-      sv_dim_set_value(d, 0, u->dim_vals[0][i]);
-      sv_dim_set_value(d, 1, u->dim_vals[1][i]);
-      sv_dim_set_value(d, 2, u->dim_vals[2][i]);
+      _sv_dim_set_thumb(d, 0, u->dim_vals[0][i]);
+      _sv_dim_set_thumb(d, 1, u->dim_vals[1][i]);
+      _sv_dim_set_thumb(d, 2, u->dim_vals[2][i]);
     }
   }
 



More information about the commits mailing list