[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sending around contexts
From: |
Kieren MacMillan |
Subject: |
Re: Sending around contexts |
Date: |
Thu, 28 Oct 2021 16:06:43 -0400 |
Hi Lukas (and Aaron),
> Wow.
Agreed.
> That's what you might call elegant (and I have to admit that this is the
> first time I hear about dispatchers).
+1 x 2 (which, ironically, still equals 1…)
> But as I imagine Kieren is going to want to use this a LOT :-)
YOU DON’T KNOW ME!!! ;)
Yeah… this will end up getting overused in my code.
> %%%%
> \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
> >>
> >>
> }
> %%%%
Oh! Nice. This is really becoming a cool mechanism. Can’t wait to take it out
for a real spin.
Thanks all!
Kieren.
________________________________
Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kieren@kierenmacmillan.info
- Re: Sending around contexts, Kieren MacMillan, 2021/10/28
- Re: Sending around contexts, Kieren MacMillan, 2021/10/28
- Re: Sending around contexts, Aaron Hill, 2021/10/28
- Re: Sending around contexts, Aaron Hill, 2021/10/28
- Re: Sending around contexts, Lukas-Fabian Moser, 2021/10/28
- Re: Sending around contexts,
Kieren MacMillan <=
- Re: Sending around contexts, Valentin Petzel, 2021/10/28
- Re: Sending around contexts, Kieren MacMillan, 2021/10/28
- Re: Sending around contexts, David Kastrup, 2021/10/29
- Re: Sending around contexts, Kieren MacMillan, 2021/10/29
- Re: Sending around contexts, Stefano Troncaro, 2021/10/29
- Re: Sending around contexts, Kieren MacMillan, 2021/10/29
- Re: Sending around contexts, Kieren MacMillan, 2021/10/29
- Re: Sending around contexts, Lukas-Fabian Moser, 2021/10/29
- Re: Sending around contexts, Kieren MacMillan, 2021/10/29
- Re: Sending around contexts, Kieren MacMillan, 2021/10/29