After a few test I have one further question.
I managed to tweak your functions to my needs (i.e. make it _less_
generic, because I need it for a specific purpose).
Attached you'll find my version of the function with example.
I created a function that only takes the \book as its argument, then
processes it twice, assigning different first pages each.
While this actually does what I want I would like to make the input
structure still more simple by passing the \score instead of the \book
to the function.
What I'm actually doing is:
mybook = \book {
\include "file-containing-score-block.ily"
}
\writeBookOddEven #mybook
which is somewhat redundant.
What I would like to write is:
\writeBookOddEven \include "file-containing-score-block.ily"
(or - slightly more generic:
\writeBookOddEven
\score {
...
}
Probably my problem is really tiny, but I can't find the solution
because the documentation of the ly:... functions isn't really helpful.
If I change the passed parameter from ly:book? to ly:score? then I don't
know how to access the implicit \book object inside the function.
I assume that I should use ly:book-add-score! to add the score object
passed into the function to the book. But I don't know how to access
this book object (i.e. what to write instead of book-smob in
*"ly:book-add-score!*/book-smob score")
/
Attached is my attempt (writeScoreOddEven.ly) with comments on where I
assume changes to be done.
Help is highly appreciated.
Best
Urs
Am 15.02.2013 09:37, schrieb Jan-Peter Voigt:
Hello Urs,
On 14.02.2013 20:50, Urs Liska wrote:
Hi list,
maybe it's an academic question, but maybe it also triggers the
curiosity of some Scheme-hackers ;-)
I wouldn't call it academic - if want to build some kind of workflow,
you will face the need for creating several pdfs from one ly-file.
Is it possible to write something (probably a Scheme function) that
lets LilyPond compile a file twice with a different file included or
a different command line option?
... you can process a book object in scheme as often you like
(ly:process-book)
Or is it possible from within a document to launch a second LilyPond
instance with an arbitrary command line option set?
You can play with schemes 'system' command, but I wouldn't use that,
to call lilypond - it is already running.
The background is: I want to create a scenario where I can compile
two different pdf files in one run. The two files should have a
different first-page-number and a different filename suffix. I would
like to have two versions of a score starting on odd and even pages.
(Afterwards I want to include the appropriate file in a LaTeX
document, depending on the page in the document.)
I can imagine doing this with two layout include files (like
'start-odd.ily' and 'start-even.ily') or with a function that
directly writes the right commands depending on command line options
(like '-dstartodd' or 'dstarteven').
So maybe the easiest way would be to have a function that triggers
two separate lilypond runs on the same file, providing different
command line options. I'd then have a main .ly file as usual that
includes one of two style sheets depending on the presence of command
line options, but I would explicitely run lilypond on a 'master' file
that doesn't actually contain music but only controls the build process.
My approach is using a book variable. A scheme-function then sets all
given paper vars in the book paper before it starts processing it with
ly:process-book. The example file creates writeBook.pdf (odd version),
writeBook-even.pdf and writeBook-music.midi.
HTH
Best, Jan-Peter
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user
\version "2.16.0"
% get the current output name
myname = #(ly:parser-output-name parser)
% process a book with ly:book-process
% book - the book
writeBookOddEven =
#(define-void-function (parser location book)
(ly:book?)
; process with first-number 1
(ly:output-def-set-variable! (ly:book-paper book) 'first-page-number 1)
(ly:book-process book #{ \paper {} #} #{ \layout {} #} myname)
; process with first-number 2
(ly:output-def-set-variable! (ly:book-paper book) 'first-page-number 2)
(ly:book-process book #{ \paper {} #} #{ \layout {} #} (format "~A-even" myname)))
% Define a score block
thescore = {
\relative c'' {
c b a g c1
}
}
% Let the first page number be visible (to see the result)
\paper {
print-first-page-number = ##t
}
% Define a book context with the score included
mybook = \book {
\thescore
}
% Call the function
\writeBookOddEven #mybook
\version "2.16.0"
% get the current output name
myname = #(ly:parser-output-name parser)
% process a score with ly:book-process
% score - the score
writeScoreOddEven =
#(define-void-function (parser location score)
(ly:score?)
; The next line is probably what I have to fix:
(ly:book-add-score! XXXX score)
; for the rest of the function I assume I have either to
; - define a variable 'book or
; - change book to the same as XXXX above
;
; process with first-number 1
(ly:output-def-set-variable! (ly:book-paper book) 'first-page-number 1)
(ly:book-process book #{ \paper {} #} #{ \layout {} #} myname)
; process with first-number 2
(ly:output-def-set-variable! (ly:book-paper book) 'first-page-number 2)
(ly:book-process book #{ \paper {} #} #{ \layout {} #} (format "~A-even" myname)))
% Let the first page number be visible (to see the result)
\paper {
print-first-page-number = ##t
}
% Call the function
\writeScoreOddEven
\score {
\relative c'' {
c b a g c1
}
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user