Hi Jonathan, here's the function I proposed earlier. it takes a number
as an argument: if you want to add upper octaves, specify #1, if you
want lower octaves, type #-1. Its very dirty and it suffers from the
same bug (i.e. it's probably a bad idea to use it inside a \relative
block when you have to use commas and single quotes), but hopefully
someone will clean the code and address the issue.
#(define (octave-up m t)
(make-music 'NoteEvent
'duration (ly:music-property m 'duration)
'pitch (ly:make-pitch (+ t (ly:pitch-octave
(ly:music-property m 'pitch)))
(ly:pitch-notename (ly:music-property m 'pitch))
(ly:pitch-alteration (ly:music-property m 'pitch)))))
#(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?)
(if (> arg 0) (octavize mus 1) (octavize mus -1)))
\relative { c d e \octaves #-1 { f g c }}
Cheers,
Valentin