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"));
52 SCM pc = updated_grob_properties (context (),
53 ly_symbol2scm ("PaperColumn"));
55 set_columns (new Paper_column (nmp), new Paper_column (pc));
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);
99 Score_engraver::initialize ()
101 Font_metric *fm = all_fonts_global->find_afm ("feta20");
103 error (_f ("can't find `%s'", "feta20.afm")
104 + "\n" +_ ("Music font has not been installed properly. Aborting"));
106 SCM pfa_path = ly_kpathsea_expand_path (scm_makfrom0str ("ecrm10.pfa"));
107 if (!scm_is_string (pfa_path))
108 error (_f ("can't find `%s'", "ecrm10.pfa")
109 + "\n" +_f ("Install the ec-mftraced package from %s. Aborting",
110 "http://lilypond.org/download/fonts/"));
113 pscore_ = new Paper_score;
114 pscore_->layout_ = dynamic_cast<Output_def*> (get_output_def ());
116 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
118 pscore_->typeset_line (new System (props));
121 system_ = pscore_->system_;
122 system_->set_bound (LEFT, command_column_);
123 command_column_->set_property ("breakable", SCM_BOOL_T);
125 Engraver_group_engraver::initialize ();
130 Score_engraver::finalize ()
132 Score_translator::finalize ();
135 = unsmob_grob (get_property ("currentCommandColumn"));
136 system_->set_bound (RIGHT, cc);
137 cc->set_property ("breakable", SCM_BOOL_T);
144 Score_engraver::one_time_step ()
146 if (!to_boolean (get_property ("skipTypesetting")))
148 recurse_over_translators (context (), &Engraver::process_music, UP);
149 Engraver_group_engraver::do_announces();
152 recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
156 Score_engraver::announce_grob (Grob_info info)
158 announce_infos_.push (info);
159 pscore_->system_->typeset_grob (info.grob_);
160 elems_.push (info.grob_);
165 Score_engraver::typeset_all ()
167 for (int i =0; i < elems_.size (); i++)
169 Grob * elem = elems_[i];
172 if (dynamic_cast<Item*> (elem))
174 if (!elem->get_parent (X_AXIS)
175 && elem != command_column_
176 && elem != musical_column_
179 bool br = to_boolean (elem->get_property ("breakable"));
180 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
184 if (!elem->get_parent (Y_AXIS))
185 Axis_group_interface::add_element (system_, elem);
191 Score_engraver::stop_translation_timestep ()
193 // this generates all items.
194 Engraver_group_engraver::stop_translation_timestep ();
197 if (to_boolean (command_column_->get_property ("breakable")))
201 progress_indication ("[" + to_string (breaks_) + "]");
205 system_->add_column (command_column_);
206 system_->add_column (musical_column_);
213 Score_engraver::set_columns (Paper_column *new_command,
214 Paper_column *new_musical)
216 assert (!command_column_ && !musical_column_);
218 command_column_ = new_command;
219 musical_column_ = new_musical;
222 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
227 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
232 Score_engraver::get_output ()
234 Music_output *o = pscore_;
235 ///FIXME WTF? pscore_ = 0;
240 Score_engraver::try_music (Music *m)
242 if (Engraver_group_engraver::try_music (m))
245 if (m->is_mus_type ("break-event"))
247 SCM pen = command_column_->get_property ("penalty");
248 Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0;
250 SCM mpen = m->get_property ("penalty");
251 if (scm_is_number (mpen))
252 total_penalty += scm_to_double (mpen);
254 command_column_->set_property ("penalty", scm_make_real (total_penalty));
256 /* ugh. arbitrary, hardcoded */
257 if (total_penalty > 10000.0)
260 SCM page_pen = command_column_->get_property ("page-penalty");
261 Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0;
262 SCM mpage_pen = m->get_property ("page-penalty");
263 if (scm_is_number (mpage_pen))
264 total_pp += scm_to_double (mpage_pen);
266 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
273 Score_engraver::forbid_breaks ()
276 command_column_->set_property ("breakable", SCM_EOL);
280 Score_engraver::acknowledge_grob (Grob_info gi)
282 if (Staff_spacing::has_interface (gi.grob_))
284 Pointer_group_interface::add_grob (command_column_,
285 ly_symbol2scm ("spacing-wishes"),
288 if (Note_spacing::has_interface (gi.grob_))
290 Pointer_group_interface::add_grob (musical_column_,
291 ly_symbol2scm ("spacing-wishes"),
295 if (Axis_group_interface::has_interface (gi.grob_)
296 && gi.grob_->internal_has_interface (ly_symbol2scm ("vertically-spaceable-interface")))
298 SCM spaceable = get_property ("verticallySpacedContexts");
299 Context *orig = gi.origin_contexts (this)[0];
301 if (scm_memq (ly_symbol2scm (orig->context_name ().to_str0()),
302 spaceable) != SCM_BOOL_F)
304 Pointer_group_interface::add_grob (system_,
305 ly_symbol2scm ("spaceable-staves"),
314 ENTER_DESCRIPTION (Score_engraver,
315 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
317 "This engraver decides whether a column is breakable. The default is "
318 "that a column is always breakable. However, when every Bar_engraver "
319 "that does not have a barline at a certain point will call "
320 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
321 "means that you can make a breakpoint by creating a barline (assuming "
322 "that there are no beams or notes that prevent a breakpoint.) "
324 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
325 /* accepts */ "break-event",
326 /* acks */ "note-spacing-interface staff-spacing-interface axis-group-interface",
327 /* reads */ "currentMusicalColumn currentCommandColumn verticallySpacedContexts",