]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-options.cc
(Two-pass vertical spacing): add documentation for two-pass spacing
[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 Han-Wen Nienhuys <hanwen@lilypond.org>
7
8 */
9
10 #include "spacing-spanner.hh"
11 #include "grob.hh"
12 #include "misc.hh"
13 #include "moment.hh"
14
15 void
16 Spacing_options::init_from_grob (Grob *me)
17 {
18   increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
19
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);
27
28
29   Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
30                                            Moment (Rational (1,8), Rational (1,16)));
31
32   if (shortest_dur.main_part_)
33     global_shortest_ = shortest_dur.main_part_;
34   else
35     global_shortest_ = shortest_dur.grace_part_;
36
37 }
38
39 Spacing_options::Spacing_options ()
40 {
41   packed_ = false;
42   stretch_uniformly_ = false;
43   float_nonmusical_columns_ = false;
44   float_grace_columns_ = false;
45
46   shortest_duration_space_ = 2.0;
47   increment_ = 1.2;
48
49   global_shortest_ = Rational (1, 8);
50 }
51
52
53
54 /*
55   Get the measure wide ant for arithmetic spacing.
56 */
57 Real
58 Spacing_options::get_duration_space (Rational d,
59                                      bool *expand_only) 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       *expand_only = false;
95
96       return (log_2 (d) + k) * increment_;
97     }
98 }
99