lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use keep-alive-together / hara-kiri-together


From: H. S. Teoh
Subject: Re: How to use keep-alive-together / hara-kiri-together
Date: Fri, 10 Apr 2015 12:35:00 -0700
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, Apr 07, 2015 at 01:26:53PM -0700, H. S. Teoh wrote:
> Hi All,
> 
> I have a ScoreMarks context (basically, something to collect score
> marks, tempo changes, etc.) placed above a StaffGroup, that I want to
> elide when the StaffGroup is elided by \removeEmptyStaves. How do I do
> this?
> 
> I've tried searching online and found references to
> keep-alive-together and hara-kiri-together, but couldn't find any
> examples of how to actually use these properties. The docs are rather
> scanty and I didn't find anything helpful in the list archives except
> for Kieran's post regarding essentially the same question, but there
> was no response:
> 
> http://lilypond.1069038.n5.nabble.com/keep-alive-together-or-hara-kiri-together-to-kill-a-Marks-context-td154704.html
[...]

Since it looks like nobody has a solution, today I decided to delve into
lilypond's innards to see if I can figure it out myself. I did find a
partial solution; however, it's still not yet a usable solution
(explanation below).

The basic idea is to use \RemoveEmptyStaves on both the staves inside
the StaffGroup as well as in the ScoreMarks context -- score marks and
tempo changes seem to be excluded from the list of "interesting" grobs,
so this means the ScoreMarks won't show up by default; but create a new
context with a Keep_alive_together_engraver to make the ScoreMarks show
up when the StaffGroup has not been elided.

Here's what I have so far:

        \layout {
            % A context for collecting score markings like \tempo and
            % \mark into a single line that can be placed above groups
            % of staffs. This code is basically copied and pasted from
            % Kieran's code.
            \context {
                \type "Engraver_group"
                \name ScoreMarks
                \consists "Staff_collecting_engraver"
                \consists "Axis_group_engraver"
                \override VerticalAxisGroup.staff-affinity = #DOWN
                \consists "Mark_engraver"
                \consists "Time_signature_engraver"
                \override TimeSignature.stencil = #point-stencil
                \consists "Metronome_mark_engraver"
                \override 
VerticalAxisGroup.nonstaff-unrelatedstaff-spacing.padding = #3
            }

            % Groups together a ScoreMarks context with a Staff or
            % StaffGroup such that the ScoreMarks will be kept alive
            % only if the Staff or StaffGroup is still alive.  The
            % intended usage is to use \RemoveEmptyStaves on the
            % ScoreMarks context, so that it will be invisible whenever
            % the associated Staff / StaffGroup is elided.
            \context {
                \type "Engraver_group"
                \name MarksGroup
                \consists "Keep_alive_together_engraver"
                \accepts ScoreMarks
                \accepts Staff
                \accepts StaffGroup
            }

            % This removes the default Mark_engraver and 
Metronome_mark_engraver from
            % the Score context.
            \context {
                \Score
                \remove "Mark_engraver"
                \remove "Metronome_mark_engraver"
                \accepts MarksGroup
                \accepts ScoreMarks
            }
        }

        global = ... % \tempo's and \mark's go here
        \score {
                \new MarksGroup <<
                        \new ScoreMarks \global
                        \new StaffGroup = "winds" <<
                                ... % staves for winds section
                        >>
                >>
                \new MarksGroup <<
                        \new ScoreMarks \global
                        \new StaffGroup = "brass" <<
                                ... % staves for brass section
                        >>
                >>
                ... % similarly for percussion/string sections

                \layout {
                        % These are necessary otherwise nothing will get
                        % elided.
                        \context { \Staff \RemoveEmptyStaves }
                        \context { \ScoreMarks \RemoveEmptyStaves }
                }
        }


There is one major drawback, though. The Keep_alive_together_engraver is
recursive; it scans for all contexts below it and will keep them *all*
alive unless everything in the StaffGroup is empty. This means that
empty staves will now show up within each instrument section
(StaffGroup) unless the entire section is silent, then it will remove
that section along with the associated ScoreMarks context.

What I need, however, is for empty staves to be removed from within the
StaffGroup as usual, but the ScoreMarks to be kept alive until the
entire StaffGroup is going to be removed. Is there a way to limit the
Keep_alive_together_engraver to only the top-level, so that it won't try
to keep individual staves inside the StaffGroup alive?


T

-- 
This sentence is false.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]