]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
Use between-system-padding as a default for
[lilypond.git] / lily / include / translator.hh
1 /*
2   translator.hh -- declare Translator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef TRANSLATOR_HH
10 #define TRANSLATOR_HH
11
12 #include "global-ctor.hh"
13 #include "lily-proto.hh"
14 #include "virtual-methods.hh"
15 #include "input.hh"             // for error reporting
16 #include "smobs.hh"
17 #include "std-vector.hh"
18 #include "protected-scm.hh"
19
20 struct Acknowledge_information
21 {
22   SCM symbol_;
23   Engraver_void_function_engraver_grob_info function_;
24 };
25
26
27 /*
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.
31 */
32 typedef struct translator_listener_record {
33   Listener (*get_listener_) (void *);
34   SCM event_class_;
35   struct translator_listener_record *next_;
36 } translator_listener_record;
37
38 #define TRANSLATOR_DECLARATIONS(NAME)                                   \
39 private:                                                                \
40   static translator_listener_record *listener_list_;                    \
41   public:                                                               \
42   NAME ();                                                              \
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) \
50   {                                                                     \
51     return static_get_acknowledger (sym);                               \
52   }                                                                     \
53   virtual Engraver_void_function_engraver_grob_info get_end_acknowledger (SCM sym) \
54   {                                                                     \
55     return static_get_end_acknowledger (sym);                           \
56   } \
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); \
59 public:                                                                 \
60   virtual translator_listener_record *get_listener_list () const        \
61   {                                                                     \
62     return listener_list_;                                              \
63   }                                                                     \
64   /* end #define */
65
66 #define DECLARE_TRANSLATOR_LISTENER(m)                  \
67 public:                                                 \
68 inline void listen_ ## m (Stream_event *);              \
69 /* Should be private */                                 \
70 static void _internal_declare_ ## m ();                 \
71 private:                                                \
72 static Listener _get_ ## m ## _listener (void *);       \
73 DECLARE_LISTENER (_listen_scm_ ## m);
74
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:
77
78 enum Translator_precompute_index
79   {
80     START_TRANSLATION_TIMESTEP,
81     STOP_TRANSLATION_TIMESTEP,
82     PROCESS_MUSIC,
83     PROCESS_ACKNOWLEDGED,
84     TRANSLATOR_METHOD_PRECOMPUTE_COUNT,
85   };
86
87 /*
88   Translate music into grobs.
89 */
90 class Translator
91 {
92   void init ();
93
94 protected:
95   bool must_be_last_;
96
97 public:
98   bool must_be_last () const;
99
100   Context *context () const { return daddy_context_; }
101
102   Translator (Translator const &);
103
104   SCM internal_get_property (SCM symbol) const;
105
106   virtual Output_def *get_output_def () const;
107   virtual Translator_group *get_daddy_translator ()const;
108   virtual Moment now_mom () const;
109
110   virtual void initialize ();
111   virtual void finalize ();
112
113   /*should maybe be virtual*/
114   void connect_to_context (Context *c);
115   void disconnect_from_context (Context *c);
116
117   void stop_translation_timestep ();
118   void start_translation_timestep ();
119   void process_music ();
120   void process_acknowledged ();
121
122   Context *get_score_context () const;
123   Global_context *get_global_context () const;
124
125   TRANSLATOR_DECLARATIONS (Translator);
126   DECLARE_SMOBS (Translator);
127
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, 
134                                      const char *desc,
135                                      translator_listener_record *listener_list,
136                                      const char *read, 
137                                      const char *write) const;
138
139   friend class Translator_group;
140 };
141 void add_translator (Translator *trans);
142
143 Translator *get_translator (SCM s);
144 Moment get_event_length (Stream_event *s);
145 DECLARE_UNSMOB (Translator, translator);
146
147
148 /*
149   This helper is only meaningful inside listen_* methods.
150 */
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__)
153
154
155 #endif // TRANSLATOR_HH