On 19/05/2024 20:27, Carolyn Beeton wrote:
I would like to include some Staff and Voice context settings in the \midi 
block only if a flag is set to ##t and I have not been able to figure out how 
to do this.  When I try to wrap the \context blocks in a code block with #{…#} 
I get this error:
trackPerVoiceMWE.ly:31:16: error: syntax error, unexpected '{', expecting 
SCM_IDENTIFIER or SCM_TOKEN or STRING or SYMBOL
       \context                 {
Is there any way to conditionally change the Staff_performer based on a flag 
setting?

I think this does what you want.

\version "2.24.0"

\include "english.ly" TrackPerVoice = ##t nostaffmidi = #(define-scheme-function () () (if TrackPerVoice #{ \context { \Staff \remove "Staff_performer" } #})) voicemidi = #(define-scheme-function () () (if TrackPerVoice #{ \context { \Voice \consists "Staff_performer" } #})) global = { \key c \major \time 4/4 } \score { \new ChoirStaff << \new Staff << \new Voice = "soprano" << \global \relative c' { c'4 d e f << g1 \\ { g4 f e2 } >> } >> \new Voice = "alto" << \global \voiceTwo \relative c' { c'4 b a g | f e d2 } >> >> >> \layout {} \midi { #(ly:message "TrackPerVoice is ~a\n" TrackPerVoice) #(when TrackPerVoice (ly:message "One track per Voice (may make too many voices with polyphony)") (ly:message "Turn this off to get sop and alto combined in one track.")) \nostaffmidi \voicemidi }

Although, I don't understand why the contents of the scheme functions cannot be placed directly into the midi block like this

\midi { #(if TrackPerVoice #{ \context { \Staff \remove "Staff_performer" } #}) #(if TrackPerVoice #{ \context { \Voice \consists "Staff_performer" } #}) }

--
Timothy Lanfear, Bristol, UK.

Reply via email to