lilypond-user
[Top][All Lists]
Advanced

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

Re: Inserting alternative endings from a music function


From: Thomas Morley
Subject: Re: Inserting alternative endings from a music function
Date: Wed, 26 Jun 2019 22:53:31 +0200

Am Mi., 26. Juni 2019 um 17:41 Uhr schrieb Leah Velleman
<address@hidden>:
>
> I'm writing a music function to insert a specific pattern of alternative 
> endings with partial measures. Lilypond gives an error suggesting the 
> \alternative block is in the wrong place, even though writing it in the same 
> place by hand gives no error.
>
> For instance, this works as you'd expect:
>
> \version "2.19.83"
> shortMeasure = \set Timing.measureLength = #(ly:make-moment 3/4)
> longMeasure = \set Timing.measureLength = #(ly:make-moment 4/4)
> \relative c' {
>     c4 c c
>     \repeat volta 2 {
>         c | c c c c | c c c c
>     }
>     \alternative {
>         { \shortMeasure c2. }
>         { \longMeasure c1 }
>     }
> }
>
>
> But this, which I'd expect to do the same thing, doesn't:
>
> \version "2.19.83"
> shortMeasure = \set Timing.measureLength = #(ly:make-moment 3/4)
> longMeasure = \set Timing.measureLength = #(ly:make-moment 4/4)
> alts = #(define-music-function (parser location p) (ly:pitch?)
>                 #{ \alternative {
>                         { \shortMeasure $p 2. }
>                         { \longMeasure $p 1 } } #} )
> \relative c' {
>     c4 c c
>     \repeat volta 2 {
>         c | c c c c | c c c c
>     }
>     \alts c
> }
>
>
> Instead, it gives the error "syntax error, unexpected \alternative."
>
> Can anyone give me insight into why?
>
> Thanks,
> Leah
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

`repeat´ and `alternative´ are keywords.
Their usage follows strict rules:
\repeat may be use with
a name (volta, unfold, percent, tremolo)
a number for the repeat-count
the main music
and probably with alternative endings, which must be introduced by
\alternative (in ly-syntax)

But \alternative { ... } is _not_ a musical expression of its own, so
you can't store it in variable or let a music-function return it.

As a side note: because of above all of below is valid syntax:
\repeat volta 4 { b1 }   \alternative { c' cis' d' dis' }
\repeat unfold 4 { b1 }  \alternative { c' cis' d' dis' }
\repeat percent 4 { b1 } \alternative { c' cis' d' dis' }
\repeat tremolo 4 { b1 } \alternative { c' cis' d' dis' }
Ofcourse only the first two return meaningful output. Probably because
nobody suggested so far what the latter ones could mean ...
Anyway, it's valid syntax
sideNoteOff

Back to the problem...
So you can't have a music-function return \alternative. But what does
it actually? It fills the elements-property of 'VoltaRepeatedMusic.
Well, setting such a property a music-function is pretty suitable :)

Leading to:


\version "2.19.83"

shortMeasure = \set Timing.measureLength = #(ly:make-moment 3/4)
longMeasure = \set Timing.measureLength = #(ly:make-moment 4/4)

alts =
#(define-music-function (parser location p mus) (ly:pitch? ly:music?)
  (ly:music-set-property! mus 'elements
    (list
      #{ \shortMeasure $p 2. #}
      #{ \longMeasure  $p 1 #}) )
  mus)


\relative c' {
  c4 c c
  \alts
    %% the pitch-argument:
    c
    %% the music-argument:
    \repeat volta 2 {
      c | c c c c | c c c c
    }
  R1
}


HTH,
  Harm



reply via email to

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