2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2011 Jan Nieuwenhuizen <janneke@gnu.org>
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 "multi-measure-rest.hh"
22 #include "font-interface.hh"
25 #include "output-def.hh"
26 #include "paper-column.hh" // urg
27 #include "percent-repeat-item.hh"
29 #include "separation-item.hh"
31 #include "staff-symbol-referencer.hh"
33 #include "text-interface.hh"
37 Multi_measure_rest::bar_width (Spanner *me)
39 SCM spacing_pair = me->get_property ("spacing-pair");
44 Item *col = me->get_bound (d)->get_column ();
46 = (scm_is_pair (spacing_pair)
47 ? index_get_cell (spacing_pair, d)
48 : ly_symbol2scm ("staff-bar"));
49 Interval coldim = Paper_column::break_align_width (col, align_sym);
53 while (flip (&d) != LEFT);
58 MAKE_SCHEME_CALLBACK (Multi_measure_rest, percent, 1);
60 Multi_measure_rest::percent (SCM smob)
62 Grob *me = unsmob_grob (smob);
63 Spanner *sp = dynamic_cast<Spanner *> (me);
65 Stencil r = Percent_repeat_item_interface::x_percent (me, 1);
66 r.translate_axis (-r.extent (X_AXIS).center (), X_AXIS);
70 Grob *common_x = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT),
72 Interval sp_iv = bar_width (sp);
75 Real rx = sp->get_bound (LEFT)->relative_coordinate (common_x, X_AXIS);
77 we gotta stay clear of sp_iv, so move a bit to the right if
80 x_off += max (sp_iv[LEFT] - rx, 0.0);
85 x_off += sp_iv.length () / 2;
87 r.translate_axis (x_off, X_AXIS);
89 return r.smobbed_copy ();
92 MAKE_SCHEME_CALLBACK (Multi_measure_rest, print, 1);
94 Multi_measure_rest::print (SCM smob)
96 Grob *me = unsmob_grob (smob);
97 Spanner *sp = dynamic_cast<Spanner *> (me);
99 Interval sp_iv = bar_width (sp);
100 Real space = sp_iv.length ();
102 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
104 we gotta stay clear of sp_iv, so move a bit to the right if
107 Real x_off = max (sp_iv[LEFT] - rx, 0.0);
110 mol.add_stencil (symbol_stencil (me, space));
113 SCM m (me->get_property ("measure-count"));
114 if (scm_is_number (m))
115 measures = scm_to_int (m);
117 mol.translate_axis (x_off, X_AXIS);
118 return mol.smobbed_copy ();
122 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
125 SCM m (me->get_property ("measure-count"));
126 if (scm_is_number (m))
127 measures = scm_to_int (m);
131 SCM limit = me->get_property ("expand-limit");
132 if (measures > scm_to_int (limit))
135 Stencil s = big_rest (me, (1.0 - 2 * padding) * space);
136 s.translate_axis (padding * space, X_AXIS);
140 Real staff_space = Staff_symbol_referencer::staff_space (me);
142 Font_metric *musfont = Font_interface::get_default_font (me);
144 SCM sml = me->get_property ("use-breve-rest");
147 if (to_boolean (sml))
149 Stencil s = musfont->find_by_name (Rest::glyph_name (me, -1, "", false));
151 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
157 Stencil s = musfont->find_by_name (Rest::glyph_name (me, 0, "", true));
162 if (Staff_symbol_referencer::get_position (me) == 0.0)
163 s.translate_axis (staff_space, Y_AXIS);
165 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
171 return church_rest (me, musfont, measures, space);
175 WIDTH can also be 0 to determine the minimum size of the object.
178 Multi_measure_rest::big_rest (Grob *me, Real width)
180 Real thick_thick = robust_scm2double (me->get_property ("thick-thickness"), 1.0);
181 Real hair_thick = robust_scm2double (me->get_property ("hair-thickness"), .1);
183 Real ss = Staff_symbol_referencer::staff_space (me);
184 Real slt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
185 Real y = slt * thick_thick / 2 * ss;
186 Real ythick = hair_thick * slt * ss;
187 Box b (Interval (0.0, max (0.0, (width - 2 * ythick))), Interval (-y, y));
189 Real blot = width ? (.8 * min (y, ythick)) : 0.0;
191 Stencil m = Lookup::round_filled_box (b, blot);
192 Stencil yb = Lookup::round_filled_box (Box (Interval (-0.5, 0.5) * ythick, Interval (-ss, ss)), blot);
194 m.add_at_edge (X_AXIS, RIGHT, yb, 0);
195 m.add_at_edge (X_AXIS, LEFT, yb, 0);
197 m.align_to (X_AXIS, LEFT);
206 Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measures,
211 /* See Wanske pp. 125 */
214 Real symbols_width = 0.0;
216 bool use_breve = to_boolean (me->get_property ("use-breve-rest"));
234 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
235 symbols_width += r.extent (X_AXIS).length ();
236 mols = scm_cons (r.smobbed_copy (), mols);
257 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
260 Real staff_space = Staff_symbol_referencer::staff_space (me);
261 r.translate_axis (staff_space, Y_AXIS);
263 symbols_width += r.extent (X_AXIS).length ();
264 mols = scm_cons (r.smobbed_copy (), mols);
269 /* Make outer padding this much bigger. */
270 Real outer_padding_factor = 1.5;
271 Real inner_padding = (space - symbols_width)
272 / (2 * outer_padding_factor + (count - 1));
273 if (inner_padding < 0)
277 for (SCM s = mols; scm_is_pair (s); s = scm_cdr (s))
278 mol.add_at_edge (X_AXIS, LEFT, *unsmob_stencil (scm_car (s)),
280 mol.align_to (X_AXIS, LEFT);
281 mol.translate_axis (outer_padding_factor * inner_padding, X_AXIS);
287 Multi_measure_rest::add_column (Grob *me, Item *c)
289 add_bound_item (dynamic_cast<Spanner *> (me), c);
293 Multi_measure_rest::calculate_spacing_rods (Grob *me, Real length)
295 Spanner *sp = dynamic_cast<Spanner *> (me);
296 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
298 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
302 Item *li = sp->get_bound (LEFT)->get_column ();
303 Item *ri = sp->get_bound (RIGHT)->get_column ();
304 Item *lb = li->find_prebroken_piece (RIGHT);
305 Item *rb = ri->find_prebroken_piece (LEFT);
307 Item *combinations[4][2] = {{li, ri},
312 for (int i = 0; i < 4; i++)
314 Item *li = combinations[i][0];
315 Item *ri = combinations[i][1];
321 rod.item_drul_[LEFT] = li;
322 rod.item_drul_[RIGHT] = ri;
324 rod.distance_ = Paper_column::minimum_distance (li, ri)
326 + 2 * robust_scm2double (me->get_property ("bound-padding"), 1.0);
328 Real minlen = robust_scm2double (me->get_property ("minimum-length"), 0);
329 rod.distance_ = max (rod.distance_, minlen);
334 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods, 1);
336 Multi_measure_rest::set_spacing_rods (SCM smob)
338 Grob *me = unsmob_grob (smob);
339 Real sym_width = symbol_stencil (me, 0.0).extent (X_AXIS).length ();
340 calculate_spacing_rods (me, sym_width);
342 return SCM_UNSPECIFIED;
345 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_text_rods, 1);
347 Multi_measure_rest::set_text_rods (SCM smob)
349 Grob *me = unsmob_grob (smob);
350 Stencil *stil = me->get_stencil ();
353 Real len = (stil && !stil->extent (X_AXIS).is_empty ())
354 ? stil->extent (X_AXIS).length ()
356 calculate_spacing_rods (me, len);
358 return SCM_UNSPECIFIED;
361 ADD_INTERFACE (Multi_measure_rest,
362 "A rest that spans a whole number of measures.",