I think this got lost in the ether earlier in the week when the lists
were down, but someone might find the attached solution helpful.  It is
good enough for my purposes.  Grateful acknowledgments to Pierre
Perol-Schneider, Frank Z., and Urs Liska, all of whom unknowingly helped
with the solution.

-- Graham

On Wed, 2015-09-30 at 13:58 +0100, Graham King wrote:

> In transcribing a piece of renaissance music, I am trying to refine
> the following key signature:
> 
> \version 2.19.21
> \relative c' {
>   \set Staff.keyAlterations = #`(((-1 . 6) . ,NATURAL)
>                                  (( 0 . 6) . ,FLAT))
>   R1 b2 bes b' bes
> }
> 
> Ideally, the flat in the key signature should have a ledger line, and
> should be vertically aligned with the natural sign.  (There is a
> corresponding keysig in bass clef which also needs this alignment)

Oops, of course I meant that the _natural_ sign should have a ledger
line (in treble clef).

> 
> I have looked at:
> 1) The re-writing of the key signature engraver in Scheme:
> https://lists.gnu.org/archive/html/lilypond-user/2015-08/msg00429.html
> 
> 
> 2) The addition of ledger lines to a key signature:
> https://lists.gnu.org/archive/html/lilypond-user/2014-11/msg00454.html
> 
> 
> 3) The Notation Reference
> http://lilypond.org/doc/v2.19/Documentation/notation/displaying-pitches#key-signature
>  and the sections of the Internals Reference that this refers to;
> 
> and I confess that I'm floundering a bit.  Well, more than a bit.  
> 
> This specific issue is quite common in early music, where the composer
> uses the hard hexachord.
> 
> Grateful for any help/guidance !
> 
> -- Graham 
> 
> _______________________________________________
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user
\version "2.19.21"

%{
    Print key signatures for transcriptions of early music in 
    which hard and soft hexachords are juxtaposed.  In other 
    words, in the absence of accidentals, B is natural or flat
    depending on its octave.

    Acknowledgments to:
    * Urs Liska 
    
(http://lilypondblog.org/2014/03/music-functions-2-start-doing-something-useful/)
    for drawing my attention to \temporary \override ... \revert.
    * Pierre Perol-Schneider 
    (http://lists.gnu.org/archive/html/lilypond-user/2014-11/msg00454.html)
    for the lambda function on which this code is based.

    To do: 
    * This code is ripe for refactoring, but might be 
    easier to read in its present form.  If refactored,
    the interface could be something like:
    \keysigBfaBmi "clef" "upperB" "lowerB" { ...music... }
      where: clef   := treble | bass
             upperB := natural | flat
             lowerB := natural | flat
    * Add some error-checking.
%}

keysigBfaBmiTreble = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-1 . 6) . ,NATURAL)
                                     (( 0 . 6) . ,FLAT))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        \translate #'(0 . -3.5) {
                        \combine 
                        \translate #'(0 . 3.5)  
                        \musicglyph #"accidentals.flat"
                          \combine
                          \translate #'(-.4 . .5)
                          \override #'(thickness . 2)
                          \draw-line #'(1.5 . 0)
                          \musicglyph #"accidentals.natural"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )

keysigBfaBmiBass = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-2 . 6) . ,FLAT)
                                     (( -1 . 6) . ,NATURAL))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        {
                        \combine 
                        \translate #'(0 . -1)  
                        \musicglyph #"accidentals.flat"
                        \translate #'(0 . 2.5)
                        \musicglyph #"accidentals.natural"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )

keysigBfaBfaTreble = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-1 . 6) . ,FLAT)
                                     (( 0 . 6) . ,FLAT))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        \translate #'(0 . -3.5) {
                        \combine 
                        \translate #'(0 . 3.5)  
                        \musicglyph #"accidentals.flat"
                          \combine
                          \translate #'(-.4 . .5)
                          \override #'(thickness . 2)
                          \draw-line #'(1.5 . 0)
                          \musicglyph #"accidentals.flat"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )

keysigBfaBfaBass = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-2 . 6) . ,FLAT)
                                     (( -1 . 6) . ,FLAT))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        {
                        \combine 
                        \translate #'(0 . -1)  
                        \musicglyph #"accidentals.flat"
                        \translate #'(0 . 2.5)
                        \musicglyph #"accidentals.flat"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )

keysigBmiBmiTreble = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-1 . 6) . ,NATURAL)
                                     (( 0 . 6) . ,NATURAL))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        \translate #'(0 . -3.5) {
                        \combine 
                        \translate #'(0 . 3.5)  
                        \musicglyph #"accidentals.natural"
                          \combine
                          \translate #'(-.4 . .5)
                          \override #'(thickness . 2)
                          \draw-line #'(1.5 . 0)
                          \musicglyph #"accidentals.natural"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )

keysigBmiBmiBass = 
  #(define-music-function (P L my-music)
                          (ly:music?)
    #{
      \set Staff.keyAlterations = #`(((-1 . 6) . ,NATURAL)
                                     (( 0 . 6) . ,NATURAL))
      \set Staff.printKeyCancellation = ##f 
      \temporary \override Staff.KeySignature.stencil =
      #(lambda (grob) (grob-interpret-markup grob
                      #{
                        \markup
                        {
                        \combine 
                        \translate #'(0 . -1)  
                        \musicglyph #"accidentals.natural"
                        \translate #'(0 . 2.5)
                        \musicglyph #"accidentals.natural"
                        }
                      #}))
    #my-music
    \revert Staff.KeySignature.stencil
    #}
  )


% Test harness begins...

% N.B. Important to test:
% 1. Change of keysig;
% 2. Continuation of keysig onto new line;
% 3. Cancellation of keysig, and any residual effects.

%{ % begin block comment...

music = {
  b,2 bes b' bes
  \break
  b,2 bes b' bes
}

\relative c'' {
  \keysigBfaBmiTreble \music
  
  \keysigBfaBfaTreble \music
  
  \keysigBfaBmiTreble \music
  
  \keysigBmiBmiTreble \music
  
  \key f \major \music
  
  \clef "bass"
  
  \keysigBfaBmiBass { b,1 \music }
  
  \keysigBfaBfaBass \music
  
  \keysigBfaBmiBass \music
  
  \keysigBmiBmiBass \music
  
  \key f \major \music
}  

\layout {
  ragged-right = ##t
}
%}
% ... Test harness ends

Attachment: BfaBmi_keysigs.pdf
Description: Adobe PDF document

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

Reply via email to