2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 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"
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 Molecule r = Percent_repeat_item_interface::x_percent (me, 1, 0.75, 1.6);
40 Item * col = sp->get_bound (d)->column_l ();
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 ();
70 variable-sized multi-measure rest symbol: |====| ??
72 MAKE_SCHEME_CALLBACK (Multi_measure_rest,brew_molecule,1);
74 Multi_measure_rest::brew_molecule (SCM smob)
76 Grob *me = unsmob_grob (smob);
77 Spanner * sp = dynamic_cast<Spanner*> (me);
79 SCM alist_chain = Font_interface::font_alist_chain (me);
84 Grob *common = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT), X_AXIS);
87 Item * col = sp->get_bound (d)->column_l ();
89 Interval coldim = col->extent (common, X_AXIS);
91 sp_iv[d] = coldim[-d] ;
93 while ((flip (&d)) != LEFT);
95 Real space = sp_iv.length();
97 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
99 we gotta stay clear of sp_iv, so move a bit to the right if
102 Real x_off = (sp_iv[LEFT] - rx) >? 0;
106 mol.add_molecule (symbol_molecule (me, space));
109 SCM m (me->get_grob_property ("measure-count"));
112 measures = gh_scm2int (m);
115 SCM s = me->get_grob_property ("number-threshold");
116 if (measures > gh_scm2int (s))
118 Molecule s = Text_item::text2molecule (me,
119 ly_str02scm (to_str (measures).ch_C ()),
122 s.align_to (X_AXIS, CENTER);
123 s.translate_axis (gh_scm2double (me->get_grob_property ("padding")) + 2,
126 s.translate_axis (mol.extent (X_AXIS).center (), X_AXIS);
127 mol.add_molecule (s);
129 mol.translate_axis (x_off, X_AXIS);
130 return mol.smobbed_copy ();
135 Multi_measure_rest::symbol_molecule (Grob *me, Real space)
138 SCM m (me->get_grob_property ("measure-count"));
141 measures = gh_scm2int (m);
145 SCM limit = me->get_grob_property ("expand-limit");
149 if (measures > gh_scm2int (limit))
152 Molecule s = big_rest (me, (1.0 - 2*padding) * space);
153 s.translate_axis (padding * space, X_AXIS);
157 SCM alist_chain = Font_interface::font_alist_chain (me);
160 Font_interface::add_style (me, ly_symbol2scm ("mmrest-symbol"),
163 Real staff_space = Staff_symbol_referencer::staff_space (me);
165 = Font_interface::get_font (me,style_chain);
169 Molecule s = musfont->find_by_name (Rest::glyph_name (me, 0, ""));
174 if (Staff_symbol_referencer::position_f (me) == 0.0)
175 s.translate_axis (staff_space, Y_AXIS);
177 s.translate_axis ((space - s.extent (X_AXIS).length ())/2, X_AXIS);
183 return church_rest (me, musfont, measures, space);
190 Multi_measure_rest::big_rest (Grob *me, Real width)
192 Real thick = gh_scm2double (me->get_grob_property ("thickness"));
193 Real ss = Staff_symbol_referencer::staff_space (me);
195 Real slt = me->paper_l ()->get_var ("linethickness");
196 Real y = slt * thick/2 * ss;
197 Box b(Interval (0, width), Interval (-y, y));
198 Real ythick = slt * ss;
200 Molecule m = Lookup::filledbox (b);
201 Molecule yb = Lookup::filledbox (Box (Interval (-ythick, ythick), Interval (-ss, ss)));
203 m.add_at_edge (X_AXIS, RIGHT, yb, -ythick);
204 m.add_at_edge (X_AXIS, LEFT, yb, -ythick);
206 m.align_to (X_AXIS, LEFT);
215 Multi_measure_rest::church_rest (Grob*me, Font_metric *musfont, int measures,
225 Real symbols_width = 0.0;
245 Molecule r (musfont->find_by_name ("rests-" + to_str (k)));
248 Real staff_space = Staff_symbol_referencer::staff_space (me);
249 r.translate_axis (staff_space, Y_AXIS);
251 symbols_width += r.extent (X_AXIS).length ();
252 mols = gh_cons (r.smobbed_copy (), mols);
258 Real outer_padding_factor = 1.5; // make outer padding this much bigger.
259 Real inner_padding = (space - symbols_width) / (2 * outer_padding_factor + (count-1));
260 if (inner_padding < 0)
266 for (SCM s = mols; gh_pair_p (s); s = gh_cdr(s))
268 mol.add_at_edge (X_AXIS, LEFT, *unsmob_molecule (gh_car (s)), inner_padding);
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);
283 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods,1);
286 Multi_measure_rest::set_spacing_rods (SCM smob)
288 return SCM_UNSPECIFIED;
290 Grob*me = unsmob_grob (smob);
292 Spanner*sp = dynamic_cast<Spanner*> (me);
293 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
295 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
296 return SCM_UNSPECIFIED;
299 Item * l = sp->get_bound (LEFT)->column_l ();
300 Item * r = sp->get_bound (RIGHT)->column_l ();
301 Item * lb = l->find_prebroken_piece (RIGHT);
302 Item * rb = r->find_prebroken_piece (LEFT);
304 Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
306 Real sym_width = symbol_molecule (me, 0.0).extent (X_AXIS).length ();
308 for (int i=0; i < 4; i++)
310 Item * l = combinations[i][0];
311 Item *r = combinations[i][1];
317 rod.item_l_drul_[LEFT] = l;
318 rod.item_l_drul_[RIGHT] = r;
321 rod.distance_f_ = l->extent (l, X_AXIS)[BIGGER] - r->extent (r, X_AXIS)[SMALLER]
322 + sym_width + 2.0; // 2.0 = magic!
326 return SCM_UNSPECIFIED;
331 ADD_INTERFACE (Multi_measure_rest,"multi-measure-rest-interface",
332 "A rest that spans a whole number of measures. For typesetting the
333 numbers, fields from font-interface may be used.
337 "expand-limit measure-count number-threshold padding thickness");