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
|
/******************************************************
*
* 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 "m_pd.h"
#include "g_canvas.h"
/* ------------------------- propertybang ---------------------------- */
static t_class *propertybang_class;
typedef struct _propertybang
{
t_object x_obj;
t_symbol *x_d0name;
} t_propertybang;
static void propertybang_free(t_propertybang *x)
{
pd_unbind(&x->x_obj.ob_pd, x->x_d0name);
}
static void propertybang_anything(t_propertybang *x, t_symbol*s, int argc, t_atom*argv) {
if(s==&s_bang && argc==0) {
outlet_bang(x->x_obj.ob_outlet);
}
}
static void propertybang_properties(t_gobj*z, t_glist*owner) {
// argh: z is the abstraction! but we need to access ourselfs!
// we handle this by binding to a special symbol. e.g. "$0-propertybang"
t_symbol*s_d0name=canvas_realizedollar((t_canvas*)z, gensym("$0 propertybang"));
pd_bang(s_d0name->s_thing);
}
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);
x->x_d0name=canvas_realizedollar(canvas, gensym("$0 propertybang"));
pd_bind(&x->x_obj.ob_pd, x->x_d0name);
class_setpropertiesfn(class, propertybang_properties);
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_addanything(propertybang_class, propertybang_anything);
}
|