-Real
-Spacing_spanner::get_duration_space (Grob*me, Moment d, Rational shortest, bool * expand_only)
-{
- Real k = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
- Real incr = robust_scm2double (me->get_property ("spacing-increment"), 1);
-
- if (d < shortest)
- {
- /*
- We don't space really short notes using the log of the
- duration, since it would disproportionally stretches the long
- notes in a piece. In stead, we use geometric spacing with constant 0.5
- (i.e. linear.)
-
- This should probably be tunable, to use other base numbers.
-
- In Mozart hrn3 by EB., we have 8th note = 3.9 mm (total), 16th note =
- 3.6 mm (total). head-width = 2.4, so we 1.2mm for 16th, 1.5
- mm for 8th. (white space), suggesting that we use
-
- (1.2 / 1.5)^{-log2(duration ratio)}
-
-
- */
- Rational ratio = d.main_part_ / shortest;
-
- return ((k-1) + double (ratio)) * incr;
- }
- else
- {
- /*
- John S. Gourlay. ``Spacing a Line of Music, '' Technical
- Report OSU-CISRC-10/87-TR35, Department of Computer and
- Information Science, The Ohio State University, 1987.
- */
- Real log = log_2 (shortest);
- k -= log;
- Rational compdur = d.main_part_ + d.grace_part_ /Rational (3);
- *expand_only = false;
-
- return (log_2 (compdur) + k) * incr;
- }
-}
-
-Real
-Spacing_spanner::note_spacing (Grob*me, Grob *lc, Grob *rc,
- Moment shortest, bool * expand_only)
-{
- Moment shortest_playing_len = 0;
- SCM s = lc->get_property ("shortest-playing-duration");
-
- if (unsmob_moment (s))
- shortest_playing_len = *unsmob_moment (s);
-
- if (! shortest_playing_len.to_bool ())
- {
- programming_error ("can't find a ruling note at " + Paper_column::when_mom (lc).to_string ());
- shortest_playing_len = 1;
- }
-
- Moment lwhen = Paper_column::when_mom (lc);
- Moment rwhen = Paper_column::when_mom (rc);
-
- Moment delta_t = rwhen - lwhen;
- if (!Paper_column::is_musical (rc))
- {
- /*
- when toying with mmrests, it is possible to have musical
- column on the left and non-musical on the right, spanning
- several measures.
- */
-
- Moment *dt = unsmob_moment (rc->get_property ("measure-length"));
- if (dt)
- {
- delta_t = delta_t <? *dt;
-
- /*
- The following is an extra safety measure, such that
- the length of a mmrest event doesn't cause havoc.
- */
- shortest_playing_len = shortest_playing_len <? *dt;
- }
- }
- Real dist = 0.0;
-
- /*
- In normal situations, the next column is at most
- SHORTEST_PLAYING_LEN away. However chord-tremolos do funky faking stuff
- with durations, invalidating this assumption. Here we kludge
- around to get chord tremolos to behave properly.
-
- */
- shortest_playing_len = shortest_playing_len >? delta_t;
- if (delta_t.main_part_ && !lwhen.grace_part_)
- {
- dist = get_duration_space (me, shortest_playing_len, shortest.main_part_, expand_only);
- dist *= (double) (delta_t.main_part_ / shortest_playing_len.main_part_);
- }
- else if (delta_t.grace_part_)
- {
- /*
- TODO: figure out how to space grace notes.
- */
- dist = get_duration_space (me, shortest, shortest.main_part_, expand_only);
-
- Real grace_fact
- = robust_scm2double (me->get_property ("grace-space-factor"), 1);
-
- dist *= grace_fact;
- }
-
-
- return dist;