>
> ---------- Forwarded message ----------
> From: Klaus Blum <benbigno...@gmx.de>
> To: "lilypond-user@gnu.org" <lilypond-user@gnu.org>
> Cc:
> Bcc:
> Date: Fri, 15 May 2020 12:01:06 +0200
> Subject: Current octave in relative mode
> Hi,
>
> I have a function that uses a music expression twice.
> My problem is:
> In relative mode, this expression can lead into a different octave. Then
> the second application of the music expression starts from that new octave.
> (See the last two invocations of "\highlight" in the example below)
>
> Is there something I can do INSIDE my function to prevent this? E.g.
> storing and re-applying the current octave? Thanks for any hint.  :)
>
>
> % ----------------------------------------
> highlight =
> #(define-music-function (mus)
>     (ly:music?)
>     #{
>       <<
>         $mus
>         \makeClusters $mus
>       >>
>     #})
>
> \new Staff {
>    \highlight { c'8 d' e' f' g' a' b' c'' }
>    \relative c' {
>      c1  \highlight { c8 d e f g f e d }
>      c1  \highlight { c8 d e f g a b c }
>      c1  \highlight { f,4 e d c }
>      c1
>    }
> }
> % ----------------------------------------
>
> Cheers,
> Klaus
>
I'm not quite sure what you are after here, except that some things are not
in the octave you want, but I'm not sure which.

In any case, the solution to runaway relatives is actually to use more of
them.

You see, each music expression with curly braces { } may or may not be
distinct.  If you do not say \relative or \fixed, then that music
expression { } does take it's octave from whatever the current octave is,
and whatever follows it starts off from the octave that the music
expression { } ends with.

However, if you use \relative on every one, then:

1) The octave of the notes inside the \relative c' {} you pass to your
function is defined and it does not matter what the current octave is of
the enclosing expression.

But more importantly
2) The entirety of the music expression inside the \relative c' {} you pass
to your function is omitted from the calculation of the octave of what
follows.

So, in your example, if all the c1's are supposed to be the same octave
this is accomplished by just specifying each of the ones you pass to your
function.


\version "2.19.81"
% ----------------------------------------
highlight =
#(define-music-function (mus)
  (ly:music?)
  (make-relative (mus) mus
   #{
     <<
       $mus
       \makeClusters $mus
     >>
   #}))

% Unsafe
\new Staff {
  \highlight { c'8 d' e' f' g' a' b' c'' }
  \relative c' {
    c1  \highlight { c8 d e f g f e d }
    c1  \highlight { c8 d e f g a b c }
    c1  \highlight { f,4 e d c }
    c1
  }
}

% Safe
\new Staff {
  \highlight { c'8 d' e' f' g' a' b' c'' }
  \relative c' {
    c1  \highlight \relative c' { c8 d e f g f e d }
    c1  \highlight \relative c' { c8 d e f g a b c }
    c1  \highlight \relative c' { f,4 e d c }
    c1
  }
}
% ----------------------------------------


HTH,

Elaine Alt
415 . 341 .4954                                           "*Confusion is
highly underrated*"
ela...@flaminghakama.com
Producer ~ Composer ~ Instrumentalist ~ Educator
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to