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