static Real default_bar_spacing (Grob *, Grob *, Grob *, Moment);
static Real note_spacing (Grob *, Grob *, Grob *, Spacing_options const *, bool *);
static Real get_duration_space (Moment dur, Spacing_options const *, bool *);
- static Rational find_shortest (Grob *, vector<Grob*> const &);
static Rational effective_shortest_duration (Grob *me, vector<Grob*> const &all);
static void breakable_column_spacing (Grob *, Item *l, Item *r, Spacing_options const *);
static void prune_loose_columns (Grob *, vector<Grob*> *cols, Spacing_options const *);
static void set_implicit_neighbor_columns (vector<Grob*> const &cols);
static void generate_springs (Grob *me, vector<Grob*> const &cols, Spacing_options const *);
static void musical_column_spacing (Grob *, Item *, Item *, Spacing_options const *);
+ static vector<Grob*> get_columns (Spanner *me);
+
DECLARE_SCHEME_CALLBACK (set_springs, (SCM));
+ DECLARE_SCHEME_CALLBACK (calc_common_shortest_duration, (SCM));
static bool has_interface (Grob *);
};
--- /dev/null
+/*
+ spacing-options.cc -- implement Spacing_options
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
+
+*/
+
+#include "spacing-spanner.hh"
+#include "grob.hh"
+
+void
+Spacing_options::init_from_grob (Grob *me)
+{
+ increment_ = robust_scm2double (me->get_property ("spacing-increment"), 1);
+
+ packed_ = to_boolean (me->get_property ("packed-spacing"));
+ stretch_uniformly_ = to_boolean (me->get_property ("uniform-stretching"));
+ float_nonmusical_columns_
+ = to_boolean (me->get_property ("strict-note-spacing"));
+ float_grace_columns_
+ = to_boolean (me->get_property ("strict-grace-spacing"));
+ shortest_duration_space_ = robust_scm2double (me->get_property ("shortest-duration-space"), 1);
+}
+
+Spacing_options::Spacing_options ()
+{
+ increment_ = 1.2;
+ packed_ = false;
+ stretch_uniformly_ = false;
+ float_nonmusical_columns_ = false;
+ float_grace_columns_ = false;
+ shortest_duration_space_ = 2.0;
+
+ global_shortest_ = Rational (1, 8);
+}
#include "system.hh"
#include "warn.hh"
-
-/*
- TODO:
-
- use callback instead?
-
-*/
-Rational
-Spacing_spanner::effective_shortest_duration (Grob *me,
- vector<Grob*> const &all)
+vector<Grob*>
+Spacing_spanner::get_columns (Spanner *me)
{
- SCM preset_shortest = me->get_property ("common-shortest-duration");
- Rational global_shortest;
- if (unsmob_moment (preset_shortest))
- global_shortest = unsmob_moment (preset_shortest)->main_part_;
- else
- {
- global_shortest = Spacing_spanner::find_shortest (me, all);
- if (be_verbose_global)
- message (_f ("Global shortest duration is %s", global_shortest.to_string ()) + "\n");
- }
+ vector<Grob*> all (get_root_system (me)->columns ());
+ vsize start = binary_search (all, (Grob*)me->get_bound (LEFT),
+ &Paper_column::compare);
+ vsize end = binary_search (all, (Grob*) me->get_bound (RIGHT),
+ &Paper_column::compare);
- return global_shortest;
+ all = vector<Grob*>::vector<Grob*> (all.begin () + start,
+ all.begin () + end + 1);
+ return all;
}
-
MAKE_SCHEME_CALLBACK (Spacing_spanner, set_springs, 1);
SCM
Spacing_spanner::set_springs (SCM smob)
/*
can't use get_system() ? --hwn.
*/
- vector<Grob*> all (get_root_system (me)->columns ());
- vsize start = binary_search (all, (Grob*)me->get_bound (LEFT),
- &Paper_column::compare);
- vsize end = binary_search (all, (Grob*) me->get_bound (RIGHT),
- &Paper_column::compare);
-
- all = vector<Grob*>::vector<Grob*> (all.begin () + start,
- all.begin () + end + 1);
-
+ vector<Grob*> all (get_columns (me));
set_explicit_neighbor_columns (all);
Spacing_options options;
options.init_from_grob (me);
- options.global_shortest_ = effective_shortest_duration (me, all);
+ options.global_shortest_ = robust_scm2moment (me->get_property ("common-shortest-duration"),
+ Moment (1,8)).main_part_;
prune_loose_columns (me, &all, &options);
set_implicit_neighbor_columns (all);
note has a different duration, but hey, don't write that kind of
stuff, then.
*/
-Rational
-Spacing_spanner::find_shortest (Grob *me, vector<Grob*> const &cols)
+
+MAKE_SCHEME_CALLBACK (Spacing_spanner, calc_common_shortest_duration, 1);
+SCM
+Spacing_spanner::calc_common_shortest_duration (SCM grob)
{
+ Spanner *me = unsmob_spanner (grob);
+
+ vector<Grob*> cols (get_columns (me));
+
/*
ascending in duration
*/
if (max_idx >= 0)
d = min (d, durations[max_idx]);
- return d;
+ return Moment (d).smobbed_copy ();
}
void