2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "multi-measure-rest.hh"
12 #include "output-def.hh"
13 #include "paper-column.hh" // urg
14 #include "font-interface.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "text-interface.hh"
20 #include "percent-repeat-item.hh"
22 #include "separation-item.hh"
24 MAKE_SCHEME_CALLBACK (Multi_measure_rest, percent, 1);
26 Multi_measure_rest::percent (SCM smob)
28 Grob *me = unsmob_grob (smob);
29 Spanner *sp = dynamic_cast<Spanner *> (me);
31 Stencil r = Percent_repeat_item_interface::x_percent (me, 1, 0.75, 1.6);
39 Item *col = sp->get_bound (d)->get_column ();
41 Interval coldim = col->extent (0, X_AXIS);
43 sp_iv[d] = coldim[-d];
45 while ((flip (&d)) != LEFT);
48 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
50 we gotta stay clear of sp_iv, so move a bit to the right if
53 x_off += max (sp_iv[LEFT] - rx, 0.0);
58 x_off += sp_iv.length () / 2;
60 r.translate_axis (x_off, X_AXIS);
62 return r.smobbed_copy ();
65 MAKE_SCHEME_CALLBACK (Multi_measure_rest, print, 1);
67 Multi_measure_rest::print (SCM smob)
69 Grob *me = unsmob_grob (smob);
70 Spanner *sp = dynamic_cast<Spanner *> (me);
75 Grob *common = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
78 Item *b = sp->get_bound (d);
80 Interval coldim = (Separation_item::has_interface (b))
81 ? Separation_item::relative_width (b, common)
82 : b->extent (common, X_AXIS);
84 sp_iv[d] = coldim.is_empty () ? b->relative_coordinate (common, X_AXIS) : coldim[-d];
86 while ((flip (&d)) != LEFT);
88 Real space = sp_iv.length ();
90 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
92 we gotta stay clear of sp_iv, so move a bit to the right if
95 Real x_off = max (sp_iv[LEFT] - rx, 0.0);
98 mol.add_stencil (symbol_stencil (me, space));
101 SCM m (me->get_property ("measure-count"));
102 if (scm_is_number (m))
103 measures = scm_to_int (m);
105 mol.translate_axis (x_off, X_AXIS);
106 return mol.smobbed_copy ();
110 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
113 SCM m (me->get_property ("measure-count"));
114 if (scm_is_number (m))
115 measures = scm_to_int (m);
119 SCM limit = me->get_property ("expand-limit");
120 if (measures > scm_to_int (limit))
123 Stencil s = big_rest (me, (1.0 - 2 * padding) * space);
124 s.translate_axis (padding * space, X_AXIS);
128 SCM alist_chain = Font_interface::music_font_alist_chain (me);
130 Real staff_space = Staff_symbol_referencer::staff_space (me);
132 = select_font (me->get_layout (), alist_chain);
134 SCM sml = me->get_property ("use-breve-rest");
137 if (to_boolean (sml))
139 Stencil s = musfont->find_by_name (Rest::glyph_name (me, -1, "", false));
141 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
147 Stencil s = musfont->find_by_name (Rest::glyph_name (me, 0, "", true));
152 if (Staff_symbol_referencer::get_position (me) == 0.0)
153 s.translate_axis (staff_space, Y_AXIS);
155 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
161 return church_rest (me, musfont, measures, space);
165 WIDTH can also be 0 to determine the minimum size of the object.
168 Multi_measure_rest::big_rest (Grob *me, Real width)
170 Real thick_thick = robust_scm2double (me->get_property ("thick-thickness"), 1.0);
171 Real hair_thick = robust_scm2double (me->get_property ("hair-thickness"), .1);
173 Real ss = Staff_symbol_referencer::staff_space (me);
174 Real slt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
175 Real y = slt * thick_thick / 2 * ss;
176 Real ythick = hair_thick * slt * ss;
177 Box b (Interval (0.0, max (0.0, (width - 2 * ythick))), Interval (-y, y));
179 Real blot = width ? (.8 * min (y, ythick)) : 0.0;
181 Stencil m = Lookup::round_filled_box (b, blot);
182 Stencil yb = Lookup::round_filled_box (Box (Interval (-0.5, 0.5) * ythick, Interval (-ss, ss)), blot);
184 m.add_at_edge (X_AXIS, RIGHT, yb, 0, 0);
185 m.add_at_edge (X_AXIS, LEFT, yb, 0, 0);
187 m.align_to (X_AXIS, LEFT);
196 Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measures,
201 /* See Wanske pp. 125 */
204 Real symbols_width = 0.0;
206 SCM sml = me->get_property ("use-breve-rest");
210 if (sml == SCM_BOOL_T)
224 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
225 symbols_width += r.extent (X_AXIS).length ();
226 mols = scm_cons (r.smobbed_copy (), mols);
247 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
250 Real staff_space = Staff_symbol_referencer::staff_space (me);
251 r.translate_axis (staff_space, Y_AXIS);
253 symbols_width += r.extent (X_AXIS).length ();
254 mols = scm_cons (r.smobbed_copy (), mols);
259 /* Make outer padding this much bigger. */
260 Real outer_padding_factor = 1.5;
261 Real inner_padding = (space - symbols_width)
262 / (2 * outer_padding_factor + (count - 1));
263 if (inner_padding < 0)
267 for (SCM s = mols; scm_is_pair (s); s = scm_cdr (s))
268 mol.add_at_edge (X_AXIS, LEFT, *unsmob_stencil (scm_car (s)),
270 mol.align_to (X_AXIS, LEFT);
271 mol.translate_axis (outer_padding_factor * inner_padding, X_AXIS);
277 Multi_measure_rest::add_column (Grob *me, Item *c)
279 add_bound_item (dynamic_cast<Spanner *> (me), c);
282 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods, 1);
284 Multi_measure_rest::set_spacing_rods (SCM smob)
286 Grob *me = unsmob_grob (smob);
288 Spanner *sp = dynamic_cast<Spanner *> (me);
289 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
291 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
292 return SCM_UNSPECIFIED;
295 Item *li = sp->get_bound (LEFT)->get_column ();
296 Item *ri = sp->get_bound (RIGHT)->get_column ();
297 Item *lb = li->find_prebroken_piece (RIGHT);
298 Item *rb = ri->find_prebroken_piece (LEFT);
300 Item *combinations[4][2] = {{li, ri},
305 Real sym_width = symbol_stencil (me, 0.0).extent (X_AXIS).length ();
307 for (int i = 0; i < 4; i++)
309 Item *li = combinations[i][0];
310 Item *ri = combinations[i][1];
316 rod.item_drul_[LEFT] = li;
317 rod.item_drul_[RIGHT] = ri;
319 rod.distance_ = li->extent (li, X_AXIS)[BIGGER]
320 - ri->extent (ri, X_AXIS)[SMALLER]
324 Real minlen = robust_scm2double (me->get_property ("minimum-length"), 0);
325 rod.distance_ = max (rod.distance_, minlen);
328 return SCM_UNSPECIFIED;
331 ADD_INTERFACE (Multi_measure_rest, "multi-measure-rest-interface",
332 "A rest that spans a whole number of measures.",
333 "expand-limit measure-count hair-thickness thick-thickness use-breve-rest minimum-length");