From 4cabd2305eda952e2d29e4a04e75e1cfb499257a Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 10 Aug 2009 10:21:42 +1000 Subject: [PATCH] Move rehearsal marks, etc. to the top staff. --- .../regression/page-spacing-rehearsal-mark.ly | 22 +++++++ lily/grob.cc | 2 + lily/include/grob.hh | 4 +- lily/include/page-layout-problem.hh | 1 - lily/include/side-position-interface.hh | 1 + lily/include/system.hh | 2 + lily/page-layout-problem.cc | 18 +----- lily/side-position-interface.cc | 31 ++++++++++ lily/system.cc | 58 ++++++++++++++++--- lily/vertically-spaced-context-engraver.cc | 1 + scm/define-grobs.scm | 4 ++ 11 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 input/regression/page-spacing-rehearsal-mark.ly diff --git a/input/regression/page-spacing-rehearsal-mark.ly b/input/regression/page-spacing-rehearsal-mark.ly new file mode 100644 index 0000000000..7603d933df --- /dev/null +++ b/input/regression/page-spacing-rehearsal-mark.ly @@ -0,0 +1,22 @@ +\version "2.13.4" + +\header { + texidoc = "The space taken up by rehearsal marks is correctly +accounted for, even though they live in the Score context." +} + +#(set-default-paper-size "a6") + +\book { + \paper { + oddHeaderMarkup = "header" + ragged-last-bottom = ##f + } + \score { + << + \new Staff { \mark \markup \column { T A L L M A R K } c'1 \break + \mark \markup \column { T A L L M A R K } c'1 } + \new Staff { c'1 \break c'1 } + >> + } +} diff --git a/lily/grob.cc b/lily/grob.cc index ce3e41c76d..540f279b44 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -11,6 +11,7 @@ #include #include "align-interface.hh" +#include "axis-group-interface.hh" #include "input.hh" #include "international.hh" #include "item.hh" @@ -761,3 +762,4 @@ Grob::check_cross_staff (Grob *commony) return false; } + diff --git a/lily/include/grob.hh b/lily/include/grob.hh index 3a724c8d95..9ff7613561 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -54,8 +54,8 @@ public: friend SCM ly_grob_basic_properties (SCM); /* standard callbacks */ - DECLARE_SCHEME_CALLBACK(x_parent_positioning, (SCM)); - DECLARE_SCHEME_CALLBACK(y_parent_positioning, (SCM)); + DECLARE_SCHEME_CALLBACK (x_parent_positioning, (SCM)); + DECLARE_SCHEME_CALLBACK (y_parent_positioning, (SCM)); DECLARE_SCHEME_CALLBACK (stencil_height, (SCM smob)); DECLARE_SCHEME_CALLBACK (stencil_width, (SCM smob)); diff --git a/lily/include/page-layout-problem.hh b/lily/include/page-layout-problem.hh index f5039821f7..74c6ca440f 100644 --- a/lily/include/page-layout-problem.hh +++ b/lily/include/page-layout-problem.hh @@ -34,7 +34,6 @@ protected: SCM find_system_offsets (); void distribute_loose_lines (vector const&, vector const&, Real, Real); - static Grob* find_vertical_alignment (System*); static void build_system_skyline (vector const&, vector const&, Skyline* up, Skyline* down); static vector filter_dead_elements (vector const&); diff --git a/lily/include/side-position-interface.hh b/lily/include/side-position-interface.hh index 0febd15be3..0304035720 100644 --- a/lily/include/side-position-interface.hh +++ b/lily/include/side-position-interface.hh @@ -27,6 +27,7 @@ public: DECLARE_SCHEME_CALLBACK (y_aligned_side, (SCM element, SCM current)); DECLARE_SCHEME_CALLBACK (pure_y_aligned_side, (SCM element, SCM start, SCM end, SCM current)); DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM element)); + DECLARE_SCHEME_CALLBACK (move_to_extremal_staff, (SCM)); static SCM aligned_side (Grob*me, Axis a, bool pure, int start, int end, Real *current_off_ptr); diff --git a/lily/include/system.hh b/lily/include/system.hh index 3fc805a959..f69a3cee67 100644 --- a/lily/include/system.hh +++ b/lily/include/system.hh @@ -26,6 +26,8 @@ class System : public Spanner public: Paper_score *paper_score () const; + Grob *get_vertical_alignment (); + Grob *get_extremal_staff (Direction dir, Interval const&); int get_rank () const; void do_break_substitution_and_fixup_refpoints (); void post_processing (); diff --git a/lily/page-layout-problem.cc b/lily/page-layout-problem.cc index 07013aa2b7..fb9e27d12b 100644 --- a/lily/page-layout-problem.cc +++ b/lily/page-layout-problem.cc @@ -160,26 +160,12 @@ Page_layout_problem::set_footer_height (Real height) footer_height_ = height; } -Grob* -Page_layout_problem::find_vertical_alignment (System *sys) -{ - extract_grob_set (sys, "elements", elts); - for (vsize i = 0; i < elts.size (); ++i) - if (Align_interface::has_interface (elts[i])) - return elts[i]; - - return 0; -} - void Page_layout_problem::append_system (System *sys, Spring const& spring, Real padding) { - Grob *align = find_vertical_alignment (sys); + Grob *align = sys->get_vertical_alignment (); if (!align) - { - sys->programming_error ("no VerticalAlignment in system: can't do vertical spacing"); - return; - } + return; align->set_property ("positioning-done", SCM_BOOL_T); diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index ed3af0577a..61ab61f5d4 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -13,6 +13,7 @@ using namespace std; +#include "axis-group-interface.hh" #include "directional-element-interface.hh" #include "grob.hh" #include "main.hh" @@ -23,6 +24,7 @@ using namespace std; #include "staff-symbol.hh" #include "stem.hh" #include "string-convert.hh" +#include "system.hh" #include "warn.hh" void @@ -309,6 +311,35 @@ Side_position_interface::get_axis (Grob *me) return NO_AXES; } +MAKE_SCHEME_CALLBACK (Side_position_interface, move_to_extremal_staff, 1); +SCM +Side_position_interface::move_to_extremal_staff (SCM smob) +{ + Grob *me = unsmob_grob (smob); + System *sys = dynamic_cast (me->get_system ()); + Direction dir = Side_position_interface::get_direction (me); + if (dir != DOWN) + dir = UP; + + Grob *top_staff = sys->get_extremal_staff (dir, me->extent (sys, X_AXIS)); + + if (!top_staff) + return SCM_BOOL_F; + + // Only move this grob if it is a direct child of the system. We + // are not interested in moving marks from other staves to the top + // staff; we only want to move marks from the system to the top + // staff. + if (sys != me->get_parent (Y_AXIS)) + return SCM_BOOL_F; + + me->set_parent (top_staff, Y_AXIS); + me->flush_extent_cache (Y_AXIS); + Axis_group_interface::add_element (top_staff, me); + return SCM_BOOL_T; +} + + ADD_INTERFACE (Side_position_interface, "Position a victim object (this one) next to other objects" " (the support). The property @code{direction} signifies where" diff --git a/lily/system.cc b/lily/system.cc index e0964482fc..a43c1b4aac 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -12,10 +12,12 @@ #include "all-font-metrics.hh" #include "axis-group-interface.hh" #include "grob-array.hh" +#include "hara-kiri-group-spanner.hh" #include "international.hh" #include "lookup.hh" #include "main.hh" #include "output-def.hh" +#include "page-layout-problem.hh" #include "paper-column.hh" #include "paper-score.hh" #include "paper-system.hh" @@ -172,6 +174,12 @@ System::do_break_substitution_and_fixup_refpoints () { System *child = dynamic_cast (broken_intos_[i]); child->all_elements_->remove_duplicates (); + for (vsize j = 0; j < child->all_elements_->size (); j++) + { + Grob *g = child->all_elements_->grob (j); + + (void) g->get_property ("after-line-breaking"); + } } if (be_verbose_global) @@ -295,13 +303,6 @@ System::pre_processing () void System::post_processing () { - for (vsize i = 0; i < all_elements_->size (); i++) - { - Grob *g = all_elements_->grob (i); - - (void) g->get_property ("after-line-breaking"); - } - Interval iv (extent (this, Y_AXIS)); if (iv.is_empty ()) programming_error ("system with empty extent"); @@ -515,6 +516,49 @@ get_root_system (Grob *me) return dynamic_cast (system_grob); } +Grob * +System::get_vertical_alignment () +{ + extract_grob_set (this, "elements", elts); + Grob *ret = 0; + for (vsize i = 0; i < elts.size (); i++) + if (Align_interface::has_interface (elts[i])) + { + if (ret) + programming_error ("found multiple vertical alignments in this system"); + ret = elts[i]; + } + + if (!ret) + programming_error ("didn't find a vertical alignment in this system"); + return ret; +} + +// Finds the furthest staff in the given direction whose x-extent +// overlaps with the given interval. +Grob * +System::get_extremal_staff (Direction dir, Interval const &iv) +{ + Grob *align = get_vertical_alignment (); + if (!align) + return 0; + + extract_grob_set (align, "elements", elts); + vsize start = (dir == UP) ? 0 : elts.size () - 1; + vsize end = (dir == UP) ? elts.size () : VPOS; + for (vsize i = start; i != end; i += dir) + { + if (Hara_kiri_group_spanner::has_interface (elts[i])) + Hara_kiri_group_spanner::consider_suicide (elts[i]); + + Interval intersection = elts[i]->extent (this, X_AXIS); + intersection.intersect (iv); + if (elts[i]->is_live () && !intersection.is_empty ()) + return elts[i]; + } + return 0; +} + ADD_INTERFACE (System, "This is the top-level object: Each object in a score" " ultimately has a @code{System} object as its X and" diff --git a/lily/vertically-spaced-context-engraver.cc b/lily/vertically-spaced-context-engraver.cc index 750f2e3721..bc64f1bc5c 100644 --- a/lily/vertically-spaced-context-engraver.cc +++ b/lily/vertically-spaced-context-engraver.cc @@ -1,5 +1,6 @@ /* vertically-spaced-contexts-engraver.cc -- implement Vertically_spaced_contexts_engraver + TODO: junk this, since we now determine spaceability using Page_layout_problem::is_spaceable. source file of the GNU LilyPond music typesetter diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 9a43c08933..4e15a0576d 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -216,6 +216,7 @@ (BarNumber . ( + (after-line-breaking . ,ly:side-position-interface::move-to-extremal-staff) ;; want the bar number before the clef at line start. (break-align-symbols . (left-edge staff-bar)) @@ -1097,6 +1098,7 @@ (MetronomeMark . ( + (after-line-breaking . ,ly:side-position-interface::move-to-extremal-staff) (direction . ,UP) (extra-spacing-width . (+inf.0 . -inf.0)) (outside-staff-priority . 1000) @@ -1404,6 +1406,7 @@ (RehearsalMark . ( + (after-line-breaking . ,ly:side-position-interface::move-to-extremal-staff) (baseline-skip . 2) (break-align-symbols . (staff-bar clef)) (break-visibility . ,end-of-line-invisible) @@ -2217,6 +2220,7 @@ (VoltaBracket . ( + (after-line-breaking . ,ly:side-position-interface::move-to-extremal-staff) (direction . ,UP) (edge-height . (2.0 . 2.0)) ;; staff-space; (font-encoding . fetaNumber) -- 2.39.5