2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "multi-measure-rest.hh"
12 #include "paper-def.hh"
13 #include "paper-column.hh" // urg
14 #include "font-interface.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "text-item.hh"
21 #include "percent-repeat-item.hh"
23 #include "separation-item.hh"
25 MAKE_SCHEME_CALLBACK (Multi_measure_rest,percent,1);
27 Multi_measure_rest::percent (SCM smob)
29 Grob *me = unsmob_grob (smob);
30 Spanner *sp = dynamic_cast<Spanner*> (me);
32 Stencil r = Percent_repeat_item_interface::x_percent (me, 1, 0.75, 1.6);
40 Item * col = sp->get_bound (d)->get_column ();
42 Interval coldim = col->extent (0, X_AXIS);
44 sp_iv[d] = coldim[-d] ;
46 while ((flip (&d)) != LEFT);
49 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
51 we gotta stay clear of sp_iv, so move a bit to the right if
54 x_off += (sp_iv[LEFT] - rx) >? 0;
59 x_off += sp_iv.length ()/ 2;
61 r.translate_axis (x_off,X_AXIS);
64 return r.smobbed_copy ();
67 MAKE_SCHEME_CALLBACK (Multi_measure_rest,print,1);
69 Multi_measure_rest::print (SCM smob)
71 Grob *me = unsmob_grob (smob);
72 Spanner * sp = dynamic_cast<Spanner*> (me);
77 Grob *common = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
80 Item * b = sp->get_bound (d);
82 Interval coldim = (Separation_item::has_interface (b))
83 ? Separation_item::relative_width (b, common)
84 : b->extent (common, X_AXIS);
86 sp_iv[d] = coldim.is_empty () ? b->relative_coordinate (common, X_AXIS) : coldim[-d];
88 while ((flip (&d)) != LEFT);
90 Real space = sp_iv.length ();
92 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
94 we gotta stay clear of sp_iv, so move a bit to the right if
97 Real x_off = (sp_iv[LEFT] - rx) >? 0;
101 mol.add_stencil (symbol_stencil (me, space));
104 SCM m (me->get_property ("measure-count"));
107 measures = gh_scm2int (m);
110 mol.translate_axis (x_off, X_AXIS);
111 return mol.smobbed_copy ();
117 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
120 SCM m (me->get_property ("measure-count"));
123 measures = gh_scm2int (m);
129 SCM limit = me->get_property ("expand-limit");
130 if (measures > gh_scm2int (limit))
133 Stencil s = big_rest (me, (1.0 - 2*padding) * space);
134 s.translate_axis (padding * space, X_AXIS);
138 SCM alist_chain = Font_interface::text_font_alist_chain (me);
140 Real staff_space = Staff_symbol_referencer::staff_space (me);
142 = select_font (me->get_paper (), alist_chain);
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, ""));
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, ""));
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);
172 return church_rest (me, musfont, measures, space);
178 WIDTH can also be 0 to determine the minimum size of the object.
181 Multi_measure_rest::big_rest (Grob *me, Real width)
183 Real thick_thick =robust_scm2double (me->get_property ("thick-thickness"), 1.0);
184 Real hair_thick = robust_scm2double (me->get_property ("hair-thickness"), .1);
187 Real ss = Staff_symbol_referencer::staff_space (me);
188 Real slt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
189 Real y = slt * thick_thick/2 * ss;
190 Real ythick = hair_thick * slt * ss;
191 Box b (Interval (0, 0 >? (width - 2 * ythick)), Interval (-y, y));
193 Real blot = width ? (.8 * (y <? ythick)) : 0.0;
195 Stencil m = Lookup::round_filled_box (b, blot);
196 Stencil yb = Lookup::round_filled_box (Box (Interval (-0.5, 0.5)* ythick, Interval (-ss, ss)), blot);
198 m.add_at_edge (X_AXIS, RIGHT, yb, 0, 0);
199 m.add_at_edge (X_AXIS, LEFT, yb, 0, 0);
201 m.align_to (X_AXIS, LEFT);
210 Multi_measure_rest::church_rest (Grob*me, Font_metric *musfont, int measures,
220 Real symbols_width = 0.0;
222 SCM sml = me->get_property ("use-breve-rest");
226 if (sml == SCM_BOOL_T)
240 Stencil r (musfont->find_by_name ("rests-" + to_string (k)));
241 symbols_width += r.extent (X_AXIS).length ();
242 mols = gh_cons (r.smobbed_copy (), mols);
263 Stencil r (musfont->find_by_name ("rests-" + to_string (k)));
266 Real staff_space = Staff_symbol_referencer::staff_space (me);
267 r.translate_axis (staff_space, Y_AXIS);
269 symbols_width += r.extent (X_AXIS).length ();
270 mols = gh_cons (r.smobbed_copy (), mols);
277 Real outer_padding_factor = 1.5; // make outer padding this much bigger.
278 Real inner_padding = (space - symbols_width) / (2 * outer_padding_factor + (count-1));
279 if (inner_padding < 0)
285 for (SCM s = mols; gh_pair_p (s); s = gh_cdr (s))
287 mol.add_at_edge (X_AXIS, LEFT, *unsmob_stencil (gh_car (s)), inner_padding, 0);
289 mol.align_to (X_AXIS, LEFT);
290 mol.translate_axis (outer_padding_factor * inner_padding, X_AXIS);
296 Multi_measure_rest::add_column (Grob*me,Item* c)
298 add_bound_item (dynamic_cast<Spanner*> (me),c);
302 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods,1);
304 Multi_measure_rest::set_spacing_rods (SCM smob)
306 Grob*me = unsmob_grob (smob);
308 Spanner*sp = dynamic_cast<Spanner*> (me);
309 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
311 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
312 return SCM_UNSPECIFIED;
315 Item * l = sp->get_bound (LEFT)->get_column ();
316 Item * r = sp->get_bound (RIGHT)->get_column ();
317 Item * lb = l->find_prebroken_piece (RIGHT);
318 Item * rb = r->find_prebroken_piece (LEFT);
320 Item* combinations[4][2] = {{l,r},
325 Real sym_width = symbol_stencil (me, 0.0).extent (X_AXIS).length ();
327 for (int i=0; i < 4; i++)
329 Item *l = combinations[i][0];
330 Item *r = combinations[i][1];
336 rod.item_l_drul_[LEFT] = l;
337 rod.item_l_drul_[RIGHT] = r;
340 rod.distance_ = l->extent (l, X_AXIS)[BIGGER] - r->extent (r, X_AXIS)[SMALLER]
341 + sym_width + 2.0; // 2.0 = magic!
343 Real minlen = robust_scm2double (me->get_property ("minimum-length"), 0.0);
344 rod.distance_ = max (rod.distance_,
348 return SCM_UNSPECIFIED;
354 ADD_INTERFACE (Multi_measure_rest,"multi-measure-rest-interface",
355 "A rest that spans a whole number of measures.",
356 "expand-limit measure-count hair-thickness thick-thickness use-breve-rest minimum-length");