2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "all-font-metrics.hh"
15 #include "score-engraver.hh"
16 #include "paper-score.hh"
17 #include "paper-column.hh"
18 #include "output-def.hh"
19 #include "axis-group-interface.hh"
20 #include "context-def.hh"
21 #include "staff-spacing.hh"
22 #include "note-spacing.hh"
24 #include "global-context.hh"
30 TODO: the column creation logic is rather hairy. Revise it.
32 Score_engraver::Score_engraver ()
42 Score_engraver::make_columns ()
50 = updated_grob_properties (context (),
51 ly_symbol2scm ("NonMusicalPaperColumn"));
53 Object_key const *key1 = context()->get_grob_key ("NonMusicalPaperColumn");
55 SCM pc = updated_grob_properties (context (),
56 ly_symbol2scm ("PaperColumn"));
57 Object_key const *key2 = context()->get_grob_key ("PaperColumn");
58 set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2));
61 scm_gc_unprotect_object (key1->self_scm());
62 scm_gc_unprotect_object (key2->self_scm());
65 i1.grob_ = command_column_;
66 i1.origin_trans_ = this;
71 i2.grob_ = musical_column_;
72 i2.origin_trans_ = this;
79 Score_engraver::prepare (Moment m)
82 TODO: don't make columns when skipTypesetting is true.
86 SCM w = m.smobbed_copy ();
87 command_column_->set_property ("when", w);
88 musical_column_->set_property ("when", w);
90 recurse_over_translators (context (), &Translator::start_translation_timestep, DOWN);
94 Score_engraver::finish ()
97 progress_indication ("[" + to_string (breaks_) + "]");
99 recurse_over_translators (context (), &Translator::finalize, UP);
106 Score_engraver::initialize ()
108 Font_metric *fm = all_fonts_global->find_afm ("feta20");
110 error (_f ("can't find `%s'", "feta20.afm")
111 + "\n" +_ ("Music font has not been installed properly. Aborting"));
113 SCM pfa_path = ly_kpathsea_expand_path (scm_makfrom0str ("ecrm10.pfa"));
114 if (!scm_is_string (pfa_path))
115 error (_f ("can't find `%s'", "ecrm10.pfa")
116 + "\n" +_f ("Install the ec-mftraced package from %s. Aborting",
117 "http://lilypond.org/download/fonts/"));
120 pscore_ = new Paper_score;
121 pscore_->layout_ = dynamic_cast<Output_def*> (get_output_def ());
123 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
125 Object_key const *sys_key = context()->get_grob_key ("System");
126 pscore_->typeset_line (new System (props, sys_key));
127 scm_gc_unprotect_object (sys_key->self_scm ());
130 system_ = pscore_->system_;
131 system_->set_bound (LEFT, command_column_);
132 command_column_->set_property ("breakable", SCM_BOOL_T);
134 Engraver_group_engraver::initialize ();
139 Score_engraver::finalize ()
141 Score_translator::finalize ();
144 = unsmob_grob (get_property ("currentCommandColumn"));
145 system_->set_bound (RIGHT, cc);
146 cc->set_property ("breakable", SCM_BOOL_T);
153 Score_engraver::one_time_step ()
155 if (!to_boolean (get_property ("skipTypesetting")))
157 recurse_over_translators (context (), &Engraver::process_music, UP);
158 Engraver_group_engraver::do_announces();
161 recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
165 Score_engraver::announce_grob (Grob_info info)
167 announce_infos_.push (info);
168 pscore_->system_->typeset_grob (info.grob_);
169 elems_.push (info.grob_);
174 Score_engraver::typeset_all ()
176 for (int i =0; i < elems_.size (); i++)
178 Grob * elem = elems_[i];
181 if (dynamic_cast<Item*> (elem))
183 if (!elem->get_parent (X_AXIS)
184 && elem != command_column_
185 && elem != musical_column_
188 bool br = to_boolean (elem->get_property ("breakable"));
189 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
193 if (!elem->get_parent (Y_AXIS))
194 Axis_group_interface::add_element (system_, elem);
200 Score_engraver::stop_translation_timestep ()
202 // this generates all items.
203 Engraver_group_engraver::stop_translation_timestep ();
206 if (to_boolean (command_column_->get_property ("breakable")))
210 progress_indication ("[" + to_string (breaks_) + "]");
214 system_->add_column (command_column_);
215 system_->add_column (musical_column_);
222 Score_engraver::set_columns (Paper_column *new_command,
223 Paper_column *new_musical)
225 assert (!command_column_ && !musical_column_);
227 command_column_ = new_command;
228 musical_column_ = new_musical;
231 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
236 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
241 Score_engraver::get_output ()
243 Music_output *o = pscore_;
244 ///FIXME WTF? pscore_ = 0;
249 Score_engraver::try_music (Music *m)
251 if (Engraver_group_engraver::try_music (m))
254 if (m->is_mus_type ("break-event"))
256 SCM pen = command_column_->get_property ("penalty");
257 Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0;
259 SCM mpen = m->get_property ("penalty");
260 if (scm_is_number (mpen))
261 total_penalty += scm_to_double (mpen);
263 command_column_->set_property ("penalty", scm_make_real (total_penalty));
265 /* ugh. arbitrary, hardcoded */
266 if (total_penalty > 10000.0)
269 SCM page_pen = command_column_->get_property ("page-penalty");
270 Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0;
271 SCM mpage_pen = m->get_property ("page-penalty");
272 if (scm_is_number (mpage_pen))
273 total_pp += scm_to_double (mpage_pen);
275 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
282 Score_engraver::forbid_breaks ()
285 command_column_->set_property ("breakable", SCM_EOL);
289 Score_engraver::acknowledge_grob (Grob_info gi)
291 if (Staff_spacing::has_interface (gi.grob_))
293 Pointer_group_interface::add_grob (command_column_,
294 ly_symbol2scm ("spacing-wishes"),
297 if (Note_spacing::has_interface (gi.grob_))
299 Pointer_group_interface::add_grob (musical_column_,
300 ly_symbol2scm ("spacing-wishes"),
304 if (Axis_group_interface::has_interface (gi.grob_)
305 && gi.grob_->internal_has_interface (ly_symbol2scm ("vertically-spaceable-interface")))
307 SCM spaceable = get_property ("verticallySpacedContexts");
308 Context *orig = gi.origin_contexts (this)[0];
310 if (scm_memq (ly_symbol2scm (orig->context_name ().to_str0()),
311 spaceable) != SCM_BOOL_F)
313 Pointer_group_interface::add_grob (system_,
314 ly_symbol2scm ("spaceable-staves"),
323 ENTER_DESCRIPTION (Score_engraver,
324 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
326 "This engraver decides whether a column is breakable. The default is "
327 "that a column is always breakable. However, when every Bar_engraver "
328 "that does not have a barline at a certain point will call "
329 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
330 "means that you can make a breakpoint by creating a barline (assuming "
331 "that there are no beams or notes that prevent a breakpoint.) "
333 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
334 /* accepts */ "break-event",
335 /* acks */ "note-spacing-interface staff-spacing-interface axis-group-interface",
336 /* reads */ "currentMusicalColumn currentCommandColumn verticallySpacedContexts",