lilypond-user
[Top][All Lists]
Advanced

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

Re: \include problem in Scheme function


From: Urs Liska
Subject: Re: \include problem in Scheme function
Date: Thu, 09 May 2013 15:31:42 +0200

Am Donnerstag, den 09.05.2013, 13:21 +0200 schrieb David Kastrup:
> Urs Liska <address@hidden> writes:
> 
> > Am Donnerstag, den 09.05.2013, 11:38 +0200 schrieb David Kastrup:
> >> Urs Liska <address@hidden> writes:
> >> 
> >> ...
> >
> > ################################################
> >
> > What I didn't achieve so far is how to \include library files.
> 
> Separate \include library
> perhaps?

Thanks, that actually worked, but I had to ensure that the include is
only done when compiled from the subfile (see below), otherwise it would
be included >2.000 times (because there are so many segments in the
score).

> 
> > It seems I can write an \include statement within \book before \score,
> > and it seems to find the file.
> > But it seems there are two problems with that:
> > a)
> > 'music' is parsed before the \include is done within the function, so
> > \origBreak is still 'unknown'
> > b)
> > I get all sorts of messages about syntax errors in the included file, so
> > I have the impression such an \include from within a Scheme function is
> > something quite different from a regular \include in LilyPond mode.
> 
> It is more like an \include from within a \book being something quite
> different.  Also with #{ ... #}, ... is not "top level" but a music
> expression.
> 
> To get top-level, you'll need something like
> 
> $(begin
>   (ly:parser-parse-string (ly:parser-clone parser) "\\include \"zzz.ly\"")
>   #{ \xxx c' c' c' c' #})
> which works reasonably well here.
> 

Thank you.
Took me a while to get it right, but I managed to find the solution
without asking back again :-) 
Here is the solution (relevant excerpts):

% initEdition.ily
% set a flag when this file is read for the first time
#(define-public editionInitialized #t)

% segmentLayout.ily
% set different layout settings
% set a flag
#(define-public isSegment #t

% compileSegment.ily
includeDefaults = 
#(define-void-function (parser location)()
   (if (defined? 'editionInitialized)
    () ; initEdition already read (i.e. we're compiling the score or a part
    (ly:parser-parse-string (ly:parser-clone parser) "\\include 
\"initEdition.ily\"
                                                      \\include 
\"segmentLayout.ily\"")
    ))
\includeDefaults

compileSegment = 
#(define-void-function (parser location segment)
   (ly:music?)
   ; construct book
   (let ((book 
          #{ \book { \score { \new Staff $segment } } #} )) 
         (ly:book-process book #{ \paper {} #} #{ \layout {} #} 
(ly:parser-output-name parser))
    ); close let
) % end function

% 01.ily etc.

\include "compileSegment.ily"

music = { c d e d }

\compileSegment \music

Now I can also use commands in \music that have been defined in
initEdition.ily

######################################################
BUT: One (hopefully last) issue still drives me crazy:

The above version of compileSegment works but lacks the if-condition:

If I wrap the function body in an if condition:

   (if (defined? 'isSegment)
       ((let ((book 
               #{ \book { \score { \new Staff $segment } } #} ))
         (ly:book-process book #{ \paper {} #} #{ \layout {} #} 
(ly:parser-output-name parser))
         ); close let
       ); close if true expression
   ); close if condition

I get an error:

In expression ((let* # #)):
Wrong type to apply: #<unspecified>

What am I doing wrong wiht this (let) block? Can't I use that inside the
'if true' expression?

Urs




reply via email to

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