]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
* lily/parser.yy (context_def_mod): remove \consistsend
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef TRANSLATOR_HH
11 #define TRANSLATOR_HH
12
13 #include "global-ctor.hh"
14 #include "string.hh"
15 #include "lily-proto.hh"
16 #include "virtual-methods.hh"
17 #include "lily-guile.hh"
18 #include "input.hh"
19 #include "smobs.hh"
20
21 #define get_property(x) internal_get_property(ly_symbol2scm(x))
22
23
24 #define TRANSLATOR_DECLARATIONS(NAME)                   \
25 public:                                                 \
26   NAME ();                                              \
27   VIRTUAL_COPY_CONSTRUCTOR (Translator, NAME);          \
28   static SCM static_description_;                       \
29   virtual SCM static_translator_description () const;   \
30   virtual SCM translator_description () const;
31
32 /*
33   Translate music into grobs.
34 */
35 class Translator
36 {
37   void init ();
38
39 protected:
40   bool must_be_last_;
41
42 public:
43   bool must_be_last () const;
44   
45   Context * context () const { return daddy_context_; }
46   
47   Translator (Translator const &);
48
49   SCM internal_get_property (SCM symbol) const;
50   
51   virtual Output_def *get_output_def () const;
52   virtual Translator_group* get_daddy_translator ()const;
53   virtual Moment now_mom () const;  
54   virtual bool try_music (Music *req);
55   virtual void stop_translation_timestep ();
56   virtual void start_translation_timestep ();
57   virtual void initialize () ;
58   virtual void process_music ();
59   virtual void do_announces ();
60   virtual void finalize ();
61   
62   Score_context * get_score_context () const;
63   Global_context * get_global_context () const;
64
65   
66   TRANSLATOR_DECLARATIONS(Translator);
67   DECLARE_SMOBS (Translator, dummy);
68 protected:                      // should be private.
69   Context * daddy_context_ ;
70   SCM simple_trans_list_;
71   friend class Context_def;
72   friend class Context;
73 };
74
75 /**
76   A macro to automate administration of translators.
77  */
78 #define ADD_THIS_TRANSLATOR(T)                          \
79 SCM T::static_description_ = SCM_EOL;\
80 static void  _ ## T ## _adder () {\
81       T *t = new T;\
82       T::static_description_ = t->static_translator_description ();\
83       scm_permanent_object (T::static_description_);\
84       add_translator (t);\
85 }\
86 SCM T::translator_description() const\
87 { \
88   return static_description_;\
89 }\
90 ADD_GLOBAL_CTOR (_ ## T ## _adder);
91
92
93
94
95 #define ENTER_DESCRIPTION(classname,desc,grobs,accepted,acked,read,write)                                               \
96 ADD_THIS_TRANSLATOR (classname);\
97 SCM                                                                                             \
98 classname::static_translator_description () const \
99 {                                                                                               \
100   SCM  static_properties= SCM_EOL;                                                              \
101   /*  static_properties= acons (name ,gh_str02scm (Translator::name (self_scm ())),             \
102                               static_properties_);                                              \
103   */                                                                                            \
104   static_properties= scm_acons (ly_symbol2scm ("grobs-created"),                                \
105                               parse_symbol_list (grobs), static_properties);    \
106                                                                                                 \
107   static_properties= scm_acons (ly_symbol2scm ("description"),                                  \
108                               scm_makfrom0str (desc), static_properties);                               \
109                                                                                                 \
110   static_properties= scm_acons (ly_symbol2scm ("interfaces-acked"),                             \
111                               parse_symbol_list (acked), static_properties);                    \
112   static_properties= scm_acons (ly_symbol2scm ("events-accepted"),                              \
113                               parse_symbol_list (accepted), static_properties);                 \
114                                                                                                 \
115   static_properties= scm_acons (ly_symbol2scm ("properties-read"),                              \
116                               parse_symbol_list (read), static_properties);                     \
117                                                                                                 \
118   static_properties= scm_acons (ly_symbol2scm ("properties-written"),                           \
119                                 parse_symbol_list (write), static_properties);                  \
120                                                                                                 \
121   return static_properties;                                                                     \
122 }
123
124
125
126 void add_translator (Translator*trans);
127
128 Translator*get_translator (SCM s);
129 DECLARE_UNSMOB(Translator,translator);
130 #endif // TRANSLATOR_HH