\version "2.16.0" % tonic is equal - octave is not checked! #(define (ly:tonic=? p1 p2) (or (and (ly:pitch? p1) (ly:pitch? p2) (= (ly:pitch-notename p1) (ly:pitch-notename p2)) (= (ly:pitch-alteration p1) (ly:pitch-alteration p2)) ) (and (eq? #f p1) (eq? #f p2)) )) %%%%%%%%%%% don't watch this hack ... just to display "real" notenames here ... % pitch-notename #(define (nona pp) (if (ly:pitch? pp) (let ((str "?")) (define (search pl pp) (if (pair? pl) (let* ((pr (car pl)) (pq (cdr pr))) (if (ly:tonic=? pq pp) (set! str (car pr)) (search (cdr pl) pp)) ) )) (search pitchnames pp) str ) "?") ) %%%%%%%%%%%%%% % engraver to ... % recognize every change of instrument transposition #(define-public keyT (lambda (context) (let ((tonic (ly:make-pitch 0 0 0)) (sig '()) (last-pitch (ly:make-pitch 0 0 0))) ; no transp assumed `((process-music . ,(lambda (trans) (let ((current-pitch (ly:context-property context 'instrumentTransposition))) ; if pitch (instrument transposition) has changed, create new time signature (if (and (not (ly:tonic=? last-pitch current-pitch)) (ly:pitch? current-pitch)) (begin ; how to create a time signature grob? ; how to create the needed properties ; -> concert pitch = bes maj, instr transp bes ; => should give c maj key sig with key cancelation (let ((time-sig (ly:engraver-make-grob trans 'KeySignature '()))) (ly:message "What to do here?") ) (let ((time-sig (ly:engraver-make-grob trans 'TextScript '()))) (set! tonic (ly:context-property context 'tonic)) (set! sig (ly:context-property context 'keySignature)) (ly:grob-set-property! time-sig 'text (format "~A>~A" (nona last-pitch) (nona current-pitch))) (set! last-pitch current-pitch) ) ) ; if #t ; if #f not set ) ; fi ))) (stop-translation-timestep . ,(lambda (trans) (set! tonic (ly:make-pitch 0 0 0))))) ) )) % use this engraver \layout { \context { \Staff \consists #keyT } } % a test score \score { \relative c'' { \key bes \major bes2 a \transposition bes c^"we should get a c maj with key cancel." b } \layout { } \midi { } }