Hi Kieren,

just stumbled across this thread. I once was trying to create an engraver, that recognizes transposition/instrument changes and inserts a time signature there. (IIRC it was a piece with a change between oboe and english horn) In the end I inserted tagged key-sigs, whenever I inserted an instrumentSwitch. But perhaps now is the time to look at this again?

Cheers, Jan-Peter

Am 16.01.2013 06:43, schrieb Kieren MacMillan:
Hi Jay,

There's this: http://lsr.dsi.unimi.it/LSR/Item?id=697 which is useful
when the transposition changes mid-piece (like for clarinets, horns,
and trumpets). Also you don't have to think about the 'from' pitch.
You only need the 'to' pitch.
That doesn't seem to handle key signatures very well — is there a workaround?

Thanks,
Kieren.
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


\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 { }
}

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to