2 spacing-basic.cc -- implement Spacing_spanner, simplistic spacing routines
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "spacing-spanner.hh"
11 #include "spacing-options.hh"
13 #include "paper-column.hh"
15 #include "pointer-group-interface.hh"
17 #include "spacing-interface.hh"
21 LilyPond spaces by taking a simple-minded spacing algorithm, and
22 adding subtle adjustments to that. This file does the simple-minded
26 The one-size-fits all spacing. It doesn't take into account
27 different spacing wishes from one to the next column.
30 Spacing_spanner::standard_breakable_column_spacing (Grob
*me
, Item
*l
, Item
*r
, Spacing_options
const *options
)
32 Real min_dist
= max (0.0, Paper_column::minimum_distance (l
, r
));
35 if (Paper_column::is_breakable (l
) && Paper_column::is_breakable (r
))
37 Moment
*dt
= unsmob_moment (l
->get_property ("measure-length"));
42 Real incr
= robust_scm2double (me
->get_property ("spacing-increment"), 1);
44 ideal
= min_dist
+ incr
* double (mlen
.main_part_
/ options
->global_shortest_
) * 0.8;
48 Moment dt
= Paper_column::when_mom (r
) - Paper_column::when_mom (l
);
50 if (dt
== Moment (0, 0))
53 In this case, Staff_spacing should handle the job,
54 using dt when it is 0 is silly.
56 ideal
= min_dist
+ 0.5;
59 ideal
= min_dist
+ options
->get_duration_space (dt
.main_part_
);
61 return Spring (ideal
, min_dist
);
65 get_measure_length (Grob
*column
)
67 Grob
* sys
= column
->get_parent (X_AXIS
);
69 extract_grob_set (sys
, "columns", cols
);
71 vsize col_idx
= Paper_column::get_rank (column
);
75 if (Moment
*len
= unsmob_moment (cols
[col_idx
]->get_property ("measure-length")))
80 while (col_idx
-- != 0);
86 Spacing_spanner::note_spacing (Grob
* /* me */,
89 Spacing_options
const *options
)
91 Moment shortest_playing_len
= 0;
92 SCM s
= lc
->get_property ("shortest-playing-duration");
94 if (unsmob_moment (s
))
95 shortest_playing_len
= *unsmob_moment (s
);
97 if (! shortest_playing_len
.to_bool ())
99 programming_error ("cannot find a ruling note at: " + Paper_column::when_mom (lc
).to_string ());
100 shortest_playing_len
= 1;
103 Moment lwhen
= Paper_column::when_mom (lc
);
104 Moment rwhen
= Paper_column::when_mom (rc
);
106 Moment delta_t
= rwhen
- lwhen
;
109 when toying with mmrests, it is possible to have musical
110 column on the left and non-musical on the right, spanning
113 TODO: efficiency: measure length can be cached, or stored as
114 property in paper-column.
117 if (Moment
*measure_len
= get_measure_length (lc
))
119 delta_t
= min (delta_t
, *measure_len
);
122 The following is an extra safety measure, such that
123 the length of a mmrest event doesn't cause havoc.
125 shortest_playing_len
= min (shortest_playing_len
, *measure_len
);
129 if (delta_t
.main_part_
&& !lwhen
.grace_part_
)
131 dist
= options
->get_duration_space (shortest_playing_len
.main_part_
);
132 dist
*= double (delta_t
.main_part_
/ shortest_playing_len
.main_part_
);
134 else if (delta_t
.grace_part_
)
137 Crude hack for spacing graces: we take the shortest space
138 available (namely the space for the global shortest note), and
139 multiply that by grace-space-factor
141 dist
= options
->get_duration_space (options
->global_shortest_
) / 2.0;
142 Grob
*grace_spacing
= unsmob_grob (lc
->get_object ("grace-spacing"));
145 Spacing_options grace_opts
;
146 grace_opts
.init_from_grob (grace_spacing
);
147 dist
= grace_opts
.get_duration_space (delta_t
.grace_part_
);