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 "paper-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 (daddy_context_,
51 ly_symbol2scm ("NonMusicalPaperColumn"));
52 SCM pc = updated_grob_properties (daddy_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 (daddy_context_, &Translator::start_translation_timestep, DOWN);
87 Score_engraver::finish ()
90 progress_indication ("[" + to_string (breaks_) + "]");
92 recurse_over_translators (daddy_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<Paper_def*> (get_output_def ());
110 SCM props = updated_grob_properties (daddy_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 (daddy_context_, &Engraver::process_music, UP);
143 recurse_over_translators (daddy_context_, &Engraver::do_announces, UP);
146 recurse_over_translators (daddy_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_);
157 Score_engraver::typeset_grob (Grob *elem)
160 programming_error ("Score_engraver: empty elt\n");
166 Score_engraver::typeset_all ()
168 for (int i =0; i < elems_.size (); i++)
170 Grob * elem = elems_[i];
172 if (Spanner *s = dynamic_cast <Spanner *> (elem))
175 do something sensible if spanner not
180 if (!s->get_bound (d))
183 = unsmob_grob (get_property ("currentCommandColumn"));
184 s->set_bound (d, cc);
185 /* don't warn for empty/suicided spanners,
186 it makes real warningsinvisible.
187 maybe should be junked earlier? */
189 elem->warning (_f ("unbound spanner `%s'", s->name ().to_str0 ()));
192 while (flip (&d) != LEFT);
194 if (dynamic_cast<Item*> (s->get_parent (Y_AXIS)))
195 programming_error ("Spanner Y-parent is an item.");
199 if (!elem->get_parent (X_AXIS))
201 bool br = to_boolean (elem->get_property ("breakable"));
202 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
206 if (!elem->get_parent (Y_AXIS))
207 Axis_group_interface::add_element (system_, elem);
213 Score_engraver::stop_translation_timestep ()
215 // this generates all items.
216 Engraver_group_engraver::stop_translation_timestep ();
219 if (to_boolean (command_column_->get_property ("breakable")))
223 progress_indication ("[" + to_string (breaks_) + "]");
227 system_->add_column (command_column_);
228 system_->add_column (musical_column_);
235 Score_engraver::set_columns (Paper_column *new_command,
236 Paper_column *new_musical)
238 assert (!command_column_ && !musical_column_);
240 command_column_ = new_command;
241 musical_column_ = new_musical;
244 daddy_context_->set_property ("currentCommandColumn", new_command->self_scm ());
249 daddy_context_->set_property ("currentMusicalColumn", new_musical->self_scm ());
254 Score_engraver::get_output ()
256 Music_output *o = pscore_;
257 ///FIXME WTF? pscore_ = 0;
262 Score_engraver::try_music (Music *m)
264 if (Engraver_group_engraver::try_music (m))
267 if (m->is_mus_type ("break-event"))
269 SCM pen = command_column_->get_property ("penalty");
270 Real total_penalty = is_number (pen) ? ly_scm2double (pen) : 0.0;
272 SCM mpen = m->get_property ("penalty");
273 if (is_number (mpen))
274 total_penalty += ly_scm2double (mpen);
276 command_column_->set_property ("penalty", scm_make_real (total_penalty));
278 /* ugh. arbitrary, hardcoded */
279 if (total_penalty > 10000.0)
282 SCM page_pen = command_column_->get_property ("page-penalty");
283 Real total_pp = is_number (page_pen) ? ly_scm2double (page_pen) : 0.0;
284 SCM mpage_pen = m->get_property ("page-penalty");
285 if (is_number (mpage_pen))
286 total_pp += ly_scm2double (mpage_pen);
288 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
295 Score_engraver::forbid_breaks ()
298 command_column_->set_property ("breakable", SCM_EOL);
302 Score_engraver::acknowledge_grob (Grob_info gi)
304 if (Staff_spacing::has_interface (gi.grob_))
306 Pointer_group_interface::add_grob (command_column_,
307 ly_symbol2scm ("spacing-wishes"),
310 if (Note_spacing::has_interface (gi.grob_))
312 Pointer_group_interface::add_grob (musical_column_,
313 ly_symbol2scm ("spacing-wishes"),
320 ENTER_DESCRIPTION (Score_engraver,
321 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
323 "This engraver decides whether a column is breakable. The default is "
324 "that a column is always breakable. However, when every Bar_engraver "
325 "that does not have a barline at a certain point will call "
326 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
327 "means that you can make a breakpoint by creating a barline (assuming "
328 "that there are no beams or notes that prevent a breakpoint.) "
330 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
331 /* accepts */ "break-event",
332 /* acks */ "note-spacing-interface staff-spacing-interface",
333 /* reads */ "currentMusicalColumn currentCommandColumn",