]> git.donarmstrong.com Git - lilypond.git/blob - lily/translator.cc
* lily/music.cc (Music): fix very subtle and nasty memory
[lilypond.git] / lily / translator.cc
1 /*
2   translator.cc -- implement 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 #include "translator.hh"
11 #include "debug.hh"
12 #include "translator-group.hh"
13 #include "translator-def.hh"
14
15 #include "moment.hh"
16 #include "ly-smobs.icc"
17
18
19 Translator::~Translator ()
20 {
21 }
22
23 void
24 Translator::init ()
25 {
26   simple_trans_list_ = SCM_EOL;
27   trans_group_list_ = SCM_EOL;
28   properties_scm_ = SCM_EOL;
29   definition_ = SCM_EOL;
30   daddy_trans_l_ =0;
31 }
32
33 Translator::Translator ()
34 {
35   init ();
36   output_def_l_ = 0;
37   smobify_self ();
38 }
39
40 Translator::Translator (Translator const &s)
41 {
42   init ();
43   output_def_l_ = s.output_def_l_;
44   type_str_ = s.type_str_;
45
46   smobify_self ();
47 }
48
49 bool
50 Translator::is_alias_b (String s) const
51 {
52   bool b  = s == type_str_;
53
54   for (SCM a = unsmob_translator_def (definition_)->type_aliases_;
55        !b && gh_pair_p (a); a = ly_cdr (a))
56     b = b || s == ly_scm2string (ly_car (a));
57
58   return b;
59 }
60
61 bool
62 Translator::try_music (Music *)
63 {
64   return false;
65 }
66                             
67
68 Moment
69 Translator::now_mom () const
70 {
71   return daddy_trans_l_->now_mom ();
72 }
73
74 void
75 Translator::removal_processing ()
76 {
77   finalize ();
78 }
79
80 void
81 Translator::announces ()
82 {
83   do_announces ();
84 }
85
86 Music_output_def *
87 Translator::output_def_l () const
88 {
89   return output_def_l_;
90 }
91
92 SCM
93 Translator::internal_get_property (SCM sym) const
94 {
95   return daddy_trans_l_->internal_get_property (sym);
96 }
97
98 void
99 Translator:: stop_translation_timestep ()
100 {
101 }
102
103 void
104 Translator::start_translation_timestep ()
105 {
106 }
107
108 void
109 Translator::do_announces ()
110 {
111 }
112
113 void
114 Translator::initialize ()
115 {
116 }
117
118 void
119 Translator::finalize ()
120 {
121 }
122
123
124 /*
125
126   SMOBS
127
128 */
129 SCM
130 Translator::mark_smob (SCM sm)
131 {
132   Translator * me = (Translator*) SCM_CELL_WORD_1 (sm);
133   scm_gc_mark (me->simple_trans_list_);
134   scm_gc_mark (me->trans_group_list_);
135   scm_gc_mark (me->definition_);  
136   scm_gc_mark (me->properties_scm_);  
137
138   return me->properties_scm_;
139 }
140
141 LY_DEFINE(ly_translator_name,
142           "ly-translator-name", 1,0,0,  (SCM trans),
143           "Return the type name of the translator @var{trans}.
144 ")
145 {
146   Translator* tr =  unsmob_translator (trans);
147   SCM_ASSERT_TYPE(tr, trans, SCM_ARG1, __FUNCTION__, "Context");
148
149   char const* nm = classname (tr);
150   return ly_str02scm (nm);
151 }
152
153 LY_DEFINE(ly_translator_description,
154           "ly-translator-description",
155           1,0,0, (SCM me),
156           "Return an alist of properties of  translator @var{me}.")
157 {
158   Translator *tr =unsmob_translator (me);
159   SCM_ASSERT_TYPE (tr, me, SCM_ARG1, __FUNCTION__, "Context");
160
161   return tr->translator_description ();
162 }
163
164 SCM
165 Translator::translator_description () const
166 {
167   return SCM_EOL;
168 }
169
170 int
171 Translator::print_smob (SCM s, SCM port, scm_print_state *)
172 {
173   Translator *sc = (Translator *) ly_cdr (s);
174      
175   scm_puts ("#<Translator ", port);
176   scm_display (ly_translator_name (s), port);
177   scm_display (sc->simple_trans_list_, port);
178   /*
179     don't try to print properties, that is too much hassle.
180    */
181   scm_puts (" >", port);
182   
183   return 1;
184 }
185
186 SCM
187 Translator::static_translator_description ()const
188 {
189   return SCM_EOL;
190 }
191
192
193 IMPLEMENT_SMOBS (Translator);
194 IMPLEMENT_DEFAULT_EQUAL_P (Translator);