Lilypond function; add a rhythm to a note

256 views Asked by At

How can you write a Lilypond function that takes in a note and outputs a note with a rhythm? say: input: c' output: c'8 c'16 c'

1

There are 1 answers

3
PeterBjuhr On

In the LilyPond documentation you can find this example:

rhythm =
#(define-music-function (parser location p) (ly:pitch?)
   "Make the rhythm in Mars (the Planets) at the given pitch"
  #{ \tuplet 3/2 { $p 8 $p $p } $p 4 $p $p 8 $p $p 4 #})

\new Staff {
  \time 5/4
  \rhythm c'
  \rhythm c''
  \rhythm g
}

enter image description here

Hopefully that can be adapted to do what you want! Replace the Mars rhythm with your own. And please note that a space is needed between the variable $p and the durations.