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::derived_mark () const
41 scm_gc_mark (pscore_->self_scm ());
42 Score_translator::derived_mark ();
43 Engraver_group_engraver::derived_mark ();
47 Score_engraver::make_columns ()
55 = updated_grob_properties (context (),
56 ly_symbol2scm ("NonMusicalPaperColumn"));
58 Object_key const *key1 = context ()->get_grob_key ("NonMusicalPaperColumn");
60 SCM pc = updated_grob_properties (context (),
61 ly_symbol2scm ("PaperColumn"));
62 Object_key const *key2 = context ()->get_grob_key ("PaperColumn");
63 set_columns (new Paper_column (nmp, key1), new Paper_column (pc, key2));
65 Grob_info i1 (this, command_column_);
68 Grob_info i2 (this, musical_column_);
74 Score_engraver::prepare (Moment m)
77 TODO: don't make columns when skipTypesetting is true.
81 SCM w = m.smobbed_copy ();
82 command_column_->set_property ("when", w);
83 musical_column_->set_property ("when", w);
85 recurse_over_translators (context (), &Translator::start_translation_timestep, DOWN);
89 Score_engraver::finish ()
92 progress_indication ("[" + to_string (breaks_) + "]");
94 recurse_over_translators (context (), &Translator::finalize, UP);
97 #define MUSIC_FONT "emmentaler-20"
103 Score_engraver::initialize ()
105 Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
108 error (_f ("cannot find `%s'", MUSIC_FONT ".otf")
110 + _ ("Music font has not been installed properly.")
112 + _f ("Search path `%s'", global_path.to_string ().to_str0 ())
117 pscore_ = new Paper_score (dynamic_cast<Output_def *> (get_output_def ()));
118 scm_gc_unprotect_object (pscore_->self_scm ());
120 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
122 Object_key const *sys_key = context ()->get_grob_key ("System");
123 pscore_->typeset_system (new System (props, sys_key));
125 system_ = pscore_->root_system ();
127 system_->set_bound (LEFT, command_column_);
128 command_column_->set_property ("breakable", SCM_BOOL_T);
130 Engraver_group_engraver::initialize ();
134 Score_engraver::finalize ()
136 Score_translator::finalize ();
139 = unsmob_grob (get_property ("currentCommandColumn"));
140 system_->set_bound (RIGHT, cc);
141 cc->set_property ("breakable", SCM_BOOL_T);
147 Score_engraver::one_time_step ()
149 if (!to_boolean (get_property ("skipTypesetting")))
151 recurse_over_translators (context (), &Engraver::process_music, UP);
152 Engraver_group_engraver::do_announces ();
155 recurse_over_translators (context (), &Translator::stop_translation_timestep, UP);
159 Score_engraver::announce_grob (Grob_info info)
161 announce_infos_.push (info);
162 pscore_->root_system ()->typeset_grob (info.grob ());
163 elems_.push (info.grob ());
167 Score_engraver::typeset_all ()
169 for (int i = 0; i < elems_.size (); i++)
171 Grob *elem = elems_[i];
173 if (dynamic_cast<Item *> (elem))
175 if ((!elem->get_parent (X_AXIS)
176 || !unsmob_grob (elem->get_property ("axis-group-parent-X")))
177 && elem != command_column_
178 && elem != musical_column_)
180 bool br = to_boolean (elem->get_property ("breakable"));
181 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_) + "]");
209 Score_engraver::set_columns (Paper_column *new_command,
210 Paper_column *new_musical)
212 assert (!command_column_ && !musical_column_);
214 command_column_ = new_command;
215 musical_column_ = new_musical;
218 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
223 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
226 system_->add_column (command_column_);
227 system_->add_column (musical_column_);
231 Score_engraver::get_output ()
233 Music_output *o = pscore_;
234 return o->self_scm ();
238 Score_engraver::try_music (Music *m)
240 if (Engraver_group_engraver::try_music (m))
243 if (m->is_mus_type ("break-event"))
245 SCM pen = command_column_->get_property ("penalty");
246 Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0;
248 SCM mpen = m->get_property ("penalty");
249 if (scm_is_number (mpen))
250 total_penalty += scm_to_double (mpen);
252 command_column_->set_property ("penalty", scm_make_real (total_penalty));
254 /* ugh. arbitrary, hardcoded */
255 if (total_penalty > 10000.0)
258 SCM page_pen = command_column_->get_property ("page-penalty");
259 Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0;
260 SCM mpage_pen = m->get_property ("page-penalty");
261 if (scm_is_number (mpage_pen))
262 total_pp += scm_to_double (mpage_pen);
264 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
271 Score_engraver::forbid_breaks ()
274 command_column_->set_property ("breakable", SCM_EOL);
278 Score_engraver::acknowledge_grob (Grob_info gi)
280 if (Staff_spacing::has_interface (gi.grob ()))
282 Pointer_group_interface::add_grob (command_column_,
283 ly_symbol2scm ("spacing-wishes"),
286 if (Note_spacing::has_interface (gi.grob ()))
288 Pointer_group_interface::add_grob (musical_column_,
289 ly_symbol2scm ("spacing-wishes"),
293 if (Axis_group_interface::has_interface (gi.grob ())
294 && gi.grob ()->internal_has_interface (ly_symbol2scm ("vertically-spaceable-interface")))
296 SCM spaceable = get_property ("verticallySpacedContexts");
297 Context *orig = gi.origin_contexts (this)[0];
299 if (scm_memq (ly_symbol2scm (orig->context_name ().to_str0 ()),
300 spaceable) != SCM_BOOL_F)
302 Pointer_group_interface::add_grob (system_,
303 ly_symbol2scm ("spaceable-staves"),
309 ADD_TRANSLATOR (Score_engraver,
310 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
312 "This engraver decides whether a column is breakable. The default is "
313 "that a column is always breakable. However, when every Bar_engraver "
314 "that does not have a barline at a certain point will call "
315 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
316 "means that you can make a breakpoint by creating a barline (assuming "
317 "that there are no beams or notes that prevent a breakpoint.) ",
318 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
319 /* accepts */ "break-event",
320 /* acks */ "note-spacing-interface staff-spacing-interface axis-group-interface",
321 /* reads */ "currentMusicalColumn currentCommandColumn verticallySpacedContexts",