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: Urs Liska
Subject: Re: function that inserts a toplevel expression
Date: Thu, 10 May 2012 14:40:17 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

Hello Jan-Peter,

thank you for the ideas, that I have partly understood.

Am 10.05.2012 13:35, schrieb Jan-Peter Voigt:
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, I don't really understand it, but the cleaner
\layout { \debugCurvesOn }
is perfectly acceptable.
...
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/
So this is what I came up with. This is a minimal example of how it could work:
% inside included (library) file:
liedScore = \score {
  \new Staff {
    \set Staff.instrumentName = \instName
    \music
  }
}

music = \relative c' { c4 e g b } % Defined in another (piece specific) included file
instName = "Test" % already defined with default value in the library, so I don't _have_ to write this
\score { \liedScore }

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.
Unfortunately this doesn't seem to work for me. I don't want to pass the music as parameter but one or more strings containing the instrument names of the staves.

But thinking of it the above solution is probably sufficient. I can define default values in the library and override them in the master file if necessary.


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.
I'll look into it later
Best
Urs

Cheers, Jan-Peter



_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user


reply via email to

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