2 paper-column-engraver.cc -- implement Paper_column_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "paper-column-engraver.hh"
11 #include "international.hh"
12 #include "accidental-placement.hh"
13 #include "accidental-interface.hh"
14 #include "axis-group-interface.hh"
16 #include "note-spacing.hh"
17 #include "paper-column.hh"
18 #include "pointer-group-interface.hh"
19 #include "separation-item.hh"
20 #include "staff-spacing.hh"
24 #include "translator.icc"
26 Paper_column_engraver::Paper_column_engraver ()
28 last_moment_.main_part_ = Rational (-1,1);
37 Paper_column_engraver::finalize ()
40 progress_indication ("[" + to_string (breaks_) + "]");
44 if (!scm_is_symbol (command_column_->get_property ("line-break-permission")))
45 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
46 system_->set_bound (RIGHT, command_column_);
51 Paper_column_engraver::make_columns ()
56 Paper_column *p1 = make_paper_column ("NonMusicalPaperColumn");
57 Paper_column *p2 = make_paper_column ("PaperColumn");
59 The columns are timestamped with now_mom () in
60 stop_translation_timestep. Cannot happen now, because the
61 first column is sometimes created before now_mom is initialised.
68 Paper_column_engraver::initialize ()
70 system_ = dynamic_cast<System *> (unsmob_grob (get_property ("rootSystem")));
73 system_->set_bound (LEFT, command_column_);
74 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
78 Paper_column_engraver::acknowledge_item (Grob_info gi)
80 items_.push_back (gi.item ());
84 Paper_column_engraver::acknowledge_staff_spacing (Grob_info gi)
86 Pointer_group_interface::add_grob (command_column_,
87 ly_symbol2scm ("spacing-wishes"),
92 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi)
94 Pointer_group_interface::add_grob (musical_column_,
95 ly_symbol2scm ("spacing-wishes"),
100 Paper_column_engraver::set_columns (Paper_column *new_command,
101 Paper_column *new_musical)
103 command_column_ = new_command;
104 musical_column_ = new_musical;
106 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
109 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
111 system_->add_column (command_column_);
112 system_->add_column (musical_column_);
115 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, break);
117 Paper_column_engraver::listen_break (Stream_event *ev)
119 break_events_.push_back (ev);
122 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, label);
124 Paper_column_engraver::listen_label (Stream_event *ev)
126 label_events_.push_back (ev);
130 Paper_column_engraver::process_music ()
132 for (vsize i = 0; i < break_events_.size (); i++)
135 SCM name_sym = break_events_[i]->get_property ("class");
136 string name = ly_scm2string (scm_symbol_to_string (name_sym));
137 size_t end = name.rfind ("-event");
139 prefix = name.substr (0, end);
142 programming_error ("Paper_column_engraver doesn't know about this break-event");
146 string perm_str = prefix + "-permission";
147 string pen_str = prefix + "-penalty";
149 SCM cur_pen = command_column_->get_property (pen_str.c_str ());
150 SCM pen = break_events_[i]->get_property ("break-penalty");
151 SCM perm = break_events_[i]->get_property ("break-permission");
153 if (scm_is_number (pen))
155 Real new_pen = robust_scm2double (cur_pen, 0.0) + scm_to_double (pen);
156 command_column_->set_property (pen_str.c_str (), scm_from_double (new_pen));
157 command_column_->set_property (perm_str.c_str (), ly_symbol2scm ("allow"));
160 command_column_->set_property (perm_str.c_str (), perm);
163 for (vsize i = 0 ; i < label_events_.size () ; i ++)
165 SCM label = label_events_[i]->get_property ("page-label");
166 SCM labels = command_column_->get_property ("labels");
167 command_column_->set_property ("labels", scm_cons (label, labels));
170 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
171 && !measure_position (context ()).main_part_);
174 We can't do this in start_translation_timestep (), since time sig
175 changes won't have happened by then.
177 if (start_of_measure)
179 Moment mlen = Moment (measure_length (context ()));
180 Grob *column = unsmob_grob (get_property ("currentCommandColumn"));
182 column->set_property ("measure-length", mlen.smobbed_copy ());
184 programming_error ("No command column?");
189 Paper_column_engraver::stop_translation_timestep ()
191 SCM m = now_mom ().smobbed_copy ();
192 command_column_->set_property ("when", m);
193 musical_column_->set_property ("when", m);
195 for (vsize i = 0; i < items_.size (); i++)
197 Item *elem = items_[i];
198 Grob *col = Item::is_non_musical (elem) ? command_column_ : musical_column_;
200 if (!elem->get_parent (X_AXIS))
201 elem->set_parent (col, X_AXIS);
202 if (!unsmob_grob (elem->get_object ("axis-group-parent-X")))
203 elem->set_object ("axis-group-parent-X", col->self_scm ());
205 if (Accidental_placement::has_interface (elem))
206 Separation_item::add_conditional_item (col, elem);
207 else if (!Accidental_interface::has_interface (elem))
208 Separation_item::add_item (col, elem);
212 if (to_boolean (get_property ("forbidBreak"))
213 && breaks_) /* don't honour forbidBreak if it occurs on the first moment of a score */
215 command_column_->set_property ("page-break-permission", SCM_EOL);
216 command_column_->set_property ("line-break-permission", SCM_EOL);
217 for (vsize i = 0; i < break_events_.size (); i++)
219 SCM perm = break_events_[i]->get_property ("break-permission");
220 if (perm == ly_symbol2scm ("force") || perm == ly_symbol2scm ("allow"))
221 warning (_f ("forced break was overridden by some other event, should you be using bar checks?"));
224 else if (Paper_column::is_breakable (command_column_))
229 progress_indication ("[" + to_string (breaks_) + "]");
232 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
235 break_events_.clear ();
236 label_events_.clear ();
238 SCM mpos = get_property ("measurePosition");
239 SCM barnum = get_property ("internalBarNumber");
240 if (unsmob_moment (mpos)
241 && scm_is_integer (barnum))
243 SCM where = scm_cons (barnum,
246 command_column_->set_property ("rhythmic-location", where);
247 musical_column_->set_property ("rhythmic-location", where);
252 Paper_column_engraver::start_translation_timestep ()
255 TODO: don't make columns when skipTypesetting is true.
261 ADD_ACKNOWLEDGER (Paper_column_engraver, item);
262 ADD_ACKNOWLEDGER (Paper_column_engraver, note_spacing);
263 ADD_ACKNOWLEDGER (Paper_column_engraver, staff_spacing);
265 ADD_TRANSLATOR (Paper_column_engraver,
266 /* doc */ "Takes care of generating columns."
268 "This engraver decides whether a column is breakable. The default is "
269 "that a column is always breakable. However, every Bar_engraver "
270 "that does not have a barline at a certain point will set forbidBreaks "
271 "in the score context to stop linebreaks. In practice, this "
272 "means that you can make a breakpoint by creating a barline (assuming "
273 "that there are no beams or notes that prevent a breakpoint.) ",
277 "NonMusicalPaperColumn",
283 "currentCommandColumn "
284 "currentMusicalColumn "