2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "paper-column-engraver.hh"
22 #include "international.hh"
23 #include "accidental-placement.hh"
24 #include "accidental-interface.hh"
25 #include "axis-group-interface.hh"
27 #include "note-spacing.hh"
28 #include "paper-column.hh"
29 #include "pointer-group-interface.hh"
30 #include "separation-item.hh"
31 #include "staff-spacing.hh"
35 #include "translator.icc"
37 Paper_column_engraver::Paper_column_engraver ()
39 last_moment_
.main_part_
= Rational (-1,1);
45 made_columns_
= false;
49 Paper_column_engraver::finalize ()
52 progress_indication ("[" + to_string (breaks_
) + "]");
57 SCM m
= now_mom ().smobbed_copy ();
58 command_column_
->set_property ("when", m
);
59 musical_column_
->set_property ("when", m
);
64 if (!scm_is_symbol (command_column_
->get_property ("line-break-permission")))
65 command_column_
->set_property ("line-break-permission", ly_symbol2scm ("allow"));
66 system_
->set_bound (RIGHT
, command_column_
);
71 Paper_column_engraver::make_columns ()
76 Paper_column
*p1
= make_paper_column ("NonMusicalPaperColumn");
77 Paper_column
*p2
= make_paper_column ("PaperColumn");
79 The columns are timestamped with now_mom () in
80 stop_translation_timestep. Cannot happen now, because the
81 first column is sometimes created before now_mom is initialised.
88 Paper_column_engraver::initialize ()
90 system_
= dynamic_cast<System
*> (unsmob_grob (get_property ("rootSystem")));
93 system_
->set_bound (LEFT
, command_column_
);
94 command_column_
->set_property ("line-break-permission", ly_symbol2scm ("allow"));
98 Paper_column_engraver::acknowledge_item (Grob_info gi
)
100 items_
.push_back (gi
.item ());
104 Paper_column_engraver::acknowledge_staff_spacing (Grob_info gi
)
106 Pointer_group_interface::add_grob (command_column_
,
107 ly_symbol2scm ("spacing-wishes"),
112 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi
)
114 Pointer_group_interface::add_grob (musical_column_
,
115 ly_symbol2scm ("spacing-wishes"),
120 Paper_column_engraver::set_columns (Paper_column
*new_command
,
121 Paper_column
*new_musical
)
123 command_column_
= new_command
;
124 musical_column_
= new_musical
;
126 context ()->set_property ("currentCommandColumn", new_command
->self_scm ());
129 context ()->set_property ("currentMusicalColumn", new_musical
->self_scm ());
131 system_
->add_column (command_column_
);
132 system_
->add_column (musical_column_
);
135 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver
, break);
137 Paper_column_engraver::listen_break (Stream_event
*ev
)
139 break_events_
.push_back (ev
);
142 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver
, label
);
144 Paper_column_engraver::listen_label (Stream_event
*ev
)
146 label_events_
.push_back (ev
);
150 Paper_column_engraver::process_music ()
152 for (vsize i
= 0; i
< break_events_
.size (); i
++)
155 SCM name_sym
= break_events_
[i
]->get_property ("class");
156 string name
= ly_scm2string (scm_symbol_to_string (name_sym
));
157 size_t end
= name
.rfind ("-event");
159 prefix
= name
.substr (0, end
);
162 programming_error ("Paper_column_engraver doesn't know about this break-event");
166 string perm_str
= prefix
+ "-permission";
167 string pen_str
= prefix
+ "-penalty";
169 SCM cur_pen
= command_column_
->get_property (pen_str
.c_str ());
170 SCM pen
= break_events_
[i
]->get_property ("break-penalty");
171 SCM perm
= break_events_
[i
]->get_property ("break-permission");
173 if (scm_is_number (pen
))
175 Real new_pen
= robust_scm2double (cur_pen
, 0.0) + scm_to_double (pen
);
176 command_column_
->set_property (pen_str
.c_str (), scm_from_double (new_pen
));
177 command_column_
->set_property (perm_str
.c_str (), ly_symbol2scm ("allow"));
180 command_column_
->set_property (perm_str
.c_str (), perm
);
183 for (vsize i
= 0 ; i
< label_events_
.size () ; i
++)
185 SCM label
= label_events_
[i
]->get_property ("page-label");
186 SCM labels
= command_column_
->get_property ("labels");
187 command_column_
->set_property ("labels", scm_cons (label
, labels
));
190 bool start_of_measure
= (last_moment_
.main_part_
!= now_mom ().main_part_
191 && !measure_position (context ()).main_part_
);
194 We can't do this in start_translation_timestep (), since time sig
195 changes won't have happened by then.
197 if (start_of_measure
)
199 Moment mlen
= Moment (measure_length (context ()));
200 Grob
*column
= unsmob_grob (get_property ("currentCommandColumn"));
202 column
->set_property ("measure-length", mlen
.smobbed_copy ());
204 programming_error ("No command column?");
209 Paper_column_engraver::stop_translation_timestep ()
211 if (to_boolean (get_property ("skipTypesetting")))
214 SCM m
= now_mom ().smobbed_copy ();
215 command_column_
->set_property ("when", m
);
216 musical_column_
->set_property ("when", m
);
218 for (vsize i
= 0; i
< items_
.size (); i
++)
220 Item
*elem
= items_
[i
];
221 Grob
*col
= Item::is_non_musical (elem
) ? command_column_
: musical_column_
;
223 if (!elem
->get_parent (X_AXIS
))
224 elem
->set_parent (col
, X_AXIS
);
225 if (!unsmob_grob (elem
->get_object ("axis-group-parent-X")))
226 elem
->set_object ("axis-group-parent-X", col
->self_scm ());
228 if (Accidental_placement::has_interface (elem
))
229 Separation_item::add_conditional_item (col
, elem
);
230 else if (!Accidental_interface::has_interface (elem
))
231 Separation_item::add_item (col
, elem
);
235 if (to_boolean (get_property ("forbidBreak"))
236 && breaks_
) /* don't honour forbidBreak if it occurs on the first moment of a score */
238 command_column_
->set_property ("page-turn-permission", SCM_EOL
);
239 command_column_
->set_property ("page-break-permission", SCM_EOL
);
240 command_column_
->set_property ("line-break-permission", SCM_EOL
);
241 for (vsize i
= 0; i
< break_events_
.size (); i
++)
243 SCM perm
= break_events_
[i
]->get_property ("break-permission");
244 if (perm
== ly_symbol2scm ("force") || perm
== ly_symbol2scm ("allow"))
245 warning (_ ("forced break was overridden by some other event, "
246 "should you be using bar checks?"));
249 else if (Paper_column::is_breakable (command_column_
))
254 progress_indication ("[" + to_string (breaks_
) + "]");
257 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
260 break_events_
.clear ();
261 label_events_
.clear ();
263 SCM mpos
= get_property ("measurePosition");
264 SCM barnum
= get_property ("internalBarNumber");
265 if (unsmob_moment (mpos
)
266 && scm_is_integer (barnum
))
268 SCM where
= scm_cons (barnum
,
271 command_column_
->set_property ("rhythmic-location", where
);
272 musical_column_
->set_property ("rhythmic-location", where
);
277 Paper_column_engraver::start_translation_timestep ()
279 if (!first_
&& !to_boolean (get_property ("skipTypesetting")))
282 made_columns_
= true;
286 ADD_ACKNOWLEDGER (Paper_column_engraver
, item
);
287 ADD_ACKNOWLEDGER (Paper_column_engraver
, note_spacing
);
288 ADD_ACKNOWLEDGER (Paper_column_engraver
, staff_spacing
);
290 ADD_TRANSLATOR (Paper_column_engraver
,
292 "Take care of generating columns.\n"
294 "This engraver decides whether a column is breakable. The"
295 " default is that a column is always breakable. However,"
296 " every @code{Bar_engraver} that does not have a barline at a"
297 " certain point will set @code{forbidBreaks} in the score"
298 " context to stop line breaks. In practice, this means that"
299 " you can make a break point by creating a bar line (assuming"
300 " that there are no beams or notes that prevent a break"
305 "NonMusicalPaperColumn ",
312 "currentCommandColumn "
313 "currentMusicalColumn "