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