lilypond-user
[Top][All Lists]
Advanced

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

Re: How to correctly use scheme functions and/or math in define-music-fu


From: Matt Huber
Subject: Re: How to correctly use scheme functions and/or math in define-music-function?
Date: Mon, 5 Aug 2019 17:11:44 -0400

Ugh, it does, in fact. I totally missed it in the manual somehow, but you have to include "articulate.ly" and use the \articulate command to make it work.

Thanks!
~Matt

On Mon, Aug 5, 2019 at 12:45 PM Simon Albrecht <address@hidden> wrote:
Hi Matt,

before I dive into your music functions: doesn’t

\version "2.19.83"
{ sn4 4:64 8: 8 }

do what you want?

This is covered in NR (Notation Reference) 1.4.2.b. I haven’t tried it’s
MIDI playback, but since it’s a synonym for the \repeat tremolo 16 sn64
notation, there shouldn’t be a problem.

Best, Simon

On 04.08.19 22:39, Matt Huber wrote:
> 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
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

reply via email to

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