lilypond-user
[Top][All Lists]
Advanced

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

Re: relative music inside music functions explodes when used twice


From: Janek Warchoł
Subject: Re: relative music inside music functions explodes when used twice
Date: Sun, 12 Oct 2014 11:51:36 +0200

Thanks David and Paul - that's helpful.  However, while the situation improved the output is still not what i want:
\version "2.19.13"

voiceDivisi =
#(define-music-function (parser location m1 m2) (ly:music? ly:music?)
   #{
     \tag divI { $m1 }
     \tag divII { $m2 }
     \tag together << { \dynamicUp $m1 } \\ { \dynamicDown $m2 } >>
   #})

music = \relative c' {
  \voiceDivisi {
    c4 d e f
  }{
    a,1
  }
}
musicII = \relative c' {
  \voiceDivisi {
    f4 e d c
  } {
    a1
  }
}

\new Staff \with { instrumentName = "part I" }
\removeWithTag divII.together { \music \musicII }

\new Staff \with { instrumentName = "part II" }
\removeWithTag divI.together { \music \musicII }

\new Staff \with { instrumentName = "combined" }
\removeWithTag divI.divII { \music \musicII }

if i understand correctly, "relativization" happens too late, i.e. after the music is processed by the voiceDivisi function.
How should i work around this?  Maybe instead of using tags i should write a function with a switch statement inside?  I know that i can put \relative command inside \voiceDivisi, but i'd like to avoid this as it would add a lot of typing.

best,
Janek

2014-10-11 21:01 GMT+02:00 David Kastrup <address@hidden>:
Janek Warchoł <address@hidden> writes:

> Hi,
>
> i have a function that takes music as an argument and uses it twice - each
> time with a different tag appended, so that later on i can decide what to
> output:
>
> voiceDivisi =
> #(define-music-function (parser location m1 m2) (ly:music? ly:music?)
>    #{
>      \tag divI \context Voice = "divI" { #m1 }
>      \tag divII \context Voice = "divII" { #m2 }
>      \tag together \context Voice = "both" << #m1 #m2 >>
>    #})
>
> The problem is that when used with relative mode, the output gets crazy:
>
> music = \relative c' {
>   \voiceDivisi {
>     c4 d e f
>   }
>   {
>     e4 f g a
>   }
> }
>
> \new Staff \keepWithTag divI \music
> \new Staff \keepWithTag divII \music
> \new Staff \keepWithTag together \music
>
> (see attachment)
>
> I have checked that the problem disappears when the function uses the
> arguments (m1 and m2) only once.  Is this a bug?

No.

<URL:http://www.lilypond.org/doc/v2.19/Documentation/extending/adding-articulation-to-notes-_0028example_0029>

    In an earlier example, we constructed music by repeating a given
    music argument. In that case, at least one repetition had to be a
    copy of its own. If it weren’t, strange things may happen. For
    example, if you use \relative or \transpose on the resulting music
    containing the same elements multiple times, those will be subjected
    to relativation or transposition multiple times. If you assign them
    to a music variable, the curse is broken since referencing ‘\name’
    will again create a copy which does not retain the identity of the
    repeated elements.

> Can i work around it, or maybe i should be doing this in an altogether
> different way?

Use ly:music-deep-copy on one of the copies.  Better both.  Or write $x
instead of #x in order to get such a copy.

--
David Kastrup


_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user

Attachment: output.png
Description: PNG image


reply via email to

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