]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-options.cc
Merge branch 'master' of ssh+git://git.sv.gnu.org/srv/git/lilypond
[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-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   columns_ = Spacing_spanner::get_columns (me); // ugh.
40 }
41
42 Spacing_options::Spacing_options ()
43 {
44   packed_ = false;
45   stretch_uniformly_ = false;
46   float_nonmusical_columns_ = false;
47   float_grace_columns_ = false;
48
49   shortest_duration_space_ = 2.0;
50   increment_ = 1.2;
51
52   global_shortest_ = Rational (1, 8);
53 }
54
55
56
57 /*
58   Get the measure wide ant for arithmetic spacing.
59 */
60 Real
61 Spacing_options::get_duration_space (Rational d,
62                                      bool *expand_only) const
63 {
64   Real k = shortest_duration_space_;
65
66   if (d < global_shortest_)
67     {
68       /*
69         We don't space really short notes using the log of the
70         duration, since it would disproportionally stretches the long
71         notes in a piece. In stead, we use geometric spacing with constant 0.5
72         (i.e. linear.)
73
74         This should probably be tunable, to use other base numbers.
75
76         In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
77         3.6 mm (total).  head-width = 2.4, so we 1.2mm for 16th, 1.5
78         mm for 8th. (white space), suggesting that we use
79
80         (1.2 / 1.5)^{-log2(duration ratio)}
81
82
83       */
84       Rational ratio = d / global_shortest_;
85
86       return ((k - 1) + double (ratio)) * increment_;
87     }
88   else
89     {
90       /*
91         John S. Gourlay. ``Spacing a Line of Music, '' Technical
92         Report OSU-CISRC-10/87-TR35, Department of Computer and
93         Information Science, The Ohio State University, 1987.
94       */
95       Real log = log_2 (global_shortest_);
96       k -= log;
97       *expand_only = false;
98
99       return (log_2 (d) + k) * increment_;
100     }
101 }
102