lilypond-user
[Top][All Lists]
Advanced

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

Re: Sending around contexts


From: Aaron Hill
Subject: Re: Sending around contexts
Date: Thu, 28 Oct 2021 12:32:39 -0700
User-agent: Roundcube Webmail/1.4.9

On 2021-10-28 12:25 pm, Aaron Hill wrote:
Not an engraver, but a dispatcher trick could be a first step:

Wait... there's no need to share a source dispatcher... also, that code duplicates the listener...

%%%%
\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 #})

piano_upper = {
  c'4\p d' e' f'
  g'1\mp
  g'4\f f' e' d'
  c'1
}

piano_lower = {
  \clef bass
  c1
  g,1
  g,1
  c1\ff
}

\score {
  <<
    \new PianoStaff <<
      \new Staff \with {
        \eventTransferSource dynamic-event
        \omit DynamicText
      } \piano_upper
\new Dynamics \with { \eventTransferSink } { #(skip-of-length piano_upper) }
      \new Staff \with {
        \eventTransferSource dynamic-event
        \omit DynamicText
      } \piano_lower
    >>
  >>
}
%%%%


-- Aaron Hill



reply via email to

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