[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parenthesized second key signature
From: |
Thomas Morley |
Subject: |
Re: Parenthesized second key signature |
Date: |
Thu, 29 Nov 2018 22:10:16 +0100 |
Am Do., 29. Nov. 2018 um 11:57 Uhr schrieb Tyler Mitchell <address@hidden>:
>
> I'm trying to figure out how to add a "parenthesized" second key
> signature to my music, something like this:
>
> https://www.ldx.ca/tmp/paren-key-1.png
>
> I experimented with adding two \key commands one after the other,
> but I get the error:
>
> foo.ly:5:9: warning: Two simultaneous key-change events, junking this
> one
>
> The following comes somewhat close, though there's a bit of an
> undesirable gap between the two key signatures; and I can't figure
> out how to increase the size of the parentheses; and I have to use
> the 'second' key signature throughout to avoid a lot of unneeded
> accidentals; and I wouldn't be able to use a time signature, as it
> would be stuck between these two key signatures.
>
> \version "2.18.2"
>
> \relative c'' {
> \key a \major
> \once\override NoteHead.stencil = ##f
> \once\override Stem.stencil = ##f
> a4
> % Doesn't seem to have any effect:
> \override ParenthesesItem.font-size = #5
> \parenthesize
> \key aes \major
> aes4
> }
>
> \layout { \context { \Staff printKeyCancellation = ##f \remove
> Time_signature_engraver } }
>
> Any suggestions for how I should approach this?
>
> A "stretch goal" would be to have accidentals handled automatically
> in the same way, eg:
>
> https://www.ldx.ca/tmp/paren-key-2.png
>
> But this seems a bit more involved (and unneeded, at least
> initially).
>
> Many thanks,
> Tyler
Hi,
I once made below (here a little lifted up):
\version "2.19.82"
alternativeKey =
#(define-music-function (p-1 p-2 scale-def)
(ly:pitch? ly:pitch? number-pair-list?)
#{
\override Staff.KeySignature.stencil =
#(lambda (grob)
(let* ((staff-space (ly:staff-symbol-staff-space grob))
(line-thickness (ly:staff-symbol-line-thickness grob))
(th line-thickness)
(default-stil (ly:key-signature-interface::print grob))
;; To avoid programming error @code{(markup #:null)} is returned if
;; the scale would not result in a printed KeySignature.
;; TODO: add the other scales: ionian, locrian etc
(stil-to-add
(grob-interpret-markup grob
(if (or (and (= (ly:pitch-notename p-2) 5)
(= (ly:pitch-alteration p-2) 0)
(eq? scale-def minor))
(and (= (ly:pitch-notename p-2) 0)
(= (ly:pitch-alteration p-2) 0)
(eq? scale-def major)))
(markup #:null)
#{
\markup
\score {
{ \key $p-2 $scale-def }
\layout {
\override Staff.TimeSignature #'stencil = ##f
\override Staff.Clef #'stencil = ##f
\override Staff.StaffSymbol #'line-count = #0
indent = 0
}
}
#})
))
(stil-to-add-x-ext (ly:stencil-extent stil-to-add X))
(stil-to-add-y-ext (ly:stencil-extent stil-to-add Y)))
(if (< 0 (interval-length stil-to-add-x-ext))
(if (or (and (= (ly:pitch-notename p-1) 5)
(= (ly:pitch-alteration p-1) 0)
(eq? scale-def minor))
(and (= (ly:pitch-notename p-1) 0)
(= (ly:pitch-alteration p-1) 0)
(eq? scale-def major)))
(bracketify-stencil
(ly:make-stencil
(ly:stencil-expr stil-to-add)
;; left bracket is to far away
;; trimmed a little
(cons
(+ (car stil-to-add-x-ext) (* 0.7 staff-space) )
(cdr stil-to-add-x-ext))
;; adjusting the top and bottom ending of the bracket
(cons
(+ (car stil-to-add-y-ext) (* 0.2 staff-space))
(- (cdr stil-to-add-y-ext) (* 0.5 staff-space))))
Y th (* 2.5 th) th)
(ly:stencil-combine-at-edge
default-stil
X
RIGHT
(bracketify-stencil
(ly:make-stencil
(ly:stencil-expr stil-to-add)
;; left bracket is to far away
;; trimmed a little
(cons
(+ (car stil-to-add-x-ext) (* 0.7 staff-space) )
(cdr stil-to-add-x-ext))
;; adjusting the top and bottom ending of the bracket
(cons
(+ (car stil-to-add-y-ext) (* 0.2 staff-space))
(- (cdr stil-to-add-y-ext) (* 0.5 staff-space))))
Y th (* 2.5 th) th)
1))
default-stil)))
\key $p-1 $scale-def
#})
%%%%%%%%%%%%%%
% EXAMPLES
%%%%%%%%%%%%%%
%%{
\relative c' {
\alternativeKey c f \major
c1
\alternativeKey b c \major
c
\alternativeKey e ees \major
c
\alternativeKey a aes \major
c
\alternativeKey d des \major
c
\alternativeKey g ges \major
c
\alternativeKey c ces \major
c
\alternativeKey ges g \major
c1
\alternativeKey des d \major
c
\alternativeKey aes a \major
c
\alternativeKey ees e \major
c
\alternativeKey bes b \major
c
\alternativeKey f fis \major
c
\alternativeKey ces cis \major
c
}
Current limitation: both keys need to use the same scale, i.e.
supported is neither something like a \minor a \major or other scales
like \dorian etc
HTH,
Harm