]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-engraver.cc
remove
[lilypond.git] / lily / score-engraver.cc
1 /*
2   score-engraver.cc -- implement Score_engraver
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 #include "all-font-metrics.hh"
10 #include "afm.hh"
11 #include "warn.hh"
12 #include "main.hh"
13 #include "system.hh"
14 #include "item.hh"
15 #include "score-engraver.hh"
16 #include "paper-score.hh"
17 #include "paper-column.hh"
18 #include "paper-def.hh"
19 #include "axis-group-interface.hh"
20 #include "context-def.hh"
21 #include "staff-spacing.hh"
22 #include "note-spacing.hh"
23 #include "context.hh"
24 #include "global-context.hh"
25
26
27
28
29 /*
30   TODO: the column creation logic is rather hairy. Revise it.
31  */
32 Score_engraver::Score_engraver ()
33 {
34   system_ =0;
35   command_column_ =0;
36   musical_column_ =0;
37   breaks_ =0;
38   pscore_ = 0;
39 }
40
41 void
42 Score_engraver::make_columns ()
43 {
44   /*
45     ugh.
46    */
47   if (!command_column_)
48     {
49       SCM nmp
50         = updated_grob_properties (context (),
51                                    ly_symbol2scm ("NonMusicalPaperColumn"));
52       SCM pc = updated_grob_properties (context (),
53                                         ly_symbol2scm ("PaperColumn"));
54       
55       set_columns (new Paper_column (nmp), new Paper_column (pc));
56
57       Grob_info i1;
58       i1.grob_ = command_column_;
59       i1.origin_trans_ = this;
60   
61       announce_grob (i1);
62
63       Grob_info i2;
64       i2.grob_ = musical_column_;
65       i2.origin_trans_ = this;
66
67       announce_grob (i2);
68     }
69 }
70
71 void
72 Score_engraver::prepare (Moment m)
73 {
74   /*
75     TODO: don't make columns when skipTypesetting is true.
76    */
77   make_columns ();
78
79   SCM w = m.smobbed_copy ();
80   command_column_->set_property ("when", w);
81   musical_column_->set_property ("when", w);
82   
83   recurse_over_translators (context (), &Translator::start_translation_timestep, DOWN);
84 }
85
86 void
87 Score_engraver::finish ()
88 {
89   if ((breaks_%8))
90     progress_indication ("[" + to_string (breaks_) + "]");
91
92   recurse_over_translators (context (), &Translator::finalize, UP);
93 }
94
95 /*
96   use start/finish?
97  */
98 void
99 Score_engraver::initialize ()
100 {
101   Font_metric *fm = all_fonts_global->find_afm ("feta20");
102   if (!fm)
103     error (_f ("can't find `%s'", "feta20.afm")
104            + "\n" +_ ("Fonts have not been installed properly.  Aborting"));
105    
106
107   pscore_ = new Paper_score;
108   pscore_->paper_ = dynamic_cast<Paper_def*> (get_output_def ());
109
110   SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
111
112   pscore_->typeset_line (new System (props));
113   
114   make_columns ();
115   system_ = pscore_->system_;
116   system_->set_bound (LEFT, command_column_);
117   command_column_->set_property ("breakable", SCM_BOOL_T);
118
119   Engraver_group_engraver::initialize ();
120 }
121
122
123 void
124 Score_engraver::finalize ()
125 {
126   Score_translator::finalize ();
127
128   Grob * cc
129     = unsmob_grob (get_property ("currentCommandColumn"));
130   system_->set_bound (RIGHT, cc);
131   cc->set_property ("breakable", SCM_BOOL_T);
132   
133   typeset_all ();
134 }
135
136
137 void
138 Score_engraver::one_time_step ()
139 {
140   if (!to_boolean (get_property ("skipTypesetting")))
141     {
142       recurse_over_translators (context (), &Engraver::process_music, UP);
143       recurse_over_translators (context (), &Engraver::do_announces, UP);
144     }
145   
146   recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
147 }
148
149 void
150 Score_engraver::announce_grob (Grob_info info)
151 {
152   announce_infos_.push (info);
153   pscore_->system_->typeset_grob (info.grob_);
154   elems_.push (info.grob_);
155 }
156
157
158 void
159 Score_engraver::typeset_all ()
160 {
161   for (int i =0; i < elems_.size (); i++) 
162     {
163       Grob * elem = elems_[i];
164
165       
166       if (dynamic_cast<Item*> (elem)) 
167         {
168           if (!elem->get_parent (X_AXIS)
169               && elem != command_column_
170               && elem != musical_column_
171               )
172             {
173               bool br = to_boolean (elem->get_property ("breakable"));
174               Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
175
176             }
177         }
178       if (!elem->get_parent (Y_AXIS))
179         Axis_group_interface::add_element (system_, elem);
180     }
181   elems_.clear ();
182 }
183
184 void
185 Score_engraver::stop_translation_timestep ()
186 {
187   // this generates all items.
188   Engraver_group_engraver::stop_translation_timestep ();
189   
190   typeset_all ();
191   if (to_boolean (command_column_->get_property ("breakable")))
192     {
193       breaks_ ++;
194       if (! (breaks_%8))
195         progress_indication ("[" + to_string (breaks_) + "]");
196     }
197
198
199   system_->add_column (command_column_);
200   system_->add_column (musical_column_);
201   
202   command_column_ = 0;
203   musical_column_ = 0;
204 }
205
206 void
207 Score_engraver::set_columns (Paper_column *new_command, 
208                              Paper_column *new_musical)
209 {
210   assert (!command_column_ && !musical_column_);
211
212   command_column_ = new_command;
213   musical_column_ = new_musical;
214   if (new_command)
215     {
216       context ()->set_property ("currentCommandColumn", new_command->self_scm ());  
217     }
218   
219   if (new_musical)
220     {
221       context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
222     }
223 }
224
225 Music_output*
226 Score_engraver::get_output ()
227 {
228   Music_output *o = pscore_;
229   ///FIXME WTF?  pscore_ = 0;
230   return o;
231 }
232
233 bool
234 Score_engraver::try_music (Music *m)
235 {
236   if (Engraver_group_engraver::try_music (m))
237     return true;
238
239   if (m->is_mus_type ("break-event"))
240     {
241       SCM pen = command_column_->get_property ("penalty");
242       Real total_penalty = ly_c_number_p (pen) ? ly_scm2double (pen) : 0.0;
243
244       SCM mpen = m->get_property ("penalty");
245       if (ly_c_number_p (mpen))
246         total_penalty += ly_scm2double (mpen);
247
248       command_column_->set_property ("penalty", scm_make_real (total_penalty));
249
250       /* ugh.  arbitrary, hardcoded */
251       if (total_penalty > 10000.0)
252         forbid_breaks ();
253
254       SCM page_pen = command_column_->get_property ("page-penalty");
255       Real total_pp = ly_c_number_p (page_pen) ? ly_scm2double (page_pen) : 0.0;
256       SCM mpage_pen = m->get_property ("page-penalty");
257       if (ly_c_number_p (mpage_pen))
258         total_pp += ly_scm2double (mpage_pen);
259       
260       command_column_->set_property ("page-penalty", scm_make_real (total_pp));
261       return true;
262     }
263   return false;
264 }
265
266 void
267 Score_engraver::forbid_breaks ()
268 {
269   if (command_column_)
270     command_column_->set_property ("breakable", SCM_EOL);
271 }
272   
273 void
274 Score_engraver::acknowledge_grob (Grob_info gi)
275 {
276   if (Staff_spacing::has_interface (gi.grob_))
277     {
278       Pointer_group_interface::add_grob (command_column_,
279                                          ly_symbol2scm ("spacing-wishes"),
280                                          gi.grob_);
281     }
282   if (Note_spacing::has_interface (gi.grob_))
283     {
284       Pointer_group_interface::add_grob (musical_column_,
285                                          ly_symbol2scm ("spacing-wishes"),
286                                          gi.grob_);
287     }
288 }
289
290
291
292 ENTER_DESCRIPTION (Score_engraver,
293 /* descr */       "Top level engraver. Takes care of generating columns and the complete  system (ie. System) "
294 "\n\n "
295 "This engraver decides whether a column is breakable. The default is "
296 "that a column is always breakable. However, when every Bar_engraver "
297 "that does not have a barline at a certain point will call "
298 "Score_engraver::forbid_breaks to stop linebreaks.  In practice, this "
299 "means that you can make a breakpoint by creating a barline (assuming "
300 "that there are no beams or notes that prevent a breakpoint.) "
301 ,
302 /* creats*/       "System PaperColumn NonMusicalPaperColumn", 
303 /* accepts */     "break-event",
304 /* acks  */       "note-spacing-interface staff-spacing-interface",
305 /* reads */       "currentMusicalColumn currentCommandColumn",
306 /* write */       "");