2 paper-column-engraver.cc -- implement Paper_column_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "paper-column-engraver.hh"
13 #include "paper-column.hh"
14 #include "staff-spacing.hh"
15 #include "note-spacing.hh"
16 #include "pointer-group-interface.hh"
18 #include "axis-group-interface.hh"
21 #include "translator.icc"
24 Paper_column_engraver::Paper_column_engraver ()
35 Paper_column_engraver::finalize ()
38 progress_indication ("[" + to_string (breaks_) + "]");
42 command_column_->set_property ("breakable", SCM_BOOL_T);
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 SCM m = now_mom().smobbed_copy();
57 p1->set_property ("when", m);
58 p2->set_property ("when", m);
65 Paper_column_engraver::initialize ()
67 system_ = dynamic_cast<System*> (unsmob_grob (get_property ("rootSystem")));
71 system_->set_bound (LEFT, command_column_);
72 command_column_->set_property ("breakable", SCM_BOOL_T);
76 Paper_column_engraver::acknowledge_grob (Grob_info gi)
78 Item *item = dynamic_cast<Item *> (gi.grob ());
81 programming_error ("Spanner found in Paper_column_engraver::acknowledge_grob()");
87 if (Staff_spacing::has_interface (item))
89 Pointer_group_interface::add_grob (command_column_,
90 ly_symbol2scm ("spacing-wishes"),
93 if (Note_spacing::has_interface (item))
95 Pointer_group_interface::add_grob (musical_column_,
96 ly_symbol2scm ("spacing-wishes"),
102 Paper_column_engraver::set_columns (Paper_column *new_command,
103 Paper_column *new_musical)
105 command_column_ = new_command;
106 musical_column_ = new_musical;
109 context ()->set_property ("currentCommandColumn", new_command->self_scm ());
114 context ()->set_property ("currentMusicalColumn", new_musical->self_scm ());
117 system_->add_column (command_column_);
118 system_->add_column (musical_column_);
123 Paper_column_engraver::forbid_breaks ()
125 if (command_column_ && !first_)
126 command_column_->set_property ("breakable", SCM_EOL);
131 Paper_column_engraver::try_music (Music *m)
139 Paper_column_engraver::process_music ()
143 SCM pen = command_column_->get_property ("penalty");
144 Real total_penalty = scm_is_number (pen) ? scm_to_double (pen) : 0.0;
146 SCM mpen = break_event_->get_property ("penalty");
147 if (scm_is_number (mpen))
148 total_penalty += scm_to_double (mpen);
150 command_column_->set_property ("penalty", scm_make_real (total_penalty));
152 /* ugh. arbitrary, hardcoded */
153 if (total_penalty > 10000.0)
156 SCM page_pen = command_column_->get_property ("page-penalty");
157 Real total_pp = scm_is_number (page_pen) ? scm_to_double (page_pen) : 0.0;
158 SCM mpage_pen = break_event_->get_property ("page-penalty");
159 if (scm_is_number (mpage_pen))
160 total_pp += scm_to_double (mpage_pen);
162 command_column_->set_property ("page-penalty", scm_make_real (total_pp));
166 bool start_of_measure = (last_moment_.main_part_ != now_mom ().main_part_
167 && !measure_position (context ()).main_part_);
170 We can't do this in start_translation_timestep(), since time sig
171 changes won't have happened by then.
173 if (start_of_measure)
175 Moment mlen = Moment (measure_length (context ()));
176 Grob * column = unsmob_grob (get_property ("currentCommandColumn"));
178 column->set_property ("measure-length", mlen.smobbed_copy ());
180 programming_error("No command column?");
185 Paper_column_engraver::stop_translation_timestep ()
187 for (int i = 0; i < items_.size (); i++)
189 Item *elem = items_[i];
190 if (!elem->get_parent (X_AXIS)
191 || !unsmob_grob (elem->get_object ("axis-group-parent-X")))
193 bool br = to_boolean (elem->get_property ("breakable"));
194 Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
199 if (to_boolean (command_column_->get_property ("breakable")))
203 progress_indication ("[" + to_string (breaks_) + "]");
211 Paper_column_engraver::start_translation_timestep ()
214 TODO: don't make columns when skipTypesetting is true.
223 ADD_TRANSLATOR (Paper_column_engraver,
224 /* descr */ "Takes care of generating columns."
226 "This engraver decides whether a column is breakable. The default is "
227 "that a column is always breakable. However, when every Bar_engraver "
228 "that does not have a barline at a certain point will call "
229 "Score_engraver::forbid_breaks to stop linebreaks. In practice, this "
230 "means that you can make a breakpoint by creating a barline (assuming "
231 "that there are no beams or notes that prevent a breakpoint.) ",
232 /* creats*/ "PaperColumn NonMusicalPaperColumn",
233 /* accepts */ "break-event",
234 /* acks */ "item-interface",
236 /* write */ "currentCommandColumn currentMusicalColumn");