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 "accidental-placement.hh"
13 #include "axis-group-interface.hh"
15 #include "note-spacing.hh"
16 #include "paper-column.hh"
17 #include "pointer-group-interface.hh"
18 #include "separation-item.hh"
19 #include "staff-spacing.hh"
23 #include "translator.icc"
25 Paper_column_engraver::Paper_column_engraver ()
27 last_moment_
.main_part_
= Rational (-1,1);
36 Paper_column_engraver::finalize ()
39 progress_indication ("[" + to_string (breaks_
) + "]");
43 if (!scm_is_symbol (command_column_
->get_property ("line-break-permission")))
44 command_column_
->set_property ("line-break-permission", ly_symbol2scm ("allow"));
45 system_
->set_bound (RIGHT
, command_column_
);
50 Paper_column_engraver::make_columns ()
55 Paper_column
*p1
= make_paper_column ("NonMusicalPaperColumn");
56 Paper_column
*p2
= make_paper_column ("PaperColumn");
58 The columns are timestamped with now_mom () in
59 stop_translation_timestep. Cannot happen now, because the
60 first column is sometimes created before now_mom is initialised.
67 Paper_column_engraver::initialize ()
69 system_
= dynamic_cast<System
*> (unsmob_grob (get_property ("rootSystem")));
72 system_
->set_bound (LEFT
, command_column_
);
73 command_column_
->set_property ("line-break-permission", ly_symbol2scm ("allow"));
77 Paper_column_engraver::acknowledge_item (Grob_info gi
)
79 items_
.push_back (gi
.item ());
83 Paper_column_engraver::acknowledge_staff_spacing (Grob_info gi
)
85 Pointer_group_interface::add_grob (command_column_
,
86 ly_symbol2scm ("spacing-wishes"),
91 Paper_column_engraver::acknowledge_note_spacing (Grob_info gi
)
93 Pointer_group_interface::add_grob (musical_column_
,
94 ly_symbol2scm ("spacing-wishes"),
99 Paper_column_engraver::set_columns (Paper_column
*new_command
,
100 Paper_column
*new_musical
)
102 command_column_
= new_command
;
103 musical_column_
= new_musical
;
105 context ()->set_property ("currentCommandColumn", new_command
->self_scm ());
108 context ()->set_property ("currentMusicalColumn", new_musical
->self_scm ());
110 system_
->add_column (command_column_
);
111 system_
->add_column (musical_column_
);
114 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver
, break);
116 Paper_column_engraver::listen_break (Stream_event
*ev
)
118 break_events_
.push_back (ev
);
121 IMPLEMENT_TRANSLATOR_LISTENER (Paper_column_engraver
, label
);
123 Paper_column_engraver::listen_label (Stream_event
*ev
)
125 label_events_
.push_back (ev
);
129 Paper_column_engraver::process_music ()
131 for (vsize i
= 0; i
< break_events_
.size (); i
++)
134 SCM name_sym
= break_events_
[i
]->get_property ("class");
135 string name
= ly_scm2string (scm_symbol_to_string (name_sym
));
136 size_t end
= name
.rfind ("-event");
138 prefix
= name
.substr (0, end
);
141 programming_error ("Paper_column_engraver doesn't know about this break-event");
145 string perm_str
= prefix
+ "-permission";
146 string pen_str
= prefix
+ "-penalty";
148 SCM cur_pen
= command_column_
->get_property (pen_str
.c_str ());
149 SCM pen
= break_events_
[i
]->get_property ("break-penalty");
150 SCM perm
= break_events_
[i
]->get_property ("break-permission");
152 if (scm_is_number (pen
))
154 Real new_pen
= robust_scm2double (cur_pen
, 0.0) + scm_to_double (pen
);
155 command_column_
->set_property (pen_str
.c_str (), scm_from_double (new_pen
));
156 command_column_
->set_property (perm_str
.c_str (), ly_symbol2scm ("allow"));
159 command_column_
->set_property (perm_str
.c_str (), perm
);
162 for (vsize i
= 0 ; i
< label_events_
.size () ; i
++)
164 SCM label
= label_events_
[i
]->get_property ("page-label");
165 SCM labels
= command_column_
->get_property ("labels");
166 command_column_
->set_property ("labels", scm_cons (label
, labels
));
169 bool start_of_measure
= (last_moment_
.main_part_
!= now_mom ().main_part_
170 && !measure_position (context ()).main_part_
);
173 We can't do this in start_translation_timestep (), since time sig
174 changes won't have happened by then.
176 if (start_of_measure
)
178 Moment mlen
= Moment (measure_length (context ()));
179 Grob
*column
= unsmob_grob (get_property ("currentCommandColumn"));
181 column
->set_property ("measure-length", mlen
.smobbed_copy ());
183 programming_error ("No command column?");
188 Paper_column_engraver::stop_translation_timestep ()
190 SCM m
= now_mom ().smobbed_copy ();
191 command_column_
->set_property ("when", m
);
192 musical_column_
->set_property ("when", m
);
194 for (vsize i
= 0; i
< items_
.size (); i
++)
196 Item
*elem
= items_
[i
];
197 Grob
*col
= Item::is_non_musical (elem
) ? command_column_
: musical_column_
;
199 if (!elem
->get_parent (X_AXIS
)
200 || !unsmob_grob (elem
->get_object ("axis-group-parent-X")))
202 Axis_group_interface::add_element (col
, elem
);
204 else if (Accidental_placement::has_interface (elem
))
205 Separation_item::add_conditional_item (col
, elem
);
207 Separation_item::add_item (col
, elem
);
211 if (to_boolean (get_property ("forbidBreak"))
212 && breaks_
) /* don't honour forbidBreak if it occurs on the first moment of a score */
214 command_column_
->set_property ("page-break-permission", SCM_EOL
);
215 command_column_
->set_property ("line-break-permission", SCM_EOL
);
216 for (vsize i
= 0; i
< break_events_
.size (); i
++)
218 SCM perm
= break_events_
[i
]->get_property ("break-permission");
219 if (perm
== ly_symbol2scm ("force") || perm
== ly_symbol2scm ("allow"))
220 warning (_f ("forced break was overridden by some other event, should you be using bar checks?"));
223 else if (Paper_column::is_breakable (command_column_
))
228 progress_indication ("[" + to_string (breaks_
) + "]");
231 context ()->get_score_context ()->unset_property (ly_symbol2scm ("forbidBreak"));
234 break_events_
.clear ();
235 label_events_
.clear ();
237 SCM mpos
= get_property ("measurePosition");
238 SCM barnum
= get_property ("internalBarNumber");
239 if (unsmob_moment (mpos
)
240 && scm_is_integer (barnum
))
242 SCM where
= scm_cons (barnum
,
245 command_column_
->set_property ("rhythmic-location", where
);
246 musical_column_
->set_property ("rhythmic-location", where
);
251 Paper_column_engraver::start_translation_timestep ()
254 TODO: don't make columns when skipTypesetting is true.
260 ADD_ACKNOWLEDGER (Paper_column_engraver
, item
);
261 ADD_ACKNOWLEDGER (Paper_column_engraver
, note_spacing
);
262 ADD_ACKNOWLEDGER (Paper_column_engraver
, staff_spacing
);
264 ADD_TRANSLATOR (Paper_column_engraver
,
265 /* doc */ "Takes care of generating columns."
267 "This engraver decides whether a column is breakable. The default is "
268 "that a column is always breakable. However, every Bar_engraver "
269 "that does not have a barline at a certain point will set forbidBreaks "
270 "in the score context to stop linebreaks. In practice, this "
271 "means that you can make a breakpoint by creating a barline (assuming "
272 "that there are no beams or notes that prevent a breakpoint.) ",
276 "NonMusicalPaperColumn",
282 "currentCommandColumn "
283 "currentMusicalColumn "