[prev in list] [next in list] [prev in thread] [next in thread]
List: lilypond-user
Subject: Re: scheme function containing score {...}
From: Gianmaria Lari <gianmarialari () gmail ! com>
Date: 2017-11-25 9:00:50
Message-ID: CAKhGe3w8vB_o_VjPgiD1HB9LvRHYXC11kpgYpG8On-i_F7H5Xw () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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 <dak@gnu.org> wrote:
> Gianmaria Lari <gianmarialari@gmail.com> 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
>
[Attachment #5 (text/html)]
<div dir="ltr">David, I changed "define" in \
"define-music-function" and now it works perfectly, thank you \
David!<div><br><div>I think this is something can be useful to others so I post the \
new working code:</div><div><br></div><blockquote style="margin:0 0 0 \
40px;border:none;padding:0px"><div><div><span style="font-size:12.8px">\version \
"2.19.80"</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px">myScore = </span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px">#(define-scheme-function \
(music) (ly:music?) #{</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px"> \score {</span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px"> \
$music</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px"> \layout{}</span></div></div><div><div \
style="font-size:12.8px"><span style="font-size:12.8px"> \
\midi{}</span></div></div><div><div style="font-size:12.8px"><span \
style="font-size:12.8px"> } #} )</span></div></div><div><div \
style="font-size:12.8px"><br></div></div><div><div><span \
style="font-size:12.8px">\myScore {a b \
c'}</span></div></div></blockquote><div><span \
style="font-size:12.8px"><br></span></div><div>Regards, g.</div></div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On 24 November 2017 at 18:18, David \
Kastrup <span dir="ltr"><<a href="mailto:dak@gnu.org" \
target="_blank">dak@gnu.org</a>></span> wrote:<br><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span \
class="">Gianmaria Lari <<a \
href="mailto:gianmarialari@gmail.com">gianmarialari@gmail.com</a>> writes:<br> \
<br> > I'm trying to put the score functionality inside a function (consider \
it a<br> > test). Here it is the code:<br>
><br>
> \version "2.19.80"<br>
> myScore =<br>
> #(define (music) (ly:music?) #{<br>
> \score {<br>
> $music<br>
> \layout{}<br>
> \midi{}<br>
> } #} )<br>
><br>
> \myScore {a b c'}<br>
><br>
><br>
> The code correctly generate a score but it does not generate the midi file.<br>
> Why???<br>
<br>
</span>There is a difference between define (which defines a pure Scheme<br>
function or expression) and define-music-function (which defines<br>
something taking arguments in LilyPond syntax and returning a music<br>
expression) and your input is an interesting mashup where \myScore will<br>
probably be left as *unspecified* after you define an argumentless<br>
Scheme function named `music' that first calls ly:music? without<br>
argument and then would return a score if the ly:music? call had not<br>
already caused an error due to a missing argument.<br>
<br>
Now a score is not a music expression anyway, so you should rather<br>
replace define with define-scheme-function here in order to avoid<br>
errors: the resulting \myScore can then return arbitrary expressions<br>
including whole scores.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
David Kastrup<br>
</font></span></blockquote></div><br></div>
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic