2 translator.icc -- declare Translator glue wiring.
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #define TRANSLATOR_ICC
12 #include "listener.hh"
13 #include "std-vector.hh"
14 #include "translator.hh"
17 TODO: derive "foo-bar-interface" from Foo_bar classname.
21 A macro to automate administration of translators.
23 #define ADD_THIS_TRANSLATOR(T) \
24 translator_listener_record *T::listener_list_; \
25 SCM T::static_description_ = SCM_EOL; \
26 static void _ ## T ## _adder () \
29 T::static_description_ = t->static_translator_description (); \
30 scm_permanent_object (T::static_description_); \
33 SCM T::translator_description () const \
35 return static_description_; \
37 ADD_GLOBAL_CTOR (_ ## T ## _adder);
39 #define ADD_TRANSLATOR(classname, desc, grobs, read, write) \
40 Drul_array< vector<Acknowledge_information> > classname::acknowledge_static_array_drul_; \
41 IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS (classname); \
42 ADD_THIS_TRANSLATOR (classname); \
43 Engraver_void_function_engraver_grob_info \
44 classname::static_get_acknowledger (SCM sym) \
46 return generic_get_acknowledger (sym, &acknowledge_static_array_drul_[START]); \
48 Engraver_void_function_engraver_grob_info \
49 classname::static_get_end_acknowledger (SCM sym) \
51 return generic_get_acknowledger (sym, &acknowledge_static_array_drul_[STOP]); \
54 classname::static_translator_description () const \
56 return Translator::static_translator_description (grobs, desc, listener_list_, read, write); \
59 #define IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS(T) \
61 T::fetch_precomputable_methods (Translator_void_method_ptr ptrs[]) \
63 ptrs[START_TRANSLATION_TIMESTEP] = \
64 ((Translator_void_method_ptr) & T::start_translation_timestep == \
65 (Translator_void_method_ptr) & Translator::start_translation_timestep) \
67 : (Translator_void_method_ptr) & T::start_translation_timestep; \
69 ptrs[STOP_TRANSLATION_TIMESTEP] = \
70 ((Translator_void_method_ptr) & T::stop_translation_timestep == (Translator_void_method_ptr) & Translator::stop_translation_timestep) \
72 : (Translator_void_method_ptr) & T::stop_translation_timestep; \
74 ptrs[PROCESS_MUSIC] = \
75 ((Translator_void_method_ptr) & T::process_music == (Translator_void_method_ptr) & Translator::process_music) \
77 : (Translator_void_method_ptr) & T::process_music; \
79 ptrs[PROCESS_ACKNOWLEDGED] = \
80 ((Translator_void_method_ptr) & T::process_acknowledged == (Translator_void_method_ptr) & Translator::process_acknowledged) \
82 : (Translator_void_method_ptr) & T::process_acknowledged; \
85 void add_acknowledger (Engraver_void_function_engraver_grob_info ptr,
86 char const *func_name,
87 vector<Acknowledge_information> *ack_array);
89 Engraver_void_function_engraver_grob_info
90 generic_get_acknowledger (SCM sym,
91 vector<Acknowledge_information> const *ack_array);
93 #define ADD_ACKNOWLEDGER(CLASS, NAME) \
94 void CLASS ## NAME ## _ack_adder () \
96 add_acknowledger ((Engraver_void_function_engraver_grob_info) & CLASS::acknowledge_ ## NAME, #NAME, &CLASS::acknowledge_static_array_drul_[START]); \
98 ADD_SCM_INIT_FUNC (CLASS ## NAME ## _ack_adder_initclass, CLASS ## NAME ## _ack_adder);
100 #define ADD_END_ACKNOWLEDGER(CLASS, NAME) \
101 void CLASS ## NAME ## _end_ack_adder () \
103 add_acknowledger ((Engraver_void_function_engraver_grob_info) & CLASS::acknowledge_end_ ## NAME, #NAME, &CLASS::acknowledge_static_array_drul_[STOP]); \
105 ADD_SCM_INIT_FUNC (CLASS ## NAME ## _end_ack_adder_initclass, CLASS ## NAME ## _end_ack_adder);
108 Implement the method cl::listen_##m, and make it listen to stream
111 #define IMPLEMENT_TRANSLATOR_LISTENER(cl, m) \
113 cl :: _internal_declare_ ## m () \
115 static translator_listener_record r; \
116 add_translator_listener (&listener_list_, &r, _get_ ## m ## _listener, #m); \
119 ADD_SCM_INIT_FUNC (cl ## _declare_event_ ## m, cl::_internal_declare_ ## m); \
122 cl :: _get_ ## m ## _listener (void *me) \
124 cl *obj = (cl *) me; \
125 return obj->GET_LISTENER (_listen_scm_ ## m); \
128 IMPLEMENT_LISTENER (cl, _listen_scm_ ## m) \
130 cl::_listen_scm_ ## m (SCM sev) \
132 Stream_event *ev = unsmob_stream_event (sev); \
133 protect_event (sev); \
137 #endif /* TRANSLATOR_ICC */