From 3846cd517023c7e63379eefb8dde3a8de3b8fbe4 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 30 Apr 2007 21:51:16 +1000 Subject: [PATCH] Finish fixing 97. Give barlines and rehearsal marks a priority list for break-align instead of a single symbol. --- .../break-alignment-anchor-alignment.ly | 4 +- input/regression/break-alignment-anchors.ly | 4 +- input/regression/rehearsal-mark-align.ly | 6 +- lily/break-alignment-interface.cc | 58 ++++++++++++++----- lily/include/break-align-interface.hh | 1 + lily/include/item.hh | 1 + lily/item.cc | 18 +++--- python/convertrules.py | 8 +++ scm/define-grob-properties.scm | 4 ++ scm/define-grobs.scm | 5 +- 10 files changed, 78 insertions(+), 31 deletions(-) diff --git a/input/regression/break-alignment-anchor-alignment.ly b/input/regression/break-alignment-anchor-alignment.ly index b0925541c7..56d3f387b4 100644 --- a/input/regression/break-alignment-anchor-alignment.ly +++ b/input/regression/break-alignment-anchor-alignment.ly @@ -1,4 +1,4 @@ -\version "2.11.22" +\version "2.11.23" \header { texidoc = "The default callback for break-align-anchor in clefs and time/key @@ -7,7 +7,7 @@ the anchor to the extent of the break-aligned grob." } { - \override Score.RehearsalMark #'break-align-symbol = #'key-signature + \override Score.RehearsalMark #'break-align-symbols = #'(key-signature) c1 \key cis \major \once \override Staff.KeySignature #'break-align-anchor-alignment = #LEFT diff --git a/input/regression/break-alignment-anchors.ly b/input/regression/break-alignment-anchors.ly index ced785dc15..4b32619e97 100644 --- a/input/regression/break-alignment-anchors.ly +++ b/input/regression/break-alignment-anchors.ly @@ -1,4 +1,4 @@ -\version "2.11.22" +\version "2.11.23" \header { texidoc = "The break-align-anchor property of a break-aligned grob gives @@ -6,7 +6,7 @@ the horizontal offset at which other grobs should attach." } { - \override Score.RehearsalMark #'break-align-symbol = #'staff-bar + \override Score.RehearsalMark #'break-align-symbols = #'(staff-bar) c'1 \once \override Staff.BarLine #'break-align-anchor = #-5 \mark \default diff --git a/input/regression/rehearsal-mark-align.ly b/input/regression/rehearsal-mark-align.ly index 5238a3889e..d69e8385ec 100644 --- a/input/regression/rehearsal-mark-align.ly +++ b/input/regression/rehearsal-mark-align.ly @@ -2,7 +2,7 @@ \header { texidoc = "The rehearsal mark is put on top a breakable symbol, - according to the value of @code{break-align-symbol} value of the + according to the value of @code{break-align-symbols} value of the @code{RehearsalMark}. The same holds for @code{BarNumber} grobs." } @@ -14,11 +14,11 @@ c1 \key cis \major \clef alto - \override Score.RehearsalMark #'break-align-symbol = #'key-signature + \override Score.RehearsalMark #'break-align-symbols = #'(key-signature) \mark "on-key" cis \key ces \major - \override Score.RehearsalMark #'break-align-symbol = #'clef + \override Score.RehearsalMark #'break-align-symbols = #'(clef) \clef treble \mark "on clef" ces diff --git a/lily/break-alignment-interface.cc b/lily/break-alignment-interface.cc index 1487252716..c40219b8d2 100644 --- a/lily/break-alignment-interface.cc +++ b/lily/break-alignment-interface.cc @@ -268,29 +268,35 @@ Break_alignable_interface::self_align_callback (SCM grob) if (!Break_alignment_interface::has_interface (alignment)) return scm_from_int (0); - SCM my_align = me->get_property ("break-align-symbol"); - SCM order = Break_alignment_interface::break_align_order (alignment); - + SCM symbol_list = me->get_property ("break-align-symbols"); vector elements = Break_alignment_interface::ordered_elements (alignment); if (elements.size () == 0) return scm_from_int (0); - int last_idx_found = -1; - vsize i = 0; - for (SCM s = order; scm_is_pair (s); s = scm_cdr (s)) + int break_aligned_grob = -1; + for (; scm_is_pair (symbol_list); symbol_list = scm_cdr (symbol_list)) { - if (i < elements.size () - && elements[i]->get_property ("break-align-symbol") == scm_car (s)) + SCM sym = scm_car (symbol_list); + for (vsize i = 0; i < elements.size (); i++) { - last_idx_found = i; - i ++; + if (elements[i]->get_property ("break-align-symbol") == sym) + { + if (Item::break_visible (elements[i])) + { + break_aligned_grob = i; + goto found_break_aligned_grob; /* ugh. need to break out of 2 loops */ + } + else if (break_aligned_grob == -1) + break_aligned_grob = i; + } } + } - if (scm_car (s) == my_align) - break ; - } +found_break_aligned_grob: + if (break_aligned_grob == -1) + return scm_from_int (0); - Grob *alignment_parent = elements[last_idx_found]; + Grob *alignment_parent = elements[break_aligned_grob]; Grob *common = me->common_refpoint (alignment_parent, X_AXIS); Real anchor = robust_scm2double (alignment_parent->get_property ("break-align-anchor"), 0); @@ -332,11 +338,33 @@ Break_aligned_interface::calc_extent_aligned_anchor (SCM smob) return scm_from_double (me->extent (me, X_AXIS).linear_combination (alignment)); } +MAKE_SCHEME_CALLBACK (Break_aligned_interface, calc_break_visibility, 1) +SCM +Break_aligned_interface::calc_break_visibility (SCM smob) +{ + /* a BreakAlignGroup is break-visible iff it has one element that is break-visible */ + Grob *me = unsmob_grob (smob); + SCM ret = scm_c_make_vector (3, SCM_EOL); + extract_grob_set (me, "elements", elts); + for (int dir = 0; dir <= 2; dir++) + { + bool visible = false; + for (vsize i = 0; i < elts.size (); i++) + { + SCM vis = elts[i]->get_property ("break-visibility"); + if (scm_is_vector (vis) && to_boolean (scm_c_vector_ref (vis, dir))) + visible = true; + } + scm_c_vector_set_x (ret, dir, scm_from_bool (visible)); + } + return ret; +} + ADD_INTERFACE (Break_alignable_interface, "Object that is aligned on a break aligment. ", /* properties */ - "break-align-symbol " + "break-align-symbols " ) diff --git a/lily/include/break-align-interface.hh b/lily/include/break-align-interface.hh index f3633c2bad..9ac29c7ae0 100644 --- a/lily/include/break-align-interface.hh +++ b/lily/include/break-align-interface.hh @@ -27,6 +27,7 @@ struct Break_aligned_interface { DECLARE_SCHEME_CALLBACK (calc_average_anchor, (SCM)); DECLARE_SCHEME_CALLBACK (calc_extent_aligned_anchor, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_break_visibility, (SCM)); DECLARE_GROB_INTERFACE(); }; diff --git a/lily/include/item.hh b/lily/include/item.hh index f1f094a7b4..0838c00a49 100644 --- a/lily/include/item.hh +++ b/lily/include/item.hh @@ -28,6 +28,7 @@ public: virtual Grob *clone () const; static bool is_non_musical (Grob *); + static bool break_visible(Grob *); bool is_broken () const; bool pure_is_visible (int start, int end) const; diff --git a/lily/item.cc b/lily/item.cc index f7e832b30b..33e5e2027e 100644 --- a/lily/item.cc +++ b/lily/item.cc @@ -149,14 +149,18 @@ Item::handle_prebroken_dependencies () Can't do this earlier, because try_visibility_lambda () might set the elt property transparent, which would then be copied. */ - SCM vis = get_property ("break-visibility"); - if (scm_is_vector (vis)) - { - bool visible = to_boolean (scm_c_vector_ref (vis, break_status_dir () + 1)); + if (!Item::break_visible (this)) + suicide (); +} - if (!visible) - suicide (); - } +bool +Item::break_visible (Grob *g) +{ + Item *it = dynamic_cast (g); + SCM vis = g->get_property ("break-visibility"); + if (scm_is_vector (vis)) + return to_boolean (scm_c_vector_ref (vis, it->break_status_dir () + 1)); + return true; } bool diff --git a/python/convertrules.py b/python/convertrules.py index 1cd2d4e766..f2d9dbd9ca 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -2999,3 +2999,11 @@ def conv (str): return str conversions.append (((2, 11, 15), conv, """#'edge-height -> #'bound-details #'right/left #'text = ...""")) + +def conv (str): + str = re.sub (r"\\override\s*([a-zA-Z.]+)\s*#'break-align-symbol\s*=\s*#'([a-z-]+)", + r"\\override \1 #'break-align-symbols = #'(\2)", str) + return str + +conversions.append (((2, 11, 23), conv, """#'break-align-symbol -> #'break-align-symbols""")) + diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 3bf185ac42..34a87a20cf 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -102,6 +102,10 @@ ly:break-aligned-interface::calc-extent-aligned-anchor for aligning an anchor to a grobs extent") (break-align-symbol ,symbol? "This key is used for aligning and spacing breakable items.") + (break-align-symbols ,list? "A list of symbols that determine +which break-aligned grobs to align this to. If the grob selected by +the first symbol in the list is invisible due to break-visibility, +we will align to the next grob (and so on).") (break-align-orders ,vector? "Defines the order in which prefatory matter (clefs, key signatures) appears. The format is a vector of length@tie{}3, where each element is one order for diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 3ab5b2c677..15d59483a8 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -226,7 +226,7 @@ (self-alignment-X . 1) ;; want the bar number before the clef at line start. - (break-align-symbol . left-edge) + (break-align-symbols . (left-edge staff-bar)) (meta . ((class . Item) (interfaces . (side-position-interface @@ -412,6 +412,7 @@ (axes . (0)) (X-extent . ,ly:axis-group-interface::width) (break-align-anchor . ,ly:break-aligned-interface::calc-average-anchor) + (break-visibility . ,ly:break-aligned-interface::calc-break-visibility) (meta . ((class . Item) (interfaces . (break-aligned-interface axis-group-interface)))))) @@ -1333,7 +1334,7 @@ (font-size . 2) (baseline-skip . 2) (break-visibility . ,end-of-line-invisible) - (break-align-symbol . clef) + (break-align-symbols . (staff-bar clef)) (padding . 0.8) (outside-staff-priority . 1500) (meta . ((class . Item) -- 2.39.5