2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2007 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"
20 #include "text-interface.hh"
21 #include "percent-repeat-item.hh"
23 #include "separation-item.hh"
26 Multi_measure_rest::bar_width (Spanner
*me
)
32 Item
*col
= me
->get_bound (d
)->get_column ();
34 Interval coldim
= Paper_column::break_align_width (col
);
38 while ((flip (&d
)) != LEFT
);
43 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, percent
, 1);
45 Multi_measure_rest::percent (SCM smob
)
47 Grob
*me
= unsmob_grob (smob
);
48 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
50 Stencil r
= Percent_repeat_item_interface::x_percent (me
, 1, 0.75, 1.6);
54 Grob
*common_x
= sp
->get_bound (LEFT
)->common_refpoint (sp
->get_bound (RIGHT
),
56 Interval sp_iv
= bar_width (sp
);
59 Real rx
= sp
->get_bound (LEFT
)->relative_coordinate (common_x
, X_AXIS
);
61 we gotta stay clear of sp_iv, so move a bit to the right if
64 x_off
+= max (sp_iv
[LEFT
] - rx
, 0.0);
69 x_off
+= sp_iv
.length () / 2;
71 r
.translate_axis (x_off
, X_AXIS
);
73 return r
.smobbed_copy ();
76 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, print
, 1);
78 Multi_measure_rest::print (SCM smob
)
80 Grob
*me
= unsmob_grob (smob
);
81 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
83 Interval sp_iv
= bar_width (sp
);
84 Real space
= sp_iv
.length ();
86 Real rx
= sp
->get_bound (LEFT
)->relative_coordinate (0, X_AXIS
);
88 we gotta stay clear of sp_iv, so move a bit to the right if
91 Real x_off
= max (sp_iv
[LEFT
] - rx
, 0.0);
94 mol
.add_stencil (symbol_stencil (me
, space
));
97 SCM
m (me
->get_property ("measure-count"));
98 if (scm_is_number (m
))
99 measures
= scm_to_int (m
);
101 mol
.translate_axis (x_off
, X_AXIS
);
102 return mol
.smobbed_copy ();
106 Multi_measure_rest::symbol_stencil (Grob
*me
, Real space
)
109 SCM
m (me
->get_property ("measure-count"));
110 if (scm_is_number (m
))
111 measures
= scm_to_int (m
);
115 SCM limit
= me
->get_property ("expand-limit");
116 if (measures
> scm_to_int (limit
))
119 Stencil s
= big_rest (me
, (1.0 - 2 * padding
) * space
);
120 s
.translate_axis (padding
* space
, X_AXIS
);
124 SCM alist_chain
= Font_interface::music_font_alist_chain (me
);
126 Real staff_space
= Staff_symbol_referencer::staff_space (me
);
128 = select_font (me
->layout (), alist_chain
);
130 SCM sml
= me
->get_property ("use-breve-rest");
133 if (to_boolean (sml
))
135 Stencil s
= musfont
->find_by_name (Rest::glyph_name (me
, -1, "", false));
137 s
.translate_axis ((space
- s
.extent (X_AXIS
).length ()) / 2, X_AXIS
);
143 Stencil s
= musfont
->find_by_name (Rest::glyph_name (me
, 0, "", true));
148 if (Staff_symbol_referencer::get_position (me
) == 0.0)
149 s
.translate_axis (staff_space
, Y_AXIS
);
151 s
.translate_axis ((space
- s
.extent (X_AXIS
).length ()) / 2, X_AXIS
);
157 return church_rest (me
, musfont
, measures
, space
);
161 WIDTH can also be 0 to determine the minimum size of the object.
164 Multi_measure_rest::big_rest (Grob
*me
, Real width
)
166 Real thick_thick
= robust_scm2double (me
->get_property ("thick-thickness"), 1.0);
167 Real hair_thick
= robust_scm2double (me
->get_property ("hair-thickness"), .1);
169 Real ss
= Staff_symbol_referencer::staff_space (me
);
170 Real slt
= me
->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
171 Real y
= slt
* thick_thick
/ 2 * ss
;
172 Real ythick
= hair_thick
* slt
* ss
;
173 Box
b (Interval (0.0, max (0.0, (width
- 2 * ythick
))), Interval (-y
, y
));
175 Real blot
= width
? (.8 * min (y
, ythick
)) : 0.0;
177 Stencil m
= Lookup::round_filled_box (b
, blot
);
178 Stencil yb
= Lookup::round_filled_box (Box (Interval (-0.5, 0.5) * ythick
, Interval (-ss
, ss
)), blot
);
180 m
.add_at_edge (X_AXIS
, RIGHT
, yb
, 0);
181 m
.add_at_edge (X_AXIS
, LEFT
, yb
, 0);
183 m
.align_to (X_AXIS
, LEFT
);
192 Multi_measure_rest::church_rest (Grob
*me
, Font_metric
*musfont
, int measures
,
197 /* See Wanske pp. 125 */
200 Real symbols_width
= 0.0;
202 bool use_breve
= to_boolean (me
->get_property ("use-breve-rest"));
220 Stencil
r (musfont
->find_by_name ("rests." + to_string (k
)));
221 symbols_width
+= r
.extent (X_AXIS
).length ();
222 mols
= scm_cons (r
.smobbed_copy (), mols
);
243 Stencil
r (musfont
->find_by_name ("rests." + to_string (k
)));
246 Real staff_space
= Staff_symbol_referencer::staff_space (me
);
247 r
.translate_axis (staff_space
, Y_AXIS
);
249 symbols_width
+= r
.extent (X_AXIS
).length ();
250 mols
= scm_cons (r
.smobbed_copy (), mols
);
255 /* Make outer padding this much bigger. */
256 Real outer_padding_factor
= 1.5;
257 Real inner_padding
= (space
- symbols_width
)
258 / (2 * outer_padding_factor
+ (count
- 1));
259 if (inner_padding
< 0)
263 for (SCM s
= mols
; scm_is_pair (s
); s
= scm_cdr (s
))
264 mol
.add_at_edge (X_AXIS
, LEFT
, *unsmob_stencil (scm_car (s
)),
266 mol
.align_to (X_AXIS
, LEFT
);
267 mol
.translate_axis (outer_padding_factor
* inner_padding
, X_AXIS
);
273 Multi_measure_rest::add_column (Grob
*me
, Item
*c
)
275 add_bound_item (dynamic_cast<Spanner
*> (me
), c
);
279 Multi_measure_rest::calculate_spacing_rods (Grob
*me
, Real length
)
281 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
282 if (! (sp
->get_bound (LEFT
) && sp
->get_bound (RIGHT
)))
284 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
288 Item
*li
= sp
->get_bound (LEFT
)->get_column ();
289 Item
*ri
= sp
->get_bound (RIGHT
)->get_column ();
290 Item
*lb
= li
->find_prebroken_piece (RIGHT
);
291 Item
*rb
= ri
->find_prebroken_piece (LEFT
);
293 Item
*combinations
[4][2] = {{li
, ri
},
298 for (int i
= 0; i
< 4; i
++)
300 Item
*li
= combinations
[i
][0];
301 Item
*ri
= combinations
[i
][1];
307 rod
.item_drul_
[LEFT
] = li
;
308 rod
.item_drul_
[RIGHT
] = ri
;
310 rod
.distance_
= Paper_column::minimum_distance (li
, ri
)
312 + 2 * robust_scm2double (me
->get_property ("bound-padding"), 1.0);
314 Real minlen
= robust_scm2double (me
->get_property ("minimum-length"), 0);
315 rod
.distance_
= max (rod
.distance_
, minlen
);
320 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, set_spacing_rods
, 1);
322 Multi_measure_rest::set_spacing_rods (SCM smob
)
324 Grob
*me
= unsmob_grob (smob
);
325 Real sym_width
= symbol_stencil (me
, 0.0).extent (X_AXIS
).length ();
326 calculate_spacing_rods (me
, sym_width
);
328 return SCM_UNSPECIFIED
;
331 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, set_text_rods
, 1);
333 Multi_measure_rest::set_text_rods (SCM smob
)
335 Grob
*me
= unsmob_grob (smob
);
336 Stencil
*stil
= me
->get_stencil ();
339 Real len
= (stil
&& !stil
->extent (X_AXIS
).is_empty ())
340 ? stil
->extent (X_AXIS
).length ()
342 calculate_spacing_rods (me
, len
);
344 return SCM_UNSPECIFIED
;
347 ADD_INTERFACE (Multi_measure_rest
,
348 "A rest that spans a whole number of measures.",