X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdispatcher.cc;h=3758f46347da55032002c7555b60216149cf27ce;hb=55d9ad39acee4288ee0d36230f70110b02546ab3;hp=b86d045bc1cb5a01b2657b102e48f1606ca19be0;hpb=c4c0ba811cd526f047de3f4d3c77abcc32a3e076;p=lilypond.git diff --git a/lily/dispatcher.cc b/lily/dispatcher.cc index b86d045bc1..3758f46347 100644 --- a/lily/dispatcher.cc +++ b/lily/dispatcher.cc @@ -1,20 +1,30 @@ /* - dispatcher.cc -- implement Dispatcher + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2012 Erik Sandberg - (c) 2005-2006 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" #include "input.hh" #include "international.hh" #include "ly-smobs.icc" -#include "stream-event.hh" #include "warn.hh" IMPLEMENT_SMOBS (Dispatcher); -IMPLEMENT_TYPE_P (Dispatcher, "dispatcher"); +IMPLEMENT_TYPE_P (Dispatcher, "ly:dispatcher?"); IMPLEMENT_DEFAULT_EQUAL_P (Dispatcher); Dispatcher::~Dispatcher () @@ -44,7 +54,7 @@ Dispatcher::mark_smob (SCM sm) } int -Dispatcher::print_smob (SCM s, SCM p, scm_print_state*) +Dispatcher::print_smob (SCM s, SCM p, scm_print_state *) { Dispatcher *me = (Dispatcher *) SCM_CELL_WORD_1 (s); scm_puts ("#get_property ("class"); - if (!scm_symbol_p (class_symbol)) + if (!scm_is_symbol (class_symbol)) { - warning (_f ("Event class should be a symbol")); + warning (_ ("Event class should be a symbol")); return; } @@ -79,7 +89,9 @@ Dispatcher::dispatch (SCM sev) ev->origin ()->warning (_f ("Unknown event class %s", ly_symbol2string (class_symbol).c_str ())); return; } +#if 0 bool sent = false; +#endif int num_classes = scm_ilength (class_list); /* @@ -99,23 +111,23 @@ Dispatcher::dispatch (SCM sev) The first step is to collect all listener lists and to initially insert them in the priority queue. */ - struct { int prio; SCM list; } lists[num_classes+1]; + struct { int prio; SCM list; } lists[num_classes + 1]; int i = 0; - for (SCM cl = class_list; scm_is_pair(cl); cl = scm_cdr (cl)) + for (SCM cl = class_list; scm_is_pair (cl); cl = scm_cdr (cl)) { SCM list = scm_hashq_ref (listeners_, scm_car (cl), SCM_EOL); - if (!scm_is_pair(list)) - num_classes--; + if (!scm_is_pair (list)) + num_classes--; else - { + { // bubblesort. int prio = scm_to_int (scm_caar (list)); - int j; - for (j = i; j > 0 && lists[j-1].prio > prio; j--) - lists[j] = lists[j-1]; - lists[j].prio = prio; - lists[j].list = list; - i++; + int j; + for (j = i; j > 0 && lists[j - 1].prio > prio; j--) + lists[j] = lists[j - 1]; + lists[j].prio = prio; + lists[j].list = list; + i++; } } lists[num_classes].prio = INT_MAX; @@ -138,23 +150,26 @@ 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); - if (!scm_is_pair(next)) + if (!scm_is_pair (next)) num_classes--; - int prio = (scm_is_pair(next)) ? scm_to_int (scm_caar (next)) : INT_MAX; - for (i = 0; prio > lists[i+1].prio; i++) - lists[i] = lists[i+1]; + int prio = (scm_is_pair (next)) ? scm_to_int (scm_caar (next)) : INT_MAX; + for (i = 0; prio > lists[i + 1].prio; i++) + lists[i] = lists[i + 1]; lists[i].prio = prio; lists[i].list = next; } -/* TODO: Uncomment. +#if 0 + /* TODO: Uncomment. */ if (!sent) warning (_f ("Junking event: %s", ly_symbol2string (class_symbol).c_str ())); -*/ +#endif } void @@ -175,17 +190,17 @@ Dispatcher::internal_add_listener (Listener l, SCM ev_class, int priority) SCM list = scm_hashq_ref (listeners_, ev_class, SCM_EOL); if (!scm_is_pair (list)) { - /* Tell all dispatchers that we listen to, that we want to hear ev_class + /* Tell all dispatchers that we listen to, that we want to hear ev_class events */ - for (SCM disp = dispatchers_; scm_is_pair(disp); disp = scm_cdr (disp)) - { - int priority = scm_to_int (scm_cdar (disp)); - Dispatcher *d = unsmob_dispatcher (scm_caar (disp)); - d->internal_add_listener (GET_LISTENER (dispatch), ev_class, priority); - } + for (SCM disp = dispatchers_; scm_is_pair (disp); disp = scm_cdr (disp)) + { + int priority = scm_to_int (scm_cdar (disp)); + Dispatcher *d = unsmob_dispatcher (scm_caar (disp)); + d->internal_add_listener (GET_LISTENER (dispatch), ev_class, priority); + } listen_classes_ = scm_cons (ev_class, listen_classes_); } - SCM entry = scm_cons (scm_int2num (priority), l.smobbed_copy ()); + SCM entry = scm_cons (scm_from_int (priority), l.smobbed_copy ()); list = scm_merge (list, scm_list_1 (entry), ly_lily_module_constant ("car<")); scm_hashq_set_x (listeners_, ev_class, list); } @@ -206,12 +221,12 @@ Dispatcher::remove_listener (Listener l, SCM ev_class) SCM dummy = scm_cons (SCM_EOL, list); SCM e = dummy; - while (scm_is_pair(scm_cdr (e))) + while (scm_is_pair (scm_cdr (e))) if (*unsmob_listener (scm_cdadr (e)) == l && first) { - scm_set_cdr_x (e, scm_cddr(e)); - first = false; - break; + scm_set_cdr_x (e, scm_cddr (e)); + first = false; + break; } else e = scm_cdr (e); @@ -223,11 +238,11 @@ Dispatcher::remove_listener (Listener l, SCM ev_class) else if (!scm_is_pair (list)) { /* Unregister with all dispatchers. */ - for (SCM disp = dispatchers_; disp != SCM_EOL; disp = scm_cdr (disp)) - { - Dispatcher *d = unsmob_dispatcher (scm_caar (disp)); - d->remove_listener (GET_LISTENER (dispatch), ev_class); - } + for (SCM disp = dispatchers_; scm_is_pair (disp); disp = scm_cdr (disp)) + { + Dispatcher *d = unsmob_dispatcher (scm_caar (disp)); + d->remove_listener (GET_LISTENER (dispatch), ev_class); + } listen_classes_ = scm_delq_x (ev_class, listen_classes_); } } @@ -245,10 +260,10 @@ Dispatcher::register_as_listener (Dispatcher *disp) return; } - dispatchers_ = scm_acons (disp->self_scm (), scm_int2num (priority), dispatchers_); + dispatchers_ = scm_acons (disp->self_scm (), scm_from_int (priority), dispatchers_); Listener list = GET_LISTENER (dispatch); - for (SCM cl = listen_classes_; cl != SCM_EOL; cl = scm_cdr (cl)) + for (SCM cl = listen_classes_; scm_is_pair (cl); cl = scm_cdr (cl)) { disp->internal_add_listener (list, scm_car (cl), priority); }