On Nov 11, 2012, at 7:38 AM, MING TSANG <tsan...@rogers.com> wrote:

> Hi, Paul:  Thank you for the custom key signature.  I have been dreaming this 
> for sometime, but hesitate to ask lilypond user community.  I have been using 
> circle of fifths to identify the key signature.

Hi Ming,  I'm glad you find it useful.


> You mention this custom key signature can be adapted to print above the clef 
> sign.  I am not a programmer, so not able to change (adapt).
> 
> Questions:  
> 1. Print the custom key signature above the clef sign
> 2. Is it possible to retain the traditional key signature then print the 
> custom key signature above
> 3. Can this custom key signature use with \include "english.ly" or \language 
> english?
> 4. Can ais (as in english) print as A# Major & f# Minor; same for flat as 
> well?

The new code below will print the name of the key above the standard key 
signature.  It now uses actual sharp and flat signs in the key names ("Fb" 
rather than "Fes"), and the text is smaller.  

It should work fine with \include "english.ly" or \language english, but I have 
not tried it.  You can edit the names of the keys by changing the relevant text 
in the following parts of the code.  For example change:

  #{ \markup \magnify #0.7 {B Major} #

  #{ \markup \magnify #0.7 {G\raise #.6 {\sharp} Minor} #

to
 
  #{ \markup \magnify #0.7 {B M} #

  #{ \markup \magnify #0.7 {G\raise #.6 {\sharp} m} #

for an abbreviated text ("B M"  and "G# m" instead of "B Major" and "G Minor").


I think this has reached the "potentially useful" stage, for anyone who is 
still learning the key signatures or wants to know explicitly whether keys are 
major or minor.

(Ideally it would be better if it did not print the name of the key signature 
above a key cancellation, as with the transition from A# Minor to F Major in 
the code below.  I would have to figure out how to somehow access whether it 
was engraving a key-cancellation or a key-signature.)

Any suggestions for improvement are welcome.  I am an amateur hack at this and 
stand on the shoulders of giant snippets.  :-)

(Like this one http://lsr.dsi.unimi.it/LSR/Item?id=233 for this most recent 
version).

Cheers,
-Paul


%%  Begin snippet

\version "2.16.0"

#(define Custom_key_sig_engraver
   (make-engraver
    (acknowledgers
     ((key-signature-interface engraver grob source-engraver)
      (let* (
                          (context (ly:translator-context engraver))
                          (tonic-pitch (ly:context-property context 'tonic))
                          (tonic-semi (modulo (ly:pitch-semitones tonic-pitch) 
12))
                          (acclist  (ly:grob-property grob 'alteration-alist))
                          (accsign  (if (null? acclist) 0 (cdr (list-ref 
acclist 0))))
                          (psn          (if (null? acclist) 0 (car (list-ref 
acclist 0))))
                          (sig-stencil  (ly:key-signature-interface::print 
grob))
                        )
                        (cond 
                        ((= accsign 0) 
                                (if (= tonic-semi 0) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil  1 1 
                                                                
(grob-interpret-markup grob #{ \markup \raise #2.3 \magnify #0.7 {C Major} #}) 
.5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \raise #2.3 \magnify #0.7 {A Minor} #}) 
.5 ))
                                ))
                        ((= accsign 1/2)        ;; SHARP KEYS
                          (cond 
                                ((= psn 3) 
                                        (if (= tonic-semi 7) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {G Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {E Minor} #}) .5 ))
                                ))
                                ((= psn 0) 
                                        (if (= tonic-semi 2) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {D Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {B Minor} #}) .5 ))
                                ))
                                ((= psn 4) 
                                        (if (= tonic-semi 9) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {A Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {F\raise #.6 {\sharp} 
Minor} #}) .5 ))
                                ))
                                ((= psn 1) 
                                        (if (= tonic-semi 4) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {E Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {C\raise #.6 {\sharp} 
Minor} #}) .5 ))
                                ))
                                ((= psn 5) 
                                        (if (= tonic-semi 11)
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {B Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {G\raise #.6 {\sharp} 
Minor} #}) .5 ))
                                ))
                                ((= psn 2) 
                                        (if (= tonic-semi 6) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {F\raise #.6 {\sharp} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {D\raise #.6 {\sharp} 
Minor} #}) .5 ))
                                ))
                                ((= psn 6) 
                                        (if (= tonic-semi 1) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {C\raise #.6 {\sharp} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {A\raise #.6 {\sharp} 
Minor} #}) .5 ))
                                ))
                          )
                        )
                        ((= accsign -1/2)       ;; FLAT KEYS
                          (cond
                                ((= psn 6) 
                                        (if (= tonic-semi 5) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {F Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {D Minor} #}) .5 ))
                                ))
                                ((= psn 2) 
                                        (if (= tonic-semi 10) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {B\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {G Minor} #}) .5 ))
                                ))
                                ((= psn 5) 
                                        (if (= tonic-semi 3) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {E\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {C Minor} #}) .5 ))
                                ))
                                ((= psn 1) 
                                        (if (= tonic-semi 8) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {A\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {F Minor} #}) .5 ))
                                ))
                                ((= psn 4) 
                                        (if (= tonic-semi 1) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {D\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {B\raise #.4 {\flat} 
Minor} #}) .5 ))
                                ))
                                ((= psn 0) 
                                        (if (= tonic-semi 6) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {G\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {E\raise #.4 {\flat} 
Minor} #}) .5 ))
                                ))
                                ((= psn 3) 
                                        (if (= tonic-semi 11) 
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {C\raise #.4 {\flat} 
Major} #}) .5 ))
                                                (ly:grob-set-property! grob 
'stencil 
                                                        
(ly:stencil-combine-at-edge sig-stencil 1 1 
                                                                
(grob-interpret-markup grob #{ \markup \magnify #0.7 {A\raise #.4 {\flat} 
Minor} #}) .5 ))
                                ))
                          )     
                        )
                )
)))))

\layout {
  \context {
    \Staff
    \consists \Custom_key_sig_engraver
  }
}

\new Staff {
  \key c \major
  c'1
  \key a \minor
  a'1
  \key g \major 
  g'1 
  \key e \minor
  e'1
  \key d \major 
  d'1
  \key b \minor
  b'1 
  \key a \major 
  a'1 
  \key fis \minor
  fis'1
  \key e \major 
  e'1
  \key cis \minor
  cis'1
  \key b \major 
  b'1 
  \key gis \minor
  gis'1
  \key fis \major 
  fis'1 
  \key dis \minor
  dis'1
  \key cis \major 
  cis'1
  \key ais \minor
  ais'1
  \key f \major 
  f'1
  \key d \minor
  d'1
  \key bes \major 
  bes'1
  \key g \minor
  g'1
  \key ees \major 
  ees'1
  \key c \minor
  c'1
  \key aes \major 
  aes'1
  \key f \minor
  f'1
  \key des \major 
  des'1
  \key bes \minor
  bes'1
  \key ges \major 
  ges'1
  \key ees \minor
  ees'1
  \key ces \major 
  ces'1
  \key aes \minor
  aes'1
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to