]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/translator.hh
* lily/include/context.hh (class Context): make members protected.
[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 public:
40   Context * get_parent_context () const { return daddy_context_; }
41   
42   Translator (Translator const &);
43
44   void removal_processing ();
45   SCM internal_get_property (SCM symbol) const;
46   
47   virtual Music_output_def *get_output_def () const;
48   virtual Translator_group* get_daddy_translator ()const;
49   virtual Moment now_mom () const;  
50   virtual bool try_music (Music *req);
51   virtual void stop_translation_timestep ();
52   virtual void start_translation_timestep ();
53   virtual void initialize () ;
54   virtual void process_music ();
55   virtual void do_announces ();
56   virtual void finalize ();
57   
58   Score_context * get_score_context () const;
59   Global_context * get_global_context () const;
60   
61   TRANSLATOR_DECLARATIONS(Translator);
62   DECLARE_SMOBS (Translator, dummy);
63 protected:                      // should be private.
64   Context * daddy_context_ ;
65   SCM simple_trans_list_;
66   friend class Context_def;
67   friend class Context;
68 };
69
70 /**
71   A macro to automate administration of translators.
72  */
73 #define ADD_THIS_TRANSLATOR(T)                          \
74 SCM T::static_description_ = SCM_EOL;\
75 static void  _ ## T ## _adder () {\
76       T *t = new T;\
77       T::static_description_ = t->static_translator_description ();\
78       scm_permanent_object (T::static_description_);\
79       add_translator (t);\
80 }\
81 SCM T::translator_description() const\
82 { \
83   return static_description_;\
84 }\
85 ADD_GLOBAL_CTOR (_ ## T ## _adder);
86
87
88
89
90 #define ENTER_DESCRIPTION(classname,desc,grobs,accepted,acked,read,write)                                               \
91 ADD_THIS_TRANSLATOR (classname);\
92 SCM                                                                                             \
93 classname::static_translator_description () const \
94 {                                                                                               \
95   SCM  static_properties= SCM_EOL;                                                              \
96   /*  static_properties= acons (name ,gh_str02scm (Translator::name (self_scm ())),             \
97                               static_properties_);                                              \
98   */                                                                                            \
99   static_properties= scm_acons (ly_symbol2scm ("grobs-created"),                                \
100                               parse_symbol_list (grobs), static_properties);    \
101                                                                                                 \
102   static_properties= scm_acons (ly_symbol2scm ("description"),                                  \
103                               scm_makfrom0str (desc), static_properties);                               \
104                                                                                                 \
105   static_properties= scm_acons (ly_symbol2scm ("interfaces-acked"),                             \
106                               parse_symbol_list (acked), static_properties);                    \
107   static_properties= scm_acons (ly_symbol2scm ("events-accepted"),                              \
108                               parse_symbol_list (accepted), static_properties);                 \
109                                                                                                 \
110   static_properties= scm_acons (ly_symbol2scm ("properties-read"),                              \
111                               parse_symbol_list (read), static_properties);                     \
112                                                                                                 \
113   static_properties= scm_acons (ly_symbol2scm ("properties-written"),                           \
114                                 parse_symbol_list (write), static_properties);                  \
115                                                                                                 \
116   return static_properties;                                                                     \
117 }
118
119
120
121 void add_translator (Translator*trans);
122
123 Translator*get_translator (SCM s);
124 DECLARE_UNSMOB(Translator,translator);
125 #endif // TRANSLATOR_HH