diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-22 21:58:48 +0000 |
commit | 513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch) | |
tree | 10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/g_guiconnect.c | |
parent | 95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff) | |
download | rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip |
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_guiconnect.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/g_guiconnect.c | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_guiconnect.c b/apps/plugins/pdbox/PDa/src/g_guiconnect.c new file mode 100644 index 0000000000..c1673827fe --- /dev/null +++ b/apps/plugins/pdbox/PDa/src/g_guiconnect.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* Copyright (c) 1997-2000 Miller Puckette. | ||
2 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
3 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
4 | |||
5 | /* a thing to forward messages from the GUI, dealing with race conditions | ||
6 | in which the "target" gets deleted while the GUI is sending it something. | ||
7 | */ | ||
8 | |||
9 | #include "m_pd.h" | ||
10 | #include "g_canvas.h" | ||
11 | |||
12 | struct _guiconnect | ||
13 | { | ||
14 | t_object x_obj; | ||
15 | t_pd *x_who; | ||
16 | t_symbol *x_sym; | ||
17 | t_clock *x_clock; | ||
18 | }; | ||
19 | |||
20 | static t_class *guiconnect_class; | ||
21 | |||
22 | t_guiconnect *guiconnect_new(t_pd *who, t_symbol *sym) | ||
23 | { | ||
24 | t_guiconnect *x = (t_guiconnect *)pd_new(guiconnect_class); | ||
25 | x->x_who = who; | ||
26 | x->x_sym = sym; | ||
27 | pd_bind(&x->x_obj.ob_pd, sym); | ||
28 | return (x); | ||
29 | } | ||
30 | |||
31 | /* cleanup routine; delete any resources we have */ | ||
32 | static void guiconnect_free(t_guiconnect *x) | ||
33 | { | ||
34 | if (x->x_sym) | ||
35 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
36 | if (x->x_clock) | ||
37 | clock_free(x->x_clock); | ||
38 | } | ||
39 | |||
40 | /* this is called when the clock times out to indicate the GUI should | ||
41 | be gone by now. */ | ||
42 | static void guiconnect_tick(t_guiconnect *x) | ||
43 | { | ||
44 | pd_free(&x->x_obj.ob_pd); | ||
45 | } | ||
46 | |||
47 | /* the target calls this to disconnect. If the gui has "signed off" | ||
48 | we're ready to delete the object; otherwise we wait either for signoff | ||
49 | or for a timeout. */ | ||
50 | void guiconnect_notarget(t_guiconnect *x, double timedelay) | ||
51 | { | ||
52 | if (!x->x_sym) | ||
53 | pd_free(&x->x_obj.ob_pd); | ||
54 | else | ||
55 | { | ||
56 | x->x_who = 0; | ||
57 | if (timedelay > 0) | ||
58 | { | ||
59 | x->x_clock = clock_new(x, (t_method)guiconnect_tick); | ||
60 | clock_delay(x->x_clock, timedelay); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /* the GUI calls this to send messages to the target. */ | ||
66 | static void guiconnect_anything(t_guiconnect *x, | ||
67 | t_symbol *s, int ac, t_atom *av) | ||
68 | { | ||
69 | if (x->x_who) | ||
70 | typedmess(x->x_who, s, ac, av); | ||
71 | } | ||
72 | |||
73 | /* the GUI calls this when it disappears. (If there's any chance the | ||
74 | GUI will fail to do this, the "target", when it signs off, should specify | ||
75 | a timeout after which the guiconnect will disappear.) */ | ||
76 | static void guiconnect_signoff(t_guiconnect *x) | ||
77 | { | ||
78 | if (!x->x_who) | ||
79 | pd_free(&x->x_obj.ob_pd); | ||
80 | else | ||
81 | { | ||
82 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
83 | x->x_sym = 0; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void g_guiconnect_setup(void) | ||
88 | { | ||
89 | guiconnect_class = class_new(gensym("guiconnect"), 0, | ||
90 | (t_method)guiconnect_free, sizeof(t_guiconnect), CLASS_PD, 0); | ||
91 | class_addanything(guiconnect_class, guiconnect_anything); | ||
92 | class_addmethod(guiconnect_class, (t_method)guiconnect_signoff, | ||
93 | gensym("signoff"), 0); | ||
94 | } | ||
95 | /* Copyright (c) 1997-2000 Miller Puckette. | ||
96 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
97 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
98 | |||
99 | /* a thing to forward messages from the GUI, dealing with race conditions | ||
100 | in which the "target" gets deleted while the GUI is sending it something. | ||
101 | */ | ||
102 | |||
103 | #include "m_pd.h" | ||
104 | #include "g_canvas.h" | ||
105 | |||
106 | struct _guiconnect | ||
107 | { | ||
108 | t_object x_obj; | ||
109 | t_pd *x_who; | ||
110 | t_symbol *x_sym; | ||
111 | t_clock *x_clock; | ||
112 | }; | ||
113 | |||
114 | static t_class *guiconnect_class; | ||
115 | |||
116 | t_guiconnect *guiconnect_new(t_pd *who, t_symbol *sym) | ||
117 | { | ||
118 | t_guiconnect *x = (t_guiconnect *)pd_new(guiconnect_class); | ||
119 | x->x_who = who; | ||
120 | x->x_sym = sym; | ||
121 | pd_bind(&x->x_obj.ob_pd, sym); | ||
122 | return (x); | ||
123 | } | ||
124 | |||
125 | /* cleanup routine; delete any resources we have */ | ||
126 | static void guiconnect_free(t_guiconnect *x) | ||
127 | { | ||
128 | if (x->x_sym) | ||
129 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
130 | if (x->x_clock) | ||
131 | clock_free(x->x_clock); | ||
132 | } | ||
133 | |||
134 | /* this is called when the clock times out to indicate the GUI should | ||
135 | be gone by now. */ | ||
136 | static void guiconnect_tick(t_guiconnect *x) | ||
137 | { | ||
138 | pd_free(&x->x_obj.ob_pd); | ||
139 | } | ||
140 | |||
141 | /* the target calls this to disconnect. If the gui has "signed off" | ||
142 | we're ready to delete the object; otherwise we wait either for signoff | ||
143 | or for a timeout. */ | ||
144 | void guiconnect_notarget(t_guiconnect *x, double timedelay) | ||
145 | { | ||
146 | if (!x->x_sym) | ||
147 | pd_free(&x->x_obj.ob_pd); | ||
148 | else | ||
149 | { | ||
150 | x->x_who = 0; | ||
151 | if (timedelay > 0) | ||
152 | { | ||
153 | x->x_clock = clock_new(x, (t_method)guiconnect_tick); | ||
154 | clock_delay(x->x_clock, timedelay); | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | |||
159 | /* the GUI calls this to send messages to the target. */ | ||
160 | static void guiconnect_anything(t_guiconnect *x, | ||
161 | t_symbol *s, int ac, t_atom *av) | ||
162 | { | ||
163 | if (x->x_who) | ||
164 | typedmess(x->x_who, s, ac, av); | ||
165 | } | ||
166 | |||
167 | /* the GUI calls this when it disappears. (If there's any chance the | ||
168 | GUI will fail to do this, the "target", when it signs off, should specify | ||
169 | a timeout after which the guiconnect will disappear.) */ | ||
170 | static void guiconnect_signoff(t_guiconnect *x) | ||
171 | { | ||
172 | if (!x->x_who) | ||
173 | pd_free(&x->x_obj.ob_pd); | ||
174 | else | ||
175 | { | ||
176 | pd_unbind(&x->x_obj.ob_pd, x->x_sym); | ||
177 | x->x_sym = 0; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | void g_guiconnect_setup(void) | ||
182 | { | ||
183 | guiconnect_class = class_new(gensym("guiconnect"), 0, | ||
184 | (t_method)guiconnect_free, sizeof(t_guiconnect), CLASS_PD, 0); | ||
185 | class_addanything(guiconnect_class, guiconnect_anything); | ||
186 | class_addmethod(guiconnect_class, (t_method)guiconnect_signoff, | ||
187 | gensym("signoff"), 0); | ||
188 | } | ||