Hi Aaron,
%%%%
\version "2.22.0"
#(define event-transfer-sink (ly:make-dispatcher))
eventTransferSink = \applyContext
#(lambda (ctxt)
(ly:connect-dispatchers
(ly:context-event-source ctxt)
event-transfer-sink))
eventTransferSource =
#(define-music-function (event-type) (symbol?)
(define (event-proc ev)
(ly:broadcast event-transfer-sink (ly:event-deep-copy ev)))
(define (context-proc ctxt)
(ly:add-listener event-proc (ly:context-events-below ctxt)
event-type))
#{ \applyContext #context-proc #})
Wow.
That's what you might call elegant (and I have to admit that this is the
first time I hear about dispatchers).
But as I imagine Kieren is going to want to use this a LOT :-), it might
be reasonable to use named transfer channels:
%%%%
\version "2.22.0"
newChannel =
#(define-scheme-function () () (ly:make-dispatcher))
receiveFromChannel =
#(define-music-function (chan) (ly:dispatcher?)
#{
\applyContext
#(lambda (ctxt)
(ly:connect-dispatchers
(ly:context-event-source ctxt)
chan))
#})
sendToChannel =
#(define-music-function (chan event-type) (ly:dispatcher? symbol?)
(define (event-proc ev)
(ly:broadcast chan (ly:event-deep-copy ev)))
(define (context-proc ctxt)
(ly:add-listener event-proc (ly:context-events-below ctxt) event-type))
#{ \applyContext #context-proc #})
piano_upper = {
c'4\p d' e' f'
g'1\mp
g'4\f f' e' d'
c'1
}
piano_upper_II = {
c'4\ff\< d' e' f'
g'1\ffff
g'4 f' e' d'
c'1
}
piano_lower = {
\clef bass
c1
g,1
g,1
c1\ff
}
myChannel = \newChannel
myOtherChannel = \newChannel
\score {
<<
\new PianoStaff <<
\new Staff \with {
\sendToChannel \myChannel dynamic-event
\omit DynamicText
} \piano_upper
\new Dynamics \with { \receiveFromChannel \myChannel } {
#(skip-of-length piano_upper) }
\new Staff \with {
\sendToChannel \myChannel dynamic-event
\omit DynamicText
} \piano_lower
>>
\new PianoStaff <<
\new Staff \with {
\sendToChannel \myOtherChannel dynamic-event
\sendToChannel \myOtherChannel span-dynamic-event
\omit DynamicText
\omit Hairpin
} \piano_upper_II
\new Dynamics \with { \receiveFromChannel \myOtherChannel } {
#(skip-of-length piano_upper) }
\new Staff \with {
\receiveFromChannel \myOtherChannel
} \piano_lower
>>
>>
}
%%%%
Lukas