lilypond-user
[Top][All Lists]
Advanced

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

Re: Sending around contexts


From: Valentin Petzel
Subject: Re: Sending around contexts
Date: Sun, 22 Nov 2020 22:41:54 +0100

That’s more or less what I said before: It does not make a lot of sense to do 
this, as different contexts will behave differently.

You are sending notes to a Staff context, but a Staff does not in fact handle 
the notes, this is done by Voice contexts. Now usually \new Staff *some stuff* 
will automatically create a Voice, but in this case you are sending the Notes 
to a staff, not to a voice.

So you eighter have to create a new Voice by doing
<< #music1 \new Voice { \change Staff = #context #music2 } >>

(which would be the standard way to do this, you do not need special Contexts 
for sending Voices between Staves), OR you could send Notes to a voice, so you 
can do

\new Staff \new Voice = „test”

And then send notes to this voice by
\new Notes { \change Voice = „test” ... }
Which is what I did in the past and allows us to send notes from one existing 
voice to another existing voice.

But this does also not work with your function, as Voice does not accept 
Container, so the Container is placed outside of the Voice, meaning you cannot 
change the voice context, because you are not in a voice context.
Note that it is important that the voice context does not accept the container 
context. Because if it did, the whole \new Container \new Notes ... Would be 
inside of the voice, meaning we’ll send the whole voice over when sending 
between contexts.

Thus I strongly suggest using specific functions for different contexts. If 
you really want a common function, you could then do one function with cond 
like

(cond
 ((= context „Dynamics”) (toDyn args))
 ((= context „Staff”) (toStaff args))
 ((= context „Voice”) (toVoice args))
 ...)

Cheers,
Valentin

Am Sonntag, 22. November 2020, 21:58:10 CET schrieben Sie:
> Hi Valentin,
> 
> > That’s because at this point the Dynamics context does not exist anymore,
> > so  you cannot switch to it.
> 
> Okay, thanks — that worked.
> 
> But how about the attached?
> (n.b. I tried with \new Staff \new Container = "test", and that didn’t seem
> to work either.)
> 
> Cheers,
> Kieren.
> 
> %%%
> \version "2.20"
> 
> \layout {
>   \context {
>     \name "Notes"
>     \type "Engraver_group"
>   }
>   \context {
>     \Voice
>     \accepts "Notes"
>   }
>   \context {
>     \name "Container"
>     \type "Engraver_group"
>     \accepts "Notes"
>     \accepts "Voice"
>   }
>   \context {
>     \Staff
>     \accepts "Container"
>   }
>   \context {
>     \Dynamics
>     \accepts "Container"
>   }
> }
> 
> send =
> #(define-music-function (cname context music1 music2) (string? string?
> ly:music? ly:music?) #{
>      << #music1 \new Container \new Notes { \change #cname = #context
> #music2 } >> #})
> 
> pfdyn = \send Container "piano_dynamics" \etc
> 
> piano_upper = {
>   c'4\p d' e' f'
>   \pfdyn g'1 <>\mp
>   g'4\f f' e' d'
>   \send Staff "test" g'4 c''\f f' e' d'
>   c'1
> }
> 
> piano_lower = {
>   \clef bass
>   c1
>   g,1
>   g,1
>   c1
> }
> 
> \score {
>   <<
>     \new Staff = "test" { #(skip-of-length piano_upper) }
>     \new Staff { c''1 }
>     \new Staff { c''1 }
>     \new Staff { c''1 }
>     \new Staff { c''1 }
>     \new Staff { c''1 }
>     \new PianoStaff <<
>       \new Staff \piano_upper
>       \new Dynamics \new Container = "piano_dynamics" { #(skip-of-length
> piano_upper) } \new Staff \piano_lower
> 
> 
>   %%%  layout mod to show the centred dynamics
>   \layout {
>     \context {
>       \PianoStaff
>       \override VerticalAxisGroup.staff-staff-spacing.padding = #10
>     }
>   }
> }
> %%%
> ________________________________
> 
> Kieren MacMillan, composer (he/him/his)
> ‣ website: www.kierenmacmillan.info
> ‣ email: kieren@kierenmacmillan.info

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


reply via email to

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