lilypond-user
[Top][All Lists]
Advanced

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

Re: bookparts


From: Jan-Peter Voigt
Subject: Re: bookparts
Date: Tue, 6 Mar 2018 13:46:07 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Am 06.03.2018 um 13:12 schrieb David Kastrup:
IISC a major change to the codebase would be needed to allow something
like this: \bookpart { music = { c''4 } { \music } }
but there are a lot users who would like to use it this way.
I don't want to talk about scopes and coding style, but want to show
how I deal with it:
Using void-functions is a great thing because the can be called
anywhere. So if you want to define something inside a file that is to
be included inside curly brackets you can use a function like this:
--------------------------------------
\version "2.19.80"

def = #(define-void-function (sym val)(symbol? scheme?)
          (ly:parser-define! sym val))

\bookpart {
   \def music { c''4 } % this might be part of an included file
   { \music }
}
It would be utterly trivial to make assignments work like that void
function in the parser.
OK> It still would not introduce scoping, so people would be surprised that
assignments made in one book overrode assignments in an earlier book or
at top level.

People would expect to set the same named variables in different books
to different values and it would not work.
Essentially I talked about that in the second paragraph.

A generic function like "def" is about as useful as a generic opener for
child-proof bottle caps: the only person needing it is one you don't
want to have it.
You may be right. But still, *sometimes* I use such a function for files which are included and which *might* throw an error otherwise.

Now books and bookparts actually have a \header with associated scopes.
Anything wrong with doing assignments in there?
That might look like this?
------------------------------
\version "2.19.80"

headerVal =
#(define-scheme-function (name)(symbol?)
   (let ((alist (ly:module->alist (ly:book-header $current-bookpart))))
     (assoc-get name alist)
     ))

\bookpart {
  \header {
    thevoice = \relative { a'4 c g f }
    thelyrics = \lyricmode { la la la la }
  }
  <<
    \new Voice = "heinz" { \headerVal thevoice }
    \new Lyrics \lyricsto "heinz" { \headerVal thelyrics }
  >>
}
----------------------------------

This might be useful and essentially lead to something. Now, I am used to my own toolchain and prefer delegating score- and bookpart-creation to music- and scheme-functions. And I really don't like using the header for content. (Btw. I didn't follow the whole thread so maybe nobody was asking for that)

Jan-Peter




reply via email to

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