Hello David,

if I understand this correctly the intent here is to have different staff 
behaviour in one staff. I believe that there might be a more general concept 
here. Instead of creating a new context and mechanic to set additional clefs, 
maybe it would make sense to have a more general concept of say sub staves, 
which would allow us to do the same thing for a more general set of staff 
features? So instead of

\extraClef #-3 "bass" ...

one could have

\new SubStaff {
  \override SubStaff.Clef.Y-offset = #-3
  \clef "bass"
  ...
}

This should then allow for similar things such as multiple individual 
handlings of Accidentals, multiple bar lines, key signatures, lines and 
brackets, ...

Cheers,
Valentin

Am Montag, 5. Februar 2024, 12:30:31 CET schrieb David Kastrup:
> \version "2.25.10"
> 
> \header {
>   tagline = ##f
> }
> 
> \layout {
>   \context {
>     \Staff
>     \accepts ExtraClefStaff
>   }
>   \context {
>     \name ExtraClefStaff
>     \type Engraver_group
>     \alias Staff
>     \accepts Voice
>     \consists Clef_engraver
>     \override Clef.font-size = #-4
>     %% The break-align-symbol stacks the extra clef to the right of
>     %% the normal clef
>     \override Clef.break-align-symbol = #'cue-clef
>     %% This break-visibility repeats the extra clef every bar.  Should
>     %% this be the actual default?  Or should the default just be
>     %% the normal #begin-of-line-visible ?
>     \override Clef.break-visibility = #end-of-line-invisible
>     %% different size for first clef in line is uncalled for
>     firstClef = ##f
>   }
> }
> 
> \midi {
>   \context {
>     \Staff
>     \accepts ExtraClefStaff
>   }
>   \context {
>     \name ExtraClefStaff
>     \type Performer_group
>     \alias Staff
>     \accepts Voice
>   }
> }
> 
> extraClef =
> #(define-music-function (offset clef-type) ((number?) string?)
>   #{ \new ExtraClefStaff = "extraclef" { }
>      \change Staff = "extraclef"
>      #(if offset #{ \override Staff.Clef.Y-offset = #offset #})
>      \clef #clef-type
>      #})
> 
> all-clef-properties =
> #(map (lambda (x) (ly:music-property x 'symbol))
>   (extract-named-music (make-clef-set "treble_(8)") 'PropertySet))
> 
> extraClefEnd =
> #(context-spec-music
>   (make-apply-context
>    (lambda (ctx)
>      ;; Should be a given in context-spec-music
>      (if (eq? (ly:context-name ctx) 'ExtraClefStaff)
>        (begin
>          ;; revert clef-specific settings in case some clef is still
>          ;; issued before the context dies: in that case it should
>          ;; correspond to the supervening Staff clef.
>          (for-each (lambda (p) (ly:context-unset-property ctx p))
>                    all-clef-properties)
>          ;; All children of the ExtraClefStaff are reseated to its
>          ;; parent context, removing it from the hierarchy
>          (let ((switch (ly:make-stream-event
>                         (ly:make-event-class 'ChangeParent)
>                         `((context . ,(ly:context-parent ctx))))))
>            (for-each
>             (lambda (x)
>               (ly:broadcast (ly:context-event-source x) switch))
>             (ly:context-children ctx))))
>        (ly:programming-error "Not in ExtraClefStaff"))))
>   'ExtraClefStaff)
> 
> 
> \score {
>     \new Staff = "lower" {
>         \key d \minor
>         \numericTimeSignature
>         \time 3/4
>         \clef bass
>         \relative c' {
>           \voices 1,""
>             <<
>                 {
>                     s2. r4 r8. \clef treble
>                     \tuplet 3/2 16 { g'32 (a bes }
>                     c8.) c16--
>                     c16-- bes g a
>                     g8.
>                     \omit TupletBracket
>                     \tuplet 3/2 16 { f32 (g a }
>                     bes8.) bes16
>                   } \\
>                 {
>                   d,,,8.-- d16-- d2--~ 2.~
>                   \extraClef #-3 "bass"
>                   \voiceTwo
>                   2.~ \break 2.~2.
>                   \oneVoice
>                 \extraClefEnd
>                 c''2.
>                 }
> 
>         }
>     }
> }

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to