\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