X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftranslator.cc;h=9ebe2cd4bf97fcc829030087c4b0e0713450e106;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=d90c8be045b4b3526ab778e5d54862037171469e;hpb=5f2a9e631fb2415fe1c97d372243de90b6807917;p=lilypond.git diff --git a/lily/translator.cc b/lily/translator.cc index d90c8be045..9ebe2cd4bf 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2006 Han-Wen Nienhuys + (c) 1997--2008 Han-Wen Nienhuys */ #include "translator.hh" @@ -132,7 +132,8 @@ ensure_listened_hash () LY_DEFINE (ly_get_listened_event_classes, "ly:get-listened-event-classes", 0, 0, 0, (), - "Returns a list of all event classes that some translator listens to.") + "Return a list of all event classes that some translator listens" + " to.") { ensure_listened_hash (); return ly_hash_table_keys (listened_event_class_table); @@ -170,7 +171,7 @@ Translator::add_translator_listener (translator_listener_record **listener_list, { /* ev_class is the C++ identifier name. Convert to scm symbol */ string name = string (ev_class); - name = replace_all (name, '_', '-'); + name = replace_all (&name, '_', '-'); name += "-event"; SCM class_sym = scm_str2symbol (name.c_str ()); @@ -184,19 +185,38 @@ Translator::add_translator_listener (translator_listener_record **listener_list, } /* - Used by ADD_THIS_TRANSLATOR to extract a list of event-class names - for each translator. This list is used by the internals - documentation. + Helps the individual static_translator_description methods of translators. */ SCM -Translator::get_listened_class_list (const translator_listener_record *listeners) const +Translator::static_translator_description (const char *grobs, + const char *desc, + translator_listener_record *listener_list, + const char *read, + const char *write) const { + SCM static_properties = SCM_EOL; + + static_properties = scm_acons (ly_symbol2scm ("grobs-created"), + parse_symbol_list (grobs), static_properties); + + static_properties = scm_acons (ly_symbol2scm ("description"), + scm_from_locale_string (desc), static_properties); + SCM list = SCM_EOL; - for (; listeners; listeners = listeners->next_) - list = scm_cons (listeners->event_class_, list); - return list; + for (; listener_list; listener_list = listener_list->next_) + list = scm_cons (listener_list->event_class_, list); + static_properties = scm_acons (ly_symbol2scm ("events-accepted"), + list, static_properties); + + static_properties = scm_acons (ly_symbol2scm ("properties-read"), + parse_symbol_list (read), static_properties); + + static_properties = scm_acons (ly_symbol2scm ("properties-written"), + parse_symbol_list (write), static_properties); + + return static_properties; } - + /* SMOBS */ @@ -255,11 +275,11 @@ add_acknowledger (Engraver_void_function_engraver_grob_info ptr, string interface_name (func_name); - interface_name = replace_all (interface_name, '_', '-'); + interface_name = replace_all (&interface_name, '_', '-'); interface_name += "-interface"; /* - this is only called during program init, so safe to use scm_gc_protect_object() + this is only called during program init, so safe to use scm_gc_protect_object () */ inf.symbol_ = scm_gc_protect_object (ly_symbol2scm (interface_name.c_str ())); ack_array->push_back (inf); @@ -276,6 +296,7 @@ generic_get_acknowledger (SCM sym, vector const *ack_ar return 0; } + Moment get_event_length (Stream_event *e) { @@ -286,6 +307,19 @@ get_event_length (Stream_event *e) return Moment (0); } +Moment +get_event_length (Stream_event *e, Moment now) +{ + Moment len = get_event_length (e); + + if (now.grace_part_) + { + len.grace_part_ = len.main_part_; + len.main_part_ = Rational (0); + } + return len; +} + /* Helper, used through ASSIGN_EVENT_ONCE to throw warnings for simultaneous events. The helper is only useful in listen_* methods @@ -294,18 +328,21 @@ get_event_length (Stream_event *e) bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function) { - if (*old_ev) + if (*old_ev && + !to_boolean (scm_equal_p ((*old_ev)->self_scm (), + new_ev->self_scm ()))) { /* extract event class from function name */ - const char *prefix = "listen_"; string ev_class = function; + /* This assertion fails if EVENT_ASSIGNMENT was called outside a translator listener. Don't do that. */ + const char *prefix = "listen_"; assert (0 == ev_class.find (prefix)); /* "listen_foo_bar" -> "foo-bar" */ - ev_class.erase (0, strlen(prefix)); - replace_all (ev_class, '_', '-'); + ev_class.erase (0, strlen (prefix)); + replace_all (&ev_class, '_', '-'); new_ev->origin ()->warning (_f ("Two simultaneous %s events, junking this one", ev_class.c_str ())); (*old_ev)->origin ()->warning (_f ("Previous %s event here", ev_class.c_str ())); @@ -319,8 +356,15 @@ internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const ch } ADD_TRANSLATOR (Translator, - "Base class. Unused", - "", + /* doc */ + "Base class. Not instantiated.", + + /* create */ "", + + /* read */ "", - ""); + + /* write */ + "" + );