]> git.donarmstrong.com Git - lilypond.git/blob - lily/spacing-options.cc
Run grand-replace for 2010.
[lilypond.git] / lily / spacing-options.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2010 Han-Wen Nienhuys <hanwen@lilypond.org>
5
6
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.
11
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.
16
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/>.
19 */
20
21 #include "spacing-options.hh"
22 #include "spacing-spanner.hh"
23 #include "grob.hh"
24 #include "misc.hh"
25 #include "moment.hh"
26 #include "spanner.hh"
27
28 void
29 Spacing_options::init_from_grob (Grob *me)
30 {
31   increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
32
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"));
37   float_grace_columns_
38     = to_boolean (me->get_property ("strict-grace-spacing"));
39   shortest_duration_space_ = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
40
41
42   Moment shortest_dur = robust_scm2moment (me->get_property ("common-shortest-duration"),
43                                            Moment (Rational (1,8), Rational (1,16)));
44
45   if (shortest_dur.main_part_)
46     global_shortest_ = shortest_dur.main_part_;
47   else
48     global_shortest_ = shortest_dur.grace_part_;
49 }
50
51 Spacing_options::Spacing_options ()
52 {
53   packed_ = false;
54   stretch_uniformly_ = false;
55   float_nonmusical_columns_ = false;
56   float_grace_columns_ = false;
57
58   shortest_duration_space_ = 2.0;
59   increment_ = 1.2;
60
61   global_shortest_ = Rational (1, 8);
62 }
63
64
65
66 /*
67   Get the measure wide ant for arithmetic spacing.
68 */
69 Real
70 Spacing_options::get_duration_space (Rational d) const
71 {
72   Real k = shortest_duration_space_;
73
74   if (d < global_shortest_)
75     {
76       /*
77         We don't space really short notes using the log of the
78         duration, since it would disproportionally stretches the long
79         notes in a piece. In stead, we use geometric spacing with constant 0.5
80         (i.e. linear.)
81
82         This should probably be tunable, to use other base numbers.
83
84         In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
85         3.6 mm (total).  head-width = 2.4, so we 1.2mm for 16th, 1.5
86         mm for 8th. (white space), suggesting that we use
87
88         (1.2 / 1.5)^{-log2(duration ratio)}
89
90
91       */
92       Rational ratio = d / global_shortest_;
93
94       return ((k - 1) + double (ratio)) * increment_;
95     }
96   else
97     {
98       /*
99         John S. Gourlay. ``Spacing a Line of Music, '' Technical
100         Report OSU-CISRC-10/87-TR35, Department of Computer and
101         Information Science, The Ohio State University, 1987.
102       */
103       Real log = log_2 (global_shortest_);
104       k -= log;
105
106       return (log_2 (d) + k) * increment_;
107     }
108 }
109