lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom key signature stencils, differentiating major and minor keys


From: Paul Morris
Subject: Custom key signature stencils, differentiating major and minor keys
Date: Sat, 10 Nov 2012 11:59:21 -0500

Greetings everyone,  

I am trying to override the key signature stencil with a custom stencil whose 
appearance and position will depend on the key.  So far I can determine the key 
by looking at the "alteration-alist" property of the key-signature-interface 
[1] with the KeySignature grob [2].  Basically, looking at the type and 
position of the accidental sign that is furthest to the right in the key 
signature, will tell you which key it is.  (See snippet below.)  

With the custom stencils I would like to indicate whether a key is major or 
minor, and also indicate the tonic note of the key (which can't be determined 
unless you know whether the key signature is major or minor).  So my question 
is whether it is possible to tell whether a given key is major or minor based 
on the KeySignature grob (for example, C major vs A minor).  

Since standard key signatures do not indicate whether a key is major or minor, 
I realize that this may not be possible. 

From what I can tell, none of the KeySignature grob properties indicate whether 
the key is major or minor.

I noticed that the Key_engraver [3] has a tonic property (a pitch value that is 
the "tonic of the current scale") which seems like it might help, but if so, 
I'm not sure how to go about using it for this.

I searched the LSR and the user list archives but did not find anything on this 
particular topic.

Thanks in advance for any help or advice on this!
-Paul


[1] 
http://lilypond.org/doc/v2.16/Documentation/internals/key_002dsignature_002dinterface
[2] http://lilypond.org/doc/v2.16/Documentation/internals/keysignature
[3] http://lilypond.org/doc/v2.16/Documentation/internals/key_005fengraver



%% Begin Snippet
%% Still very much a work in progress.  

%% Currently it breaks with the keys of C major and A minor 
%% (since the alteration-alist is empty for those keys).  

%% Eventually different stencils and/or vertical positions would be defined 
%% for each key, "someStencil" is just a placeholder

\version "2.16.0"

someStencil = #(make-circle-stencil .5 .25 #f)
someOtherStencil = #(make-circle-stencil .5 .25 #t)

keysigger =
#(lambda (grob)
         (let* (
                (accsign  (cdr (list-ref (ly:grob-property grob 
'alteration-alist) 0)))
                (pstn     (car (list-ref (ly:grob-property grob 
'alteration-alist) 0)))
        )

        (cond 
                ((= accsign 1/2)        ;; SHARP KEYS
                        (cond 
                                ((= pstn 6) someStencil)
                                ((= pstn 2) someOtherStencil)
                                ((= pstn 5) someStencil)
                                ((= pstn 1) someOtherStencil)
                                ((= pstn 4) someStencil)
                                ((= pstn 0) someOtherStencil)
                                ((= pstn 3) someStencil)
                        )
                )
                ((= accsign -1/2)       ;; FLAT KEYS
                        (cond
                                ((= pstn 3) someOtherStencil)
                                ((= pstn 0) someStencil)
                                ((= pstn 4) someOtherStencil)
                                ((= pstn 1) someStencil)
                                ((= pstn 5) someOtherStencil)
                                ((= pstn 2) someStencil)
                                ((= pstn 6) someOtherStencil)
                        )       
                )
                (else someStencil) ;; C MAJOR, A MINOR
        ))
)

%% Sharp Keys
<<
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key g \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key d \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key a \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key e \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key b \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key fis \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key cis \major 
  c'4 
}
>>

%% Flat Keys
<<
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key f \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key bes \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key ees \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key aes \major 
  c'4 
}
\new Staff \with {  \override KeySignature #'stencil = #keysigger }
{ 
  \key des \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key ges \major 
  c'4 
}
\new Staff \with { \override KeySignature #'stencil = #keysigger }
{ 
  \key ces \major 
  c'4 
}
>>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]