Re: newbie: help with Scheme functions

2020-10-18 Thread Dave Seidel
Thanks, Aaron.

On Sun, Oct 18, 2020 at 4:46 PM Aaron Hill  wrote:

> On 2020-10-18 1:38 pm, Dave Seidel wrote:
> > Very cool, thanks! I'm curious -- could aBook and aBookPart have been
> > written as a lambda, or is it cleaner to use a void function?
>
> (Re-adding the mailing list on the thread for visibility.)
>
> To get the benefits of LilyPond's Scheme functions, you would need to
> use one of the define-*-function family.  Since it is our intention here
> not to return any value, we use the void function.
>
> If you do not need any parameters, you can certainly invoke procedures
> like print-book-with-defaults or ly:book-add-bookpart! without wrapping
> them in a function.  Though, without parameterization, I would wonder
> why you could not just use \book or \bookpart directly.
>
>
> -- Aaron Hill
>


Re: newbie: help with Scheme functions

2020-10-18 Thread Aaron Hill

On 2020-10-18 1:38 pm, Dave Seidel wrote:

Very cool, thanks! I'm curious -- could aBook and aBookPart have been
written as a lambda, or is it cleaner to use a void function?


(Re-adding the mailing list on the thread for visibility.)

To get the benefits of LilyPond's Scheme functions, you would need to 
use one of the define-*-function family.  Since it is our intention here 
not to return any value, we use the void function.


If you do not need any parameters, you can certainly invoke procedures 
like print-book-with-defaults or ly:book-add-bookpart! without wrapping 
them in a function.  Though, without parameterization, I would wonder 
why you could not just use \book or \bookpart directly.



-- Aaron Hill



Re: newbie: help with Scheme functions

2020-10-18 Thread Aaron Hill

On 2020-10-18 7:52 am, Dave Seidel wrote:
Having articulated the question, I figured out that apparently one 
can't
return a \bookpart from a Scheme function, but it's ok to return a 
\score,

so I am restructuring my code.


You cannot return a \book or \bookpart but you can do this:


\version "2.20.0"

aBook =
#(define-void-function
  (name music)
  (symbol? ly:music?)
  (print-book-with-defaults #{
\book {
  \bookOutputSuffix $(symbol->string name)
  \score { $music }
} #}))

\aBook one { c'8 d' ees' f' g' a' bes' c'' }
\aBook two { c'8 des' ees' f' g' aes' bes' c'' }

aBookPart =
#(define-void-function
  (name music)
  (symbol? ly:music?)
  (ly:book-add-bookpart!
   (ly:parser-lookup '$current-book)
   #{ \bookpart {
\markup \italic $(symbol->string name)
\score { $music }
  } #}))

\book {
  \bookOutputSuffix "bookparts"
  \aBookPart three { c'8 d' e' fis' g' a' b' c'' }
  \aBookPart four { c'8 d' e' f' g' a' bes' c'' }
}



-- Aaron Hill



Re: newbie: help with Scheme functions

2020-10-18 Thread Dave Seidel
Having articulated the question, I figured out that apparently one can't
return a \bookpart from a Scheme function, but it's ok to return a \score,
so I am restructuring my code.

On Sun, Oct 18, 2020 at 10:28 AM Dave Seidel  wrote:

> Hi,
>
> I have a multi-section piece, with a master .ly file that uses \include
> for each of the sections of the piece. Each included file more or less
> follows the pattern of the string quartet template that ships with
> Lilypond: a series of macros, one per voice, followed by a \bookpart
> section that builds a StaffGroup, with one Staff per voice. This bookpart
> block is nearly identical in all the included files, with the exception of
> a title string used for "piece" property in in a \header section and also
> also as a \tocItem.
>
> This all works quite well, and I have a nice score with everything. Now
> I'd like to be able to produce parts, and my thought is that rather than
> have a literal bookpart block in each file, I should be able to convert the
> block into a function that takes the title string parameter. If I can get
> this to work, then hopefully I can make the function smart enough to either
> render all voices (for the full score) or just a single voice (for parts).
>
> My problem is that I have defined the function, but I can't invoke it.
> Here's the function:
>
> scoreSection =
> #(define-scheme-function
> (parser location title)
> (string?)
>   #{
> \bookpart {
> \header {
>   piece = #title
> }
> \tocItem \markup #title
> \markup {
>   \italic "Notes other than C have different pitches than notated,
> as indicated by a number"
> }
> \markup {
>   \italic "in parentheses giving an offset in cents relative to
> the notated pitch, shown at"
> }
> \markup {
>   \italic "the first appearance of each note that requires
> alteration."
> }
> \score {
> \new StaffGroup \with { midiInstrument = "cello" } <<
> \new Staff \with { instrumentName = "String 1" }
> << \global \stringOne >>
> \new Staff \with { instrumentName = "String 2" }
> << \global \stringTwo >>
> \new Staff \with { instrumentName = "String 3" }
> << \global \stringThree >>
> \new Staff \with { instrumentName = "String 4" }
> << \global \stringFour >>
> \new Staff \with { instrumentName = "String 5" }
> << \global \stringFive >>
> \new Staff \with { instrumentName = "String 6" }
> << \global \stringSix >>
> \new Staff \with { instrumentName = "String 7" }
> << \global \stringSeven >>
> >>
> \layout { }
> \midi { }
> }
> }
>   #})
>
> And I am trying to invoke it using
>
> \scoreSection #"Part 1"
>
>
> but I keep getting the error messages like this:
>
> Parsing...
> hexany_permutations.ly:127:1: error: bad expression type
>
> \scoreSection #"Part 1"
>
>
> What am I doing wrong? I'm a Lilypond and Scheme newbie (but a programmer
> by trade).
>
> - Dave
>