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. */
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.
20 static t_class
*guiconnect_class
;
22 t_guiconnect
*guiconnect_new(t_pd
*who
, t_symbol
*sym
)
24 t_guiconnect
*x
= (t_guiconnect
*)pd_new(guiconnect_class
);
27 pd_bind(&x
->x_obj
.ob_pd
, sym
);
31 /* cleanup routine; delete any resources we have */
32 static void guiconnect_free(t_guiconnect
*x
)
35 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
37 clock_free(x
->x_clock
);
40 /* this is called when the clock times out to indicate the GUI should
42 static void guiconnect_tick(t_guiconnect
*x
)
44 pd_free(&x
->x_obj
.ob_pd
);
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
50 void guiconnect_notarget(t_guiconnect
*x
, double timedelay
)
53 pd_free(&x
->x_obj
.ob_pd
);
59 x
->x_clock
= clock_new(x
, (t_method
)guiconnect_tick
);
60 clock_delay(x
->x_clock
, timedelay
);
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
)
70 typedmess(x
->x_who
, s
, ac
, av
);
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
)
79 pd_free(&x
->x_obj
.ob_pd
);
82 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
87 void g_guiconnect_setup(void)
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);
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. */
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.
104 #include "g_canvas.h"
114 static t_class
*guiconnect_class
;
116 t_guiconnect
*guiconnect_new(t_pd
*who
, t_symbol
*sym
)
118 t_guiconnect
*x
= (t_guiconnect
*)pd_new(guiconnect_class
);
121 pd_bind(&x
->x_obj
.ob_pd
, sym
);
125 /* cleanup routine; delete any resources we have */
126 static void guiconnect_free(t_guiconnect
*x
)
129 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
131 clock_free(x
->x_clock
);
134 /* this is called when the clock times out to indicate the GUI should
136 static void guiconnect_tick(t_guiconnect
*x
)
138 pd_free(&x
->x_obj
.ob_pd
);
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
144 void guiconnect_notarget(t_guiconnect
*x
, double timedelay
)
147 pd_free(&x
->x_obj
.ob_pd
);
153 x
->x_clock
= clock_new(x
, (t_method
)guiconnect_tick
);
154 clock_delay(x
->x_clock
, timedelay
);
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
)
164 typedmess(x
->x_who
, s
, ac
, av
);
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
)
173 pd_free(&x
->x_obj
.ob_pd
);
176 pd_unbind(&x
->x_obj
.ob_pd
, x
->x_sym
);
181 void g_guiconnect_setup(void)
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);