* lexer-gcc-3.1.sh: Remove.
[lilypond/patrick.git] / lily / spacing-options.cc
blob916408aa7335af66d84c2d52ee15046a251b6ff9
1 /*
2 spacing-options.cc -- implement Spacing_options
4 source file of the GNU LilyPond music typesetter
6 (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
8 */
10 #include "spacing-spanner.hh"
11 #include "grob.hh"
12 #include "misc.hh"
13 #include "moment.hh"
15 void
16 Spacing_options::init_from_grob (Grob *me)
18 increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
20 packed_ = to_boolean (me->get_property ("packed-spacing"));
21 stretch_uniformly_ = to_boolean (me->get_property ("uniform-stretching"));
22 float_nonmusical_columns_
23 = to_boolean (me->get_property ("strict-note-spacing"));
24 float_grace_columns_
25 = to_boolean (me->get_property ("strict-grace-spacing"));
26 shortest_duration_space_ = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
29 Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
30 Moment (Rational (1,8), Rational (1,16)));
32 if (shortest_dur.main_part_)
33 global_shortest_ = shortest_dur.main_part_;
34 else
35 global_shortest_ = shortest_dur.grace_part_;
39 Spacing_options::Spacing_options ()
41 packed_ = false;
42 stretch_uniformly_ = false;
43 float_nonmusical_columns_ = false;
44 float_grace_columns_ = false;
46 shortest_duration_space_ = 2.0;
47 increment_ = 1.2;
49 global_shortest_ = Rational (1, 8);
55 Get the measure wide ant for arithmetic spacing.
57 Real
58 Spacing_options::get_duration_space (Rational d,
59 bool *expand_only) const
61 Real k = shortest_duration_space_;
63 if (d < global_shortest_)
66 We don't space really short notes using the log of the
67 duration, since it would disproportionally stretches the long
68 notes in a piece. In stead, we use geometric spacing with constant 0.5
69 (i.e. linear.)
71 This should probably be tunable, to use other base numbers.
73 In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
74 3.6 mm (total). head-width = 2.4, so we 1.2mm for 16th, 1.5
75 mm for 8th. (white space), suggesting that we use
77 (1.2 / 1.5)^{-log2(duration ratio)}
81 Rational ratio = d / global_shortest_;
83 return ((k - 1) + double (ratio)) * increment_;
85 else
88 John S. Gourlay. ``Spacing a Line of Music, '' Technical
89 Report OSU-CISRC-10/87-TR35, Department of Computer and
90 Information Science, The Ohio State University, 1987.
92 Real log = log_2 (global_shortest_);
93 k -= log;
94 *expand_only = false;
96 return (log_2 (d) + k) * increment_;