\mask and \unmaskWithTag

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

\mask and \unmaskWithTag

Dan Eble
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 { }
}


Reply | Threaded
Open this post in threaded view
|

Re: \mask and \unmaskWithTag

Dan Eble
On Apr 23, 2020, at 19:25, Dan Eble <[hidden email]> wrote:
>
>    (let ((masked-music (ly:music-property m 'void)))
>     (if (and (ly:music? masked-music) (tags-keep-predicate tags))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
Oops.  This is bogus and the output of the score is correct in spite of it.  What I intended was to check whether the masked music has the right tags.

Dan