aboutsummaryrefslogtreecommitdiff
path: root/src/propertybang.c
blob: d100ad31af77982380ec8aeef276218ac5f1cb6a (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

/******************************************************
 *
 * propertybang - implementation file
 *
 * copyleft (c) IOhannes m zm-bölnig-A
 *
 *   2007:forum::f-bür::umläute:2007-A
 *
 *   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;


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);
   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;

  outlet_new(&x->x_obj, &s_bang);

  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);
}