2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2009 Han-Wen Nienhuys <hanwen@lilypond.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include "spacing-options.hh"
22 #include "spacing-spanner.hh"
29 Spacing_options::init_from_grob (Grob *me)
31 increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
33 packed_ = to_boolean (me->get_property ("packed-spacing"));
34 stretch_uniformly_ = to_boolean (me->get_property ("uniform-stretching"));
35 float_nonmusical_columns_
36 = to_boolean (me->get_property ("strict-note-spacing"));
38 = to_boolean (me->get_property ("strict-grace-spacing"));
39 shortest_duration_space_ = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
42 Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
43 Moment (Rational (1,8), Rational (1,16)));
45 if (shortest_dur.main_part_)
46 global_shortest_ = shortest_dur.main_part_;
48 global_shortest_ = shortest_dur.grace_part_;
51 Spacing_options::Spacing_options ()
54 stretch_uniformly_ = false;
55 float_nonmusical_columns_ = false;
56 float_grace_columns_ = false;
58 shortest_duration_space_ = 2.0;
61 global_shortest_ = Rational (1, 8);
67 Get the measure wide ant for arithmetic spacing.
70 Spacing_options::get_duration_space (Rational d) const
72 Real k = shortest_duration_space_;
74 if (d < global_shortest_)
77 We don't space really short notes using the log of the
78 duration, since it would disproportionally stretches the long
79 notes in a piece. In stead, we use geometric spacing with constant 0.5
82 This should probably be tunable, to use other base numbers.
84 In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
85 3.6 mm (total). head-width = 2.4, so we 1.2mm for 16th, 1.5
86 mm for 8th. (white space), suggesting that we use
88 (1.2 / 1.5)^{-log2(duration ratio)}
92 Rational ratio = d / global_shortest_;
94 return ((k - 1) + double (ratio)) * increment_;
99 John S. Gourlay. ``Spacing a Line of Music, '' Technical
100 Report OSU-CISRC-10/87-TR35, Department of Computer and
101 Information Science, The Ohio State University, 1987.
103 Real log = log_2 (global_shortest_);
106 return (log_2 (d) + k) * increment_;