]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-options.cc
a3e512525b5c8352a825e08f81f2fc95cfbedcf5
[lilypond.git] / lily / spacing-options.cc
1 /*
2   spacing-options.cc -- implement Spacing_options 
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2006--2007 Han-Wen Nienhuys <hanwen@lilypond.org>
7
8 */
9
10 #include "spacing-options.hh"
11 #include "spacing-spanner.hh"
12 #include "grob.hh"
13 #include "misc.hh"
14 #include "moment.hh"
15 #include "spanner.hh"
16
17 void
18 Spacing_options::init_from_grob (Grob *me)
19 {
20   increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
21
22   packed_ = to_boolean (me->get_property ("packed-spacing"));
23   stretch_uniformly_ = to_boolean (me->get_property ("uniform-stretching"));
24   float_nonmusical_columns_
25     = to_boolean (me->get_property ("strict-note-spacing"));
26   float_grace_columns_
27     = to_boolean (me->get_property ("strict-grace-spacing"));
28   shortest_duration_space_ = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
29
30
31   Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
32                                            Moment (Rational (1,8), Rational (1,16)));
33
34   if (shortest_dur.main_part_)
35     global_shortest_ = shortest_dur.main_part_;
36   else
37     global_shortest_ = shortest_dur.grace_part_;
38 }
39
40 Spacing_options::Spacing_options ()
41 {
42   packed_ = false;
43   stretch_uniformly_ = false;
44   float_nonmusical_columns_ = false;
45   float_grace_columns_ = false;
46
47   shortest_duration_space_ = 2.0;
48   increment_ = 1.2;
49
50   global_shortest_ = Rational (1, 8);
51 }
52
53
54
55 /*
56   Get the measure wide ant for arithmetic spacing.
57 */
58 Real
59 Spacing_options::get_duration_space (Rational d) const
60 {
61   Real k = shortest_duration_space_;
62
63   if (d < global_shortest_)
64     {
65       /*
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.)
70
71         This should probably be tunable, to use other base numbers.
72
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
76
77         (1.2 / 1.5)^{-log2(duration ratio)}
78
79
80       */
81       Rational ratio = d / global_shortest_;
82
83       return ((k - 1) + double (ratio)) * increment_;
84     }
85   else
86     {
87       /*
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.
91       */
92       Real log = log_2 (global_shortest_);
93       k -= log;
94
95       return (log_2 (d) + k) * increment_;
96     }
97 }
98