|
From: | Gianmaria Lari |
Subject: | Re: scheme function containing score {...} |
Date: | Sun, 24 Dec 2017 13:42:36 +0100 |
On 24 November 2017 at 18:18, David Kastrup <address@hidden> wrote:Gianmaria Lari <address@hidden> writes:
> I'm trying to put the score functionality inside a function (consider it a
> test). Here it is the code:
>
> \version "2.19.80"
> myScore =
> #(define (music) (ly:music?) #{
> \score {
> $music
> \layout{}
> \midi{}
> } #} )
>
> \myScore {a b c'}
>
>
> The code correctly generate a score but it does not generate the midi file.
> Why???
There is a difference between define (which defines a pure Scheme
function or _expression_) and define-music-function (which defines
something taking arguments in LilyPond syntax and returning a music
_expression_) and your input is an interesting mashup where \myScore will
probably be left as *unspecified* after you define an argumentless
Scheme function named `music' that first calls ly:music? without
argument and then would return a score if the ly:music? call had not
already caused an error due to a missing argument.
Now a score is not a music _expression_ anyway, so you should rather
replace define with define-scheme-function here in order to avoid
errors: the resulting \myScore can then return arbitrary expressions
including whole scores.
--
David Kastrup
David, I changed "define" in "define-music-function" and now it works perfectly, thank you David!I think this is something can be useful to others so I post the new working code:\version "2.19.80"myScore =#(define-scheme-function (music) (ly:music?) #{\score {$music\layout{}\midi{}} #} )\myScore {a b c'}
\version "2.19.80"myScore =#(define-scheme-function (music) (ly:music?) #{\score {$music\layout{}}\score {$music\midi{}}#})\myScore {a b c'}
error: syntax error, unexpected \score, expecting end of input
\score {
error: error in #{ ... #}
[Prev in Thread] | Current Thread | [Next in Thread] |