]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[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--2002 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_CONS (Translator);                               \
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 public:
39   Music_output_def * output_def_;
40   String type_string_;
41   
42   bool is_alias_b (String) const;
43     
44
45   Translator (Translator const &);
46
47   
48   Translator_group * daddy_trans_ ;
49   void removal_processing ();
50   /**
51     ask daddy for a feature
52     */
53   Music_output_def *get_output_def () const;
54
55   SCM internal_get_property (SCM symbol) const;
56   
57   virtual Moment now_mom () const;  
58
59   /*
60     ugh: bubbled up from Translator_group. 
61    */
62   SCM simple_trans_list_;
63   SCM trans_group_list_;
64   SCM definition_;
65   
66   SCM properties_scm_;
67   DECLARE_SMOBS (Translator, dummy);
68
69
70 public:
71   Global_translator * top_translator () const;
72   TRANSLATOR_DECLARATIONS(Translator);
73     /**
74     try to fit the request in this engraver
75
76     @return
77     false: not noted,  not taken.
78
79     true: request swallowed. Don't try to put the request elsewhere.
80
81     */
82   virtual bool try_music (Music *req);
83   virtual void stop_translation_timestep ();
84   virtual void start_translation_timestep ();
85   virtual void do_announces () ;
86   virtual void initialize () ;
87   virtual void finalize ();
88 };
89
90
91 /**
92   A macro to automate administration of translators.
93  */
94 #define ADD_THIS_TRANSLATOR(T)                          \
95 SCM T::static_description_ = SCM_EOL;\
96 static void  _ ## T ## _adder () {\
97       T *t = new T;\
98       T::static_description_ = t->static_translator_description ();\
99       scm_permanent_object (T::static_description_);\
100       t->type_string_ = classname (t);\
101       add_translator (t);\
102 }\
103 SCM T::translator_description() const\
104 { \
105   return static_description_;\
106 }\
107 ADD_GLOBAL_CTOR (_ ## T ## _adder);
108
109
110
111
112 #define ENTER_DESCRIPTION(classname,desc,grobs,acked,read,write)                                                \
113 ADD_THIS_TRANSLATOR (classname);\
114 SCM                                                                                             \
115 classname::static_translator_description () const \
116 {                                                                                               \
117   SCM  static_properties= SCM_EOL;                                                              \
118   /*  static_properties= acons (name ,gh_str02scm (Translator::name (self_scm ())),             \
119                               static_properties_);                                              \
120   */                                                                                            \
121   static_properties= scm_acons (ly_symbol2scm ("grobs-created"),                                \
122                               parse_symbol_list (grobs), static_properties);    \
123                                                                                                 \
124   static_properties= scm_acons (ly_symbol2scm ("description"),                                  \
125                               scm_makfrom0str (desc), static_properties);                               \
126                                                                                                 \
127   static_properties= scm_acons (ly_symbol2scm ("interfaces-acked"),                             \
128                               parse_symbol_list (acked), static_properties);                    \
129                                                                                                 \
130   static_properties= scm_acons (ly_symbol2scm ("properties-read"),                              \
131                               parse_symbol_list (read), static_properties);                     \
132                                                                                                 \
133   static_properties= scm_acons (ly_symbol2scm ("properties-written"),                           \
134                                 parse_symbol_list (write), static_properties);                  \
135                                                                                                 \
136   return static_properties;                                                                     \
137 }
138
139
140
141 extern Dictionary<Translator*> *global_translator_dict;
142 void add_translator (Translator*trans);
143
144 Translator*get_translator (String s);
145 DECLARE_UNSMOB(Translator,translator);
146 #endif // TRANSLATOR_HH