Fix type predicates/docstrings for two music properties.
[lilypond/mpolesky.git] / lily / multi-measure-rest.cc
bloba36d7c01ed071a53bd627c0c4aadd027617b6c60
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2010 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "multi-measure-rest.hh"
22 #include "warn.hh"
23 #include "output-def.hh"
24 #include "paper-column.hh" // urg
25 #include "font-interface.hh"
26 #include "rest.hh"
27 #include "misc.hh"
28 #include "spanner.hh"
29 #include "staff-symbol-referencer.hh"
30 #include "system.hh"
31 #include "text-interface.hh"
32 #include "percent-repeat-item.hh"
33 #include "lookup.hh"
34 #include "separation-item.hh"
36 Interval
37 Multi_measure_rest::bar_width (Spanner *me)
39 Interval iv;
40 Direction d = LEFT;
43 Item *col = me->get_bound (d)->get_column ();
45 Interval coldim = Paper_column::break_align_width (col);
47 iv[d] = coldim[-d];
49 while ((flip (&d)) != LEFT);
51 return iv;
54 MAKE_SCHEME_CALLBACK (Multi_measure_rest, percent, 1);
55 SCM
56 Multi_measure_rest::percent (SCM smob)
58 Grob *me = unsmob_grob (smob);
59 Spanner *sp = dynamic_cast<Spanner *> (me);
61 Stencil r = Percent_repeat_item_interface::x_percent (me, 1);
63 // ugh copy & paste.
65 Grob *common_x = sp->get_bound (LEFT)->common_refpoint (sp->get_bound (RIGHT),
66 X_AXIS);
67 Interval sp_iv = bar_width (sp);
68 Real x_off = 0.0;
70 Real rx = sp->get_bound (LEFT)->relative_coordinate (common_x, X_AXIS);
72 we gotta stay clear of sp_iv, so move a bit to the right if
73 needed.
75 x_off += max (sp_iv[LEFT] - rx, 0.0);
78 center between stuff.
80 x_off += sp_iv.length () / 2;
82 r.translate_axis (x_off, X_AXIS);
84 return r.smobbed_copy ();
87 MAKE_SCHEME_CALLBACK (Multi_measure_rest, print, 1);
88 SCM
89 Multi_measure_rest::print (SCM smob)
91 Grob *me = unsmob_grob (smob);
92 Spanner *sp = dynamic_cast<Spanner *> (me);
94 Interval sp_iv = bar_width (sp);
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
100 needed.
102 Real x_off = max (sp_iv[LEFT] - rx, 0.0);
104 Stencil mol;
105 mol.add_stencil (symbol_stencil (me, space));
107 int measures = 0;
108 SCM m (me->get_property ("measure-count"));
109 if (scm_is_number (m))
110 measures = scm_to_int (m);
112 mol.translate_axis (x_off, X_AXIS);
113 return mol.smobbed_copy ();
116 Stencil
117 Multi_measure_rest::symbol_stencil (Grob *me, Real space)
119 int measures = 0;
120 SCM m (me->get_property ("measure-count"));
121 if (scm_is_number (m))
122 measures = scm_to_int (m);
123 if (measures <= 0)
124 return Stencil ();
126 SCM limit = me->get_property ("expand-limit");
127 if (measures > scm_to_int (limit))
129 Real padding = 0.15;
130 Stencil s = big_rest (me, (1.0 - 2 * padding) * space);
131 s.translate_axis (padding * space, X_AXIS);
132 return s;
135 Real staff_space = Staff_symbol_referencer::staff_space (me);
137 Font_metric *musfont = Font_interface::get_default_font (me);
139 SCM sml = me->get_property ("use-breve-rest");
140 if (measures == 1)
142 if (to_boolean (sml))
144 Stencil s = musfont->find_by_name (Rest::glyph_name (me, -1, "", false));
146 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
148 return s;
150 else
152 Stencil s = musfont->find_by_name (Rest::glyph_name (me, 0, "", true));
155 ugh.
157 if (Staff_symbol_referencer::get_position (me) == 0.0)
158 s.translate_axis (staff_space, Y_AXIS);
160 s.translate_axis ((space - s.extent (X_AXIS).length ()) / 2, X_AXIS);
162 return s;
165 else
166 return church_rest (me, musfont, measures, space);
170 WIDTH can also be 0 to determine the minimum size of the object.
172 Stencil
173 Multi_measure_rest::big_rest (Grob *me, Real width)
175 Real thick_thick = robust_scm2double (me->get_property ("thick-thickness"), 1.0);
176 Real hair_thick = robust_scm2double (me->get_property ("hair-thickness"), .1);
178 Real ss = Staff_symbol_referencer::staff_space (me);
179 Real slt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness"));
180 Real y = slt * thick_thick / 2 * ss;
181 Real ythick = hair_thick * slt * ss;
182 Box b (Interval (0.0, max (0.0, (width - 2 * ythick))), Interval (-y, y));
184 Real blot = width ? (.8 * min (y, ythick)) : 0.0;
186 Stencil m = Lookup::round_filled_box (b, blot);
187 Stencil yb = Lookup::round_filled_box (Box (Interval (-0.5, 0.5) * ythick, Interval (-ss, ss)), blot);
189 m.add_at_edge (X_AXIS, RIGHT, yb, 0);
190 m.add_at_edge (X_AXIS, LEFT, yb, 0);
192 m.align_to (X_AXIS, LEFT);
194 return m;
198 Kirchenpause (?)
200 Stencil
201 Multi_measure_rest::church_rest (Grob *me, Font_metric *musfont, int measures,
202 Real space)
204 SCM mols = SCM_EOL;
206 /* See Wanske pp. 125 */
207 int l = measures;
208 int count = 0;
209 Real symbols_width = 0.0;
211 bool use_breve = to_boolean (me->get_property ("use-breve-rest"));
213 while (l)
215 if (use_breve)
217 int k;
218 if (l >= 2)
220 l -= 2;
221 k = -2;
223 else
225 l -= 1;
226 k = -1;
229 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
230 symbols_width += r.extent (X_AXIS).length ();
231 mols = scm_cons (r.smobbed_copy (), mols);
233 else
235 int k;
236 if (l >= 4)
238 l -= 4;
239 k = -2;
241 else if (l >= 2)
243 l -= 2;
244 k = -1;
246 else
248 k = 0;
249 l--;
252 Stencil r (musfont->find_by_name ("rests." + to_string (k)));
253 if (k == 0)
255 Real staff_space = Staff_symbol_referencer::staff_space (me);
256 r.translate_axis (staff_space, Y_AXIS);
258 symbols_width += r.extent (X_AXIS).length ();
259 mols = scm_cons (r.smobbed_copy (), mols);
261 count++;
264 /* Make outer padding this much bigger. */
265 Real outer_padding_factor = 1.5;
266 Real inner_padding = (space - symbols_width)
267 / (2 * outer_padding_factor + (count - 1));
268 if (inner_padding < 0)
269 inner_padding = 1.0;
271 Stencil mol;
272 for (SCM s = mols; scm_is_pair (s); s = scm_cdr (s))
273 mol.add_at_edge (X_AXIS, LEFT, *unsmob_stencil (scm_car (s)),
274 inner_padding);
275 mol.align_to (X_AXIS, LEFT);
276 mol.translate_axis (outer_padding_factor * inner_padding, X_AXIS);
278 return mol;
281 void
282 Multi_measure_rest::add_column (Grob *me, Item *c)
284 add_bound_item (dynamic_cast<Spanner *> (me), c);
287 void
288 Multi_measure_rest::calculate_spacing_rods (Grob *me, Real length)
290 Spanner *sp = dynamic_cast<Spanner *> (me);
291 if (! (sp->get_bound (LEFT) && sp->get_bound (RIGHT)))
293 programming_error ("Multi_measure_rest::get_rods (): I am not spanned!");
294 return ;
297 Item *li = sp->get_bound (LEFT)->get_column ();
298 Item *ri = sp->get_bound (RIGHT)->get_column ();
299 Item *lb = li->find_prebroken_piece (RIGHT);
300 Item *rb = ri->find_prebroken_piece (LEFT);
302 Item *combinations[4][2] = {{li, ri},
303 {lb, ri},
304 {li, rb},
305 {lb, rb}};
307 for (int i = 0; i < 4; i++)
309 Item *li = combinations[i][0];
310 Item *ri = combinations[i][1];
312 if (!li || !ri)
313 continue;
315 Rod rod;
316 rod.item_drul_[LEFT] = li;
317 rod.item_drul_[RIGHT] = ri;
319 rod.distance_ = Paper_column::minimum_distance (li, ri)
320 + length
321 + 2 * robust_scm2double (me->get_property ("bound-padding"), 1.0);
323 Real minlen = robust_scm2double (me->get_property ("minimum-length"), 0);
324 rod.distance_ = max (rod.distance_, minlen);
325 rod.add_to_cols ();
329 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_spacing_rods, 1);
331 Multi_measure_rest::set_spacing_rods (SCM smob)
333 Grob *me = unsmob_grob (smob);
334 Real sym_width = symbol_stencil (me, 0.0).extent (X_AXIS).length ();
335 calculate_spacing_rods (me, sym_width);
337 return SCM_UNSPECIFIED;
340 MAKE_SCHEME_CALLBACK (Multi_measure_rest, set_text_rods, 1);
342 Multi_measure_rest::set_text_rods (SCM smob)
344 Grob *me = unsmob_grob (smob);
345 Stencil *stil = me->get_stencil ();
347 /* FIXME uncached */
348 Real len = (stil && !stil->extent (X_AXIS).is_empty ())
349 ? stil->extent (X_AXIS).length ()
350 : 0.0;
351 calculate_spacing_rods (me, len);
353 return SCM_UNSPECIFIED;
356 ADD_INTERFACE (Multi_measure_rest,
357 "A rest that spans a whole number of measures.",
359 /* properties */
360 "expand-limit "
361 "measure-count "
362 "hair-thickness "
363 "thick-thickness "
364 "use-breve-rest "
365 "bound-padding "
366 "minimum-length "