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);
120 Paper_column_engraver::process_music ()
122 for (vsize i = 0; i < break_events_.size (); i++)
125 SCM name_sym = break_events_[i]->get_property ("class");
126 string name = ly_scm2string (scm_symbol_to_string (name_sym));
127 size_t end = name.rfind ("-event");
129 prefix = name.substr (0, end);
132 programming_error ("Paper_column_engraver doesn't know about this break-event");
136 string perm_str = prefix + "-permission";
137 string pen_str = prefix + "-penalty";
139 SCM cur_pen = command_column_->get_property (pen_str.c_str ());
140 SCM pen = break_events_[i]->get_property ("break-penalty");
141 SCM perm = break_events_[i]->get_property ("break-permission");
143 if (scm_is_number (pen))
145 Real new_pen = robust_scm2double (cur_pen, 0.0) + scm_to_double (pen);
146 command_column_->set_property (pen_str.c_str (), scm_from_double (new_pen));
147 command_column_->set_property (perm_str.c_str (), ly_symbol2scm ("allow"));
150 command_column_->set_property (perm_str.c_str (), perm);
153 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
154 && !measure_position (context ()).main_part_);
157 We can't do this in start_translation_timestep (), since time sig
158 changes won't have happened by then.
160 if (start_of_measure)
162 Moment mlen = Moment (measure_length (context ()));
163 Grob *column = unsmob_grob (get_property ("currentCommandColumn"));
165 column->set_property ("measure-length", mlen.smobbed_copy ());
167 programming_error ("No command column?");
172 Paper_column_engraver::stop_translation_timestep ()
174 SCM m = now_mom ().smobbed_copy ();
175 command_column_->set_property ("when", m);
176 musical_column_->set_property ("when", m);
178 for (vsize i = 0; i < items_.size (); i++)
180 Item *elem = items_[i];
181 if (!elem->get_parent (X_AXIS)
182 || !unsmob_grob (elem->get_object ("axis-group-parent-X")))
184 bool br = Item::is_non_musical (elem);
185 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
190 if (to_boolean (get_property ("forbidBreak"))
191 && breaks_) /* don't honour forbidBreak if it occurs on the first moment of a score */
193 command_column_->set_property ("page-break-permission", SCM_EOL);
194 command_column_->set_property ("line-break-permission", SCM_EOL);
195 for (vsize i = 0; i < break_events_.size (); i++)
197 SCM perm = break_events_[i]->get_property ("permission");
198 if (perm == ly_symbol2scm ("force") || perm == ly_symbol2scm ("allow"))
199 warning (_f ("forced break was overridden by some other event, should you be using bar checks?"));
202 else if (Paper_column::is_breakable (command_column_))
207 progress_indication ("[" + to_string (breaks_) + "]");
210 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
213 break_events_.clear ();
216 SCM mpos = get_property ("measurePosition");
217 SCM barnum = get_property ("internalBarNumber");
218 if (unsmob_moment (mpos)
219 && scm_is_integer (barnum))
221 SCM where = scm_cons (barnum,
224 command_column_->set_property ("rhythmic-location", where);
225 musical_column_->set_property ("rhythmic-location", where);
230 Paper_column_engraver::start_translation_timestep ()
233 TODO: don't make columns when skipTypesetting is true.
239 ADD_ACKNOWLEDGER (Paper_column_engraver, item);
240 ADD_ACKNOWLEDGER (Paper_column_engraver, note_spacing);
241 ADD_ACKNOWLEDGER (Paper_column_engraver, staff_spacing);
243 ADD_TRANSLATOR (Paper_column_engraver,
244 /* doc */ "Takes care of generating columns."
246 "This engraver decides whether a column is breakable. The default is "
247 "that a column is always breakable. However, every Bar_engraver "
248 "that does not have a barline at a certain point will set forbidBreaks "
249 "in the score context to stop linebreaks. In practice, this "
250 "means that you can make a breakpoint by creating a barline (assuming "
251 "that there are no beams or notes that prevent a breakpoint.) ",
255 "NonMusicalPaperColumn",
261 "currentCommandColumn "
262 "currentMusicalColumn "