lilypond-user
[Top][All Lists]
Advanced

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

Re: Re: Macro with pitches as parameters


From: Mats Bengtsson
Subject: Re: Re: Macro with pitches as parameters
Date: Thu, 14 Nov 2019 15:42:50 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0


On 2019-11-14 12:46, Aaron Hill wrote:
On 2019-11-14 1:02 am, David Menéndez Hurtado wrote:
>> I am transcribing a piece that is filled with the rhythmic motif "8. 16 8" at different pitches. Being a LaTeX user, I want to write a macro like \myrithm{c a g}. I found the documentation for Scheme functions, and how to edit whole music sections, but nothing on how to insert a fixed number of pitches. As I understand it, ly:music is an arbitrary music expression, so I cannot restrict it to just three pitches.
...
Ooh, you are *so* close!

...
Here's the working version:

%%%%
\version "2.19.83"

myRhythm = #(define-music-function
  (first second third)
  (ly:pitch? ly:pitch? ly:pitch?)
  #{ $first 8. $second 16 $third 8 #})

\fixed c' {
  \time 6/8
  \myRhythm g d g
  \myRhythm e d g
  \myRhythm g a b
  \myRhythm c' a b
}
%%%%

By coincidence, I encountered the same problem and came up with the same solution, the other week. I'm surprised that we don't have any such example in the manual since it really is very useful and at the same time illustrates the power of combining define-music-function with embedded LilyPond syntax. In LSR you can actually find a few more examples that seem relevant, like http://lsr.di.unimi.it/LSR/Item?id=346, but as far as I can see, the same could equally well be implemented like your example above without requiring any Scheme competence. The only LSR example that resembles the one above is http://lsr.di.unimi.it/LSR/Item?id=302, but it doesn't illustrate the possibility to include multiple pitches in the pattern.

In my own example, the same pitch is repeated multiple times in the rhythmic/melodic pattern, like

\version "2.19.82"

myPattern = #(define-music-function (p1 p2 p3 p4)
    (ly:pitch? ly:pitch? ly:pitch? ly:pitch?)
    #{ $p1 4 ( $p2 8 ) \acciaccatura $p2 $p3 $p3 16 $p4 $p3 8 #})

which can be successfully used like

\fixed c' {
  \time 6/8
  \myPattern a c' b ais |
  \myPattern a f' e' dis' |
}

However, it doesn't work in \relative mode, since the octave change is applied every time the same pitch is repeated. Since I'm used to writing in \relative mode and since \relative mode is very well suited to this violin music that spans several octaves but often moves in small intervals, I would have liked to write the above example using

\relative c'' {
  \time 6/8
  \myPattern a c b ais |
  \myPattern a f' e dis |
}

but since the second pitch of the example is repeated in the pattern, the second occurrence of f' raises the octave again, which isn't what is wanted. Searching the mailing list archives and the regression test examples for 2.19, I finally came up with

\version "2.19.82"

myPattern = #(define-music-function (p1 p2 p3 p4)
          (ly:pitch? ly:pitch? ly:pitch? ly:pitch?)
          (make-relative (p1 p2 p3 p4) (make-event-chord (list p1 p2 p3 p4))
    #{ $p1 4 ( $p2 8 ) \acciaccatura $p2 $p3 $p3 16 $p4 $p3 8 #}))

\relative c'' {
  \time 6/8
  \myPattern a c b ais |
  \myPattern a f' e dis |
}

Adding occasional dynamic indications or articulations could be done using the standard trick of attaching them to an empty chord at the suitable location, like

\relative c'' {
  \time 6/8
  <>\f \myPattern_rel  a c b ais |
  <<{\myPattern_rel a f' e dis } {s4. <>^\trill }>>
}

(not extremely convenient but still doable.)

My main remaining problem is how to add a reminder accidental or cautionary accidental on a pitch. Even if it was possible, you might only want it on the first occurrence of the note so it's more like an unsolvable problem. Probably the famous edition engraver can do the job, but I've never taken the effort to learn how to use that beast, so for the places where I urgently need a reminder accidental in the middle of the pattern, I will not use the macro.

    /Mats





reply via email to

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