2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef TRANSLATOR_ICC
21 #define TRANSLATOR_ICC
23 #include "callback.hh"
24 #include "std-vector.hh"
25 #include "engraver.hh"
28 TODO: derive "foo-bar-interface" from Foo_bar classname.
32 A macro to automate administration of translators.
34 #define ADD_THIS_TRANSLATOR(T) \
35 SCM T::static_description_ = SCM_EOL; \
36 static void _ ## T ## _adder () \
39 T::static_description_ = \
40 scm_permanent_object (t->static_translator_description ()); \
43 SCM T::translator_description () const \
45 return static_description_; \
47 ADD_GLOBAL_CTOR (_ ## T ## _adder); \
50 #define DEFINE_TRANSLATOR_LISTENER_LIST(T) \
51 Protected_scm T::listener_list_ (SCM_EOL); \
54 #define DEFINE_ACKNOWLEDGERS(classname) \
55 Drul_array<Protected_scm> classname::acknowledge_static_array_drul_; \
57 classname::static_get_acknowledger (SCM sym) \
59 return generic_get_acknowledger (sym, acknowledge_static_array_drul_[START]); \
62 classname::static_get_end_acknowledger (SCM sym) \
64 return generic_get_acknowledger (sym, acknowledge_static_array_drul_[STOP]); \
68 #define DEFINE_TRANSLATOR_DOC(classname, desc, grobs, read, write) \
70 classname::static_translator_description () const \
72 return Translator::static_translator_description (grobs, desc, listener_list_, read, write); \
75 #define ADD_TRANSLATOR_FAMILY(classname) \
76 IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS (classname); \
77 DEFINE_ACKNOWLEDGERS(classname) \
79 #define ADD_TRANSLATOR(classname, desc, grobs, read, write) \
80 ADD_TRANSLATOR_FAMILY (classname); \
81 ADD_THIS_TRANSLATOR (classname); \
82 DEFINE_TRANSLATOR_DOC(classname, desc, grobs, read, write) \
83 DEFINE_TRANSLATOR_LISTENER_LIST(classname) \
85 #define IMPLEMENT_FETCH_PRECOMPUTABLE_METHODS(T) \
87 T::fetch_precomputable_methods (SCM ptrs[]) \
89 ptrs[START_TRANSLATION_TIMESTEP] = \
90 method_finder <&T::start_translation_timestep> (); \
92 ptrs[STOP_TRANSLATION_TIMESTEP] = \
93 method_finder <&T::stop_translation_timestep> (); \
95 ptrs[PROCESS_MUSIC] = \
96 method_finder <&T::process_music> (); \
98 ptrs[PROCESS_ACKNOWLEDGED] = \
99 method_finder <&T::process_acknowledged> (); \
102 void add_acknowledger (SCM ptr,
103 char const *func_name,
104 Protected_scm &ack_hash);
107 generic_get_acknowledger (SCM sym, SCM ack_hash);
109 #define ADD_ACKNOWLEDGER(CLASS, NAME) \
110 void CLASS ## NAME ## _ack_adder () \
112 add_acknowledger (CLASS::ack_finder<&CLASS::acknowledge_ ## NAME> (), \
113 #NAME, CLASS::acknowledge_static_array_drul_[START]); \
115 ADD_SCM_INIT_FUNC (CLASS ## NAME ## _ack_adder_initclass, CLASS ## NAME ## _ack_adder);
117 #define ADD_END_ACKNOWLEDGER(CLASS, NAME) \
118 void CLASS ## NAME ## _end_ack_adder () \
120 add_acknowledger (CLASS::ack_finder<&CLASS::acknowledge_end_ ## NAME> (), \
121 #NAME, CLASS::acknowledge_static_array_drul_[STOP]); \
123 ADD_SCM_INIT_FUNC (CLASS ## NAME ## _end_ack_adder_initclass, CLASS ## NAME ## _end_ack_adder);
126 Implement the method cl::listen_##m, and make it listen to stream
129 #define IMPLEMENT_TRANSLATOR_LISTENER(cl, m) \
131 cl :: _internal_declare_ ## m () \
133 listener_list_ = scm_acons \
134 (event_class_symbol (#m), \
135 Callback_wrapper::make_smob \
136 <trampoline <cl, &cl::listen_ ## m> > (), listener_list_); \
139 ADD_SCM_INIT_FUNC (cl ## _declare_event_ ## m, cl::_internal_declare_ ## m);
141 #endif /* TRANSLATOR_ICC */