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