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"
11 #include "international.hh"
12 #include "axis-group-interface.hh"
15 #include "note-spacing.hh"
16 #include "paper-column.hh"
17 #include "pointer-group-interface.hh"
18 #include "staff-spacing.hh"
22 #include "translator.icc"
24 Paper_column_engraver::Paper_column_engraver ()
26 last_moment_.main_part_ = Rational (-1,1);
35 Paper_column_engraver::finalize ()
38 progress_indication ("[" + to_string (breaks_) + "]");
42 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
43 command_column_->set_property ("page-turn-permission", ly_symbol2scm ("allow"));
44 system_->set_bound (RIGHT, command_column_);
49 Paper_column_engraver::make_columns ()
54 Paper_column *p1 = make_paper_column ("NonMusicalPaperColumn");
55 Paper_column *p2 = make_paper_column ("PaperColumn");
57 The columns are timestamped with now_mom () in
58 stop_translation_timestep. Cannot happen now, because the
59 first column is sometimes created before now_mom is initialised.
66 Paper_column_engraver::initialize ()
68 system_ = dynamic_cast<System *> (unsmob_grob (get_property ("rootSystem")));
71 system_->set_bound (LEFT, command_column_);
72 command_column_->set_property ("line-break-permission", ly_symbol2scm ("allow"));
76 Paper_column_engraver::acknowledge_item (Grob_info gi)
78 items_.push_back (gi.item ());
82 Paper_column_engraver::acknowledge_staff_spacing (Grob_info gi)
84 Pointer_group_interface::add_grob (command_column_,
85 ly_symbol2scm ("spacing-wishes"),
90 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi)
92 Pointer_group_interface::add_grob (musical_column_,
93 ly_symbol2scm ("spacing-wishes"),
98 Paper_column_engraver::set_columns (Paper_column *new_command,
99 Paper_column *new_musical)
101 command_column_ = new_command;
102 musical_column_ = new_musical;
104 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
107 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
109 system_->add_column (command_column_);
110 system_->add_column (musical_column_);
113 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver, break);
115 Paper_column_engraver::listen_break (Stream_event *ev)
117 break_events_.push_back (ev);
121 Paper_column_engraver::process_music ()
123 for (vsize i = 0; i < break_events_.size (); i++)
126 SCM name_sym = break_events_[i]->get_property ("class");
127 string name = ly_scm2string (scm_symbol_to_string (name_sym));
128 size_t end = name.rfind ("-event");
130 prefix = name.substr (0, end);
133 programming_error ("Paper_column_engraver doesn't know about this break-event");
137 string perm_str = prefix + "-permission";
138 string pen_str = prefix + "-penalty";
140 SCM cur_pen = command_column_->get_property (pen_str.c_str ());
141 SCM pen = break_events_[i]->get_property ("break-penalty");
142 SCM perm = break_events_[i]->get_property ("break-permission");
144 if (scm_is_number (pen))
146 Real new_pen = robust_scm2double (cur_pen, 0.0) + scm_to_double (pen);
147 command_column_->set_property (pen_str.c_str (), scm_from_double (new_pen));
148 command_column_->set_property (perm_str.c_str (), ly_symbol2scm ("allow"));
151 command_column_->set_property (perm_str.c_str (), perm);
154 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
155 && !measure_position (context ()).main_part_);
158 We can't do this in start_translation_timestep(), since time sig
159 changes won't have happened by then.
161 if (start_of_measure)
163 Moment mlen = Moment (measure_length (context ()));
164 Grob *column = unsmob_grob (get_property ("currentCommandColumn"));
166 column->set_property ("measure-length", mlen.smobbed_copy ());
168 programming_error ("No command column?");
173 Paper_column_engraver::stop_translation_timestep ()
175 SCM m = now_mom ().smobbed_copy ();
176 command_column_->set_property ("when", m);
177 musical_column_->set_property ("when", m);
179 for (vsize i = 0; i < items_.size (); i++)
181 Item *elem = items_[i];
182 if (!elem->get_parent (X_AXIS)
183 || !unsmob_grob (elem->get_object ("axis-group-parent-X")))
185 bool br = Item::is_non_musical (elem);
186 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
191 if (to_boolean (get_property ("forbidBreak")))
192 command_column_->set_property ("line-break-permission", SCM_EOL);
193 else if (Paper_column::is_breakable (command_column_))
198 progress_indication ("[" + to_string (breaks_) + "]");
201 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
204 break_events_.clear ();
207 SCM mpos = get_property ("measurePosition");
208 if (unsmob_moment (mpos))
210 SCM where = scm_cons (get_property ("internalBarNumber"),
213 command_column_->set_property ("rhythmic-location", where);
214 musical_column_->set_property ("rhythmic-location", where);
219 Paper_column_engraver::start_translation_timestep ()
222 TODO: don't make columns when skipTypesetting is true.
228 ADD_ACKNOWLEDGER (Paper_column_engraver, item);
229 ADD_ACKNOWLEDGER (Paper_column_engraver, note_spacing);
230 ADD_ACKNOWLEDGER (Paper_column_engraver, staff_spacing);
232 ADD_TRANSLATOR (Paper_column_engraver,
233 /* doc */ "Takes care of generating columns."
235 "This engraver decides whether a column is breakable. The default is "
236 "that a column is always breakable. However, every Bar_engraver "
237 "that does not have a barline at a certain point will set forbidBreaks "
238 "in the score context to stop linebreaks. In practice, this "
239 "means that you can make a breakpoint by creating a barline (assuming "
240 "that there are no beams or notes that prevent a breakpoint.) ",
244 "NonMusicalPaperColumn",
246 /* accept */ "break-event",
252 "currentCommandColumn "
253 "currentMusicalColumn "