2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2015 Erik Sandberg <mandolaerik@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "dispatcher.hh"
22 LY_DEFINE (ly_make_dispatcher, "ly:make-dispatcher",
24 "Return a newly created dispatcher.")
26 return (new Dispatcher ())->unprotect ();
29 LY_DEFINE (ly_connect_dispatchers, "ly:connect-dispatchers",
30 2, 0, 0, (SCM to, SCM from),
31 "Make the dispatcher @var{to} listen to events from @var{from}.")
33 Dispatcher *t = Dispatcher::unsmob (to);
34 Dispatcher *f = Dispatcher::unsmob (from);
36 LY_ASSERT_SMOB (Dispatcher, to, 1);
37 LY_ASSERT_SMOB (Dispatcher, from, 2);
39 t->register_as_listener (f);
41 return SCM_UNSPECIFIED;
44 LY_DEFINE (ly_add_listener, "ly:add-listener",
45 2, 0, 1, (SCM list, SCM disp, SCM cl),
46 "Add the listener @var{list} to the dispatcher @var{disp}."
47 " Whenever @var{disp} hears an event of class @var{cl},"
48 " it is forwarded to @var{list}.")
50 Listener *l = Listener::unsmob (list);
51 Dispatcher *d = Dispatcher::unsmob (disp);
53 LY_ASSERT_SMOB (Listener, list, 1);
54 LY_ASSERT_SMOB (Dispatcher, disp, 2);
56 for (int arg = SCM_ARG3; scm_is_pair (cl); cl = scm_cdr (cl), arg++)
58 SCM sym = scm_car (cl);
59 SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, arg, __FUNCTION__, "symbol");
60 d->add_listener (*l, sym);
63 return SCM_UNSPECIFIED;
66 LY_DEFINE (ly_listened_event_types, "ly:listened-event-types",
68 "Return a list of all event types that @var{disp} listens"
71 LY_ASSERT_SMOB (Dispatcher, disp, 1);
73 SCM result = Dispatcher::unsmob (disp)->listened_types ();
75 scm_remember_upto_here_1 (disp);
80 LY_DEFINE (ly_listened_event_class_p, "ly:listened-event-class?",
81 2, 0, 0, (SCM disp, SCM cl),
82 "Does @var{disp} listen to any event type in the list"
85 LY_ASSERT_SMOB (Dispatcher, disp, 1);
86 LY_ASSERT_TYPE (scm_is_pair, cl, 2);
88 bool result = Dispatcher::unsmob (disp)->is_listened_class (cl);
90 scm_remember_upto_here_1 (disp);
92 return scm_from_bool (result);
95 LY_DEFINE (ly_broadcast, "ly:broadcast",
96 2, 0, 0, (SCM disp, SCM ev),
97 "Send the stream event @var{ev} to the dispatcher @var{disp}.")
99 Dispatcher *d = Dispatcher::unsmob (disp);
100 Stream_event *e = Stream_event::unsmob (ev);
102 LY_ASSERT_SMOB (Dispatcher, disp, 1);
104 LY_ASSERT_SMOB (Stream_event, ev, 2);
106 return SCM_UNSPECIFIED;