Often I find it even more useful to do the same with simple substitution
functions, where you easily can apply not only a rhythmic pattern but
also articulations and repeated notes, for example. Here's a simple example
pattern = #(define-music-function (p1 p2 p3)
(ly:pitch? ly:pitch? ly:pitch?)
#{ $p1 2 $p1 8 ( $p2 -.) $p1 -. $p3 -. #} )
\score{
\new Voice \fixed c' {
\pattern c b, e |
\pattern d e f |
\pattern d' e' g |
c'1 }
}
In the above example, I intentionally used \fixed instead of \relative
mode, since otherwise you would get some surprises if one of the pitches
that's repeated in the pattern is specified with a ' or , in relative
mode. If you want to use \relative mode (which I, for example, often
find most convenient) you have to extend the definition of the
substitution function with slightly more Scheme code:
pattern = #(define-music-function (p1 p2 p3)
(ly:pitch? ly:pitch? ly:pitch?)
(make-relative (p1 p2 p3)
(make-event-chord (list p1 p2 p3))
#{ $p1 2 $p1 8 ( $p2 -.) $p1 -. $p3 -. #} ))
\score{
\new Voice \relative c' {
\pattern c b e |
\pattern d e f |
\pattern d' e g, |
c1 }
}
The main disadvantage of this approach to abbreviate repeated patterns
of music is that you only specify the pitch as the argument, which means
that you for example want to add a dynamic indication or similarly to a
note in one of the measures, you cannot do it with
\pattern d e \p f
If, instead, you define a substitution function that takes music instead
of pitches as argument, then you can easily handle such a situation, but
then the note comes not only with pitch (and possible dynamic), but also
with the already specified duration, and you would need more advanced
functions to apply a rhythmic pattern. For completeness, here's anyway
an example of a very simple substitution function that takes music
instead of pitches as argument.
pat = #(define-music-function (m1 m2) (ly:music? ly:music?)
#{ $m1 ( $m2 ) $m1 -. #} )
\score{
\new Voice \fixed c' {
\time 6/8
\pat c8 b, \pat d e \p |
\pat d'4 e' |
g2. }
}
I think it's a pity that we don't have any example like these in the
Learning manual or the Notation reference, since they are so useful and
still simple to use.
/Mats
On 2021-10-07 12:47, Calvin Ransom wrote:
Hi everyone,
I found some code previously made in the mailing list that works for
separating pitch and rhythm.
It still works after 9 years but it cannot print tuplet numbers. Does
anyone know how to do this or create a workaround?
Re: Separating pitch and rhythm (mail-archive.com)
<https://www.mail-archive.com/lilypond-user@gnu.org/msg70504.html>
All help appreciated,
Calvin Ransom
--
=============================================
Mats Bengtsson, Prof.
Information Science and Engineering
School of Electrical Engin. and Comp. Science
Royal Institute of Technology (KTH)
SE-100 44 STOCKHOLM
Sweden
Phone: (+46) 8 790 8463
Email: mats.bengts...@ee.kth.se
WWW: https://www.kth.se/profile/matben/
=============================================