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 Multi_measure_rest::has_interface (Grob*me)
27 return me->has_interface (ly_symbol2scm ("multi-measure-rest-interface"));
30 MAKE_SCHEME_CALLBACK (Multi_measure_rest,percent,1);
32 Multi_measure_rest::percent (SCM smob)
34 Grob *me = unsmob_grob (smob);
35 Spanner *sp = dynamic_cast<Spanner*> (me);
37 Molecule r = Percent_repeat_item_interface::x_percent (me, 1, 0.75, 1.6);
45 Item * col = sp->get_bound (d)->column_l ();
47 Interval coldim = col->extent (0, X_AXIS);
49 sp_iv[d] = coldim[-d] ;
51 while ((flip (&d)) != LEFT);
54 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
56 we gotta stay clear of sp_iv, so move a bit to the right if
59 x_off += (sp_iv[LEFT] - rx) >? 0;
64 x_off += sp_iv.length ()/ 2;
66 r.translate_axis (x_off,X_AXIS);
69 return r.smobbed_copy ();
75 variable-sized multi-measure rest symbol: |====| ??
77 MAKE_SCHEME_CALLBACK (Multi_measure_rest,brew_molecule,1);
79 Multi_measure_rest::brew_molecule (SCM smob)
81 Grob *me = unsmob_grob (smob);
82 Spanner * sp = dynamic_cast<Spanner*> (me);
84 SCM alist_chain = Font_interface::font_alist_chain (me);
90 Item * col = sp->get_bound (d)->column_l ();
92 Interval coldim = col->extent (0, X_AXIS);
94 sp_iv[d] = coldim[-d] ;
96 while ((flip (&d)) != LEFT);
100 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
102 we gotta stay clear of sp_iv, so move a bit to the right if
105 x_off += (sp_iv[LEFT] - rx) >? 0;
108 center between stuff.
110 x_off += sp_iv.length ()/ 2;
112 mol.add_molecule (symbol_molecule (me));
115 SCM m (me->get_grob_property ("measure-count"));
118 measures = gh_scm2int (m);
123 Molecule s = Text_item::text2molecule (me,
124 ly_str02scm (to_str (measures).ch_C ()),
126 s.align_to (X_AXIS, CENTER);
127 s.translate_axis (3.0, Y_AXIS);
128 mol.add_molecule (s);
130 mol.translate_axis (x_off, X_AXIS);
131 return mol.smobbed_copy ();
136 Multi_measure_rest::symbol_molecule (Grob *me)
138 SCM alist_chain = Font_interface::font_alist_chain (me);
141 Font_interface::add_style (me, ly_symbol2scm ("mmrest-symbol"),
144 Real staff_space = Staff_symbol_referencer::staff_space (me);
146 = Font_interface::get_font (me,style_chain);
150 SCM m (me->get_grob_property ("measure-count"));
153 measures = gh_scm2int (m);
157 SCM limit = me->get_grob_property ("expand-limit");
162 s = musfont->find_by_name (Rest::glyph_name (me, 0, ""));
167 if (Staff_symbol_referencer::position_f (me) == 0.0)
168 s.translate_axis (staff_space, Y_AXIS);
170 else if (measures <= gh_scm2int (limit))
172 Real pad = gh_scm2double (me->get_grob_property ("padding")) * staff_space;
173 s = church_rest (musfont, measures, staff_space, pad);
177 Real w = gh_scm2double (me->get_grob_property ("width"));
178 s = big_rest (me, w);
184 Multi_measure_rest::big_rest (Grob *me, Real width)
186 Real thick = gh_scm2double (me->get_grob_property ("thickness"));
187 Real ss = Staff_symbol_referencer::staff_space (me);
189 Real slt = me->paper_l ()->get_var ("stafflinethickness");
190 Real y = slt * thick/2 * ss;
191 Box b(Interval (0, width), Interval (-y, y));
192 Real ythick = slt * ss;
194 Molecule m = Lookup::filledbox (b);
195 Molecule yb = Lookup::filledbox (Box (Interval (-ythick, ythick), Interval (-ss, ss)));
197 m.add_at_edge (X_AXIS, RIGHT, yb, -ythick);
198 m.add_at_edge (X_AXIS, LEFT, yb, -ythick);
200 m.align_to (X_AXIS, CENTER);
210 Multi_measure_rest::church_rest (Font_metric *musfont, int measures,
211 Real staff_space, Real padding)
215 Build a rest from smaller parts. Distances inbetween are
216 really variable, see Wanske pp. 125 */
238 Real pad = s.empty_b () ? 0.0 : padding;
240 Molecule r (musfont->find_by_name ("rests-" + to_str (k)));
242 r.translate_axis (staff_space, Y_AXIS);
244 s.add_at_edge (X_AXIS, RIGHT, r, pad);
247 s.align_to (X_AXIS, CENTER);
252 UGH. JUNKME elt prop "columns" isn't really needed.
255 Multi_measure_rest::add_column (Grob*me,Item* c)
257 add_bound_item (dynamic_cast<Spanner*> (me),c);
261 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods,1);
264 Multi_measure_rest::set_spacing_rods (SCM smob)
266 Grob*me = unsmob_grob (smob);
268 Spanner*sp = dynamic_cast<Spanner*> (me);
269 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
271 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
272 return SCM_UNSPECIFIED;
275 Item * l = sp->get_bound (LEFT)->column_l ();
276 Item * r = sp->get_bound (RIGHT)->column_l ();
277 Item * lb = l->find_prebroken_piece (RIGHT);
278 Item * rb = r->find_prebroken_piece (LEFT);
280 Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
281 Real staff_space = Staff_symbol_referencer::staff_space (me);
282 for (int i=0; i < 4; i++)
284 Item * l = combinations[i][0];
285 Item *r = combinations[i][1];
291 rod.item_l_drul_[LEFT] = l;
292 rod.item_l_drul_[RIGHT] = r;
295 should do something more advanced.
297 Molecule m = symbol_molecule(me);
299 rod.distance_f_ = l->extent (l, X_AXIS)[BIGGER] - r->extent (r, X_AXIS)[SMALLER]
300 + m.extent (X_AXIS).length () + 2.5*staff_space;
304 return SCM_UNSPECIFIED;
309 ADD_INTERFACE (Multi_measure_rest,"multi-measure-rest-interface",
310 "A rest that spans a whole number of measures. For typesetting the
311 numbers, fields from font-interface may be used.
313 padding is the space between number and rest. Measured in staffspace.
316 "thickness measure-count expand-limit padding");