[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
\mask and \unmaskWithTag
From: |
Dan Eble |
Subject: |
\mask and \unmaskWithTag |
Date: |
Thu, 23 Apr 2020 19:25:35 -0400 |
Is this \mask function worth developing as a feature of LilyPond? Is there
already something that can achieve this that I am overlooking?
The use case will probably be clearer if you start by running this example
through LilyPond than if you start by reading the code.
Regards,
—
Dan
\version "2.20.0"
mask =
#(define-music-function (tags music) (symbol-list-or-symbol? ly:music?)
(_i "Tag @var{music} as if with @code{\\tag} @var{tags} @var{music},
but hide it from the interpreter until @code{\\unmaskWithTag} is used.")
#{ \tag #tags #(make-music 'SequentialMusic 'void music) #} )
%% TODO (?) retain the tags on the unmasked music
unmaskWithTag =
#(define-music-function (tags music) (symbol? ly:music?)
(_i "Expose any music within @var{music} that was hidden with
@code{\\mask}. The @var{tags} are used as in @code{\\keepWithTags}.")
(music-map
(lambda (m)
(let ((masked-music (ly:music-property m 'void)))
(if (and (ly:music? masked-music) (tags-keep-predicate tags))
masked-music
m)))
music))
%%----------------------------------------------------------------------
onceUnfolded =
#(define-music-function (m) (ly:music?)
#{ \mask #'unfolded #m #})
untilUnfolded =
#(define-music-function (m) (ly:music?)
#{ \tag #'folded #m #})
newUnfoldRepeats =
#(define-music-function (m) (ly:music?)
#{ \unfoldRepeats \removeWithTag #'folded \unmaskWithTag #'unfolded #m #})
%%----------------------------------------------------------------------
song = <<
\new Staff {
\clef "treble"
%% This part is tagged to respond to \unfoldRepeats even though it
%% does not have the outer repeat that other parts do.
\onceUnfolded R1*5
\repeat volta 2 { % bar form
r4 a'\untilUnfolded ^"tacet until D.C." 2 | 2 2 |
}
b'1 |
}
\new Staff {
\clef "bass"
\repeat volta 2 { % strophic
\repeat volta 2 { % bar form
c1~ | 1
}
g,1 |
\untilUnfolded \mark "D.C."
\bar "||"
}
\bar "|."
}
>>
\score {
\song
\layout { }
}
\score {
\newUnfoldRepeats \song
\layout { }
\midi { }
}
- \mask and \unmaskWithTag,
Dan Eble <=