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