There are two things fundamentally wrong here. First defining a new music function uses the command define-music-function
, not make-music-function
. Second to access something like \sf
from within scheme code you need to omit the backslash. (\value
will try to resolve value
in the global scheme scope. If this is a music object a copy of that object is returned, if it is a music function it will try to determine the arguments and evaluate it). So you need to do
dramaticEnding = #(define-music-function
(dosf doff)
(boolean? boolean?)
#{
c #(cond
(dosf sf)
(doff ff))
c
#})
or to be on the save side even
\version "2.22.1"
dramaticEnding = #(define-music-function
(dosf doff)
(boolean? boolean?)
#{
c #(cond
(dosf (ly:music-deep-copy sf))
(doff (ly:music-deep-copy ff)))
c
#})
\relative c'' {
\dramaticEnding ##t ##f
\dramaticEnding ##f ##f
}
Alternatively you can create a parsing environment by #{ \sf #}
. This has the advantage that lilypond will automatically be able to attach location information to the event:
\version "2.22.1"
dramaticEnding = #(define-music-function
(dosf doff)
(boolean? boolean?)
#{
c #(cond
(dosf #{ \sf #})
(doff #{ \ff #}))
c
#})
\relative c'' {
\dramaticEnding ##t ##f
\dramaticEnding ##f ##f
}
Alternatively though you might want to create the function rather to take hooks for you to specify the dynamics:
\version "2.22.1"
dramaticEnding = #(define-music-function
(dyn1) ; for more places add more arguments
((lambda (x) (or (ly:music? x) (not x))))
#{
c $(if dyn1 dyn1)
c
#})
\relative c'' {
\dramaticEnding \sf
\dramaticEnding \ff
\dramaticEnding ##f
}