X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdispatcher-scheme.cc;h=3fd4decc42b28640ce77f2a76d7ca968e7d909ec;hb=a6a51abfd0195a3cf7d6ea095cf69808852f21ce;hp=9e491e0a9abc185795c01e1c1be5091dd32998da;hpb=87eedcd59f4082cb0841528ad5bc82cb1d1191e3;p=lilypond.git diff --git a/lily/dispatcher-scheme.cc b/lily/dispatcher-scheme.cc index 9e491e0a9a..3fd4decc42 100644 --- a/lily/dispatcher-scheme.cc +++ b/lily/dispatcher-scheme.cc @@ -1,62 +1,121 @@ /* - dispatcher.cc -- implement Scheme bindings for Dispatcher + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2006--2015 Erik Sandberg - (c) 2006--2007 Erik Sandberg + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "dispatcher.hh" LY_DEFINE (ly_make_dispatcher, "ly:make-dispatcher", - 0, 0, 0, (), - "Returns a newly created dispatcher.") + 0, 0, 0, (), + "Return a newly created dispatcher.") { return (new Dispatcher ())->unprotect (); } -LY_DEFINE (ly_register_dispatcher, "ly:connect-dispatchers", - 2, 0, 0, (SCM to, SCM from), - "Makes the dispatcher @var{to} listen to events from @var{from}." ) +LY_DEFINE (ly_connect_dispatchers, "ly:connect-dispatchers", + 2, 0, 0, (SCM to, SCM from), + "Make the dispatcher @var{to} listen to events from @var{from}.") { - Dispatcher *t = unsmob_dispatcher (to); - Dispatcher *f = unsmob_dispatcher (from); - SCM_ASSERT_TYPE (t, from, SCM_ARG1, __FUNCTION__, "dispatcher"); - SCM_ASSERT_TYPE (f, to, SCM_ARG2, __FUNCTION__, "dispatcher"); + Dispatcher *t = unsmob (to); + Dispatcher *f = unsmob (from); + + LY_ASSERT_SMOB (Dispatcher, to, 1); + LY_ASSERT_SMOB (Dispatcher, from, 2); + t->register_as_listener (f); - return SCM_UNDEFINED; + return SCM_UNSPECIFIED; +} + +LY_DEFINE (ly_disconnect_dispatchers, "ly:disconnect-dispatchers", + 2, 0, 0, (SCM to, SCM from), + "Stop the dispatcher @var{to} listening to events from @var{from}.") +{ + Dispatcher *t = unsmob (to); + Dispatcher *f = unsmob (from); + + LY_ASSERT_SMOB (Dispatcher, to, 1); + LY_ASSERT_SMOB (Dispatcher, from, 2); + + t->unregister_as_listener (f); + + return SCM_UNSPECIFIED; } LY_DEFINE (ly_add_listener, "ly:add-listener", - 2, 0, 1, (SCM list, SCM disp, SCM cl), - "Adds the listener @var{list} to the dispatcher @var{disp}.\n" - " Whenever @var{disp} hears an event of class @var{cl}, it will be forwarded to @var{list}.\n" ) + 2, 0, 1, (SCM callback, SCM disp, SCM cl), + "Add the single-argument procedure @var{callback} as listener" + " to the dispatcher @var{disp}. Whenever @var{disp} hears" + " an event of class @var{cl}, it calls @var{callback} with it.") { - Listener *l = unsmob_listener (list); - Dispatcher *d = unsmob_dispatcher (disp); - SCM_ASSERT_TYPE (l, list, SCM_ARG1, __FUNCTION__, "listener"); - SCM_ASSERT_TYPE (d, disp, SCM_ARG2, __FUNCTION__, "dispatcher"); - + Dispatcher *d = unsmob (disp); + + LY_ASSERT_TYPE (ly_is_procedure, callback, 1); + LY_ASSERT_SMOB (Dispatcher, disp, 2); + for (int arg = SCM_ARG3; scm_is_pair (cl); cl = scm_cdr (cl), arg++) { SCM sym = scm_car (cl); SCM_ASSERT_TYPE (scm_is_symbol (sym), sym, arg, __FUNCTION__, "symbol"); - d->add_listener (*l, sym); + d->add_listener (callback, sym); } - return SCM_UNDEFINED; + return SCM_UNSPECIFIED; +} + +LY_DEFINE (ly_listened_event_types, "ly:listened-event-types", + 1, 0, 0, (SCM disp), + "Return a list of all event types that @var{disp} listens" + " to.") +{ + LY_ASSERT_SMOB (Dispatcher, disp, 1); + + SCM result = unsmob (disp)->listened_types (); + + scm_remember_upto_here_1 (disp); + + return result; +} + +LY_DEFINE (ly_listened_event_class_p, "ly:listened-event-class?", + 2, 0, 0, (SCM disp, SCM cl), + "Does @var{disp} listen to any event type in the list" + " @var{cl}?") +{ + LY_ASSERT_SMOB (Dispatcher, disp, 1); + LY_ASSERT_TYPE (scm_is_pair, cl, 2); + + bool result = unsmob (disp)->is_listened_class (cl); + + scm_remember_upto_here_1 (disp); + + return scm_from_bool (result); } LY_DEFINE (ly_broadcast, "ly:broadcast", - 2, 0, 0, (SCM disp, SCM ev), - "Sends the stream event @var{ev} to the dispatcher\n" - "@var{disp}.") + 2, 0, 0, (SCM disp, SCM ev), + "Send the stream event @var{ev} to the dispatcher @var{disp}.") { - Dispatcher *d = unsmob_dispatcher (disp); - Stream_event *e = unsmob_stream_event (ev); - SCM_ASSERT_TYPE (d, disp, SCM_ARG1, __FUNCTION__, "dispatcher"); - SCM_ASSERT_TYPE (e, ev, SCM_ARG2, __FUNCTION__, "stream event"); + Dispatcher *d = unsmob (disp); + Stream_event *e = unsmob (ev); + + LY_ASSERT_SMOB (Dispatcher, disp, 1); + + LY_ASSERT_SMOB (Stream_event, ev, 2); d->broadcast (e); - return SCM_UNDEFINED; + return SCM_UNSPECIFIED; }