Thanks. The following works: accOne = #(define-music-function (x ) (ly:pitch?) #{ $x 8 $x 8 #})
My ultimate goal is a function which does the following accTwo = #(define-music-function (x ) (ly:pitch?) #{ $x 8 r8 <($x+4) ($x+7)>8 r8 ($x-5) 8 r8 <($x+4) ($x+7)>8 r8 #}) E.g. \accTwo c expands to { c8r8 <eg>8r8 g,8r8 <eg>8r8 } \accTwo f expands to { f8r8 <ac'>8r8 c8r8 <ac'>8r8 } What material should I read so that I'll be able to achieve this? On Mon, Jan 23, 2023 at 12:36 AM Jean Abou Samra <j...@abou-samra.fr> wrote: > > > > Le 22/01/2023 à 17:33, Jean Abou Samra a écrit : > > > > > > Le 22/01/2023 à 17:20, Darren Ng a écrit : > >> Define substitution function accOne() as: > >> > >> accOne = > >> #(define-music-function > >> (x ) > >> (ly:music?) > >> #{ > >> $x8 $x8 $x8 $x8 $x8 > >> #}) > >> > >> Call accOne() with: > >> > >> \accOne f > >> > >> Expected output is: > >> > >> f8 f8 f8 f8 f8 > >> > >> However, lilypond reports error as follows: > >> > >> GNU LilyPond 2.24.0 (running Guile 2.2) > >> Processing `main.ly' > >> Parsing... > >> accompanimentfunc.ly:19:6: error: Guile signaled an error for the > >> expression beginning here > >> $ > >> x8 $x8 $x8 $x8 $x8 > >> Unbound variable: x8 > >> accompanimentfunc.ly:19:10: error: Guile signaled an error for the > >> expression beginning here > >> $x8 $ > >> x8 $x8 $x8 $x8 > >> Unbound variable: x8 > >> accompanimentfunc.ly:19:14: error: Guile signaled an error for the > >> expression beginning here > >> $x8 $x8 $ > >> x8 $x8 $x8 > >> Unbound variable: x8 > >> accompanimentfunc.ly:19:18: error: Guile signaled an error for the > >> expression beginning here > >> $x8 $x8 $x8 $ > >> x8 $x8 > >> Unbound variable: x8 > >> accompanimentfunc.ly:19:22: error: Guile signaled an error for the > >> expression beginning here > >> $x8 $x8 $x8 $x8 $ > >> x8 > >> Unbound variable: x8 > >> Interpreting music... > >> > >> How to tell lilypond to look for variable "x" and make a 1/8 note out > >> of it, > >> instead of looking for variable "x8"? > > > > > > > > Simply insert a space between "x" and "8". > > > Also, the result will likely still surprise you because you are receiving > the argument "x" as ly:music?, which means a full note, with its duration > (implicitly taken from the previous duration if you call it as \accNote f > rather than \accNote f16 for example), so the "8" parts in the function > are standalone durations, which inherit the pitch from the previous note, > and you get something equivalent to > > f4 f8 f4 f8 f4 f8 f4 f8 f4 f8 > > So better replace ly:music? with ly:pitch?. See also > > https://extending-lilypond.readthedocs.io/en/latest/music.html#argument-type-checking > > Best, > Jean >