I didn't follow all the thread but coming back to the original message, I
have tried to make a little scheme function which seems to work. (see
attached file)
It can be also usefull for changing the mode of a music (major to minor for
example).
Merry Christmas.
Gilles
\version "2.11.63"
%% change \to to want you want.
%% changing the f to fis in \to is equivalent to a traditional \transpose
from = { c d e f g a b }
to = { g a b c d e f }
%% to = { c d ees f g aes b } %% to test a different mode
% If you want to test music with alterations, uncomment that :
%% from = {\from \transpose c cis \from \transpose c ces \from }
%% to = { \to \transpose c cis \to \transpose c ces \to }
#(define (pair<=? pair1 pair2)
(or (< (car pair1) (car pair2))
(and (= (car pair1) (car pair2))
(or (< (cdr pair1) (cdr pair2))
(= (cdr pair1) (cdr pair2))))))
#(define (music->pitch-list music)
(let ((res '()))
(music-filter
(lambda (x)
(let ((p (ly:music-property x 'pitch)))
(if (ly:pitch? p)
(set! res (append res (list (cons (ly:pitch-notename p) (ly:pitch-alteration p))))))
#t))
music)
res
))
customTranspose = #(define-music-function (parser location music) (ly:music?)
(let ((from-list (music->pitch-list from))
(to-list (music->pitch-list to)))
(music-map
(lambda (event)
(let ((p (ly:music-property event 'pitch)))
(if (ly:pitch? p)
(let* ((pitch-data (cons (ly:pitch-notename p) (ly:pitch-alteration p)))
(data-list (member pitch-data from-list))
(data-index (if data-list
(- (length from-list)(length data-list))
(ly:error " ~a don't define in from music" p)))
(new-pitch-data (list-ref to-list data-index ))
(new-pitch (if (pair<=? new-pitch-data pitch-data)
(ly:make-pitch
(ly:pitch-octave p)
(car new-pitch-data)
(cdr new-pitch-data))
(ly:make-pitch
(1- (ly:pitch-octave p))
(car new-pitch-data)
(cdr new-pitch-data)))))
(ly:music-set-property! event 'pitch new-pitch)))
event))
music)))
% If you want alterations in music, you have to redefine \from and \to
music = \relative {
c e g c b a g f e d c b c1
}
\score {
<<
\new Staff \music
\new Staff \customTranspose \music
>>}
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user