2 paper-column-engraver.cc -- implement Paper_column_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "paper-column-engraver.hh"
10 #include "axis-group-interface.hh"
13 #include "note-spacing.hh"
14 #include "paper-column.hh"
15 #include "pointer-group-interface.hh"
16 #include "staff-spacing.hh"
20 #include "translator.icc"
22 Paper_column_engraver::Paper_column_engraver ()
24 last_moment_.main_part_ = Rational (-1,1);
30 last_breakable_column_ = 0;
31 last_breakable_moment_ = Moment (-1);
35 Paper_column_engraver::finalize ()
38 progress_indication ("[" + to_string (breaks_) + "]");
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"),
88 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi)
90 Pointer_group_interface::add_grob (musical_column_,
91 ly_symbol2scm ("spacing-wishes"),
96 Paper_column_engraver::set_columns (Paper_column *new_command,
97 Paper_column *new_musical)
99 command_column_ = new_command;
100 musical_column_ = new_musical;
102 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
105 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
107 system_->add_column (command_column_);
108 system_->add_column (musical_column_);
111 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, break);
113 Paper_column_engraver::listen_break (Stream_event *ev)
115 break_events_.push_back (ev);
119 Paper_column_engraver::process_music ()
121 for (vsize i = 0; i < break_events_.size (); i++)
124 SCM name_sym = break_events_[i]->get_property ("class");
125 string name = ly_scm2string (scm_symbol_to_string (name_sym));
126 size_t end = name.rfind ("-event");
128 prefix = name.substr (0, end);
131 programming_error ("Paper_column_engraver doesn't know about this break-event");
135 string perm_str = prefix + "-permission";
136 string pen_str = prefix + "-penalty";
138 SCM cur_pen = command_column_->get_property (pen_str.c_str ());
139 SCM pen = break_events_[i]->get_property ("break-penalty");
140 SCM perm = break_events_[i]->get_property ("break-permission");
142 if (scm_is_number (pen))
144 Real new_pen = robust_scm2double (cur_pen, 0.0) + scm_to_double (pen);
145 command_column_->set_property (pen_str.c_str (), scm_from_double (new_pen));
146 command_column_->set_property (perm_str.c_str (), ly_symbol2scm ("allow"));
149 command_column_->set_property (perm_str.c_str (), perm);
152 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
153 && !measure_position (context ()).main_part_);
156 We can't do this in start_translation_timestep(), since time sig
157 changes won't have happened by then.
159 if (start_of_measure)
161 Moment mlen = Moment (measure_length (context ()));
162 Grob *column = unsmob_grob (get_property ("currentCommandColumn"));
164 column->set_property ("measure-length", mlen.smobbed_copy ());
166 programming_error ("No command column?");
171 Paper_column_engraver::stop_translation_timestep ()
173 SCM m = now_mom ().smobbed_copy ();
174 command_column_->set_property ("when", m);
175 musical_column_->set_property ("when", m);
177 for (vsize i = 0; i < items_.size (); i++)
179 Item *elem = items_[i];
180 if (!elem->get_parent (X_AXIS)
181 || !unsmob_grob (elem->get_object ("axis-group-parent-X")))
183 bool br = Item::is_non_musical (elem);
184 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
189 if (to_boolean (get_property ("forbidBreak")))
190 command_column_->set_property ("line-break-permission", SCM_EOL);
191 else if (Paper_column::is_breakable (command_column_))
194 last_breakable_column_ = command_column_;
195 last_breakable_moment_ = now_mom ();
197 progress_indication ("[" + to_string (breaks_) + "]");
200 SCM page_br = get_property ("allowPageTurn");
201 if (scm_is_pair (page_br) && last_breakable_moment_ >= Rational (0))
203 SCM pen = scm_cdr (page_br);
204 Moment *m = unsmob_moment (scm_car (page_br));
205 if (m && scm_is_number (pen) && *m <= last_breakable_moment_)
207 last_breakable_column_->set_property ("page-turn-permission", ly_symbol2scm ("allow"));
208 last_breakable_column_->set_property ("page-turn-penalty", pen);
212 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
213 context ()->get_score_context ()->unset_property (ly_symbol2scm ("allowPageTurn"));
216 break_events_.clear ();
220 Paper_column_engraver::start_translation_timestep ()
223 TODO: don't make columns when skipTypesetting is true.
229 ADD_ACKNOWLEDGER (Paper_column_engraver, item);
230 ADD_ACKNOWLEDGER (Paper_column_engraver, note_spacing);
231 ADD_ACKNOWLEDGER (Paper_column_engraver, staff_spacing);
233 ADD_TRANSLATOR (Paper_column_engraver,
234 /* doc */ "Takes care of generating columns."
236 "This engraver decides whether a column is breakable. The default is "
237 "that a column is always breakable. However, every Bar_engraver "
238 "that does not have a barline at a certain point will set forbidBreaks "
239 "in the score context to stop linebreaks. In practice, this "
240 "means that you can make a breakpoint by creating a barline (assuming "
241 "that there are no beams or notes that prevent a breakpoint.) ",
245 "NonMusicalPaperColumn",
247 /* accept */ "break-event",
254 "currentCommandColumn "
255 "currentMusicalColumn");