X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftranslator.cc;h=9ebe2cd4bf97fcc829030087c4b0e0713450e106;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=ec2b0f64a485ee0a5e4af91218800d9e9fb74091;hpb=3b9dd892d83efc979e94aa463688e0db4d97d3fc;p=lilypond.git diff --git a/lily/translator.cc b/lily/translator.cc index ec2b0f64a4..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" @@ -52,12 +52,6 @@ Translator::Translator (Translator const &src) must_be_last_ = src.must_be_last_; } -bool -Translator::try_music (Music *) -{ - return false; -} - Moment Translator::now_mom () const { @@ -94,12 +88,9 @@ Translator::stop_translation_timestep () } /* - this function has 2 properties - - - It is called before try_music () - - - It is called before any user information enters the translators. - (i.e. any \property or event is not processed yet.) + this function is called once each moment, before any user + information enters the translators. (i.e. no \property or event has + been processed yet.) */ void Translator::start_translation_timestep () @@ -141,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); @@ -159,7 +151,6 @@ void add_listened_event_class (SCM sym) { ensure_listened_hash (); - scm_hashq_set_x (listened_event_class_table, sym, SCM_BOOL_T); } @@ -180,18 +171,52 @@ 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 ()); add_listened_event_class (class_sym); + r->event_class_ = class_sym; r->get_listener_ = get_listener; r->next_ = *listener_list; *listener_list = r; } +/* + Helps the individual static_translator_description methods of translators. +*/ +SCM +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 (; 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 */ @@ -250,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); @@ -271,6 +296,7 @@ generic_get_acknowledger (SCM sym, vector const *ack_ar return 0; } + Moment get_event_length (Stream_event *e) { @@ -281,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 @@ -289,20 +328,24 @@ 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 */ + 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 (!strncmp (function, "listen_", strlen (prefix))); - function += strlen (prefix); - char ev_class[strlen (function) + 1]; - strcpy (ev_class, function); - for (char *c = ev_class; *c; c++) - if (*c == '_') - *c = '-'; - - new_ev->origin ()->warning (_f ("Two simultaneous %s events, junking this one", ev_class)); - (*old_ev)->origin ()->warning (_f ("Previous %s event here", ev_class)); + assert (0 == ev_class.find (prefix)); + + /* "listen_foo_bar" -> "foo-bar" */ + 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 ())); return false; } else @@ -313,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 */ + "" + );