On 2019-11-14 1:02 am, David Menéndez Hurtado wrote:
This is what I managed to put together, but doesn't quite work. Anyone
can
suggest how to fix it?
\version "2.19.83"
\language "english"
myrithm =
#(define-music-function
(parser location first second third)
(first second third)
(ly:pitch? ly:pitch? ly:pitch?)
#{
#first 8. #second 16 #third 8
#})
\score {
<<
%\new Staff {\relative do' {\myrithm{c, d, e}}}
\new Staff {\time 6/8 \relative c' {c4. c \myrithm a' b e
\myrithm {e
d c} c c c }} %Two different ways of calling it, neither works.
>>
\layout {
}
}
Ooh, you are *so* close!
Firstly, you have a spurious expression of (first second third) before
the type predicate list. This expression is what LilyPond assumes *is*
your type predicate list, so your (ly:pitch? ly:pitch? ly:pitch?) is
being ignored.
You might wonder why are you not getting errors about unbound variables
then. However, the procedures first, second, and third *are* defined
already by SRFI-1 as short-hand for car, cadr, and caddr, respectively.
Secondly, there's a quirk in variable substitution syntax. You need to
use the $var form, so the parser will see the ly:pitch? and ly:duration?
tokens as indicating a single note.
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
}
%%%%
Note you no longer need to explicitly specify the parser and location
arguments for a music function. You can use the global procedures
*parser* and *location* to get those values should you need them.
Also note that I went ahead and kept the parameter names as you had
them. In this situation, it is okay as we have no need to use the
existing definitions of first, second, and third. But in the future,
choose parameter names carefully to avoid hiding something you do end up
needing.
-- Aaron Hill