2 translator.hh -- declare Translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "global-ctor.hh"
13 #include "lily-proto.hh"
14 #include "virtual-methods.hh"
15 #include "input.hh" // for error reporting
17 #include "std-vector.hh"
18 #include "protected-scm.hh"
20 struct Acknowledge_information
23 Engraver_void_function_engraver_grob_info function_;
28 Each translator class has a static list of listener records. Each
29 record makes one explains how to register one of the class's stream event
30 listeners to a context.
32 typedef struct translator_listener_record {
33 Listener (*get_listener_) (void *);
35 struct translator_listener_record *next_;
36 } translator_listener_record;
38 #define TRANSLATOR_DECLARATIONS(NAME) \
40 static translator_listener_record *listener_list_; \
43 VIRTUAL_COPY_CONSTRUCTOR (Translator, NAME); \
44 static SCM static_description_; \
45 static Drul_array<vector<Acknowledge_information> > acknowledge_static_array_drul_; \
46 virtual void fetch_precomputable_methods (Translator_void_method_ptr methods[]); \
47 virtual SCM static_translator_description () const; \
48 virtual SCM translator_description () const; \
49 virtual Engraver_void_function_engraver_grob_info get_acknowledger (SCM sym) \
51 return static_get_acknowledger (sym); \
53 virtual Engraver_void_function_engraver_grob_info get_end_acknowledger (SCM sym) \
55 return static_get_end_acknowledger (sym); \
57 static Engraver_void_function_engraver_grob_info static_get_acknowledger (SCM sym); \
58 static Engraver_void_function_engraver_grob_info static_get_end_acknowledger(SCM); \
60 virtual translator_listener_record *get_listener_list () const \
62 return listener_list_; \
66 #define DECLARE_TRANSLATOR_LISTENER(m) \
68 inline void listen_ ## m (Stream_event *); \
69 /* Should be private */ \
70 static void _internal_declare_ ## m (); \
72 static Listener _get_ ## m ## _listener (void *); \
73 DECLARE_LISTENER (_listen_scm_ ## m);
75 #define DECLARE_ACKNOWLEDGER(x) public : void acknowledge_ ## x (Grob_info); protected:
76 #define DECLARE_END_ACKNOWLEDGER(x) public : void acknowledge_end_ ## x (Grob_info); protected:
78 enum Translator_precompute_index
80 START_TRANSLATION_TIMESTEP,
81 STOP_TRANSLATION_TIMESTEP,
84 TRANSLATOR_METHOD_PRECOMPUTE_COUNT,
88 Translate music into grobs.
98 bool must_be_last () const;
100 Context *context () const { return daddy_context_; }
102 Translator (Translator const &);
104 SCM internal_get_property (SCM symbol) const;
106 virtual Output_def *get_output_def () const;
107 virtual Translator_group *get_daddy_translator ()const;
108 virtual Moment now_mom () const;
110 virtual void initialize ();
111 virtual void finalize ();
113 /*should maybe be virtual*/
114 void connect_to_context (Context *c);
115 void disconnect_from_context (Context *c);
117 void stop_translation_timestep ();
118 void start_translation_timestep ();
119 void process_music ();
120 void process_acknowledged ();
122 Context *get_score_context () const;
123 Global_context *get_global_context () const;
125 TRANSLATOR_DECLARATIONS (Translator);
126 DECLARE_SMOBS (Translator);
128 protected: // should be private.
129 Context *daddy_context_;
130 void protect_event (SCM ev);
131 virtual void derived_mark () const;
132 static void add_translator_listener (translator_listener_record **listener_list, translator_listener_record *r, Listener (*get_listener) (void *), const char *ev_class);
133 SCM static_translator_description (const char *grobs,
135 translator_listener_record *listener_list,
137 const char *write) const;
139 friend class Translator_group;
141 void add_translator (Translator *trans);
143 Translator *get_translator (SCM s);
144 Moment get_event_length (Stream_event *s);
145 DECLARE_UNSMOB (Translator, translator);
149 This helper is only meaningful inside listen_* methods.
151 extern bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function);
152 #define ASSIGN_EVENT_ONCE(o,n) internal_event_assignment (&o, n, __FUNCTION__)
155 #endif // TRANSLATOR_HH