]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
Update source file headers. Fixes using standard GNU package conventions.
[lilypond.git] / lily / include / translator.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #ifndef TRANSLATOR_HH
21 #define TRANSLATOR_HH
22
23 #include "global-ctor.hh"
24 #include "lily-proto.hh"
25 #include "virtual-methods.hh"
26 #include "input.hh"             // for error reporting
27 #include "smobs.hh"
28 #include "std-vector.hh"
29 #include "protected-scm.hh"
30
31 struct Acknowledge_information
32 {
33   SCM symbol_;
34   Engraver_void_function_engraver_grob_info function_;
35 };
36
37
38 /*
39   Each translator class has a static list of listener records. Each
40   record makes one explains how to register one of the class's stream event
41   listeners to a context.
42 */
43 typedef struct translator_listener_record {
44   Listener (*get_listener_) (void *);
45   SCM event_class_;
46   struct translator_listener_record *next_;
47 } translator_listener_record;
48
49 #define TRANSLATOR_DECLARATIONS(NAME)                                   \
50 private:                                                                \
51   static translator_listener_record *listener_list_;                    \
52   public:                                                               \
53   NAME ();                                                              \
54   VIRTUAL_COPY_CONSTRUCTOR (Translator, NAME);                          \
55   static SCM static_description_;                                       \
56   static Drul_array<vector<Acknowledge_information> > acknowledge_static_array_drul_; \
57   virtual void fetch_precomputable_methods (Translator_void_method_ptr methods[]); \
58   virtual SCM static_translator_description () const;                   \
59   virtual SCM translator_description () const;                          \
60   virtual Engraver_void_function_engraver_grob_info get_acknowledger (SCM sym) \
61   {                                                                     \
62     return static_get_acknowledger (sym);                               \
63   }                                                                     \
64   virtual Engraver_void_function_engraver_grob_info get_end_acknowledger (SCM sym) \
65   {                                                                     \
66     return static_get_end_acknowledger (sym);                           \
67   } \
68   static Engraver_void_function_engraver_grob_info static_get_acknowledger (SCM sym); \
69   static Engraver_void_function_engraver_grob_info static_get_end_acknowledger(SCM); \
70 public:                                                                 \
71   virtual translator_listener_record *get_listener_list () const        \
72   {                                                                     \
73     return listener_list_;                                              \
74   }                                                                     \
75   /* end #define */
76
77 #define DECLARE_TRANSLATOR_LISTENER(m)                  \
78 public:                                                 \
79 inline void listen_ ## m (Stream_event *);              \
80 /* Should be private */                                 \
81 static void _internal_declare_ ## m ();                 \
82 private:                                                \
83 static Listener _get_ ## m ## _listener (void *);       \
84 DECLARE_LISTENER (_listen_scm_ ## m);
85
86 #define DECLARE_ACKNOWLEDGER(x) public : void acknowledge_ ## x (Grob_info); protected:
87 #define DECLARE_END_ACKNOWLEDGER(x) public : void acknowledge_end_ ## x (Grob_info); protected:
88
89 enum Translator_precompute_index
90   {
91     START_TRANSLATION_TIMESTEP,
92     STOP_TRANSLATION_TIMESTEP,
93     PROCESS_MUSIC,
94     PROCESS_ACKNOWLEDGED,
95     TRANSLATOR_METHOD_PRECOMPUTE_COUNT,
96   };
97
98 /*
99   Translate music into grobs.
100 */
101 class Translator
102 {
103   void init ();
104
105 protected:
106   bool must_be_last_;
107
108 public:
109   bool must_be_last () const;
110
111   Context *context () const { return daddy_context_; }
112
113   Translator (Translator const &);
114
115   SCM internal_get_property (SCM symbol) const;
116
117   virtual Output_def *get_output_def () const;
118   virtual Translator_group *get_daddy_translator ()const;
119   virtual Moment now_mom () const;
120
121   virtual void initialize ();
122   virtual void finalize ();
123
124   /*should maybe be virtual*/
125   void connect_to_context (Context *c);
126   void disconnect_from_context (Context *c);
127
128   void stop_translation_timestep ();
129   void start_translation_timestep ();
130   void process_music ();
131   void process_acknowledged ();
132
133   Context *get_score_context () const;
134   Global_context *get_global_context () const;
135
136   TRANSLATOR_DECLARATIONS (Translator);
137   DECLARE_SMOBS (Translator);
138
139 protected:                      // should be private.
140   Context *daddy_context_;
141   void protect_event (SCM ev);
142   virtual void derived_mark () const;
143   static void add_translator_listener (translator_listener_record **listener_list, translator_listener_record *r, Listener (*get_listener) (void *), const char *ev_class);
144   SCM static_translator_description (const char *grobs, 
145                                      const char *desc,
146                                      translator_listener_record *listener_list,
147                                      const char *read, 
148                                      const char *write) const;
149
150   friend class Translator_group;
151 };
152 void add_translator (Translator *trans);
153
154 Translator *get_translator (SCM s);
155 Moment get_event_length (Stream_event *s, Moment now);
156 Moment get_event_length (Stream_event *s);
157 DECLARE_UNSMOB (Translator, translator);
158
159
160 /*
161   This helper is only meaningful inside listen_* methods.
162 */
163 extern bool internal_event_assignment (Stream_event **old_ev, Stream_event *new_ev, const char *function);
164 #define ASSIGN_EVENT_ONCE(o,n) internal_event_assignment (&o, n, __FUNCTION__)
165
166
167 #endif // TRANSLATOR_HH