aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas O Fredericks <mrtof@users.sourceforge.net>2010-10-15 14:54:54 +0000
committerThomas O Fredericks <mrtof@users.sourceforge.net>2010-10-15 14:54:54 +0000
commit8102caed3cf783ec66de121b4124402089879f38 (patch)
tree151da5e6ee74cce55ffa9aed790bf0c032ca920a /src
parent64ba4057878501b14d2a21cba5a601548246d9e8 (diff)
Added propertybang to paramGui
svn path=/trunk/externals/tof/; revision=14230
Diffstat (limited to 'src')
-rw-r--r--src/objectlist.h162
-rw-r--r--src/paramGui.h45
2 files changed, 192 insertions, 15 deletions
diff --git a/src/objectlist.h b/src/objectlist.h
new file mode 100644
index 0000000..ebadf4b
--- /dev/null
+++ b/src/objectlist.h
@@ -0,0 +1,162 @@
+/******************************************************
+ *
+ * This file is based on iem_objlist.h by IOhannes m zmölnig
+ *
+ * Original copyleft (c):
+ * IOhannes m zmölnig
+ *
+ * 2008:forum::für::umläute:2008
+ *
+ * institute of electronic music and acoustics (iem)
+ *
+ ******************************************************
+ *
+ * license: GNU General Public License v.2
+ *
+ ******************************************************/
+
+/* this file implements some helperr functions for dealing with lists of
+ * objects (containing other objects)
+ *
+ * used for callbacks to enumerated objects without $0 tricks
+ */
+
+
+
+//#include "m_pd.h"
+
+/*
+ The basic element is a parent.
+ Elements can then be added/removed to/from this parent.
+
+ */
+
+
+/* ------------------------- helper methods for callbacks ---------------------------- */
+
+typedef struct _objectlist_element {
+ const t_pd* obj;
+ struct _objectlist_element* next;
+} t_objectlist_element;
+
+typedef struct _objectlist_list {
+ const t_pd* parent;
+ t_objectlist_element* obj;
+
+ struct _objectlist_list *next;
+} t_objectlist_list;
+
+static t_objectlist_list* static_list=0;
+
+
+// Find a list with the specified parent
+static t_objectlist_list* getList(const t_pd*parent) {
+ t_objectlist_list* list = static_list;
+ if(0==parent || 0==list)
+ return 0;
+
+ for(list=static_list; list; list=list->next) {
+ if(parent == list->parent) {
+ return list;
+ }
+ }
+ return 0;
+}
+
+static t_objectlist_list* addList(const t_pd* parent)
+{
+ t_objectlist_list* list=getList(parent);
+ if(!list) {
+ list=(t_objectlist_list*)getbytes(sizeof(t_objectlist_list));
+ list->parent=parent;
+ list->obj=0;
+ list->next=0;
+
+ if(0==static_list) {
+ /* new list */
+ static_list=list;
+ } else {
+ /* add to the end of existing list */
+ t_objectlist_list* dummy=static_list;
+ while(dummy->next)
+ dummy=dummy->next;
+ dummy->next = list;
+ }
+ }
+ return list;
+}
+
+static t_objectlist_element* getElements (const t_pd*parent) {
+ t_objectlist_list* list = getList(parent);
+ if(list)
+ return list->obj;
+
+ return 0;
+}
+
+// Add element to a list
+static void addElement (const t_pd*parent, const t_pd*obj) {
+ t_objectlist_list* p=addList(parent);
+ t_objectlist_element* list=0;
+ t_objectlist_element* entry=0;
+ if(!p || !obj)
+ return;
+ list=p->obj;
+
+ if(list&&obj==list->obj)
+ return;
+
+ while(list && list->next) {
+ if(obj==list->obj) /* obj already in list */
+ return;
+ list=list->next;
+ }
+
+ /* we are at the end of the list that does not contain obj yet, so add it */
+ entry=(t_objectlist_element*)getbytes(sizeof(t_objectlist_element));
+ entry->obj=obj;
+ entry->next=0;
+ if(list) {
+ list->next=entry;
+ } else {
+ p->obj=entry;
+ }
+}
+
+// Remove element from list
+static void removeElement(const t_pd*parent, const t_pd*obj) {
+ t_objectlist_list* p=getList(parent);
+ t_objectlist_element* list=0, *last=0, *next=0;
+ if(!p || !obj)return;
+ list=p->obj;
+ if(!list)
+ return;
+
+ while(list && obj!=list->obj) {
+ last=list;
+ list=list->next;
+ }
+
+ if(!list) /* couldn't find this object */
+ return;
+
+ next=list->next;
+
+ if(last)
+ last->next=next;
+ else
+ p->obj=next;
+
+ freebytes((void*)list, sizeof(t_objectlist_element));
+ list=0;
+}
+
+// Remove element from all lists!
+static void removeElementFromLists(const t_pd*obj) {
+ t_objectlist_list* parents=static_list;
+
+ while(parents) {
+ removeElement(parents->parent, obj);
+ parents=parents->next;
+ }
+}
diff --git a/src/paramGui.h b/src/paramGui.h
index 2ed235e..6e688df 100644
--- a/src/paramGui.h
+++ b/src/paramGui.h
@@ -1,11 +1,13 @@
+#include "objectlist.h"
+
+
-static t_class *paramGui_class;
#define GUI_X_STEP 200
#define GUI_Y_STEP 18
/*
- Version 0.3
+ Version 0.4
*/
@@ -13,6 +15,7 @@ static t_class *paramGui_class;
/*
CHANGES
+ 0.4 Added property bang code from iemguts (and objectlist.h)
0.3 Removed absolute paths. The path must start with a 'p'
0.2 Added a symbol message handler and a subpath variable
0.2 Banging inlet 2 resets the gui but does not recreate it (as before)
@@ -21,7 +24,8 @@ static t_class *paramGui_class;
*/
-
+static t_class *paramGui_class;
+static t_propertiesfn originalproperties=NULL;
typedef struct _paramGui
{
@@ -400,18 +404,22 @@ static void paramGui_free(t_paramGui *x)
if (x->receive) {
pd_unbind(&x->x_obj.ob_pd,x->receive);
}
+
+ removeElementFromLists((t_pd*)x);
+
}
-/*
- static void paramGui_properties(t_gobj*z, t_glist*owner) {
- t_iemguts_objlist*objs=objectsInCanvas((t_pd*)z);
- while(objs) {
- t_propertybang*x=(t_propertybang*)objs->obj;
- propertybang_bang(x);
- objs=objs->next;
- }
- }
- */
+static void paramGui_properties(t_gobj*z, t_glist*owner) {
+ t_objectlist_element* objs= getElements((t_pd*)z);
+ if(NULL==objs) {
+ originalproperties(z, owner);
+ }
+ while(objs) {
+ t_paramGui*x = (t_paramGui*)objs->obj;
+ paramGui_bang(x);
+ objs=objs->next;
+ }
+}
static void *paramGui_new(t_symbol *s, int ac, t_atom *av) {
t_paramGui *x = (t_paramGui *)pd_new(paramGui_class);
@@ -468,9 +476,16 @@ static void *paramGui_new(t_symbol *s, int ac, t_atom *av) {
// SET THE PROPERTIES FUNCTION
- //t_class *class = ((t_gobj*)currentcanvas)->g_pd;
- //class_setpropertiesfn(class, propertybang_properties);
+ t_class *class = ((t_gobj*)currentcanvas)->g_pd;
+ t_propertiesfn properties_tmp=NULL;
+ properties_tmp=class_getpropertiesfn(class);
+ if(properties_tmp!=paramGui_properties)
+ originalproperties=properties_tmp;
+
+ class_setpropertiesfn(class, paramGui_properties);
+
+ addElement((t_pd*)currentcanvas, (t_pd*)x);
return (x);
}