2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 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/>.
23 #include "global-ctor.hh"
24 #include "lily-proto.hh"
25 #include "virtual-methods.hh"
26 #include "input.hh" // for error reporting
28 #include "std-vector.hh"
29 #include "protected-scm.hh"
31 struct Acknowledge_information
34 Engraver_void_function_engraver_grob_info function_;
36 Acknowledge_information () {
44 Each translator class has a static list of listener records. Each
45 record makes one explains how to register one of the class's stream event
46 listeners to a context.
48 typedef struct translator_listener_record {
49 Listener (*get_listener_) (void *, SCM event_class);
51 struct translator_listener_record *next_;
53 translator_listener_record () {
55 event_class_ = SCM_EOL;
59 } translator_listener_record;
62 #define TRANSLATOR_DECLARATIONS_NO_LISTENER(NAME) \
66 VIRTUAL_COPY_CONSTRUCTOR (Translator, NAME); \
67 static SCM static_description_; \
68 static Drul_array<vector<Acknowledge_information> > acknowledge_static_array_drul_; \
69 virtual void fetch_precomputable_methods (Translator_void_method_ptr methods[]); \
70 virtual SCM static_translator_description () const; \
71 virtual SCM translator_description () const; \
72 static Engraver_void_function_engraver_grob_info static_get_acknowledger (SCM sym); \
73 static Engraver_void_function_engraver_grob_info static_get_end_acknowledger(SCM); \
74 virtual Engraver_void_function_engraver_grob_info get_acknowledger (SCM sym) \
76 return static_get_acknowledger (sym); \
78 virtual Engraver_void_function_engraver_grob_info get_end_acknowledger (SCM sym) \
80 return static_get_end_acknowledger (sym); \
84 #define TRANSLATOR_DECLARATIONS(NAME) \
85 TRANSLATOR_DECLARATIONS_NO_LISTENER(NAME) \
87 static translator_listener_record *listener_list_; \
89 virtual translator_listener_record *get_listener_list () const \
91 return listener_list_; \
95 #define DECLARE_TRANSLATOR_LISTENER(m) \
97 inline void listen_ ## m (Stream_event *); \
98 /* Should be private */ \
99 static void _internal_declare_ ## m (); \
101 static Listener _get_ ## m ## _listener (void *, SCM); \
102 DECLARE_LISTENER (_listen_scm_ ## m);
104 #define DECLARE_ACKNOWLEDGER(x) public : void acknowledge_ ## x (Grob_info); protected:
105 #define DECLARE_END_ACKNOWLEDGER(x) public : void acknowledge_end_ ## x (Grob_info); protected:
107 enum Translator_precompute_index
109 START_TRANSLATION_TIMESTEP,
110 STOP_TRANSLATION_TIMESTEP,
112 PROCESS_ACKNOWLEDGED,
113 TRANSLATOR_METHOD_PRECOMPUTE_COUNT,
117 Translate music into grobs.
124 Context *context () const { return daddy_context_; }
126 Translator (Translator const &);
128 SCM internal_get_property (SCM symbol) const;
130 virtual Output_def *get_output_def () const;
131 virtual Translator_group *get_daddy_translator ()const;
132 virtual Moment now_mom () const;
133 virtual bool must_be_last () const;
135 virtual void initialize ();
136 virtual void finalize ();
138 /* should maybe be virtual */
139 void connect_to_context (Context *c);
140 void disconnect_from_context (Context *c);
142 void stop_translation_timestep ();
143 void start_translation_timestep ();
144 void process_music ();
145 void process_acknowledged ();
147 Context *get_score_context () const;
148 Global_context *get_global_context () const;
150 TRANSLATOR_DECLARATIONS (Translator);
151 DECLARE_SMOBS (Translator);
153 protected: // should be private.
154 Context *daddy_context_;
155 void protect_event (SCM ev);
156 virtual void derived_mark () const;
157 static void add_translator_listener (translator_listener_record **listener_list,
158 translator_listener_record *r,
159 Listener (*get_listener) (void *, SCM),
160 const char *ev_class);
161 SCM static_translator_description (const char *grobs,
163 translator_listener_record *listener_list,
165 const char *write) const;
167 friend class Translator_group;
170 void add_translator (Translator *trans);
172 Translator *get_translator (SCM s);
173 Moment get_event_length (Stream_event *s, Moment now);
174 Moment get_event_length (Stream_event *s);
175 DECLARE_UNSMOB (Translator, translator);
179 This helper is only meaningful inside listen_* methods.
181 extern bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function);
182 #define ASSIGN_EVENT_ONCE(o,n) internal_event_assignment (&o, n, __FUNCTION__)
186 #endif // TRANSLATOR_HH