Once again further to this thread (see below) I've attempted a patch
(attached) to the Keep_alive_together_engraver which makes this work, at
least for my use case. There might well be a better approach, feedback
would be appreciated.

Possibly the keep-alive-with-id property should be a string (or list)
instead of an integer.

I don't have an account on the issue tracker and so haven't used the
git-cl script.

Regards, Mark

At 11:43 on 26 Jul 2016, Mark Knoop wrote:
>Further to this thread from 2013
>(https://lists.gnu.org/archive/html/lilypond-user/2013-09/msg00857.html)
>I've still not come up with a satisfactory method of duplicating a
>dedicated BarNumber/RehearsalMark context at two or more vertical
>positions in a frenched score. The context should only stay alive only
>while one or more Staff contexts are alive within the same StaffGroup.
>
>I was hoping to solve this by using the newer property
>VerticalAxisGroup.remove-layer introduced by David Kastrup in 2014 as a
>solution for issue 3518. However I can only get this to solve one
>problem - that of making the instrument staves invisible to the
>Keep_alive_together_engraver.
>
>Is there any way that the VerticalAxisGroup.keep-alive-with array can
>be set directly in scheme?
>
>%%%%%%%%%%%%%
>\version "2.19.45"
>bars = \repeat unfold 12 { \mark \default R1*2 }
>winds = \repeat unfold 96 { c''4 }
>brass = \repeat unfold 24 { R1 }
>brasstwo = { \repeat unfold 12 c'1 \repeat unfold 12 { R1 } }
>strings = \repeat unfold 192 { c''8 }
>#(set-global-staff-size 16)
>
>\layout {
>  \context {
>    \Dynamics
>    \consists Mark_engraver
>    \consists Bar_number_engraver
>  }
>  \context {
>    \Staff
>    \RemoveEmptyStaves
>  }
>  \context {
>    \Score
>    \remove Mark_engraver
>    \remove Bar_number_engraver
>  }
>}
>
>\markup "remove-layer unset for all => bars context behaves correctly,
>but b1 staff still alive in 2nd system when we want it dead"
>\score {
>  <<
>    \new Dynamics { \bars }
>    \new Staff = "winds" { \winds }
>    \new StaffGroup \with {
>      \consists Keep_alive_together_engraver
>    } <<
>      \new Dynamics \with {
>        keepAliveInterfaces = #'()
>        \override VerticalAxisGroup.remove-empty = ##t
>        \override RehearsalMark.color = #red
>      } { \bars }
>      \new Staff = "brass" \with {
>        shortInstrumentName = "b1"
>      } { \brass }
>      \new Staff = "brasstwo" \with {
>        shortInstrumentName = "b2"
>      } { \brasstwo }
>    >>  
>    \new Dynamics { \bars }
>    \new Staff = "strings" { \strings }
>  >>  
>}
>
>\markup "remove-layer bars=unset or '() or 1 or #f, b1=#f, b2=#f => b1
>and b2 staves behave correctly, but bars context dies in 2nd system"
>\score {
>  <<
>    \new Dynamics { \bars }
>    \new Staff = "winds" { \winds }
>    \new StaffGroup \with {
>      \consists Keep_alive_together_engraver
>    } <<
>      \new Dynamics \with {
>        keepAliveInterfaces = #'()
>        \override VerticalAxisGroup.remove-empty = ##t
>        \override RehearsalMark.color = #red
>        %\override VerticalAxisGroup.remove-layer = 1
>        %\override VerticalAxisGroup.remove-layer = #'()
>        %\override VerticalAxisGroup.remove-layer = ##f
>      } { \bars }
>      \new Staff = "brass" \with {
>        \override VerticalAxisGroup.remove-layer = ##f
>      } { \brass }
>      \new Staff = "brasstwo" \with {
>        \override VerticalAxisGroup.remove-layer = ##f
>      } { \brasstwo }
>    >>  
>    \new Dynamics { \bars }
>    \new Staff = "strings" { \strings }
>  >>  
>}
>
>--
>Mark Knoop
>From 25c247794ae655557de8b476e6f51951fac4e45a Mon Sep 17 00:00:00 2001
From: Mark Knoop <m...@markknoop.com>
Date: Wed, 27 Jul 2016 17:16:29 +0100
Subject: [PATCH] Keep a staff alive if a staff with the same id is alive

This adds a `VerticalAxisGroup.keep-alive-with-id' property of type integer
which allows to keep a staff or other horizontal context alive if any other
staff with matching id is alive.  In this way, any one of a set of staves can
keep another alive. Other staves in the set will still be removed if
`VerticalAxisGroup.remove-layer' is false.
---
 input/regression/keep-alive-with-id.ly | 52 ++++++++++++++++++++++++++++++++++
 lily/hara-kiri-group-spanner.cc        |  1 +
 lily/keep-alive-together-engraver.cc   | 12 ++++++++
 scm/define-grob-properties.scm         |  2 ++
 4 files changed, 67 insertions(+)
 create mode 100644 input/regression/keep-alive-with-id.ly

diff --git a/input/regression/keep-alive-with-id.ly b/input/regression/keep-alive-with-id.ly
new file mode 100644
index 0000000..1365d79
--- /dev/null
+++ b/input/regression/keep-alive-with-id.ly
@@ -0,0 +1,52 @@
+\version "2.19.46"
+
+\header {
+  texidoc = "The @code{VerticalAxisGroup.keep-alive-with-id} property
+can be used together with @code{VerticalAxisGroup.remove-layer = ##f}
+to identify groups of contexts, any of which should keep the group alive."
+}
+
+bars = \repeat unfold 12 { \mark \default R1*2 }
+winds = \repeat unfold 96 { c''4 }
+brass = \repeat unfold 192 { c''8 }
+violinone = \repeat unfold 24 { R1 }
+violintwo = { \repeat unfold 12 c'1 \repeat unfold 12 { R1 } }
+
+\layout {
+  \context { \Dynamics \consists Mark_engraver }
+  \context { \Score \remove Mark_engraver }
+}
+
+\score {
+  <<
+    \new Dynamics { \bars }
+    \new Staff \with { instrumentName = "Winds"
+      shortInstrumentName = "W"
+    } \winds
+    \new Staff \with { instrumentName = "Brass"
+      shortInstrumentName = "Br"
+    } \brass
+    \new StaffGroup \with {
+      \consists Keep_alive_together_engraver
+      instrumentName = "Strings"
+      shortInstrumentName = "St"
+    } <<
+      \new Dynamics \with {
+        keepAliveInterfaces = #'()
+        \override RehearsalMark.color = #red
+        \override VerticalAxisGroup.remove-empty = ##t
+        \override VerticalAxisGroup.keep-alive-with-id = 1
+      } \bars
+      \new Staff \with {
+		    \override VerticalAxisGroup.remove-empty = ##t
+        \override VerticalAxisGroup.remove-layer = ##f
+        \override VerticalAxisGroup.keep-alive-with-id = 1
+      } \violinone
+      \new Staff \with {
+		    \override VerticalAxisGroup.remove-empty = ##t
+        \override VerticalAxisGroup.remove-layer = ##f
+        \override VerticalAxisGroup.keep-alive-with-id = 1
+      } \violintwo
+    >>
+  >>
+}
diff --git a/lily/hara-kiri-group-spanner.cc b/lily/hara-kiri-group-spanner.cc
index 0641078..84872e8 100644
--- a/lily/hara-kiri-group-spanner.cc
+++ b/lily/hara-kiri-group-spanner.cc
@@ -198,6 +198,7 @@ ADD_INTERFACE (Hara_kiri_group_spanner,
                "items-worth-living "
                "important-column-ranks "
                "keep-alive-with "
+               "keep-alive-with-id "
                "make-dead-when "
                "remove-empty "
                "remove-first "
diff --git a/lily/keep-alive-together-engraver.cc b/lily/keep-alive-together-engraver.cc
index 9b1cbe4..d78327c 100644
--- a/lily/keep-alive-together-engraver.cc
+++ b/lily/keep-alive-together-engraver.cc
@@ -55,6 +55,8 @@ Keep_alive_together_engraver::finalize ()
       if (scm_is_false (this_layer))
         continue;
 
+      SCM this_id = group_spanners_[i]->get_property ("keep-alive-with-id");
+
       SCM live_scm = Grob_array::make_array ();
       Grob_array *live = unsmob<Grob_array> (live_scm);
       SCM dead_scm = Grob_array::make_array ();
@@ -64,6 +66,16 @@ Keep_alive_together_engraver::finalize ()
         {
           if (i == j)
             continue;
+
+          SCM that_id = group_spanners_[j]->get_property ("keep-alive-with-id");
+          if (scm_is_integer (this_id) and scm_is_integer (that_id) and
+              scm_is_true (scm_num_eq_p (that_id, this_id)))
+            {
+              // this layer is kept alive by any other layer with equal id
+              live->add (group_spanners_[j]);
+              continue;
+            }
+
           SCM that_layer = group_spanners_[j]->get_property ("remove-layer");
           if (scm_is_false (that_layer))
             continue;
diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm
index cb9103a..e52d70a 100644
--- a/scm/define-grob-properties.scm
+++ b/scm/define-grob-properties.scm
@@ -547,6 +547,8 @@ slur quants to this position, and print the respective scores.")
 ;;;
      (keep-inside-line ,boolean? "If set, this column cannot have
 objects sticking into the margin.")
+     (keep-alive-with-id ,integer? "An identifying integer for a set of
+@code{VerticalAxisGroup}s.  If any of them are alive, then we will stay alive.")
      (kern ,ly:dimension? "The space between individual elements
 in any compound bar line, expressed as a multiple of the default
 staff-line thickness (i.e. the visual output is @emph{not}
-- 
2.7.4

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to