lilypond-user
[Top][All Lists]
Advanced

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

Re: scheme function containing score {...}


From: Gianmaria Lari
Subject: Re: scheme function containing score {...}
Date: Sat, 25 Nov 2017 10:00:50 +0100

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'}

Regards, g.

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


reply via email to

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