2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "multi-measure-rest.hh"
12 #include "paper-def.hh"
13 #include "paper-column.hh" // urg
16 #include "molecule.hh"
18 #include "group-interface.hh"
20 #include "staff-symbol-referencer.hh"
23 Multi_measure_rest::set_interface (Score_element*me)
25 me->set_interface (ly_symbol2scm ("multi-measure-rest-interface"));
29 Multi_measure_rest::has_interface (Score_element*me)
31 return me->has_interface (ly_symbol2scm ("multi-measure-rest-interface"));
36 * variable-sized multi-measure rest symbol: |====| ??
38 MAKE_SCHEME_CALLBACK(Multi_measure_rest,brew_molecule,1);
40 Multi_measure_rest::brew_molecule (SCM smob)
42 Score_element *me = unsmob_element (smob);
43 Spanner * sp = dynamic_cast<Spanner*> (me);
44 Real staff_space = Staff_symbol_referencer::staff_space (me);
50 Item * col = sp->get_bound (d)->column_l ();
52 Interval coldim = col->extent (0, X_AXIS);
54 sp_iv[d] = coldim[-d] ;
56 while ((flip (&d)) != LEFT);
60 Real rx = sp->get_bound (LEFT)->relative_coordinate (0, X_AXIS);
62 we gotta stay clear of sp_iv, so move a bit to the right if
65 x_off += (sp_iv[LEFT] - rx) >? 0;
70 x_off += sp_iv.length ()/ 2;
76 SCM m (me->get_elt_property ("measure-count"));
79 measures = gh_scm2int (m);
83 SCM limit = me->get_elt_property ("expand-limit");
84 if (measures <= gh_scm2int (limit))
87 Build a rest from smaller parts. Distances inbetween are
88 really variable, see Wanske pp. 125 */
110 Real pad = s.empty_b ()
111 ? 0.0 : gh_scm2double (me->get_elt_property ("padding")) * staff_space;
113 Molecule r (me->lookup_l ()->afm_find ("rests-" + to_str (k)));
115 r.translate_axis (staff_space, Y_AXIS);
117 s.add_at_edge (X_AXIS, RIGHT, r, pad);
121 s.align_to (X_AXIS, CENTER);
125 String idx = ("rests-") + to_str (-4);
126 s = me->lookup_l ()->afm_find (idx);
129 mol.add_molecule (s);
133 Molecule s (me->lookup_l ()->text ("number", to_str (measures), me->paper_l ()));
134 s.align_to (X_AXIS, CENTER);
135 s.translate_axis (3.0 * staff_space, Y_AXIS);
136 mol.add_molecule (s);
138 mol.translate_axis (x_off, X_AXIS);
139 return mol.create_scheme();
143 UGH. JUNKME elt prop "columns" isn't really needed.
146 Multi_measure_rest::add_column (Score_element*me,Item* c)
148 Pointer_group_interface::add_element (me, "columns",c);
150 add_bound_item (dynamic_cast<Spanner*> (me),c);
154 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods,1);
157 Multi_measure_rest::set_spacing_rods (SCM smob)
159 Score_element*me = unsmob_element (smob);
161 Spanner*sp = dynamic_cast<Spanner*> (me);
162 if (!(sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
164 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
165 return SCM_UNSPECIFIED;
168 Item * l = sp->get_bound (LEFT)->column_l ();
169 Item * r = sp->get_bound (RIGHT)->column_l ();
170 Item * lb = l->find_prebroken_piece (RIGHT);
171 Item * rb = r->find_prebroken_piece (LEFT);
173 Item* combinations[4][2]={{l,r}, {lb,r}, {l,rb},{lb,rb}};
174 Real staff_space = Staff_symbol_referencer::staff_space (me);
175 for (int i=0; i < 4; i++)
177 Item * l = combinations[i][0];
178 Item *r = combinations[i][1];
184 rod.item_l_drul_[LEFT] = l;
185 rod.item_l_drul_[RIGHT] = r;
188 should do something more advanced.
190 rod.distance_f_ = l->extent (l, X_AXIS)[BIGGER] - r->extent (r, X_AXIS)[SMALLER]
191 + gh_scm2double (me->get_elt_property ("minimum-width")) * staff_space;
195 return SCM_UNSPECIFIED;