2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 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"
16 #include "molecule.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "text-item.hh"
21 #include "percent-repeat-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 Molecule 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
+= (sp_iv
[LEFT
] - rx
) >? 0;
58 x_off
+= sp_iv
.length ()/ 2;
60 r
.translate_axis (x_off
,X_AXIS
);
63 return r
.smobbed_copy ();
66 MAKE_SCHEME_CALLBACK (Multi_measure_rest
,brew_molecule
,1);
68 Multi_measure_rest::brew_molecule (SCM smob
)
70 Grob
*me
= unsmob_grob (smob
);
71 Spanner
* sp
= dynamic_cast<Spanner
*> (me
);
76 Grob
*common
= sp
->get_bound (LEFT
)->common_refpoint (sp
->get_bound (RIGHT
), X_AXIS
);
79 Item
* col
= sp
->get_bound (d
)->get_column ();
81 Interval coldim
= col
->extent (common
, X_AXIS
);
83 sp_iv
[d
] = coldim
[-d
] ;
85 while ((flip (&d
)) != LEFT
);
87 Real space
= sp_iv
.length();
89 Real rx
= sp
->get_bound (LEFT
)->relative_coordinate (0, X_AXIS
);
91 we gotta stay clear of sp_iv, so move a bit to the right if
94 Real x_off
= (sp_iv
[LEFT
] - rx
) >? 0;
98 mol
.add_molecule (symbol_molecule (me
, space
));
101 SCM
m (me
->get_grob_property ("measure-count"));
104 measures
= gh_scm2int (m
);
107 mol
.translate_axis (x_off
, X_AXIS
);
108 return mol
.smobbed_copy ();
114 Multi_measure_rest::symbol_molecule (Grob
*me
, Real space
)
117 SCM
m (me
->get_grob_property ("measure-count"));
120 measures
= gh_scm2int (m
);
126 SCM limit
= me
->get_grob_property ("expand-limit");
127 if (measures
> gh_scm2int (limit
))
130 Molecule s
= big_rest (me
, (1.0 - 2*padding
) * space
);
131 s
.translate_axis (padding
* space
, X_AXIS
);
135 SCM alist_chain
= Font_interface::font_alist_chain (me
);
137 Real staff_space
= Staff_symbol_referencer::staff_space (me
);
139 = Font_interface::get_font (me
,alist_chain
);
141 SCM sml
= me
->get_grob_property ("use-breve-rest");
144 if (sml
== SCM_BOOL_T
)
146 Molecule s
= musfont
->find_by_name (Rest::glyph_name (me
, -1, ""));
148 s
.translate_axis ((space
- s
.extent (X_AXIS
).length ())/2, X_AXIS
);
154 Molecule s
= musfont
->find_by_name (Rest::glyph_name (me
, 0, ""));
159 if (Staff_symbol_referencer::get_position (me
) == 0.0)
160 s
.translate_axis (staff_space
, Y_AXIS
);
162 s
.translate_axis ((space
- s
.extent (X_AXIS
).length ())/2, X_AXIS
);
169 return church_rest (me
, musfont
, measures
, space
);
176 Multi_measure_rest::big_rest (Grob
*me
, Real width
)
178 Real tthick
= gh_scm2double (me
->get_grob_property ("thick-thickness"));
179 Real hair_thick
= gh_scm2double (me
->get_grob_property ("hair-thickness"));
182 Real ss
= Staff_symbol_referencer::staff_space (me
);
184 Real slt
= me
->get_paper ()->get_var ("linethickness");
185 Real y
= slt
* tthick
/2 * ss
;
186 Real ythick
= hair_thick
* slt
* ss
;
187 Box
b(Interval (0, width
- 2 * ythick
), Interval (-y
, y
));
189 Molecule m
= Lookup::filledbox (b
);
190 Molecule yb
= Lookup::filledbox (Box (Interval (-0.5, 0.5)* ythick
, Interval (-ss
, ss
)));
192 m
.add_at_edge (X_AXIS
, RIGHT
, yb
, 0, 0);
193 m
.add_at_edge (X_AXIS
, LEFT
, yb
, 0, 0);
195 m
.align_to (X_AXIS
, LEFT
);
204 Multi_measure_rest::church_rest (Grob
*me
, Font_metric
*musfont
, int measures
,
214 Real symbols_width
= 0.0;
216 SCM sml
= me
->get_grob_property ("use-breve-rest");
220 if (sml
== SCM_BOOL_T
)
234 Molecule
r (musfont
->find_by_name ("rests-" + to_string (k
)));
235 symbols_width
+= r
.extent (X_AXIS
).length ();
236 mols
= gh_cons (r
.smobbed_copy (), mols
);
257 Molecule
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
= gh_cons (r
.smobbed_copy (), mols
);
271 Real outer_padding_factor
= 1.5; // make outer padding this much bigger.
272 Real inner_padding
= (space
- symbols_width
) / (2 * outer_padding_factor
+ (count
-1));
273 if (inner_padding
< 0)
279 for (SCM s
= mols
; gh_pair_p (s
); s
= gh_cdr(s
))
281 mol
.add_at_edge (X_AXIS
, LEFT
, *unsmob_molecule (gh_car (s
)), inner_padding
, 0);
283 mol
.align_to (X_AXIS
, LEFT
);
284 mol
.translate_axis (outer_padding_factor
* inner_padding
, X_AXIS
);
290 Multi_measure_rest::add_column (Grob
*me
,Item
* c
)
292 add_bound_item (dynamic_cast<Spanner
*> (me
),c
);
296 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, set_spacing_rods
,1);
299 Multi_measure_rest::set_spacing_rods (SCM smob
)
301 Grob
*me
= unsmob_grob (smob
);
303 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
304 if (! (sp
->get_bound (LEFT
) && sp
->get_bound (RIGHT
)))
306 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
307 return SCM_UNSPECIFIED
;
310 Item
* l
= sp
->get_bound (LEFT
)->get_column ();
311 Item
* r
= sp
->get_bound (RIGHT
)->get_column ();
312 Item
* lb
= l
->find_prebroken_piece (RIGHT
);
313 Item
* rb
= r
->find_prebroken_piece (LEFT
);
315 Item
* combinations
[4][2]={{l
,r
}, {lb
,r
}, {l
,rb
},{lb
,rb
}};
317 Real sym_width
= symbol_molecule (me
, 0.0).extent (X_AXIS
).length ();
319 for (int i
=0; i
< 4; i
++)
321 Item
* l
= combinations
[i
][0];
322 Item
*r
= combinations
[i
][1];
328 rod
.item_l_drul_
[LEFT
] = l
;
329 rod
.item_l_drul_
[RIGHT
] = r
;
332 rod
.distance_
= l
->extent (l
, X_AXIS
)[BIGGER
] - r
->extent (r
, X_AXIS
)[SMALLER
]
333 + sym_width
+ 2.0; // 2.0 = magic!
337 return SCM_UNSPECIFIED
;
343 ADD_INTERFACE (Multi_measure_rest
,"multi-measure-rest-interface",
344 "A rest that spans a whole number of measures.",
345 "expand-limit measure-count hair-thickness thick-thickness use-breve-rest");