Let me know how it works!
A couple more changes:
#(define (octave-up m t)
(let* ((octave (1- t))
(new-note (ly:music-deep-copy m))
(new-pitch (ly:make-pitch
octave
(ly:pitch-notename (ly:music-property m 'pitch))
(ly:pitch-alteration (ly:music-property m 'pitch)))))
(set! (ly:music-property new-note 'pitch) new-pitch)
new-note))
#(define (octavize-chord elements t)
(cond ((null? elements) elements)
((eq? (ly:music-property (car elements) 'name) 'NoteEvent)
(cons (car elements)
(cons (octave-up (car elements) t)
(octavize-chord (cdr elements) t))))
(else (cons (car elements) (octavize-chord (cdr elements ) t)))))
#(define (octavize music t)
(let* ((es (ly:music-property music 'elements))
(e (ly:music-property music 'element))
(name (ly:music-property music 'name)))
(cond ((eq? name 'EventChord)
(ly:music-set-property! music 'elements (octavize-chord es t)))
((pair? es)
(for-each (lambda(x) (octavize x t)) es))
((ly:music? e)
(octavize e))))
music)
octaves = #(define-music-function (parser location arg mus) (integer? ly:music?)
(octavize mus arg))
Now you can do silly things like: \relative c'{ \octaves #2 {c d e f'
g,,} } and it will make the new note two octaves up. I'm not sure why
you'd want that, but it seemed easy enough to do (and takes slightly
less code).
-----Jay