Hi Simon,
> Depending on what you’re trying to do it might be worth using tags for this
> as well. Unless of course you’re going to need this transformation a lot.
I was thinking about tags, but hating the concept…
Found this, which seems like it might do the trick (though Jean probably has a
better solution!):
%%% SNIPPET BEGINS
\version "2.25.11"
transposeScale =
#(define-music-function (scaleA scaleB music) (ly:music? ly:music? ly:music?)
(let* ((scaleA (ly:music-property scaleA 'elements))
(scaleB (ly:music-property scaleB 'elements))
(scaleA (map (lambda (x) (ly:music-property x 'pitch)) scaleA))
(scaleB (map (lambda (x) (ly:music-property x 'pitch)) scaleB))
(rootsA (map ly:pitch-notename scaleA)))
(map-some-music
(lambda (m)
(let ((p (ly:music-property m 'pitch)))
(if (not (null? p))
(let* ((nn (ly:pitch-notename p))
(oct (ly:pitch-octave p))
(alt (ly:pitch-alteration p))
(pos (list-index (lambda (x) (= x nn)) rootsA))
(p2 (list-ref scaleA pos))
(oct2 (ly:pitch-octave p2))
(alt2 (ly:pitch-alteration p2))
(p3 (list-ref scaleB pos))
(new-pitch (ly:pitch-transpose p3 (ly:make-pitch (- oct
oct2) 0 (- alt alt2)))))
(ly:music-set-property! m 'pitch new-pitch)
m)
#f)))
music)
music))
melody = {
c'2 g'2 es'2. d'4 |
c' es' d' c' |
b d' g2
}
{ \melody }
{ \transposeScale { c d es f g as b } { c d e f g a b } \melody }
%%% SNIPPET ENDS
Cheers,
Kieren.
______________________________________________
My work day may look different than your work day. Please do not feel obligated
to read or respond to this email outside of your normal working hours.