2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 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"
19 #include "paper-def.hh"
20 #include "axis-group-interface.hh"
21 #include "translator-def.hh"
23 #include "staff-spacing.hh"
24 #include "note-spacing.hh"
27 TODO: the column creation logic is rather hairy. Revise it.
29 Score_engraver::Score_engraver ()
39 Score_engraver::make_columns ()
46 set_columns (new Paper_column (get_property ("NonMusicalPaperColumn")),
47 new Paper_column (get_property ("PaperColumn")));
49 command_column_->set_grob_property ("breakable", SCM_BOOL_T);
53 i1.grob_ = command_column_;
54 i1.origin_trans_ = this;
59 i2.grob_ = musical_column_;
60 i2.origin_trans_ = this;
67 Score_engraver::prepare (Moment w)
69 Global_translator::prepare (w);
72 TODO: don't make columns when skipTypesetting is true.
76 command_column_->set_grob_property ("when", now_mom_.smobbed_copy ());
77 musical_column_->set_grob_property ("when", now_mom_.smobbed_copy ());
80 Translator_group::start_translation_timestep();
84 Score_engraver::finish ()
87 progress_indication ("[" + to_string (breaks_) + "]");
98 Score_engraver::initialize ()
100 Font_metric *fm = all_fonts_global->find_afm("feta20");
102 error (_f ("can't find `%s'", "feta20.afm")
103 + "\n" +_ ("Fonts have not been installed properly. Aborting"));
105 unsmob_translator_def (definition_)->apply_default_property_operations (this);
107 assert (dynamic_cast<Paper_def *> (output_def_));
108 assert (!daddy_trans_);
109 pscore_ = new Paper_score;
110 pscore_->paper_ = dynamic_cast<Paper_def*> (output_def_);
112 SCM props = get_property ("System");
114 pscore_->typeset_line (new System (props));
117 system_ = pscore_->system_;
118 system_->set_bound (LEFT, command_column_);
119 command_column_->set_grob_property ("breakable", SCM_BOOL_T);
121 Engraver_group_engraver::initialize ();
126 Score_engraver::finalize ()
128 Engraver_group_engraver::finalize ();
131 = unsmob_grob (get_property ("currentCommandColumn"));
132 system_->set_bound (RIGHT, cc);
133 cc->set_grob_property ("breakable", SCM_BOOL_T);
139 Score_engraver::one_time_step ()
141 if (!to_boolean (get_property ("skipTypesetting")))
147 stop_translation_timestep ();
149 apply_finalizations ();
153 for (int i = announce_infos_.size(); i--;)
155 Grob *g = announce_infos_[i].grob_;
156 if (!dynamic_cast<Paper_column*> (g)) // ugh.
160 + " was created too late!";
161 g->programming_error (msg);
164 announce_infos_.clear ();
168 Score_engraver::announce_grob (Grob_info info)
170 announce_infos_.push (info);
171 pscore_->system_->typeset_grob (info.grob_);
175 Score_engraver::typeset_grob (Grob *elem)
178 programming_error ("Score_engraver: empty elt\n");
184 Score_engraver::typeset_all ()
186 for (int i =0; i < elems_.size (); i++)
188 Grob * elem = elems_[i];
190 if (Spanner *s = dynamic_cast <Spanner *> (elem))
193 do something sensible if spanner not
198 if (!s->get_bound (d))
200 s->set_bound (d, command_column_);
201 /* don't warn for empty/suicided spanners,
202 it makes real warningsinvisible.
203 maybe should be junked earlier? */
207 elem->warning (_f ("unbound spanner `%s'", s->name ().to_str0 ()));
210 while (flip (&d) != LEFT);
212 if (dynamic_cast<Item*> (s->get_parent (Y_AXIS)))
213 programming_error ("Spanner Y-parent is an item.");
217 if (!elem->get_parent (X_AXIS))
219 bool br = to_boolean (elem->get_grob_property ("breakable"));
220 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
224 if (!elem->get_parent (Y_AXIS))
225 Axis_group_interface::add_element (system_, elem);
231 Score_engraver::stop_translation_timestep ()
233 // this generates all items.
234 Engraver_group_engraver::stop_translation_timestep ();
237 if (to_boolean (command_column_->get_grob_property ("breakable")))
241 progress_indication ("[" + to_string (breaks_) + "]");
245 system_->add_column (command_column_);
246 system_->add_column (musical_column_);
253 Score_engraver::set_columns (Paper_column *new_command,
254 Paper_column *new_musical)
256 assert (!command_column_ && !musical_column_);
258 command_column_ = new_command;
259 musical_column_ = new_musical;
262 set_property ("currentCommandColumn", new_command->self_scm ());
267 set_property ("currentMusicalColumn", new_musical->self_scm ());
272 Score_engraver::get_output ()
274 Music_output * o = pscore_;
280 Score_engraver::try_music (Music*r)
282 bool gotcha = Engraver_group_engraver::try_music (r);
284 if (!gotcha && r->is_mus_type ("break-event"))
288 SCM pen = command_column_->get_grob_property ("penalty");
289 Real total_penalty = gh_number_p (pen)
290 ? gh_scm2double (pen)
293 SCM rpen = r->get_mus_property ("penalty");
294 if (gh_number_p (rpen))
295 total_penalty += gh_scm2double (rpen);
297 if (total_penalty > 10000.0) // ugh. arbitrary.
300 command_column_->set_grob_property ("penalty",
301 gh_double2scm (total_penalty));
307 TODO: use property Score.breakForbidden = #t
310 Score_engraver::forbid_breaks ()
316 command_column_->set_grob_property ("breakable", SCM_EOL);
320 Score_engraver::acknowledge_grob (Grob_info gi)
322 if (Staff_spacing::has_interface (gi.grob_))
324 Pointer_group_interface::add_grob (command_column_,
325 ly_symbol2scm ("spacing-wishes"),
328 if (Note_spacing::has_interface (gi.grob_))
330 Pointer_group_interface::add_grob (musical_column_,
331 ly_symbol2scm ("spacing-wishes"),
338 ENTER_DESCRIPTION(Score_engraver,
339 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
341 "This engraver decides whether a column is breakable. The default is "
342 "that a column is always breakable. However, when every Bar_engraver "
343 "that does not have a barline at a certain point will call "
344 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
345 "means that you can make a breakpoint by creating a barline (assuming "
346 "that there are no beams or notes that prevent a breakpoint.) "
348 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
349 /* accepts */ "break-event",
350 /* acks */ "note-spacing-interface staff-spacing-interface",
351 /* reads */ "currentMusicalColumn currentCommandColumn",