From 43516525d4320a6d1af0c659c8e9036f6283faf7 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Wed, 14 Jul 2010 16:38:56 -0700 Subject: [PATCH] Fix a cyclic dependency. Prevent Rest_collision::calc_positioning_done from querying the extent of the Note_columns it is trying to position. --- lily/include/note-column.hh | 1 - lily/include/rest.hh | 1 + lily/note-column.cc | 16 ---------------- lily/rest-collision.cc | 26 +++++++++++++++++--------- lily/rest.cc | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lily/include/note-column.hh b/lily/include/note-column.hh index 4069c4046b..be673ec611 100644 --- a/lily/include/note-column.hh +++ b/lily/include/note-column.hh @@ -37,7 +37,6 @@ public: static Grob *accidentals (Grob *me); static Grob *arpeggio (Grob *me); static Slice head_positions_interval (Grob *me); - static void translate_rests (Grob *me, int dy); static Grob *first_head (Grob *me); static Grob *get_rest (Grob *me); static void set_stem (Grob *me, Grob *); diff --git a/lily/include/rest.hh b/lily/include/rest.hh index e7a78597e9..1d2c8f9aae 100644 --- a/lily/include/rest.hh +++ b/lily/include/rest.hh @@ -33,6 +33,7 @@ public: static string glyph_name (Grob *, int, string, bool); static SCM brew_internal_stencil (Grob*, bool); static SCM generic_extent_callback (Grob*, Axis); + static void translate (Grob *me, int dy); DECLARE_SCHEME_CALLBACK (polyphonic_offset_callback, (SCM)); DECLARE_SCHEME_CALLBACK (print, (SCM)); DECLARE_SCHEME_CALLBACK (width, (SCM)); diff --git a/lily/note-column.cc b/lily/note-column.cc index 843f19158a..d756a9121b 100644 --- a/lily/note-column.cc +++ b/lily/note-column.cc @@ -137,22 +137,6 @@ Note_column::add_head (Grob *me, Grob *h) Axis_group_interface::add_element (me, h); } -/** - translate the rest symbols vertically by amount DY, but only if - they have no staff-position set. -*/ -void -Note_column::translate_rests (Grob *me, int dy) -{ - Grob *r = unsmob_grob (me->get_object ("rest")); - if (r && !scm_is_number (r->get_property ("staff-position"))) - { - r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS); - Grob *p = r->get_parent (Y_AXIS); - p->flush_extent_cache (Y_AXIS); - } -} - Grob * Note_column::first_head (Grob *me) { diff --git a/lily/rest-collision.cc b/lily/rest-collision.cc index ee6935c7d8..a7f053b140 100644 --- a/lily/rest-collision.cc +++ b/lily/rest-collision.cc @@ -76,6 +76,14 @@ Rest_collision::add_column (Grob *me, Grob *p) } } +static bool +rest_shift_less (Grob *const &r1, Grob *const &r2) +{ + Grob *col1 = r1->get_parent (X_AXIS); + Grob *col2 = r2->get_parent (X_AXIS); + return Note_column::shift_less (col1, col2); +} + /* TODO: look at horizontal-shift to determine ordering between rests for more than two voices. @@ -133,14 +141,14 @@ Rest_collision::calc_positioning_done (SCM smob) Direction d = get_grob_direction (r); if (d) - ordered_rests[d].push_back (rests[i]); + ordered_rests[d].push_back (r); else rests[d]->warning (_ ("cannot resolve rest collision: rest direction not set")); } Direction d = LEFT; do - vector_sort (ordered_rests[d], Note_column::shift_less); + vector_sort (ordered_rests[d], rest_shift_less); while (flip (&d) != LEFT) ; @@ -167,23 +175,23 @@ Rest_collision::calc_positioning_done (SCM smob) { int amount_down = (int) ceil (diff / 2); diff -= amount_down; - Note_column::translate_rests (ordered_rests[DOWN].back (), - -2 * amount_down); + Rest::translate (ordered_rests[DOWN].back (), + -2 * amount_down); if (diff > 0) - Note_column::translate_rests (ordered_rests[UP].back (), - 2 * int (ceil (diff))); + Rest::translate (ordered_rests[UP].back (), + 2 * int (ceil (diff))); } do { - for (vsize i = ordered_rests[d].size () -1; i-- > 0;) + for (vsize i = ordered_rests[d].size () - 1; i-- > 0;) { Real last_y = ordered_rests[d][i + 1]->extent (common, Y_AXIS)[d]; Real y = ordered_rests[d][i]->extent (common, Y_AXIS)[-d]; Real diff = d * ((last_y - y) / staff_space); if (diff > 0) - Note_column::translate_rests (ordered_rests[d][i], d * (int) ceil (diff) * 2); + Rest::translate (ordered_rests[d][i], d * (int) ceil (diff) * 2); } } while (flip (&d) != LEFT); @@ -262,7 +270,7 @@ Rest_collision::calc_positioning_done (SCM smob) discrete_y = dir * int (ceil (dir * discrete_y / 2.0) * 2.0); } - Note_column::translate_rests (rcol, discrete_y); + Rest::translate (rest, discrete_y); } return SCM_BOOL_T; } diff --git a/lily/rest.cc b/lily/rest.cc index afa966993d..53387664b5 100644 --- a/lily/rest.cc +++ b/lily/rest.cc @@ -161,6 +161,21 @@ Rest::brew_internal_stencil (Grob *me, bool ledgered) return out.smobbed_copy (); } +/** + translate the rest vertically by amount DY, but only if + it doesn't have staff-position set. +*/ +void +Rest::translate (Grob *me, int dy) +{ + if (!scm_is_number (me->get_property ("staff-position"))) + { + me->translate_axis (dy * Staff_symbol_referencer::staff_space (me) / 2.0, Y_AXIS); + Grob *p = me->get_parent (Y_AXIS); + p->flush_extent_cache (Y_AXIS); + } +} + SCM Rest::print (SCM smob) { -- 2.39.2