lilypond-user
[Top][All Lists]
Advanced

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

How to correctly use scheme functions and/or math in define-music-functi


From: Matt Huber
Subject: How to correctly use scheme functions and/or math in define-music-function?
Date: Sun, 4 Aug 2019 16:39:23 -0400

What I want to do:
Percussion music has rolls, and while there are many references to typesetting them, I haven't found good references to how to get them to playback in a \midi {} block. My fantasy ideal is to have a "\roll" event so I could do something like this:
sn4 sn4\roll sn4 sn4
and have the "sn4\roll" term effectively translated to "\repeat tremolo 16 sn64". This needs to be a function, as both the drumtype and note value could be different (i.e. I could have a bd8\roll or other duration rolls on other instruments).

I first tried this define-event-function:
Roll = #(define-event-function (myMusic) (ly:music?)
(make-music
'TremoloRepeatedMusic
'elements
'()
'repeat-count
16
'element
(make-music
'NoteEvent
'drum-type
'll
'duration
(ly:make-duration 6)
)
)
)
(I hardcoded the repeat-count and drum-type for testing before trying to dynamically calulate those)
this generates the error:
error: post event function cannot return \repeat tremolo 16 sn64
So my assumption was that the "repeat tremolo" simply can't be in a post event (please correct me if i'm wrong on this)

Changing to a music function:
Roll = #(define-music-function (myMusic) (ly:music?)
(make-music
'TremoloRepeatedMusic
'elements
'()
'repeat-count
16
'element
(make-music
'NoteEvent
'drum-type
'sn
'duration
(ly:make-duration 6)
)
)
)
This works with syntax of "sn4 \roll sn4 sn4 \roll sn4" (i.e. specifying /roll before the note to indicate the next note is a roll) but is still hardcoded values.

To get the make-music function to calculate the repeat-count, it should be (64/duration) since an quarter note equals sixteen 64th notes, an eighth note is eight sixteenth, etc. So I replaced the "16" value with "#(/ 64 ly:music-property myMusic 'duration)" so the function would do the math; this generates the error of:
/usr/local/lilypond/usr/share/lilypond/current/scm/music-functions.scm:1407:9: In procedure ly:repeated-music::unfolded-music-length in _expression_ (ly:music-length music):
/usr/local/lilypond/usr/share/lilypond/current/scm/music-functions.scm:1407:9: Wrong type (expecting exact integer): #(/ 64 ly:music-property myMusic (quote duration))

I'll admit I'm barely competent in Scheme, but this seems to say that the math function is not returning an integer, but I'm not sure how to force that.

Secondly, when I replace "'sn" with "ly:music-property myMusic 'drum-type" I get this error:
fatal error: bad make-music argument: #<Duration 64 >
This i can't even begin to parse to understand what it doesn't like.

I'm lost, and would love some assistance on this. Even if that help is in the form "you're on the completely wrong track, you should do xx.yy.zz instead" that would be great.

Just for completeness, I'm attaching my full sample file in case the error is not in the function itself but because I booched something else in the file.

Thanks!
~Matt

Attachment: sample.ly
Description: Text Data


reply via email to

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