2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--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/>.
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 #define TRANSLATOR_DECLARATIONS_NO_LISTENER(NAME) \
34 VIRTUAL_COPY_CONSTRUCTOR (Translator, NAME); \
35 static SCM static_description_; \
36 static Drul_array<std::vector<Acknowledge_information> > acknowledge_static_array_drul_; \
37 virtual void fetch_precomputable_methods (Callback methods[]); \
38 virtual SCM static_translator_description () const; \
39 virtual SCM translator_description () const; \
40 static Grob_info_callback static_get_acknowledger (SCM sym); \
41 static Grob_info_callback static_get_end_acknowledger(SCM); \
42 virtual Grob_info_callback get_acknowledger (SCM sym) \
44 return static_get_acknowledger (sym); \
46 virtual Grob_info_callback get_end_acknowledger (SCM sym) \
48 return static_get_end_acknowledger (sym); \
53 Each translator class has a static alist of event class symbols
54 mapping to callbacks that are called with a translator instance and
55 a stream event when an event of the appropriate event class is
56 announced in a context.
59 #define TRANSLATOR_DECLARATIONS(NAME) \
60 TRANSLATOR_DECLARATIONS_NO_LISTENER(NAME) \
62 static Protected_scm listener_list_; \
64 virtual SCM get_listener_list () const \
66 return listener_list_; \
70 #define DECLARE_TRANSLATOR_LISTENER(m) \
72 inline void listen_ ## m (Stream_event *); \
73 /* Should be private */ \
74 static void _internal_declare_ ## m ();
76 #define DECLARE_ACKNOWLEDGER(x) public : void acknowledge_ ## x (Grob_info); protected:
77 #define DECLARE_END_ACKNOWLEDGER(x) public : void acknowledge_end_ ## x (Grob_info); protected:
79 enum Translator_precompute_index
81 START_TRANSLATION_TIMESTEP,
82 STOP_TRANSLATION_TIMESTEP,
85 TRANSLATOR_METHOD_PRECOMPUTE_COUNT,
89 Translate music into grobs.
91 class Translator : public Smob<Translator>
94 // We don't make Grob_info_callback specific to Engraver since we
95 // otherwise get into a circular mess with regard to the definitions
96 // as the timing of Engraver is exercised from within Translator
97 typedef void (Translator::*Grob_info_callback) (Grob_info);
98 typedef void (Translator::*Callback) (void);
99 int print_smob (SCM, scm_print_state *) const;
100 SCM mark_smob () const;
101 static const char type_p_name_[];
102 virtual ~Translator ();
107 Context *context () const { return daddy_context_; }
109 Translator (Translator const &);
111 SCM internal_get_property (SCM symbol) const;
113 virtual Output_def *get_output_def () const;
114 virtual Translator_group *get_daddy_translator ()const;
115 virtual Moment now_mom () const;
116 virtual bool must_be_last () const;
118 virtual void initialize ();
119 virtual void finalize ();
121 virtual void connect_to_context (Context *c);
122 virtual void disconnect_from_context (Context *c);
124 void stop_translation_timestep ();
125 void start_translation_timestep ();
126 void process_music ();
127 void process_acknowledged ();
129 Context *get_score_context () const;
130 Global_context *get_global_context () const;
132 TRANSLATOR_DECLARATIONS (Translator);
134 protected: // should be private.
135 Context *daddy_context_;
136 void protect_event (SCM ev);
137 friend class Callback_wrapper;
138 virtual void derived_mark () const;
139 static SCM event_class_symbol (const char *ev_class);
140 SCM static_translator_description (const char *grobs,
144 const char *write) const;
146 friend class Translator_group;
149 struct Acknowledge_information
152 Translator::Grob_info_callback function_;
154 Acknowledge_information ()
162 void add_translator (Translator *trans);
164 Translator *get_translator (SCM s);
165 Moment get_event_length (Stream_event *s, Moment now);
166 Moment get_event_length (Stream_event *s);
169 This helper is only meaningful inside listen_* methods.
171 extern bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function);
172 #define ASSIGN_EVENT_ONCE(o,n) internal_event_assignment (&o, n, __FUNCTION__)
174 #endif // TRANSLATOR_HH