Kieren MacMillan <kie...@kierenmacmillan.info> writes: > Hi again, > >> There is no necessity to return a new NoteEvent; you can just change >> pitch on the existing one. >> >> Music functions are allowed to modify their music arguments in place. > > This is what I have so far, which appears to do what I want: > > %%% 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) > (if (equal? (ly:pitch-notename (ly:music-property m 'pitch)) > (ly:pitch-notename pitchIn)) > (ly:music-set-property! m 'pitch (ly:make-pitch > (ly:pitch-octave (ly:music-property m 'pitch)) (ly:pitch-notename pitchOut) > 0)) > (make-music 'NoteEvent m)) > (ly:message "Not of type")) > m) > music)) > > \adjustPitch ees e \fixed c' { c4 d es f g c' es' } > %%% SNIPPET ENDS > > Comments before I move to the next step…?
This will also adjust eis and eses to e. Note names are numbers and can be compared with = . (make-music 'NoteEvent m) is silly and creates an unnecessary copy. You can just use m instead. If you do, you don't replace any music, so music-map is unnecessary. This can be better done with for-some-music . -- David Kastrup