aboutsummaryrefslogtreecommitdiff
path: root/src/propertybang.c
blob: 79b921fc8260c240fca9315fd502c0f2d781eb12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

/******************************************************
 *
 * propertybang - implementation file
 *
 * copyleft (c) IOhannes m zmölnig
 *
 *   2007:forum::für::umläute:2010
 *
 *   institute of electronic music and acoustics (iem)
 *
 ******************************************************
 *
 * license: GNU General Public License v.2
 *
 ******************************************************/


/* 
 * this object provides a way to make an abstraction "property" aware
 * usage:
 *   + put this object into an abstraction
 *   + put the abstraction in a patch
 *   + you can now right-click on the abstraction and select the "properties" menu
 *   + selecting the "properties" menu, will send a bang to the outlet of this object
 *
 * nice, eh?
 */


#include "iemguts-objlist.h"
#include "g_canvas.h"


/* ------------------------- propertybang ---------------------------- */

static t_class *propertybang_class;

typedef struct _propertybang
{
  t_object  x_obj;
} t_propertybang;


t_propertiesfn s_orgfun=NULL;

static void propertybang_free(t_propertybang *x)
{
  removeObjectFromCanvases((t_pd*)x);
}

static void propertybang_bang(t_propertybang *x) {
  outlet_bang(x->x_obj.ob_outlet);
}

static void propertybang_properties(t_gobj*z, t_glist*owner) {
  t_iemguts_objlist*objs=objectsInCanvas((t_pd*)z);
  if(NULL==objs) {
    s_orgfun(z, owner);
  }
  while(objs) {
    t_propertybang*x=(t_propertybang*)objs->obj;
    propertybang_bang(x);
    objs=objs->next;
  } 
}

static void *propertybang_new(void)
{
  t_propertybang *x = (t_propertybang *)pd_new(propertybang_class);
  t_glist *glist=(t_glist *)canvas_getcurrent();
  t_canvas *canvas=(t_canvas*)glist_getcanvas(glist);
  t_class *class = ((t_gobj*)canvas)->g_pd;
  t_propertiesfn orgfun=NULL;
 
  outlet_new(&x->x_obj, &s_bang);

  orgfun=class_getpropertiesfn(class);
  if(orgfun!=propertybang_properties)
    s_orgfun=orgfun;
  
  class_setpropertiesfn(class, propertybang_properties);

  addObjectToCanvas((t_pd*)canvas, (t_pd*)x);
  return (x);
}

void propertybang_setup(void)
{
  propertybang_class = class_new(gensym("propertybang"), (t_newmethod)propertybang_new,
    (t_method)propertybang_free, sizeof(t_propertybang), CLASS_NOINLET, 0);
  class_addbang(propertybang_class, propertybang_bang);

  s_orgfun=NULL;
}