2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "all-font-metrics.hh"
14 #include "score-engraver.hh"
15 #include "paper-score.hh"
16 #include "paper-column.hh"
17 #include "output-def.hh"
18 #include "axis-group-interface.hh"
19 #include "context-def.hh"
20 #include "staff-spacing.hh"
21 #include "note-spacing.hh"
22 #include "global-context.hh"
23 #include "open-type-font.hh"
26 TODO: the column creation logic is rather hairy. Revise it.
28 Score_engraver::Score_engraver ()
38 Score_engraver::make_columns ()
46 = updated_grob_properties (context (),
47 ly_symbol2scm ("NonMusicalPaperColumn"));
49 Object_key const *key1 = context()->get_grob_key ("NonMusicalPaperColumn");
51 SCM pc = updated_grob_properties (context (),
52 ly_symbol2scm ("PaperColumn"));
53 Object_key const *key2 = context()->get_grob_key ("PaperColumn");
54 set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2));
58 i1.grob_ = command_column_;
59 i1.origin_trans_ = this;
64 i2.grob_ = musical_column_;
65 i2.origin_trans_ = this;
72 Score_engraver::prepare (Moment m)
75 TODO: don't make columns when skipTypesetting is true.
79 SCM w = m.smobbed_copy ();
80 command_column_->set_property ("when", w);
81 musical_column_->set_property ("when", w);
83 recurse_over_translators (context (), &Translator::start_translation_timestep, DOWN);
87 Score_engraver::finish ()
90 progress_indication ("[" + to_string (breaks_) + "]");
92 recurse_over_translators (context (), &Translator::finalize, UP);
95 #define MUSIC_FONT "emmentaler20"
101 Score_engraver::initialize ()
103 Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
106 error (_f ("cannot find `%s'", MUSIC_FONT ".otf")
108 + _ ("Music font has not been installed properly.\n")
109 + _f ("Search path `%s'\n", global_path.to_string ().to_str0())
113 if (!scm_is_string (ly_kpathsea_find_file (scm_makfrom0str ("ecrm10.pfa")))
114 && (!scm_is_string (ly_kpathsea_find_file (scm_makfrom0str ("lmr10.pfb")))))
115 error (_f ("cannot find `%s'", "ecrm10.pfa")
117 + _f ("cannot find `%s'", "lmr10.pfb")
119 + _f ("Install the ec-fonts-mftraced package from: %s.",
120 "http://lilypond.org/download/fonts/")
124 pscore_ = new Paper_score;
125 pscore_->layout_ = dynamic_cast<Output_def*> (get_output_def ());
127 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
129 Object_key const *sys_key = context()->get_grob_key ("System");
130 pscore_->typeset_line (new System (props, sys_key));
133 system_ = pscore_->system_;
134 system_->set_bound (LEFT, command_column_);
135 command_column_->set_property ("breakable", SCM_BOOL_T);
137 Engraver_group_engraver::initialize ();
142 Score_engraver::finalize ()
144 Score_translator::finalize ();
147 = unsmob_grob (get_property ("currentCommandColumn"));
148 system_->set_bound (RIGHT, cc);
149 cc->set_property ("breakable", SCM_BOOL_T);
156 Score_engraver::one_time_step ()
158 if (!to_boolean (get_property ("skipTypesetting")))
160 recurse_over_translators (context (), &Engraver::process_music, UP);
161 Engraver_group_engraver::do_announces();
164 recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
168 Score_engraver::announce_grob (Grob_info info)
170 announce_infos_.push (info);
171 pscore_->system_->typeset_grob (info.grob_);
172 elems_.push (info.grob_);
177 Score_engraver::typeset_all ()
179 for (int i = 0; i < elems_.size (); i++)
181 Grob * elem = elems_[i];
184 if (dynamic_cast<Item*> (elem))
187 (!elem->get_parent (X_AXIS)
188 || !unsmob_grob (elem->get_property ("axis-group-parent-X")))
189 && elem != command_column_
190 && elem != musical_column_
193 bool br = to_boolean (elem->get_property ("breakable"));
194 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
198 if (!elem->get_parent (Y_AXIS))
199 Axis_group_interface::add_element (system_, elem);
205 Score_engraver::stop_translation_timestep ()
207 // this generates all items.
208 Engraver_group_engraver::stop_translation_timestep ();
211 if (to_boolean (command_column_->get_property ("breakable")))
215 progress_indication ("[" + to_string (breaks_) + "]");
219 system_->add_column (command_column_);
220 system_->add_column (musical_column_);
227 Score_engraver::set_columns (Paper_column *new_command,
228 Paper_column *new_musical)
230 assert (!command_column_ && !musical_column_);
232 command_column_ = new_command;
233 musical_column_ = new_musical;
236 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
241 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
246 Score_engraver::get_output ()
248 Music_output *o = pscore_;
249 ///FIXME WTF? pscore_ = 0;
254 Score_engraver::try_music (Music *m)
256 if (Engraver_group_engraver::try_music (m))
259 if (m->is_mus_type ("break-event"))
261 SCM pen = command_column_->get_property ("penalty");
262 Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0;
264 SCM mpen = m->get_property ("penalty");
265 if (scm_is_number (mpen))
266 total_penalty += scm_to_double (mpen);
268 command_column_->set_property ("penalty", scm_make_real (total_penalty));
270 /* ugh. arbitrary, hardcoded */
271 if (total_penalty > 10000.0)
274 SCM page_pen = command_column_->get_property ("page-penalty");
275 Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0;
276 SCM mpage_pen = m->get_property ("page-penalty");
277 if (scm_is_number (mpage_pen))
278 total_pp += scm_to_double (mpage_pen);
280 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
287 Score_engraver::forbid_breaks ()
290 command_column_->set_property ("breakable", SCM_EOL);
294 Score_engraver::acknowledge_grob (Grob_info gi)
296 if (Staff_spacing::has_interface (gi.grob_))
298 Pointer_group_interface::add_grob (command_column_,
299 ly_symbol2scm ("spacing-wishes"),
302 if (Note_spacing::has_interface (gi.grob_))
304 Pointer_group_interface::add_grob (musical_column_,
305 ly_symbol2scm ("spacing-wishes"),
309 if (Axis_group_interface::has_interface (gi.grob_)
310 && gi.grob_->internal_has_interface (ly_symbol2scm ("vertically-spaceable-interface")))
312 SCM spaceable = get_property ("verticallySpacedContexts");
313 Context *orig = gi.origin_contexts (this)[0];
315 if (scm_memq (ly_symbol2scm (orig->context_name ().to_str0()),
316 spaceable) != SCM_BOOL_F)
318 Pointer_group_interface::add_grob (system_,
319 ly_symbol2scm ("spaceable-staves"),
328 ADD_TRANSLATOR (Score_engraver,
329 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
331 "This engraver decides whether a column is breakable. The default is "
332 "that a column is always breakable. However, when every Bar_engraver "
333 "that does not have a barline at a certain point will call "
334 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
335 "means that you can make a breakpoint by creating a barline (assuming "
336 "that there are no beams or notes that prevent a breakpoint.) "
338 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
339 /* accepts */ "break-event",
340 /* acks */ "note-spacing-interface staff-spacing-interface axis-group-interface",
341 /* reads */ "currentMusicalColumn currentCommandColumn verticallySpacedContexts",