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" +_ ("Fonts have not been installed properly. Aborting"));
107 pscore_ = new Paper_score;
108 pscore_->paper_ = dynamic_cast<Output_def*> (get_output_def ());
110 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
112 pscore_->typeset_line (new System (props));
115 system_ = pscore_->system_;
116 system_->set_bound (LEFT, command_column_);
117 command_column_->set_property ("breakable", SCM_BOOL_T);
119 Engraver_group_engraver::initialize ();
124 Score_engraver::finalize ()
126 Score_translator::finalize ();
129 = unsmob_grob (get_property ("currentCommandColumn"));
130 system_->set_bound (RIGHT, cc);
131 cc->set_property ("breakable", SCM_BOOL_T);
138 Score_engraver::one_time_step ()
140 if (!to_boolean (get_property ("skipTypesetting")))
142 recurse_over_translators (context (), &Engraver::process_music, UP);
143 recurse_over_translators (context (), &Engraver::do_announces, UP);
146 recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
150 Score_engraver::announce_grob (Grob_info info)
152 announce_infos_.push (info);
153 pscore_->system_->typeset_grob (info.grob_);
154 elems_.push (info.grob_);
159 Score_engraver::typeset_all ()
161 for (int i =0; i < elems_.size (); i++)
163 Grob * elem = elems_[i];
166 if (dynamic_cast<Item*> (elem))
168 if (!elem->get_parent (X_AXIS)
169 && elem != command_column_
170 && elem != musical_column_
173 bool br = to_boolean (elem->get_property ("breakable"));
174 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
178 if (!elem->get_parent (Y_AXIS))
179 Axis_group_interface::add_element (system_, elem);
185 Score_engraver::stop_translation_timestep ()
187 // this generates all items.
188 Engraver_group_engraver::stop_translation_timestep ();
191 if (to_boolean (command_column_->get_property ("breakable")))
195 progress_indication ("[" + to_string (breaks_) + "]");
199 system_->add_column (command_column_);
200 system_->add_column (musical_column_);
207 Score_engraver::set_columns (Paper_column *new_command,
208 Paper_column *new_musical)
210 assert (!command_column_ && !musical_column_);
212 command_column_ = new_command;
213 musical_column_ = new_musical;
216 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
221 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
226 Score_engraver::get_output ()
228 Music_output *o = pscore_;
229 ///FIXME WTF? pscore_ = 0;
234 Score_engraver::try_music (Music *m)
236 if (Engraver_group_engraver::try_music (m))
239 if (m->is_mus_type ("break-event"))
241 SCM pen = command_column_->get_property ("penalty");
242 Real total_penalty = ly_c_number_p (pen) ? ly_scm2double (pen) : 0.0;
244 SCM mpen = m->get_property ("penalty");
245 if (ly_c_number_p (mpen))
246 total_penalty += ly_scm2double (mpen);
248 command_column_->set_property ("penalty", scm_make_real (total_penalty));
250 /* ugh. arbitrary, hardcoded */
251 if (total_penalty > 10000.0)
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);
260 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
267 Score_engraver::forbid_breaks ()
270 command_column_->set_property ("breakable", SCM_EOL);
274 Score_engraver::acknowledge_grob (Grob_info gi)
276 if (Staff_spacing::has_interface (gi.grob_))
278 Pointer_group_interface::add_grob (command_column_,
279 ly_symbol2scm ("spacing-wishes"),
282 if (Note_spacing::has_interface (gi.grob_))
284 Pointer_group_interface::add_grob (musical_column_,
285 ly_symbol2scm ("spacing-wishes"),
292 ENTER_DESCRIPTION (Score_engraver,
293 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
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.) "
302 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
303 /* accepts */ "break-event",
304 /* acks */ "note-spacing-interface staff-spacing-interface",
305 /* reads */ "currentMusicalColumn currentCommandColumn",