2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2011 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);
41 Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
42 Moment (Rational (1, 8), Rational (1, 16)));
44 if (shortest_dur.main_part_)
45 global_shortest_ = shortest_dur.main_part_;
47 global_shortest_ = shortest_dur.grace_part_;
50 Spacing_options::Spacing_options ()
53 stretch_uniformly_ = false;
54 float_nonmusical_columns_ = false;
55 float_grace_columns_ = false;
57 shortest_duration_space_ = 2.0;
60 global_shortest_ = Rational (1, 8);
64 Get the measure wide ant for arithmetic spacing.
67 Spacing_options::get_duration_space (Rational d) const
69 Real k = shortest_duration_space_;
71 if (d < global_shortest_)
74 We don't space really short notes using the log of the
75 duration, since it would disproportionally stretches the long
76 notes in a piece. In stead, we use geometric spacing with constant 0.5
79 This should probably be tunable, to use other base numbers.
81 In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
82 3.6 mm (total). head-width = 2.4, so we 1.2mm for 16th, 1.5
83 mm for 8th. (white space), suggesting that we use
85 (1.2 / 1.5)^{-log2(duration ratio)}
89 Rational ratio = d / global_shortest_;
91 return ((k - 1) + double (ratio)) * increment_;
96 John S. Gourlay. ``Spacing a Line of Music, '' Technical
97 Report OSU-CISRC-10/87-TR35, Department of Computer and
98 Information Science, The Ohio State University, 1987.
100 Real log = log_2 (global_shortest_);
103 return (log_2 (d) + k) * increment_;