[Top][All Lists]

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

Re: Macro with

From: Aaron Hill
Subject: Re: Macro with
Date: Thu, 14 Nov 2019 03:46:45 -0800
User-agent: Roundcube Webmail/1.3.8

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 =
 (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

reply via email to

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