2 multi-measure-rest.cc -- implement Multi_measure_rest
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 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"
18 #include "group-interface.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "text-item.hh"
22 #include "percent-repeat-item.hh"
26 Multi_measure_rest::set_interface (Grob
*me
)
28 me
->set_interface (ly_symbol2scm ("multi-measure-rest-interface"));
32 Multi_measure_rest::has_interface (Grob
*me
)
34 return me
->has_interface (ly_symbol2scm ("multi-measure-rest-interface"));
37 MAKE_SCHEME_CALLBACK (Multi_measure_rest
,percent
,1);
39 Multi_measure_rest::percent (SCM smob
)
42 Grob
*me
= unsmob_grob (smob
);
43 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
45 Font_metric
*musfont
= Font_interface::get_default_font (me
);
47 Molecule r
= Percent_repeat_item_interface::x_percent (me
, 1, 0.75, 1.6);
55 Item
* col
= sp
->get_bound (d
)->column_l ();
57 Interval coldim
= col
->extent (0, X_AXIS
);
59 sp_iv
[d
] = coldim
[-d
] ;
61 while ((flip (&d
)) != LEFT
);
64 Real rx
= sp
->get_bound (LEFT
)->relative_coordinate (0, X_AXIS
);
66 we gotta stay clear of sp_iv, so move a bit to the right if
69 x_off
+= (sp_iv
[LEFT
] - rx
) >? 0;
74 x_off
+= sp_iv
.length ()/ 2;
76 r
.translate_axis (x_off
,X_AXIS
);
79 return r
.smobbed_copy ();
85 variable-sized multi-measure rest symbol: |====| ??
87 MAKE_SCHEME_CALLBACK (Multi_measure_rest
,brew_molecule
,1);
89 Multi_measure_rest::brew_molecule (SCM smob
)
91 Grob
*me
= unsmob_grob (smob
);
92 if (to_boolean (me
->get_grob_property ("skip-timestep")))
94 me
->set_grob_property ("skip-timestep", SCM_EOL
);
98 Spanner
* sp
= dynamic_cast<Spanner
*> (me
);
100 SCM alist_chain
= Font_interface::font_alist_chain (me
);
104 Font_interface::add_style (me
, ly_symbol2scm ("mmrest-symbol"),
108 = Font_interface::get_font (me
,style_chain
);
110 Real staff_space
= Staff_symbol_referencer::staff_space (me
);
116 Item
* col
= sp
->get_bound (d
)->column_l ();
118 Interval coldim
= col
->extent (0, X_AXIS
);
120 sp_iv
[d
] = coldim
[-d
] ;
122 while ((flip (&d
)) != LEFT
);
126 Real rx
= sp
->get_bound (LEFT
)->relative_coordinate (0, X_AXIS
);
128 we gotta stay clear of sp_iv, so move a bit to the right if
131 x_off
+= (sp_iv
[LEFT
] - rx
) >? 0;
134 center between stuff.
136 x_off
+= sp_iv
.length ()/ 2;
142 SCM
m (me
->get_grob_property ("measure-count"));
145 measures
= gh_scm2int (m
);
149 SCM limit
= me
->get_grob_property ("expand-limit");
154 s
= musfont
->find_by_name (Rest::glyph_name (me
, 0, ""));
159 if (Staff_symbol_referencer::position_f (me
) == 0.0)
160 s
.translate_axis (Staff_symbol_referencer::staff_space (me
), Y_AXIS
);
162 else if (measures
<= gh_scm2int (limit
))
165 Build a rest from smaller parts. Distances inbetween are
166 really variable, see Wanske pp. 125 */
188 Real pad
= s
.empty_b ()
189 ? 0.0 : gh_scm2double (me
->get_grob_property ("padding")) * staff_space
;
191 Molecule
r (musfont
->find_by_name ("rests-" + to_str (k
)));
193 r
.translate_axis (staff_space
, Y_AXIS
);
195 s
.add_at_edge (X_AXIS
, RIGHT
, r
, pad
);
199 s
.align_to (X_AXIS
, CENTER
);
203 String idx
= ("rests-") + to_str (-4);
204 s
= musfont
->find_by_name (idx
);
207 mol
.add_molecule (s
);
211 Molecule s
= Text_item::text2molecule (me
,
212 ly_str02scm (to_str (measures
).ch_C ()),
214 s
.align_to (X_AXIS
, CENTER
);
215 s
.translate_axis (3.0 * staff_space
, Y_AXIS
);
216 mol
.add_molecule (s
);
218 mol
.translate_axis (x_off
, X_AXIS
);
219 return mol
.smobbed_copy ();
223 UGH. JUNKME elt prop "columns" isn't really needed.
226 Multi_measure_rest::add_column (Grob
*me
,Item
* c
)
228 Pointer_group_interface::add_element (me
, "columns",c
);
230 add_bound_item (dynamic_cast<Spanner
*> (me
),c
);
234 MAKE_SCHEME_CALLBACK (Multi_measure_rest
, set_spacing_rods
,1);
237 Multi_measure_rest::set_spacing_rods (SCM smob
)
239 Grob
*me
= unsmob_grob (smob
);
241 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
242 if (! (sp
->get_bound (LEFT
) && sp
->get_bound (RIGHT
)))
244 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
245 return SCM_UNSPECIFIED
;
248 Item
* l
= sp
->get_bound (LEFT
)->column_l ();
249 Item
* r
= sp
->get_bound (RIGHT
)->column_l ();
250 Item
* lb
= l
->find_prebroken_piece (RIGHT
);
251 Item
* rb
= r
->find_prebroken_piece (LEFT
);
253 Item
* combinations
[4][2]={{l
,r
}, {lb
,r
}, {l
,rb
},{lb
,rb
}};
254 Real staff_space
= Staff_symbol_referencer::staff_space (me
);
255 for (int i
=0; i
< 4; i
++)
257 Item
* l
= combinations
[i
][0];
258 Item
*r
= combinations
[i
][1];
264 rod
.item_l_drul_
[LEFT
] = l
;
265 rod
.item_l_drul_
[RIGHT
] = r
;
268 should do something more advanced.
270 rod
.distance_f_
= l
->extent (l
, X_AXIS
)[BIGGER
] - r
->extent (r
, X_AXIS
)[SMALLER
]
271 + gh_scm2double (me
->get_grob_property ("minimum-width")) * staff_space
;
275 return SCM_UNSPECIFIED
;