2 dispatcher.cc -- implement Scheme bindings for Dispatcher
4 source file of the GNU LilyPond music typesetter
6 (c) 2006--2007 Erik Sandberg <mandolaerik@gmail.com>
9 #include "dispatcher.hh"
11 LY_DEFINE (ly_make_dispatcher, "ly:make-dispatcher",
13 "Return a newly created dispatcher.")
15 return (new Dispatcher ())->unprotect ();
18 LY_DEFINE (ly_connect_dispatchers, "ly:connect-dispatchers",
19 2, 0, 0, (SCM to, SCM from),
20 "Make the dispatcher @var{to} listen to events from @var{from}.")
22 Dispatcher *t = unsmob_dispatcher (to);
23 Dispatcher *f = unsmob_dispatcher (from);
25 LY_ASSERT_SMOB (Dispatcher, to, 1);
26 LY_ASSERT_SMOB (Dispatcher, from, 2);
28 t->register_as_listener (f);
33 LY_DEFINE (ly_add_listener, "ly:add-listener",
34 2, 0, 1, (SCM list, SCM disp, SCM cl),
35 "Add the listener @var{list} to the dispatcher @var{disp}."
36 " Whenever @var{disp} hears an event of class @var{cl},"
37 " it is forwarded to @var{list}.")
39 Listener *l = unsmob_listener (list);
40 Dispatcher *d = unsmob_dispatcher (disp);
42 LY_ASSERT_SMOB (Listener, list, 1);
43 LY_ASSERT_SMOB (Dispatcher, disp, 2);
45 for (int arg = SCM_ARG3; scm_is_pair (cl); cl = scm_cdr (cl), arg++)
47 SCM sym = scm_car (cl);
48 SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, arg, __FUNCTION__, "symbol");
49 d->add_listener (*l, sym);
55 LY_DEFINE (ly_broadcast, "ly:broadcast",
56 2, 0, 0, (SCM disp, SCM ev),
57 "Send the stream event @var{ev} to the dispatcher @var{disp}.")
59 Dispatcher *d = unsmob_dispatcher (disp);
60 Stream_event *e = unsmob_stream_event (ev);
62 LY_ASSERT_SMOB (Dispatcher, disp, 1);
64 LY_ASSERT_SMOB (Stream_event, ev, 2);