X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fscheme-engraver.cc;h=8d2054161bf716b577c4f4a4c61442cbd584cd13;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=476f6d4dea610e2efb532373884047d77917bd8e;hpb=bc95f4434f760d41191341ab4508b2064eb19025;p=lilypond.git diff --git a/lily/scheme-engraver.cc b/lily/scheme-engraver.cc index 476f6d4dea..8d2054161b 100644 --- a/lily/scheme-engraver.cc +++ b/lily/scheme-engraver.cc @@ -1,9 +1,9 @@ -/* +/* scheme-engraver.cc -- implement Scheme_engraver - + source file of the GNU LilyPond music typesetter - - Copyright (c) 2009--2010 Han-Wen Nienhuys + + Copyright (c) 2009--2015 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ 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 . + along with LilyPond. If not, see . */ #include "scheme-engraver.hh" @@ -71,12 +71,12 @@ void Scheme_engraver::init_from_scheme (SCM definition) { start_translation_timestep_function_ = callable (ly_symbol2scm ("start-translation-timestep"), - definition); + definition); stop_translation_timestep_function_ = callable (ly_symbol2scm ("stop-translation-timestep"), - definition); + definition); process_music_function_ = callable (ly_symbol2scm ("process-music"), definition); process_acknowledged_function_ = callable (ly_symbol2scm ("process-acknowledged"), - definition); + definition); initialize_function_ = callable (ly_symbol2scm ("initialize"), definition); finalize_function_ = callable (ly_symbol2scm ("finalize"), definition); @@ -85,9 +85,9 @@ Scheme_engraver::init_from_scheme (SCM definition) listeners_alist_ = SCM_EOL; must_be_last_ = to_boolean (ly_assoc_get (ly_symbol2scm ("must-be-last"), - definition, - SCM_BOOL_F)); - + definition, + SCM_BOOL_F)); + translator_listener_record **tail = &per_instance_listeners_; for (SCM p = listeners; scm_is_pair (p); p = scm_cdr (p)) { @@ -95,10 +95,10 @@ Scheme_engraver::init_from_scheme (SCM definition) SCM proc = scm_cdar (p); if (!(ly_is_procedure (proc) && ly_is_symbol (event_class))) - continue; + continue; // We should check the arity of the function? - + // Record for later lookup. listeners_alist_ = scm_acons (event_class, proc, listeners_alist_); @@ -109,13 +109,13 @@ Scheme_engraver::init_from_scheme (SCM definition) tail = &rec->next_; } - init_acknowledgers (ly_assoc_get(ly_symbol2scm ("acknowledgers"), - definition, SCM_EOL), - &interface_acknowledger_hash_); - - init_acknowledgers (ly_assoc_get(ly_symbol2scm ("end-acknowledgers"), - definition, SCM_EOL), - &interface_end_acknowledger_hash_); + init_acknowledgers (ly_assoc_get (ly_symbol2scm ("acknowledgers"), + definition, SCM_EOL), + &interface_acknowledger_hash_); + + init_acknowledgers (ly_assoc_get (ly_symbol2scm ("end-acknowledgers"), + definition, SCM_EOL), + &interface_end_acknowledger_hash_); // TODO: hook up description, props read/written, grobs created // etc. to provide automatic documentation. @@ -123,16 +123,16 @@ Scheme_engraver::init_from_scheme (SCM definition) void Scheme_engraver::init_acknowledgers (SCM alist, - SCM *hash) -{ - *hash = scm_c_make_hash_table(7); + SCM *hash) +{ + *hash = scm_c_make_hash_table (7); for (SCM p = alist; scm_is_pair (p); p = scm_cdr (p)) { SCM iface = scm_caar (p); SCM proc = scm_cdar (p); if (!(ly_is_procedure (proc) && ly_is_symbol (iface))) - continue; + continue; scm_hashq_set_x (*hash, iface, proc); } @@ -141,7 +141,7 @@ Scheme_engraver::init_acknowledgers (SCM alist, // This is the easy way to do it, at the cost of too many invocations // of Scheme_engraver::acknowledge_grob. The clever dispatching of // acknowledgers is hardwired to have 1 method per engraver per -// grob-type, which doesn't work for this case. +// grob-type, which doesn't work for this case. void Scheme_engraver::acknowledge_grob (Grob_info info) { @@ -156,18 +156,18 @@ Scheme_engraver::acknowledge_end_grob (Grob_info info) void Scheme_engraver::acknowledge_grob_by_hash (Grob_info info, - SCM iface_function_hash) + SCM iface_function_hash) { - SCM meta = info.grob ()->internal_get_property (ly_symbol2scm ("meta")); + SCM meta = info.grob ()->get_property ("meta"); SCM ifaces = scm_cdr (scm_assoc (ly_symbol2scm ("interfaces"), meta)); for (SCM s = ifaces; scm_is_pair (s); s = scm_cdr (s)) { SCM func = scm_hashq_ref (iface_function_hash, - scm_car (s), SCM_BOOL_F); + scm_car (s), SCM_BOOL_F); if (ly_is_procedure (func)) - scm_call_3 (func, self_scm (), info.grob ()->self_scm (), - info.origin_translator ()->self_scm ()); + scm_call_3 (func, self_scm (), info.grob ()->self_scm (), + info.origin_translator ()->self_scm ()); } } @@ -186,42 +186,53 @@ void mark_listen_closure (void *target) scm_gc_mark ((SCM)target); } -Listener_function_table listen_closure = { - call_listen_closure, mark_listen_closure +static +bool equal_listen_closure (void *a, void *b) +{ + SCM target_a = (SCM) a; + SCM target_b = (SCM) b; + + return ly_is_equal (target_a, target_b); +} + +Listener_function_table listen_closure += +{ + call_listen_closure, mark_listen_closure, equal_listen_closure }; /* static */ Listener Scheme_engraver::get_listener (void *arg, SCM name) { - Scheme_engraver *me = (Scheme_engraver*) arg; + Scheme_engraver *me = (Scheme_engraver *) arg; SCM func = ly_assoc_get (name, me->listeners_alist_, SCM_BOOL_F); assert (ly_is_procedure (func)); - SCM closure = scm_cons (func, me->self_scm()); - return Listener((void*)closure, &listen_closure); + SCM closure = scm_cons (func, me->self_scm ()); + return Listener ((void *)closure, &listen_closure); } translator_listener_record * -Scheme_engraver::get_listener_list () const -{ +Scheme_engraver::get_listener_list () const +{ return per_instance_listeners_; } -#define DISPATCH(what) \ - void \ - Scheme_engraver::what () \ - { \ - if (what ## _function_ != SCM_BOOL_F) \ - scm_call_1 (what ## _function_, self_scm ()); \ +#define DISPATCH(what) \ + void \ + Scheme_engraver::what () \ + { \ + if (what ## _function_ != SCM_BOOL_F) \ + scm_call_1 (what ## _function_, self_scm ()); \ } -DISPATCH(start_translation_timestep); -DISPATCH(stop_translation_timestep); -DISPATCH(initialize); -DISPATCH(finalize); -DISPATCH(process_music); -DISPATCH(process_acknowledged); +DISPATCH (start_translation_timestep); +DISPATCH (stop_translation_timestep); +DISPATCH (initialize); +DISPATCH (finalize); +DISPATCH (process_music); +DISPATCH (process_acknowledged); void Scheme_engraver::derived_mark () const @@ -232,25 +243,25 @@ Scheme_engraver::derived_mark () const scm_gc_mark (finalize_function_); scm_gc_mark (process_music_function_); scm_gc_mark (process_acknowledged_function_); - scm_gc_mark (listeners_alist_); - scm_gc_mark (interface_acknowledger_hash_); - scm_gc_mark (interface_end_acknowledger_hash_); -} + scm_gc_mark (listeners_alist_); + scm_gc_mark (interface_acknowledger_hash_); + scm_gc_mark (interface_end_acknowledger_hash_); +} ADD_ACKNOWLEDGER (Scheme_engraver, grob); ADD_END_ACKNOWLEDGER (Scheme_engraver, grob); ADD_TRANSLATOR (Scheme_engraver, - /* doc */ - "Implement engravers in Scheme. Interprets arguments to @code{\\consists} " - "as callbacks. ", + /* doc */ + "Implement engravers in Scheme. Interprets arguments to" + " @code{\\consists} as callbacks.", - /* create */ - "", + /* create */ + "", - /* read */ - "", + /* read */ + "", - /* write */ - "" - ); + /* write */ + "" + );