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 "axis-group-interface.hh"
14 #include "note-spacing.hh"
15 #include "paper-column.hh"
16 #include "pointer-group-interface.hh"
17 #include "staff-spacing.hh"
21 #include "translator.icc"
23 Paper_column_engraver::Paper_column_engraver ()
25 last_moment_.main_part_ = Rational (-1,1);
34 Paper_column_engraver::finalize ()
37 progress_indication ("[" + to_string (breaks_) + "]");
41 if (!scm_is_symbol (command_column_->get_property ("line-break-permission")))
42 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
43 system_->set_bound (RIGHT, command_column_);
48 Paper_column_engraver::make_columns ()
53 Paper_column *p1 = make_paper_column ("NonMusicalPaperColumn");
54 Paper_column *p2 = make_paper_column ("PaperColumn");
56 The columns are timestamped with now_mom () in
57 stop_translation_timestep. Cannot happen now, because the
58 first column is sometimes created before now_mom is initialised.
65 Paper_column_engraver::initialize ()
67 system_ = dynamic_cast<System *> (unsmob_grob (get_property ("rootSystem")));
70 system_->set_bound (LEFT, command_column_);
71 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
75 Paper_column_engraver::acknowledge_item (Grob_info gi)
77 items_.push_back (gi.item ());
81 Paper_column_engraver::acknowledge_staff_spacing (Grob_info gi)
83 Pointer_group_interface::add_grob (command_column_,
84 ly_symbol2scm ("spacing-wishes"),
89 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi)
91 Pointer_group_interface::add_grob (musical_column_,
92 ly_symbol2scm ("spacing-wishes"),
97 Paper_column_engraver::set_columns (Paper_column *new_command,
98 Paper_column *new_musical)
100 command_column_ = new_command;
101 musical_column_ = new_musical;
103 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
106 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
108 system_->add_column (command_column_);
109 system_->add_column (musical_column_);
112 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, break);
114 Paper_column_engraver::listen_break (Stream_event *ev)
116 break_events_.push_back (ev);
119 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, label);
121 Paper_column_engraver::listen_label (Stream_event *ev)
123 label_events_.push_back (ev);
127 Paper_column_engraver::process_music ()
129 for (vsize i = 0; i < break_events_.size (); i++)
132 SCM name_sym = break_events_[i]->get_property ("class");
133 string name = ly_scm2string (scm_symbol_to_string (name_sym));
134 size_t end = name.rfind ("-event");
136 prefix = name.substr (0, end);
139 programming_error ("Paper_column_engraver doesn't know about this break-event");
143 string perm_str = prefix + "-permission";
144 string pen_str = prefix + "-penalty";
146 SCM cur_pen = command_column_->get_property (pen_str.c_str ());
147 SCM pen = break_events_[i]->get_property ("break-penalty");
148 SCM perm = break_events_[i]->get_property ("break-permission");
150 if (scm_is_number (pen))
152 Real new_pen = robust_scm2double (cur_pen, 0.0) + scm_to_double (pen);
153 command_column_->set_property (pen_str.c_str (), scm_from_double (new_pen));
154 command_column_->set_property (perm_str.c_str (), ly_symbol2scm ("allow"));
157 command_column_->set_property (perm_str.c_str (), perm);
160 for (vsize i = 0 ; i < label_events_.size () ; i ++)
162 SCM label = label_events_[i]->get_property ("page-label");
163 SCM labels = command_column_->get_property ("labels");
164 command_column_->set_property ("labels", scm_cons (label, labels));
167 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
168 && !measure_position (context ()).main_part_);
171 We can't do this in start_translation_timestep (), since time sig
172 changes won't have happened by then.
174 if (start_of_measure)
176 Moment mlen = Moment (measure_length (context ()));
177 Grob *column = unsmob_grob (get_property ("currentCommandColumn"));
179 column->set_property ("measure-length", mlen.smobbed_copy ());
181 programming_error ("No command column?");
186 Paper_column_engraver::stop_translation_timestep ()
188 SCM m = now_mom ().smobbed_copy ();
189 command_column_->set_property ("when", m);
190 musical_column_->set_property ("when", m);
192 for (vsize i = 0; i < items_.size (); i++)
194 Item *elem = items_[i];
195 if (!elem->get_parent (X_AXIS)
196 || !unsmob_grob (elem->get_object ("axis-group-parent-X")))
198 bool br = Item::is_non_musical (elem);
199 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
204 if (to_boolean (get_property ("forbidBreak"))
205 && breaks_) /* don't honour forbidBreak if it occurs on the first moment of a score */
207 command_column_->set_property ("page-break-permission", SCM_EOL);
208 command_column_->set_property ("line-break-permission", SCM_EOL);
209 for (vsize i = 0; i < break_events_.size (); i++)
211 SCM perm = break_events_[i]->get_property ("break-permission");
212 if (perm == ly_symbol2scm ("force") || perm == ly_symbol2scm ("allow"))
213 warning (_f ("forced break was overridden by some other event, should you be using bar checks?"));
216 else if (Paper_column::is_breakable (command_column_))
221 progress_indication ("[" + to_string (breaks_) + "]");
224 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
227 break_events_.clear ();
228 label_events_.clear ();
230 SCM mpos = get_property ("measurePosition");
231 SCM barnum = get_property ("internalBarNumber");
232 if (unsmob_moment (mpos)
233 && scm_is_integer (barnum))
235 SCM where = scm_cons (barnum,
238 command_column_->set_property ("rhythmic-location", where);
239 musical_column_->set_property ("rhythmic-location", where);
244 Paper_column_engraver::start_translation_timestep ()
247 TODO: don't make columns when skipTypesetting is true.
253 ADD_ACKNOWLEDGER (Paper_column_engraver, item);
254 ADD_ACKNOWLEDGER (Paper_column_engraver, note_spacing);
255 ADD_ACKNOWLEDGER (Paper_column_engraver, staff_spacing);
257 ADD_TRANSLATOR (Paper_column_engraver,
258 /* doc */ "Takes care of generating columns."
260 "This engraver decides whether a column is breakable. The default is "
261 "that a column is always breakable. However, every Bar_engraver "
262 "that does not have a barline at a certain point will set forbidBreaks "
263 "in the score context to stop linebreaks. In practice, this "
264 "means that you can make a breakpoint by creating a barline (assuming "
265 "that there are no beams or notes that prevent a breakpoint.) ",
269 "NonMusicalPaperColumn",
275 "currentCommandColumn "
276 "currentMusicalColumn "