From 3cc78b56f1b3284ebb580063f8cf9dae97ba0d39 Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Wed, 18 Sep 2013 22:17:04 -0400
Subject: [PATCH] fixed nasty regression where sliders got cross-contaminated
 in terms of last passed float

---
 pd/src/g_all_guis.h |  4 ++++
 pd/src/g_hslider.c  | 15 +++++++--------
 pd/src/g_vslider.c  | 15 +++++++--------
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/pd/src/g_all_guis.h b/pd/src/g_all_guis.h
index 83e4aba96..fed1c127a 100644
--- a/pd/src/g_all_guis.h
+++ b/pd/src/g_all_guis.h
@@ -248,6 +248,8 @@ typedef struct _hslider
     double   x_min;
     double   x_max;
     double   x_k;
+    double   x_last;
+    int      x_is_last_float;
 } t_hslider;
 
 typedef struct _hdial
@@ -288,6 +290,8 @@ typedef struct _vslider
     double   x_min;
     double   x_max;
     double   x_k;
+    double   x_last;
+    int      x_is_last_float;
 } t_vslider;
 
 typedef struct _vu
diff --git a/pd/src/g_hslider.c b/pd/src/g_hslider.c
index 594c4da6a..5f7ce6386 100644
--- a/pd/src/g_hslider.c
+++ b/pd/src/g_hslider.c
@@ -33,9 +33,6 @@ static void hslider_draw_select(t_hslider* x,t_glist* glist);
 t_widgetbehavior hslider_widgetbehavior;
 static t_class *hslider_class;
 
-static double last;
-static int is_last_float = 0;
-
 /* widget helper functions */
 
 static void hslider_draw_update(t_gobj *client, t_glist *glist)
@@ -648,8 +645,8 @@ static void hslider_bang(t_hslider *x)
     if(x->x_lin0_log1)
         out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
     else {
-		if (is_last_float && last <= x->x_max && last >= x->x_min)
-			out = last;
+		if (x->x_is_last_float && x->x_last <= x->x_max && x->x_last >= x->x_min)
+			out = x->x_last;
 		else
         	out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
 	}
@@ -705,7 +702,7 @@ static void hslider_dialog(t_hslider *x, t_symbol *s, int argc, t_atom *argv)
 
 static void hslider_motion(t_hslider *x, t_floatarg dx, t_floatarg dy)
 {
-	is_last_float = 0;
+	x->x_is_last_float = 0;
     int old = x->x_val;
 
     if(x->x_gui.x_fsf.x_finemoved)
@@ -828,8 +825,8 @@ static void hslider_steady(t_hslider *x, t_floatarg f)
 static void hslider_float(t_hslider *x, t_floatarg f)
 {
     double out;
-	is_last_float = 1;
-	last = f;
+	x->x_is_last_float = 1;
+	x->x_last = f;
 
     hslider_set(x, f);
     if(x->x_lin0_log1)
@@ -906,6 +903,8 @@ static void *hslider_new(t_symbol *s, int argc, t_atom *argv)
 
     x->x_gui.x_fsf.x_snd_able = 1;
     x->x_gui.x_fsf.x_rcv_able = 1;
+	x->x_is_last_float = 0;
+	x->x_last = 0.0;
 
     x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
     if(x->x_gui.x_isa.x_loadinit)
diff --git a/pd/src/g_vslider.c b/pd/src/g_vslider.c
index 9821bd815..92991fd39 100644
--- a/pd/src/g_vslider.c
+++ b/pd/src/g_vslider.c
@@ -33,9 +33,6 @@ static void vslider_draw_select(t_vslider* x, t_glist* glist);
 t_widgetbehavior vslider_widgetbehavior;
 static t_class *vslider_class;
 
-static double last;
-static int is_last_float = 0;
-
 /* widget helper functions */
 
 static void vslider_draw_update(t_gobj *client, t_glist *glist)
@@ -632,8 +629,8 @@ static void vslider_bang(t_vslider *x)
     if(x->x_lin0_log1)
         out = x->x_min*exp(x->x_k*(double)(x->x_val)*0.01);
     else
-		if (is_last_float && last <= x->x_max && last >= x->x_min)
-			out = last;
+		if (x->x_is_last_float && x->x_last <= x->x_max && x->x_last >= x->x_min)
+			out = x->x_last;
 		else
         	out = (double)(x->x_val)*0.01*x->x_k + x->x_min;
     if((out < 1.0e-10)&&(out > -1.0e-10))
@@ -689,7 +686,7 @@ static void vslider_dialog(t_vslider *x, t_symbol *s, int argc, t_atom *argv)
 
 static void vslider_motion(t_vslider *x, t_floatarg dx, t_floatarg dy)
 {
-	is_last_float = 0;
+	x->x_is_last_float = 0;
     int old = x->x_val;
 
     if(x->x_gui.x_fsf.x_finemoved)
@@ -778,8 +775,8 @@ static void vslider_set(t_vslider *x, t_floatarg f)
 
 static void vslider_float(t_vslider *x, t_floatarg f)
 {
-	is_last_float = 1;
-	last = f;
+	x->x_is_last_float = 1;
+	x->x_last = f;
     vslider_set(x, f);
     if(x->x_gui.x_fsf.x_put_in2out)
         vslider_bang(x);
@@ -899,6 +896,8 @@ static void *vslider_new(t_symbol *s, int argc, t_atom *argv)
     x->x_gui.x_draw = (t_iemfunptr)vslider_draw;
     x->x_gui.x_fsf.x_snd_able = 1;
     x->x_gui.x_fsf.x_rcv_able = 1;
+	x->x_is_last_float = 0;
+	x->x_last = 0.0;
     x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
     if(x->x_gui.x_isa.x_loadinit)
         x->x_val = v;
-- 
GitLab