Hi Kieren,

Am 21.06.24 um 20:25 schrieb Kieren MacMillan:
Hi all,

Thank you for the rapid-iteration non-isochronous Scheme class!  :)

Before I do the next step, is this optimal at this point?

%%%  SNIPPET BEGINS
\version "2.25.11"

adjustPitch =
#(define-music-function (pitchIn pitchOut music) (ly:pitch? ly:pitch? ly:music?)
    (music-map
     (lambda (m)
         (if (music-is-of-type? m 'note-event)
             (ly:message "Pitch is: ~a" (ly:music-property m 'pitch))
             #f)
         m)
     music))

\adjustPitch es es \fixed c' { c4 d e f g a b c' }
%%%  SNIPPET ENDS

While it's possible to use music-map, I'd still recommend
map-some-music: Instead of considering all the various music objects in
a tree (and then specialising to only considering note events),
map-some-music is tailor-made for applications where we want to reach a
specific type of music objects in our recursion and then, in each case,
declaring the job done, i.e. not recursing any further. (The actual
difference should be very small, since also music-map can't help but
stop recursing at note-events, since these don't contain other music
objects.)

But: Whether you use music-map or map-some-music, your helper function
(your lambda) is expected to return the new music into which the given
argument m should be transformed. So in any case, your lambda function
should return music - in the trivial case, it could return m itself
without change, but in the long run, you want to return a new
note-event, i.e. (make-music 'NoteEvent ...).

For this, it will come in handy that it's possible to do

(make-music 'NoteEvent m)

i.e. create a new NoteEvent that takes its 'pitch (which you're going to
overwrite using an additional 'pitch ....), 'articulation etc.
properties from m. (This is explained somewhere in Jean's guide.)

Lukas


Reply via email to