+void
+Translator::connect_to_context (Context *c)
+{
+ for (translator_listener_record *r = get_listener_list (); r; r = r->next_)
+ c->events_below ()->add_listener (r->get_listener_ (this, r->event_class_),
+ r->event_class_);
+}
+
+void
+Translator::disconnect_from_context (Context *c)
+{
+ for (translator_listener_record *r = get_listener_list (); r; r = r->next_)
+ c->events_below ()->remove_listener (r->get_listener_ (this, r->event_class_),
+ r->event_class_);
+}
+
+/*
+ internally called once, statically, for each translator
+ listener. Connects the name of an event class with a procedure that
+ fetches the corresponding listener.
+
+ The method should only be called from the macro
+ IMPLEMENT_TRANSLATOR_LISTENER.
+ */
+void
+Translator::add_translator_listener (translator_listener_record **listener_list,
+ translator_listener_record *r,
+ Listener (*get_listener) (void *, SCM),
+ const char *ev_class)
+{
+ /* ev_class is the C++ identifier name. Convert to scm symbol */
+ string name = string (ev_class);
+ name = replace_all (&name, '_', '-');
+ name += "-event";
+
+ // we make the symbol permanent in order not to have to bother about
+ // the static translator_listener_record chains while garbage
+ // collecting.
+
+ SCM class_sym = scm_permanent_object (scm_from_locale_symbol (name.c_str ()));
+
+ 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;
+}
+