[PD-dev] adding a built-in [change] object to the built-in GUI objects

Hans-Christoph Steiner hans at at.or.at
Sat Dec 1 05:20:53 CET 2012


Lots of patches use the built-in GUI objects for displays, and often a fast stream of events is hooked straight up to the GUI object, causing the GUI object to send many pointless updates, like draw commands when the number hasn't changed, or multiple draw commands per screen refresh cycle.

I propose to only send the GUI update commands when the relevant value has changed.  I think this should apply to both the main element, like the slider knob, and the label for that GUI object, since that's often used as a display.  The code change is pretty simple, but I was wondering if people thought there could be any problems caused by this

Here is the needed change, for example, for the hslider knob:

index b352fb9..88681fc 100644
--- a/src/g_all_guis.h
+++ b/src/g_all_guis.h
@@ -185,6 +185,7 @@ typedef struct _hslider
     t_iemgui x_gui;
     int      x_pos;
     int      x_val;
+    int      x_prev_val;
     int      x_center;
     int      x_thick;
     int      x_lin0_log1;
index 470771a..e1a3c83 100644
--- a/src/g_hslider.c
+++ b/src/g_hslider.c
@@ -33,7 +33,7 @@ static t_class *hslider_class;
 static void hslider_draw_update(t_gobj *client, t_glist *glist)
 {
     t_hslider *x = (t_hslider *)client;
-    if (glist_isvisible(glist))
+    if (glist_isvisible(glist) && x->x_val != x->x_prev_val)
     {
         int r = text_xpix(&x->x_gui.x_obj, glist) + (x->x_val + 50)/100;
         int ypos=text_ypix(&x->x_gui.x_obj, glist);
@@ -57,6 +57,7 @@ static void hslider_draw_update(t_gobj *client, t_glist *glist)
                 x->x_thick = 0;
             }
         }
+        x->x_prev_val = x->x_val;
     }
 }





More information about the Pd-dev mailing list