X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fdispatcher.cc;h=0d899f94ba7ea27cfcc0b610ee4bd14d0eecb52f;hb=6f14bc3f06c15ead9443df0e284eb87ed34c4fec;hp=a6cee709ce0649497a7b5a500aa8b8351e1200db;hpb=4bb29573149a0ffa1f881c5e38a0fe68e9e76b67;p=lilypond.git diff --git a/lily/dispatcher.cc b/lily/dispatcher.cc index a6cee709ce..0d899f94ba 100644 --- a/lily/dispatcher.cc +++ b/lily/dispatcher.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2005--2011 Erik Sandberg + Copyright (C) 2005--2012 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 @@ -58,7 +58,8 @@ Dispatcher::print_smob (SCM s, SCM p, scm_print_state *) { Dispatcher *me = (Dispatcher *) SCM_CELL_WORD_1 (s); scm_puts ("#listeners_), p); + scm_write (scm_call_1 (ly_lily_module_constant ("hash-table->alist"), + me->listeners_), p); scm_puts (">", p); return 1; } @@ -76,20 +77,16 @@ void Dispatcher::dispatch (SCM sev) { Stream_event *ev = unsmob_stream_event (sev); - SCM class_symbol = ev->get_property ("class"); - if (!scm_symbol_p (class_symbol)) - { - warning (_ ("Event class should be a symbol")); - return; - } - - SCM class_list = scm_call_1 (ly_lily_module_constant ("ly:make-event-class"), class_symbol); + SCM class_list = ev->get_property ("class"); if (!scm_is_pair (class_list)) { - ev->origin ()->warning (_f ("Unknown event class %s", ly_symbol2string (class_symbol).c_str ())); + ev->origin ()->warning (_ ("Event class should be a list")); return; } + +#if 0 bool sent = false; +#endif int num_classes = scm_ilength (class_list); /* @@ -148,7 +145,9 @@ Dispatcher::dispatch (SCM sev) Listener *l = unsmob_listener (scm_cdar (lists[0].list)); l->listen (ev->self_scm ()); +#if 0 sent = true; +#endif } // go to the next listener; bubble-sort the class list. SCM next = scm_cdr (lists[0].list); @@ -161,10 +160,41 @@ Dispatcher::dispatch (SCM sev) lists[i].list = next; } - /* TODO: Uncomment. - if (!sent) - warning (_f ("Junking event: %s", ly_symbol2string (class_symbol).c_str ())); - */ +#if 0 + /* TODO: Uncomment. */ + if (!sent) + warning (_f ("Junking event: %s", ly_symbol2string (class_symbol).c_str ())); +#endif +} + +bool +Dispatcher::is_listened_class (SCM cl) +{ + for (; scm_is_pair (cl); cl = scm_cdr (cl)) + { + SCM list = scm_hashq_ref (listeners_, scm_car (cl), SCM_EOL); + if (scm_is_pair (list)) + return true; + } + return false; +} + +static SCM +accumulate_types (void * /* closure */, + SCM key, + SCM val, + SCM result) +{ + if (scm_is_pair (val)) + return scm_cons (key, result); + return result; +} + +SCM +Dispatcher::listened_types () +{ + return scm_internal_hash_fold ((scm_t_hash_fold_fn) &accumulate_types, + NULL, SCM_EOL, listeners_); } void @@ -229,7 +259,7 @@ Dispatcher::remove_listener (Listener l, SCM ev_class) scm_hashq_set_x (listeners_, ev_class, list); if (first) - warning ("Attempting to remove nonexisting listener."); + warning (_ ("Attempting to remove nonexisting listener.")); else if (!scm_is_pair (list)) { /* Unregister with all dispatchers. */ @@ -251,7 +281,7 @@ Dispatcher::register_as_listener (Dispatcher *disp) // Don't register twice to the same dispatcher. if (scm_assq (disp->self_scm (), dispatchers_) != SCM_BOOL_F) { - warning ("Already listening to dispatcher, ignoring request"); + warning (_ ("Already listening to dispatcher, ignoring request")); return; }