must_be_last_ = src.must_be_last_;
}
-bool
-Translator::try_music (Music *)
-{
- return false;
-}
-
Moment
Translator::now_mom () const
{
}
/*
- 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 ()
add_listened_event_class (SCM sym)
{
ensure_listened_hash ();
-
scm_hashq_set_x (listened_event_class_table, sym, SCM_BOOL_T);
}
name = replace_all (name, '_', '-');
name += "-event";
- /* It's OK to use scm_gc_protect_object for protection, because r is
- statically allocated. */
- // NO it's damn not !!!! --hwn
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_makfrom0str (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
*/
interface_name = replace_all (interface_name, '_', '-');
interface_name += "-interface";
- inf.symbol_ = ly_symbol2scm (interface_name.c_str ());
+ /*
+ 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);
}
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
}
ADD_TRANSLATOR (Translator,
- "Base class. Unused",
- "",
+ "Base class. Not instantiated.",
"",
"",
"");