2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "score-engraver.hh"
14 #include "paper-score.hh"
15 #include "paper-column.hh"
16 #include "command-request.hh"
17 #include "paper-def.hh"
18 #include "axis-group-interface.hh"
19 #include "translator-def.hh"
21 #include "staff-spacing.hh"
22 #include "note-spacing.hh"
25 TODO: the column creation logic is rather hairy. Revise it.
27 Score_engraver::Score_engraver ()
37 Score_engraver::make_columns ()
42 if (!command_column_l_)
44 set_columns (new Paper_column (get_property ("NonMusicalPaperColumn")),
45 new Paper_column (get_property ("PaperColumn")));
47 command_column_l_->set_grob_property ("breakable", SCM_BOOL_T);
49 Grob_info i1 (command_column_l_);
50 i1.origin_trans_l_ = this;
52 Grob_info i2 (musical_column_l_);
53 i2.origin_trans_l_ = this;
61 Score_engraver::prepare (Moment w)
63 Global_translator::prepare (w);
67 command_column_l_->set_grob_property ("when", now_mom_.smobbed_copy ());
68 musical_column_l_->set_grob_property ("when", now_mom_.smobbed_copy ());
70 start_translation_timestep ();
74 Score_engraver::finish ()
77 progress_indication ("[" + to_str (breaks_i_) + "]");
80 removal_processing ();
88 Score_engraver::initialize ()
90 unsmob_translator_def (definition_)->apply_property_operations (this);
92 assert (dynamic_cast<Paper_def *> (output_def_l_));
93 assert (!daddy_trans_l_);
94 pscore_p_ = new Paper_score;
95 pscore_p_->paper_l_ = dynamic_cast<Paper_def*> (output_def_l_);
97 SCM props = get_property ("System");
99 pscore_p_->typeset_line (new System (props));
102 scoreline_l_ = pscore_p_->line_l_;
103 scoreline_l_->set_bound (LEFT, command_column_l_);
104 command_column_l_->set_grob_property ("breakable", SCM_BOOL_T);
106 Engraver_group_engraver::initialize ();
111 Score_engraver::finalize ()
113 Engraver_group_engraver::finalize ();
116 = unsmob_grob (get_property ("currentCommandColumn"));
117 scoreline_l_->set_bound (RIGHT, cc);
118 cc->set_grob_property ("breakable", SCM_BOOL_T);
124 Score_engraver::one_time_step ()
126 if (!to_boolean (get_property ("skipTypesetting")))
132 stop_translation_timestep ();
137 Score_engraver::announce_grob (Grob_info info)
139 announce_info_arr_.push (info);
140 pscore_p_->line_l_->typeset_grob (info.grob_l_);
147 Score_engraver::typeset_grob (Grob *elem_p)
150 programming_error ("Score_engraver: empty elt\n");
153 elem_p_arr_.push (elem_p);
158 Score_engraver::typeset_all ()
160 for (int i =0; i < elem_p_arr_.size (); i++)
162 Grob * elem_p = elem_p_arr_[i];
164 if (Spanner *s = dynamic_cast <Spanner *> (elem_p))
167 do something sensible if spanner not
172 if (!s->get_bound (d))
174 s->set_bound (d, command_column_l_);
175 /* don't warn for empty/suicided spanners,
176 it makes real warningsinvisible.
177 maybe should be junked earlier? */
178 if (elem_p->immutable_property_alist_ == SCM_EOL)
181 elem_p->warning (_f ("unbound spanner `%s'", s->name ().ch_C ()));
183 } while (flip (&d) != LEFT);
187 if (!elem_p->get_parent (X_AXIS))
189 bool br = to_boolean (elem_p->get_grob_property ("breakable"));
190 Axis_group_interface::add_element (br ? command_column_l_ : musical_column_l_, elem_p);
194 if (!elem_p->get_parent (Y_AXIS))
195 Axis_group_interface::add_element (scoreline_l_, elem_p);
197 elem_p_arr_.clear ();
201 Score_engraver::stop_translation_timestep ()
203 // this generates all items.
204 Engraver_group_engraver::stop_translation_timestep ();
207 if (to_boolean (command_column_l_->get_grob_property ("breakable")))
211 progress_indication ("[" + to_str (breaks_i_) + "]");
215 scoreline_l_->add_column (command_column_l_);
216 scoreline_l_->add_column (musical_column_l_);
218 command_column_l_ = 0;
219 musical_column_l_ = 0;
223 Score_engraver::set_columns (Paper_column *new_command_l,
224 Paper_column *new_musical_l)
226 assert (!command_column_l_ && !musical_column_l_);
228 command_column_l_ = new_command_l;
229 musical_column_l_ = new_musical_l;
232 set_property ("currentCommandColumn", new_command_l->self_scm ());
237 set_property ("currentMusicalColumn", new_musical_l->self_scm ());
242 Score_engraver::get_output_p ()
244 Music_output * o = pscore_p_;
250 Score_engraver::try_music (Music*r)
252 bool gotcha = Engraver_group_engraver::try_music (r);
256 if (Break_req* b = dynamic_cast<Break_req *> (r))
261 SCM pen = command_column_l_->get_grob_property ("penalty");
262 Real total_penalty = gh_number_p (pen)
263 ? gh_scm2double (pen)
266 SCM rpen = b->get_mus_property ("penalty");
267 if (gh_number_p (rpen))
268 total_penalty += gh_scm2double (rpen);
270 if (total_penalty > 10000.0) // ugh. arbitrary.
273 command_column_l_->set_grob_property ("penalty",
274 gh_double2scm (total_penalty));
281 TODO: use property Score.breakForbidden = #t
284 Score_engraver::forbid_breaks ()
289 command_column_l_->remove_grob_property ("breakable");
293 Score_engraver::acknowledge_grob (Grob_info gi)
295 if (Staff_spacing::has_interface (gi.grob_l_))
297 Pointer_group_interface::add_grob (command_column_l_,
298 ly_symbol2scm ("spacing-wishes"),
301 if (Note_spacing::has_interface (gi.grob_l_))
303 Pointer_group_interface::add_grob (musical_column_l_,
304 ly_symbol2scm ("spacing-wishes"),
311 ENTER_DESCRIPTION(Score_engraver,
312 /* descr */ "Top level engraver. Takes care of generating columns and the complete system (ie. System)
315 This engraver decides whether a column is breakable. The default is
316 that a column is always breakable. However, when every Bar_engraver
317 that does not have a barline at a certain point will call
318 Score_engraver::forbid_breaks to stop linebreaks. In practice, this
319 means that you can make a breakpoint by creating a barline (assuming
320 that there are no beams or notes that prevent a breakpoint.)
324 /* creats*/ "System PaperColumn NonMusicalPaperColumn",
325 /* acks */ "note-spacing-interface staff-spacing-interface",
326 /* reads */ "currentMusicalColumn currentCommandColumn",