lilypond-user
[Top][All Lists]
Advanced

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

Re: function that inserts a toplevel expression


From: Jan-Peter Voigt
Subject: Re: function that inserts a toplevel expression
Date: Thu, 10 May 2012 13:35:45 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

Hello Urs,

On 10.05.2012 12:40, Urs Liska wrote:
Hi David,

thank you for the reply

Am 10.05.2012 12:05, schrieb David Kastrup:
Urs Liska<address@hidden>  writes:

So now the question:
How can I write a function that produces a toplevel _expression_?
No such thing.
:-(
an _ugly_ way is to produce a string and then use #(ly:parser-include-string parser topLevelString)
This snip can then be included in a music- or scheme-function to be used in lily-syntax. There are cases, where I use this construct, but I try to avoid it.

...
OK, instead of

\debugCurvesOn

I now have to insert

\layout { \debutCurvesOn }

in my main file.
It is not perfectly what I had hoped for, but it's fine nevertheless (definitely better than the current solution).
So we may consider this as solved.
If you want to turn this into a function, you use define-scheme-function
and construct the return value using #{ \layout { ... } #}.
Not necessary anymore. But I think I see now better how this works.

Furthermore I will later want to write functions for the \score block,
and I will want to pass some parameters in there - which doesn't work
with include files.
Not clear to me what you want.

I wanted to be able to write

\liedScore "Stimme" "Klavier"
or
\liedScore "Voice" "Piano"
and get back the respective \score block with the parameters substituted.
you can write
liedScore = \score { ... }
and you can write
liedScore = #(define-scheme-function (parser layout ...)(...)
#{
\score {
...
}
#})

... thanks to Davids remarkable parser refinements. (I was not amused in the first place, rewriting/updating my scores accordingly, but IMO these changes are a major step forward for lilypond!)

If you reference this, it looks all the same
\liedScore /optional parms/

But from your answers to the other part of the question I now know that this isn't possible.
If liedScore is a music-function (returning void), it can be placed anywhere. This function can do anything possible in scheme: It can add scores or markups to the current stream:
--snip--

fun = #(define-music-function (parser location mus)(ly:music?)

(add-score parser (list #{ \markup { Hello World } #}))

(add-score parser #{ \score { $mus } #})

(make-music 'SequentialMusic 'void #t))

\fun \relative c' { c4 e g b }

--snip--

Now you can put anything in your function, to create the score.

Probably I'll look for a solution through defining a variable and then including the file with the \score definition.
For the project at hand it's not necessary because I can have the score block be hardcoded. But I want to distill a more generic library/framework for use after this project.
Using lilypond is handcraft and the artist often wishes to have his own unique tool ;-)

I also use my own functions:
http://www.xn--schne-noten-tfb.de/?tabs=3,1
http://www.xn--schne-noten-tfb.de/lalily.tgz
It is poorly to not documented, but if you are interested, I can give you more information.

Cheers, Jan-Peter


reply via email to

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