Re: Custom key signature stencils, differentiating major and minor keys

2013-12-16 Thread Paul Morris
Hanno wrote
> I'm looking for a way to include the key in my title,
> because currently I write this manually into the subtitle-field
> and keep forgetting to change this after transposing.

Hi Hanno,  Unfortunately I don't know of a way to do this.  It seems that
the title is processed before any key engravers are called, so there is no
way to access what key you've set in the music when the title is generated.  

I think your best option is to figure out how to remember to change the key
indication manually. 

Below is a revision of my code so that it just assembles the key name as a
string and assigns it to the variable "key-name" (and prints this to the log
so you can see that that part works). The key in the title has already been
generated so it is not changed.  (I also cleaned the code up a bit, using
case instead of cond, getting rid of set!, etc.).

-Paul


\version "2.17.95"

% a variable to hold the key text
key-name = "Key Text"

#(define Custom_key_engraver
   (make-engraver
(acknowledgers
 ((key-signature-interface engraver grob source-engraver)
  (let* ((grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta)
'name)))
 (context (ly:translator-context engraver))
 (tonic-pitch (ly:context-property context 'tonic))
 (tonic-num (ly:pitch-notename tonic-pitch))
 (acc-list (ly:grob-property grob 'alteration-alist))
 (acc-type (if (null? acc-list) 0 (cdr (list-ref acc-list 0
 (acc-count (length acc-list))
 (maj-num (case acc-type
;; no sharps or flats
((0) 0)
;; sharp keys
((1/2) (case acc-count
 ((1) 4)
 ((2) 1)
 ((3) 5)
 ((4) 2)
 ((5) 6)
 ((6) 3)
 ((7) 0)))
;; flat keys
((-1/2) (case acc-count
  ((1) 3)
  ((2) 6)
  ((3) 2)
  ((4) 5)
  ((5) 1)
  ((6) 4)
  ((7) 0)
 (mode-num (modulo (- tonic-num maj-num) 7))
 (key-letter (case tonic-num
   ((0) "C " )
   ((1) "D " )
   ((2) "E " )
   ((3) "F " )
   ((4) "G " )
   ((5) "A " )
   ((6) "B " )))
 (tonic-acc (if (pair? (assq tonic-num acc-list))
(if (= acc-type 0.5) "Sharp " "Flat ")
""))
 (key-mode (case mode-num
 ((0) "Major")
 ((1) "Dorian")
 ((2) "Phrygian")
 ((3) "Lydian")
 ((4) "Mixolydian")
 ((5) "Minor")
 ((6) "Locrian")))
 (full-key-text (string-append key-letter tonic-acc key-mode)))

;; display the key in the log
;; (display full-key-text)(newline)
(set! key-name full-key-text)
(display key-name)(newline))

\layout {
  \context {
\Staff
\consists \Custom_key_engraver
  }
}

\new Staff \relative c'' {

  \key c \major
  c1
  \key a \minor
  a1
  \key a \major
  a1
  \key fis \minor
  fis1
  \key ees \major
  ees1
  \key c \minor
  c'1
  \key c \dorian
  c1
  \key c \phrygian
  c1
  \key c \lydian
  c1
  \key c \mixolydian
  c1
  \key c \locrian
  c1
}

\header {
  title = #(string-append "Title Text, " key-name)
}



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Custom-key-signature-stencils-differentiating-major-and-minor-keys-tp136158p156000.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Custom key signature stencils, differentiating major and minor keys

2013-11-29 Thread Hanno
Hi,

looks like great work in my beginner's eyes!

I'm looking for a way to include the key in my title,
because currently I write this manually into the subtitle-field
and keep forgetting to change this after transposing.

Any hint would be welcome,
greetings!



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Custom-key-signature-stencils-differentiating-major-and-minor-keys-tp136158p154614.html
Sent from the User mailing list archive at Nabble.com.

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-12-06 Thread Paul Morris
On Dec 5, 2012, at 5:58 PM, Thomas Morley  wrote:

> Sorry to send this again, forgot to cc the list.
> 
> 2012/12/5 Thomas Morley :
>> 2012/12/5 Paul Morris :
>>> On Dec 4, 2012, at 7:27 PM, Thomas Morley  
>>> wrote:
>> [...]
 May I ask, if you could add a commented 2.16-version of it?
 Although your code will work for 2.16.1 up to 2.17.6 (so far I
 tested), it would be nice to show the new make-engraver-macro and the
 possibility of #{ #} in scheme-code, once the LSR is updated.
>>> 
>>> Ok, I just uploaded a new version with the 2.16 code commented out.  The 
>>> make-engraver-macro is quite nice.
>> 
>> Thanks for doing this!

Glad to help!


>>> It was a little tricky figuring out the #{ \markup ... #} syntax after 
>>> getting used to the scheme version.  If it were not for the need to 
>>> demonstrate the new syntax (which I'm happy to help with) I'd probably just 
>>> stick with the scheme version at this point.
>> 
>> I know what you mean. :)
>> I tend to use only scheme-syntax in longer scheme-expressions.
>> It's nice to show #{ #}, though.
>> 
>>> I eventually got it working in all cases, but had to move the accidental 
>>> markups into variables
>> 
>> Well, I do like variables. :)

Yeah, in this case they were only used once each, so it seemed like overkill to 
assign them to variables.  Maybe it's clearer that way though.  


>>> to avoid too much nesting, which wasn't working.  Namely this part:
>>> 
>>>  (if (pair? tonic-acc)
>>>(set! key-name (markup key-name (if (= acc-type 0.5 )
>>>  (markup #:translate (cons (* mult -0.3) (* mult 0.8)) 
>>> #:magnify (* mult 0.9) #:sharp)
>>>  (markup #:translate (cons (* mult -0.2) (* mult 0.4)) 
>>> #:magnify (* mult 0.9) #:flat)
>>> 
>>> % > the following doesn't work:
>>> 
>>>  (if (pair? tonic-acc)
>>>(set! key-name #{ \markup #key-name #(if (= acc-type 0.5 )
>>>  #{ \markup { \translate #(cons (* mult -0.3) (* mult 0.8)) 
>>> \magnify #(* mult 0.9) \sharp } #}
>>>  #{ \markup { \translate #(cons (* mult -0.2) (* mult 0.4)) 
>>> \magnify #(* mult 0.9) \flat  } #} ) #} ))
>> 
>> It will work, while adding two braces:
>> 
>> (if (pair? tonic-acc)
>>  (set! key-name
>>  #{ \markup { % <==
>>  #key-name
>>  #(if (= acc-type 0.5 )
>>   #{
>>   \markup {
>>   \translate #(cons (* mult -0.3) (* mult 0.8))
>>   \magnify #(* mult 0.9)
>>   \sharp
>>   }
>>   #}
>>   #{
>>   \markup {
>>   \translate #(cons (* mult -0.2) (* mult 0.4))
>>   \magnify #(* mult 0.9)
>>   \flat
>>   }
>>   #})
>>  } % <=
>>#}))

Argh!  The missing braces strike again.  I should have caught that.  Your 
reformatting makes it much easier to follow.


>>> %> but this does:
>>> 
>>>  (if (pair? tonic-acc)
>>>(set! key-name #{ \markup { #key-name #(if (= acc-type 0.5 ) 
>>> txt-sharp txt-flat ) } #} ))
>>> 
>>> 
>>> Regards,
>>> -Paul
>> 
>> 
>> Now approved:
>> http://lsr.dsi.unimi.it/LSR/Item?id=856
>> 
>> Regards,
>>  Harm
>> 
>> P.S.
>> I cc-ed the list, because I think it might be of interest for all.

Thanks again!
-Paul


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


Re: Custom key signature stencils, differentiating major and minor keys

2012-12-05 Thread Thomas Morley
Sorry to send this again, forgot to cc the list.

2012/12/5 Thomas Morley :
> 2012/12/5 Paul Morris :
>> On Dec 4, 2012, at 7:27 PM, Thomas Morley  
>> wrote:
> [...]
>>> May I ask, if you could add a commented 2.16-version of it?
>>> Although your code will work for 2.16.1 up to 2.17.6 (so far I
>>> tested), it would be nice to show the new make-engraver-macro and the
>>> possibility of #{ #} in scheme-code, once the LSR is updated.
>>
>> Ok, I just uploaded a new version with the 2.16 code commented out.  The 
>> make-engraver-macro is quite nice.
>
> Thanks for doing this!
>
>>
>> It was a little tricky figuring out the #{ \markup ... #} syntax after 
>> getting used to the scheme version.  If it were not for the need to 
>> demonstrate the new syntax (which I'm happy to help with) I'd probably just 
>> stick with the scheme version at this point.
>
> I know what you mean. :)
> I tend to use only scheme-syntax in longer scheme-expressions.
> It's nice to show #{ #}, though.
>
>> I eventually got it working in all cases, but had to move the accidental 
>> markups into variables
>
> Well, I do like variables. :)
>
>> to avoid too much nesting, which wasn't working.  Namely this part:
>>
>>   (if (pair? tonic-acc)
>> (set! key-name (markup key-name (if (= acc-type 0.5 )
>>   (markup #:translate (cons (* mult -0.3) (* mult 0.8)) 
>> #:magnify (* mult 0.9) #:sharp)
>>   (markup #:translate (cons (* mult -0.2) (* mult 0.4)) 
>> #:magnify (* mult 0.9) #:flat)
>>
>> % > the following doesn't work:
>>
>>   (if (pair? tonic-acc)
>> (set! key-name #{ \markup #key-name #(if (= acc-type 0.5 )
>>   #{ \markup { \translate #(cons (* mult -0.3) (* mult 0.8)) 
>> \magnify #(* mult 0.9) \sharp } #}
>>   #{ \markup { \translate #(cons (* mult -0.2) (* mult 0.4)) 
>> \magnify #(* mult 0.9) \flat  } #} ) #} ))
>
> It will work, while adding two braces:
>
> (if (pair? tonic-acc)
>   (set! key-name
>   #{ \markup { % <==
>   #key-name
>   #(if (= acc-type 0.5 )
>#{
>\markup {
>\translate #(cons (* mult -0.3) (* mult 0.8))
>\magnify #(* mult 0.9)
>\sharp
>}
>#}
>#{
>\markup {
>\translate #(cons (* mult -0.2) (* mult 0.4))
>\magnify #(* mult 0.9)
>\flat
>}
>#})
>   } % <=
> #}))
>>
>> %> but this does:
>>
>>   (if (pair? tonic-acc)
>> (set! key-name #{ \markup { #key-name #(if (= acc-type 0.5 ) 
>> txt-sharp txt-flat ) } #} ))
>>
>>
>> Regards,
>> -Paul
>
>
> Now approved:
> http://lsr.dsi.unimi.it/LSR/Item?id=856
>
> Regards,
>   Harm
>
> P.S.
> I cc-ed the list, because I think it might be of interest for all.

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-12-04 Thread Thomas Morley
2012/12/4 Paul Morris :
> I've uploaded a revised version of my snippet:
>
>   Automatically display key names above key signatures
>   http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856
>
> What's new?
>   - handles modes (dorian, phrygian, lydian, etc.)
>   - never prints key names above key cancellations (this was inconsistent 
> before)
>   - better code
>
> Cheers and enjoy!
> -Paul

Hi Paul,

thanks for your nice snippet.
I changed a closing-bracket, adding it to the previous line and the
appearance of the description.
If you don't like it change it back. :)

May I ask, if you could add a commented 2.16-version of it?
Although your code will work for 2.16.1 up to 2.17.6 (so far I
tested), it would be nice to show the new make-engraver-macro and the
possibility of #{ #} in scheme-code, once the LSR is updated.


Regards,
  Harm

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-12-04 Thread Paul Morris
I've uploaded a revised version of my snippet:

  Automatically display key names above key signatures
  http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856

What's new?
  - handles modes (dorian, phrygian, lydian, etc.)
  - never prints key names above key cancellations (this was inconsistent 
before)
  - better code

Cheers and enjoy!
-Paul
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-21 Thread Paul Morris
On Nov 18, 2012, at 7:26 AM, Thomas Morley  
wrote:

> 2012/11/18 Paul Morris :
> [...]
>> I do have some small changes I made to my local copy that I'd like to add.  
>> They are for the accidental signs in the text -- better spacing and putting 
>> them into a LilyPond variable for less repetition.  I won't be able to get 
>> to this until Wednesday at the earliest.
> 
> No problem. I'll wait.

Hi Harm,  I incorporated your 2.14 "downgrades" into my most current version, 
and uploaded it to the LSR:  http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856

I kept the commented-out 2.16 version in the snippet, for easy future 
migration.  But I am fine with removing it if that's preferred for the LSR.  

The most current code for use in 2.16 is pasted below.  

Thanks again,
-Paul


% Begin snippet

\version "2.16.0"

% tonic-semi: semitone of the tonic note, 0-11, 0=C, 2=D, etc
% psn: vertical staff position of the last accidental sign in key signature
% accsign: the accidental sign type, 1/2=sharp, -1/2=flat
%   (These 3 things let us identify the key and if it is major or minor.)
% txt-size: size of key name text
% padd: padding between key signature and key name
% C Major, F Major, A Minor, and D Minor all get extra padding 
%   so the name is above the staff
% This snippet does not work with modal keys (dorian, lydian, etc.)
% Key cancellations usually get no name above them, 
%  unless they have the same tonic note, like G major to G minor.

#(define Custom_key_signature_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 
  (key-name (markup #:null))
  (txt-size .7)
  (padd .5)
  (sharptxt (markup #:translate (cons -0.3 0.8) #:magnify .9 #:sharp))
  (flattxt  (markup #:translate (cons -0.2 0.4) #:magnify .9 #:flat))
  )
  (cond 
  ((= accsign 0) (cond
((= tonic-semi 0) (set! key-name (markup "C Major" )) (set! padd 3.2))
((= tonic-semi 9) (set! key-name (markup "A Minor" )) (set! padd 3.2))
(else (set! key-name (markup #:null)))
  ))
  ((= accsign 1/2)
(cond 
((= psn 3) (cond 
  ((= tonic-semi 7) (set! key-name (markup "G Major" )))
  ((= tonic-semi 4) (set! key-name (markup "E Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 0) (cond
  ((= tonic-semi 2)  (set! key-name (markup "D Major" )))
  ((= tonic-semi 11) (set! key-name (markup "B Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 4) (cond 
  ((= tonic-semi 9) (set! key-name (markup "A Major" )))
  ((= tonic-semi 6) (set! key-name (markup "F" sharptxt "Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 1) (cond 
  ((= tonic-semi 4) (set! key-name (markup "E Major" )))
  ((= tonic-semi 1) (set! key-name (markup "C" sharptxt "Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 5) (cond 
  ((= tonic-semi 11) (set! key-name (markup "B Major" )))
  ((= tonic-semi 8)  (set! key-name (markup "G" sharptxt "Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 2) (cond
  ((= tonic-semi 6) (set! key-name (markup "F" sharptxt "Major" )))
  ((= tonic-semi 3) (set! key-name (markup "D" sharptxt "Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 6) (cond
  ((= tonic-semi 1)  (set! key-name (markup "C" sharptxt "Major" )))
  ((= tonic-semi 10) (set! key-name (markup "A" sharptxt "Minor" )))
  (else (set! key-name (markup #:null)))
))
)
  )
  ((= accsign -1/2)
(cond
((= psn 6) (cond
  ((= tonic-semi 5) (set! key-name (markup "F Major" )) (set! padd 1.4))
  ((= tonic-semi 2) (set! key-name (markup "D Minor" )) (set! padd 1.7))
  (else (set! key-name (markup #:null)))
))
((= psn 2) (cond
  ((= tonic-semi 10) (set! key-name (markup "B" flattxt "Major" )))
  ((= tonic-semi 7)  (set! key-name (markup "G Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 5) (cond
  ((= tonic-semi 3) (set! key-name (markup "E" flattxt "Major" )))
  ((= tonic-semi 0) (set! key-name (markup "C Minor" )))
  (else (set! key-name (markup #:null)))
))
((= psn 1) (cond
  ((= tonic-semi 8) (set! key-name (markup "A" flattxt "Major" )))
  ((

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-18 Thread Thomas Morley
2012/11/18 Paul Morris :
[...]
> I do have some small changes I made to my local copy that I'd like to add.  
> They are for the accidental signs in the text -- better spacing and putting 
> them into a LilyPond variable for less repetition.  I won't be able to get to 
> this until Wednesday at the earliest.

No problem. I'll wait.

Regards,
  Harm

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-17 Thread Paul Morris
On Nov 16, 2012, at 8:55 PM, MING TSANG  wrote:

> Dear Paul,
> 
> I tested your latest version, the C Major, A Minor the alternative key 
> signature does not print on the second system. G major, E minor & D Major, B 
> Minor seems ok - that is - alternative key singature displayed on the second 
> system.

Hi Ming,  Yes, I do not know how to work around this.  It seems that in the 
keys of C Major or A Minor, LilyPond does not print a key signature at all at 
the beginning of the 2nd, 3rd, etc... lines of music (not even an "empty" or 
"invisible" key signature).  So the custom key signature engraver does not get 
called and so it does not print the name of the key there.

-Paul




> 
> Please see the .pdf
> 
>  
> Blessing in+,
> Ming.
> From: Thomas Morley 
> To: Paul Morris  
> Cc: MING TSANG ; lilypond-usermailinglist 
>  
> Sent: Friday, November 16, 2012 7:50:17 PM
> Subject: Re: Custom key signature stencils, differentiating major and minor 
> keys
> 
> 2012/11/14 Paul Morris :
> > Hi Ming,  I took another look at this and since there's only one key
> > signature where the accidentals do not extend above the staff (F major / D
> > minor) I just added extra padding for those keys.  Now the key names always
> > appear above the staff, regardless of the clef.
> >
> > The sizing of the accidental signs in the key names is better in this
> > version as well.
> >
> > Cheers,
> > -Paul
> 
> Hi Paul,
> 
> am I right you've added your engraver to LSR with a [needs upgrade]-label?
> http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856
> 
> If so:
> I downgraded your code to make it work with 2.14.2:
> changing the make-engraver-macro (created by David Kastrup) to the old
> syntax and changing the #{ #}-syntax (also made possible by David) to
> scheme-syntax.
> The 2.16.0-code is untouched and commented.
> 
> Note that I didn't have a closer look at the code. ;)
> Also note, since there is something strange with the displayed
> LSR-output I added a markup to get the spacing correct.
> 
> If you agree, I could approve it now.
> Currently, I let it unapproved, in case you may want to add or change sth.
> 
> 
> Best,
>   Harm
> 
> 
> 

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-17 Thread Paul Morris
On Nov 16, 2012, at 7:50 PM, Thomas Morley  
wrote:

> 2012/11/14 Paul Morris :
>> Hi Ming,  I took another look at this and since there's only one key
>> signature where the accidentals do not extend above the staff (F major / D
>> minor) I just added extra padding for those keys.  Now the key names always
>> appear above the staff, regardless of the clef.
>> 
>> The sizing of the accidental signs in the key names is better in this
>> version as well.
>> 
>> Cheers,
>> -Paul
> 
> Hi Paul,
> 
> am I right you've added your engraver to LSR with a [needs upgrade]-label?
> http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856

Hi Harm,  Yes, that was me.


> If so:
> I downgraded your code to make it work with 2.14.2:
> changing the make-engraver-macro (created by David Kastrup) to the old
> syntax and changing the #{ #}-syntax (also made possible by David) to
> scheme-syntax.
> The 2.16.0-code is untouched and commented.

Thanks!  I didn't know that that was what was needed, or what changes to make.


> Note that I didn't have a closer look at the code. ;)

Ok. :)  I realize there may be better ways of doing it.  


> Also note, since there is something strange with the displayed
> LSR-output I added a markup to get the spacing correct.

Hmmm, ok.


> If you agree, I could approve it now.
> Currently, I let it unapproved, in case you may want to add or change sth.

I do have some small changes I made to my local copy that I'd like to add.  
They are for the accidental signs in the text -- better spacing and putting 
them into a LilyPond variable for less repetition.  I won't be able to get to 
this until Wednesday at the earliest. 

Thanks for your help getting it to run with 2.14.2!
-Paul



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


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-16 Thread Thomas Morley
2012/11/14 Paul Morris :
> Hi Ming,  I took another look at this and since there's only one key
> signature where the accidentals do not extend above the staff (F major / D
> minor) I just added extra padding for those keys.  Now the key names always
> appear above the staff, regardless of the clef.
>
> The sizing of the accidental signs in the key names is better in this
> version as well.
>
> Cheers,
> -Paul

Hi Paul,

am I right you've added your engraver to LSR with a [needs upgrade]-label?
http://lsr.dsi.unimi.it/LSR/Item?u=1&id=856

If so:
I downgraded your code to make it work with 2.14.2:
changing the make-engraver-macro (created by David Kastrup) to the old
syntax and changing the #{ #}-syntax (also made possible by David) to
scheme-syntax.
The 2.16.0-code is untouched and commented.

Note that I didn't have a closer look at the code. ;)
Also note, since there is something strange with the displayed
LSR-output I added a markup to get the spacing correct.

If you agree, I could approve it now.
Currently, I let it unapproved, in case you may want to add or change sth.


Best,
  Harm

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


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-14 Thread MING TSANG
Paul,

Thank you.

 
Blessing in+,
Ming.


>
> From: Paul Morris 
>To: MING TSANG  
>Cc: lilypond-usermailinglist  
>Sent: Wednesday, November 14, 2012 12:13:44 AM
>Subject: Re: Custom key signature stencils, differentiating major and minor 
>keys
> 
>
>Hi Ming,  I took another look at this and since there's only one key signature 
>where the accidentals do not extend above the staff (F major / D minor) I just 
>added extra padding for those keys.  Now the key names always appear above the 
>staff, regardless of the clef.  
>
>
>The sizing of the accidental signs in the key names is better in this version 
>as well.
>
>
>Cheers,
>-Paul
>
>
>
>
>\version "2.16.0"
>
>
>% tonic-semi: semitone of tonic note, 0-11, 0=C, 2=D, etc
>% psn: vertical staff position of the last accidental sign in key signature
>% accsign: the accidental sign type, 1/2=sharp, -1/2=flat
>% Knowing these 3 things is enough to identify the key and whether it is 
>major/minor
>% txt-size: size of key name text
>% padd: padding between key signature and key name
>% F Major and D Minor get extra padding to clear the staff
>% It does not handle modal keys correctly (dorian, lydian, etc.)
>
>
>#(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 
>(key-name   #{ \markup {} #})
>(txt-size  .7)
>(padd.5)
>  )
>  (cond 
>  ((= accsign 0) (cond
>((= tonic-semi 0) (set! key-name #{ \markup {C Major} #}) (set! padd 3.2))
>((= tonic-semi 9) (set! key-name #{ \markup {A Minor} #}) (set! padd 3.2))
>(else (set! key-name #{\markup{}#}))
>))
>  ((= accsign 1/2)
>(cond 
>((= psn 3) (cond 
>((= tonic-semi 7) (set! key-name #{ \markup {G Major} #}))
>((= tonic-semi 4) (set! key-name #{ \markup {E Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 0) (cond
>((= tonic-semi 2)  (set! key-name #{ \markup {D Major} #}))
>((= tonic-semi 11) (set! key-name #{ \markup {B Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 4) (cond 
>((= tonic-semi 9) (set! key-name #{ \markup {A Major} #}))
>((= tonic-semi 6) (set! key-name #{ \markup {F\raise #.8 \magnify #.8 {\sharp} 
>Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 1) (cond 
>((= tonic-semi 4) (set! key-name #{ \markup {E Major} #}))
>((= tonic-semi 1) (set! key-name #{ \markup {C\raise #.8 \magnify #.8 {\sharp} 
>Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 5) (cond 
>((= tonic-semi 11) (set! key-name #{ \markup {B Major} #}))
>((= tonic-semi 8)  (set! key-name #{ \markup {G\raise #.8 \magnify #.8 
>{\sharp} Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 2) (cond
>((= tonic-semi 6) (set! key-name #{ \markup {F\raise #.8 \magnify #.8 {\sharp} 
>Major} #}))
>((= tonic-semi 3) (set! key-name #{ \markup {D\raise #.8 \magnify #.8 {\sharp} 
>Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 6) (cond
>((= tonic-semi 1)  (set! key-name #{ \markup {C\raise #.8 \magnify #.8 
>{\sharp} Major} #}))
>((= tonic-semi 10) (set! key-name #{ \markup {A\raise #.8 \magnify #.8 
>{\sharp} Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>)
>  )
>  ((= accsign -1/2)
>(cond
>((= psn 6) (cond
>((= tonic-semi 5) (set! key-name #{ \markup {F Major} #}) (set! padd 1.4))
>((= tonic-semi 2) (set! key-name #{ \markup {D Minor} #}) (set! padd 1.7))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 2) (cond
>((= tonic-semi 10) (set! key-name #{ \markup {B\raise #.4 \magnify #.8 {\flat} 
>Major} #}))
>((= tonic-semi 7)  (set! key-name #{ \markup {G Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 5) (cond
>((= tonic-semi 3) (set! key-name #{ \markup {E\raise #.4 \magnify #.8 {\flat} 
>Major} #}))
>((= tonic-semi 0) (set! key-name #{ \markup {C Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 1) (cond
>((= tonic-semi 8) (set! key-name #{ \markup {A\raise #.4 \magnify #.8 {\flat} 
>Major} #}))
>((= tonic-semi 5) (set! key-name #{ \markup {F Minor} #}))
>(else (set! key-name #{\markup{}#}))
>))
>((= psn 4) (cond
>((= tonic-semi 1)  (set! key-name #{ \markup {D\raise #.4 \magnify #.8 {\flat} 
>Major} #}))
>((= tonic-semi 10) (set! ke

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-13 Thread Paul Morris
Hi Ming,  I took another look at this and since there's only one key signature 
where the accidentals do not extend above the staff (F major / D minor) I just 
added extra padding for those keys.  Now the key names always appear above the 
staff, regardless of the clef.  

The sizing of the accidental signs in the key names is better in this version 
as well.

Cheers,
-Paul


\version "2.16.0"

% tonic-semi: semitone of tonic note, 0-11, 0=C, 2=D, etc
% psn: vertical staff position of the last accidental sign in key signature
% accsign: the accidental sign type, 1/2=sharp, -1/2=flat
% Knowing these 3 things is enough to identify the key and whether it is 
major/minor
% txt-size: size of key name text
% padd: padding between key signature and key name
% F Major and D Minor get extra padding to clear the staff
% It does not handle modal keys correctly (dorian, lydian, etc.)

#(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 
(key-name #{ \markup {} #})
(txt-size   .7)
(padd   .5)
  )
  (cond 
  ((= accsign 0) (cond
((= tonic-semi 0) (set! key-name #{ \markup {C Major} 
#}) (set! padd 3.2))
((= tonic-semi 9) (set! key-name #{ \markup {A Minor} 
#}) (set! padd 3.2))
(else (set! key-name #{\markup{}#}))
))
  ((= accsign 1/2)
(cond 
((= psn 3) (cond 
((= tonic-semi 7) (set! key-name #{ \markup {G Major} 
#}))
((= tonic-semi 4) (set! key-name #{ \markup {E Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 0) (cond
((= tonic-semi 2)  (set! key-name #{ \markup {D Major} 
#}))
((= tonic-semi 11) (set! key-name #{ \markup {B Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 4) (cond 
((= tonic-semi 9) (set! key-name #{ \markup {A Major} 
#}))
((= tonic-semi 6) (set! key-name #{ \markup {F\raise 
#.8 \magnify #.8 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 1) (cond 
((= tonic-semi 4) (set! key-name #{ \markup {E Major} 
#}))
((= tonic-semi 1) (set! key-name #{ \markup {C\raise 
#.8 \magnify #.8 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 5) (cond 
((= tonic-semi 11) (set! key-name #{ \markup {B Major} 
#}))
((= tonic-semi 8)  (set! key-name #{ \markup {G\raise 
#.8 \magnify #.8 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 2) (cond
((= tonic-semi 6) (set! key-name #{ \markup {F\raise 
#.8 \magnify #.8 {\sharp} Major} #}))
((= tonic-semi 3) (set! key-name #{ \markup {D\raise 
#.8 \magnify #.8 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 6) (cond
((= tonic-semi 1)  (set! key-name #{ \markup {C\raise 
#.8 \magnify #.8 {\sharp} Major} #}))
((= tonic-semi 10) (set! key-name #{ \markup {A\raise 
#.8 \magnify #.8 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
)
  )
  ((= accsign -1/2)
(cond
((= psn 6) (cond
((= tonic-semi 5) (set! key-name #{ \markup {F Major} 
#}) (set! padd 1.4))
((= tonic-semi 2) (set! key-name #{ \markup {D Minor} 
#}) (set! padd 1.7))
(else (set! key-name #{\markup{}#}))
))
((= psn 2) (cond
((= tonic-semi 10) (set! key-name #{ \markup {B\raise 
#.4 \magnify #.8 {\flat} Major} #}))
((= tonic-semi 7)  (set! key-name #{ \markup {G Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 5) (cond
((= tonic-semi 3

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-13 Thread MING TSANG
Hi, Paul:

For now I just do alternate key signature on the top staff only or use manually 
by hand . Hope you have time to re-work to use rehearsal approach. 


 
Blessing in+,
Ming


>
> From: Paul Morris 
>To: MING TSANG  
>Cc: lilypond-usermailinglist  
>Sent: Tuesday, November 13, 2012 11:49:57 AM
>Subject: Re: Custom key signature stencils, differentiating major and minor 
>keys
> 
>On Nov 13, 2012, at 7:26 AM, MING TSANG  wrote:
>
>> Hi, Paul: I apply the change, it pushes the display above the staff. However 
>> I notice (1) that the distance is not constant from system to system - it 
>> diminishes;
>
>That is expected.  It sets the padding (distance) between the top of the 
>highest accidental in the key signature and the bottom of the text.  So that 
>is constant.  But when the top of the highest accidental falls below the top 
>of the staff, and at different vertical positions below the top of the staff, 
>then the distance between the text and the top of the _staff_ will be 
>different.  
>
>Ideally it would set the padding from the top of the staff _or_ the top of the 
>highest accidental.  A better approach to achieve this would be: instead of 
>combining the text and the key signature symbol into one graphical stencil / 
>grob, add the text as a rehearsal mark centered on the key signature.  Then it 
>would inherit all of the usual smart spacing for rehearsal marks.
>
>Here's how you can do that by hand:
>
>\version "2.16.0"
>\new Staff {
>  \clef bass
>  \once \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
>  \key f \major 
>  \mark \markup \magnify #.7 {F Major} 
>  c1
>  \clef treble
>  \once \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
>  \key cis \major
>  \mark \markup \magnify #.7 {C\raise #.4 {\sharp} Major} 
>  c'1
>}
>
>As described here:
>http://lilypond.org/doc/v2.16/Documentation/notation/writing-text#text-marks
>Under: Selected Snippets > Aligning marks with various notation objects
>
>So there should be a way to get my custom key signature script to 
>automatically add such rehearsal marks to the key signature.  But this would 
>require reworking it.
>
>
>> (2) that after key change from F Major to C Major, it display at the point 
>> where it changes, but disappear on the next system onward.
>
>Hmmm...  it looks like if the key is C Major or A Minor then no key signature 
>is printed, not even an "empty" one, and so the name does not get printed 
>either.  Not sure how to work around that.
>
>-Paul
>
>
>> 
>> Here is the .png and .ly file.
>> 
>> Thank you again.
>>  
>> Blessing in+,
>> Ming.
>> From: Paul Morris 
>> To: MING TSANG  
>> Sent: Monday, November 12, 2012 10:54:56 PM
>> Subject: Re: Custom key signature stencils, differentiating major and minor 
>> keys
>> 
>> Hi Ming, 
>> Yes, I saw that too...  There is a padding setting that sets the distance 
>> between the top of the key signature and the name above it.  So you could 
>> increase this until it no longer overlapped in the bass clef, but this might 
>> create too much space in other places?  
>> 
>> For example change the .5 in this:
>> 
>> (ly:stencil-scale (grob-interpret-markup grob key-name) .7 .7)
>> .5 ))
>> 
>> To 1.1 like so:
>> 
>> (ly:stencil-scale (grob-interpret-markup grob key-name) .7 .7)
>> 1.1 ))
>> 
>> That pushes the name up above the bass staff, but it also increases the 
>> distance in all the other places as well.  
>> 
>> Cheers,
>> -Paul
>> 
>> PS. Sorry for resending my previous message.  I realized I did not send it 
>> to the lily-user list before.
>> 
>> 
>> On Nov 12, 2012, at 10:33 PM, MING TSANG  wrote:
>> 
>>> Hi, Paul:
>>> 
>>> Thank you for the sample placement of the "\consists 
>>> \Custom_key_sig_engraver".
>>> 
>>> One minor drawback:  The alternative key signature on Bass is on the staff 
>>> line, not above the staff.  How can I adjust it?
>>> 
>>>  
>>> Blessing in+,
>>> Ming.
>>> From: Paul Morris 
>>> To: MING TSANG  
>>> Sent: Monday, November 12, 2012 9:53:31 PM
>>> Subject: Re: Custom key signature stencils, differentiating major and minor 
>>> keys
>>> 
>>> 
>>> On Nov 12, 2012, at 2:42 PM, MING TSANG  wrote:
>>> 
>>>> Hi, Paul:
>>>> 
>>>> I try to use custon-key-sig

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-13 Thread Paul Morris
On Nov 13, 2012, at 7:26 AM, MING TSANG  wrote:

> Hi, Paul: I apply the change, it pushes the display above the staff. However 
> I notice (1) that the distance is not constant from system to system - it 
> diminishes;

That is expected.  It sets the padding (distance) between the top of the 
highest accidental in the key signature and the bottom of the text.  So that is 
constant.  But when the top of the highest accidental falls below the top of 
the staff, and at different vertical positions below the top of the staff, then 
the distance between the text and the top of the _staff_ will be different.  

Ideally it would set the padding from the top of the staff _or_ the top of the 
highest accidental.  A better approach to achieve this would be: instead of 
combining the text and the key signature symbol into one graphical stencil / 
grob, add the text as a rehearsal mark centered on the key signature.  Then it 
would inherit all of the usual smart spacing for rehearsal marks.

Here's how you can do that by hand:

\version "2.16.0"
\new Staff {
  \clef bass
  \once \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
  \key f \major 
  \mark \markup \magnify #.7 {F Major} 
  c1
  \clef treble
  \once \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
  \key cis \major
  \mark \markup \magnify #.7 {C\raise #.4 {\sharp} Major} 
  c'1
}

As described here:
http://lilypond.org/doc/v2.16/Documentation/notation/writing-text#text-marks
Under: Selected Snippets > Aligning marks with various notation objects

So there should be a way to get my custom key signature script to automatically 
add such rehearsal marks to the key signature.  But this would require 
reworking it.


> (2) that after key change from F Major to C Major, it display at the point 
> where it changes, but disappear on the next system onward.

Hmmm...  it looks like if the key is C Major or A Minor then no key signature 
is printed, not even an "empty" one, and so the name does not get printed 
either.  Not sure how to work around that.

-Paul


> 
> Here is the .png and .ly file.
> 
> Thank you again.
>  
> Blessing in+,
> Ming.
> From: Paul Morris 
> To: MING TSANG  
> Sent: Monday, November 12, 2012 10:54:56 PM
> Subject: Re: Custom key signature stencils, differentiating major and minor 
> keys
> 
> Hi Ming, 
> Yes, I saw that too...  There is a padding setting that sets the distance 
> between the top of the key signature and the name above it.  So you could 
> increase this until it no longer overlapped in the bass clef, but this might 
> create too much space in other places?  
> 
> For example change the .5 in this:
> 
> (ly:stencil-scale (grob-interpret-markup grob key-name) .7 .7)
> .5 ))
> 
> To 1.1 like so:
> 
> (ly:stencil-scale (grob-interpret-markup grob key-name) .7 .7)
> 1.1 ))
> 
> That pushes the name up above the bass staff, but it also increases the 
> distance in all the other places as well.  
> 
> Cheers,
> -Paul
> 
> PS. Sorry for resending my previous message.  I realized I did not send it to 
> the lily-user list before.
> 
> 
> On Nov 12, 2012, at 10:33 PM, MING TSANG  wrote:
> 
>> Hi, Paul:
>> 
>> Thank you for the sample placement of the "\consists 
>> \Custom_key_sig_engraver".
>> 
>> One minor drawback:  The alternative key signature on Bass is on the staff 
>> line, not above the staff.  How can I adjust it?
>> 
>>  
>> Blessing in+,
>> Ming.
>> From: Paul Morris 
>> To: MING TSANG  
>> Sent: Monday, November 12, 2012 9:53:31 PM
>> Subject: Re: Custom key signature stencils, differentiating major and minor 
>> keys
>> 
>> 
>> On Nov 12, 2012, at 2:42 PM, MING TSANG  wrote:
>> 
>>> Hi, Paul:
>>> 
>>> I try to use custon-key-signature in my lilypond score and I did not get 
>>> the alternative key printed above the traditional key signature.  What is 
>>> missing in the code below?  I have "\Staff \consists 
>>> \Custom_key_sig_engraver" in \layout as seen in your sample.
>> 
>> Hi Ming,  It looks like you need to just put \consists 
>> \Custom_key_sig_engraver in the \with block for each of the three staves in 
>> your score as shown below.  Then you don't need it in the layout block.  The 
>> following changes below got it to work for me.
>> 
>> Cheers,
>> -Paul
>> 
>> [...]
>> 
>> sopranoVoicePart = \new Staff \with { \consists #numbr
>> \consists \Custom_key_sig_engraver
>> instrumentName = "Soprano"
>> %midiInstrument = "choir aahs"
>> } { \sopranoVoiceI }
>>

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-12 Thread Paul Morris
On Nov 12, 2012, at 2:42 PM, MING TSANG  wrote:

> Hi, Paul:
> 
> I try to use custon-key-signature in my lilypond score and I did not get the 
> alternative key printed above the traditional key signature.  What is missing 
> in the code below?  I have "\Staff \consists \Custom_key_sig_engraver" in 
> \layout as seen in your sample.

Hi Ming,  It looks like you need to just put \consists \Custom_key_sig_engraver 
in the \with block for each of the three staves in your score as shown below.  
Then you don't need it in the layout block.  The following changes below got it 
to work for me.

Cheers,
-Paul

[...]

sopranoVoicePart = \new Staff \with { \consists #numbr
\consists \Custom_key_sig_engraver
instrumentName = "Soprano"
%midiInstrument = "choir aahs"
} { \sopranoVoiceI }
\addlyrics { \verseSopranoVoiceI }
pianoPart = \new PianoStaff \with {
instrumentName = "Piano"
} <<
\new Staff = "right" \with {
\consists \Custom_key_sig_engraver
midiInstrument = "acoustic grand"
} \right
\new Staff = "left" \with {
\consists \Custom_key_sig_engraver
midiInstrument = "acoustic grand"
} { \clef bass \left }
>>
\score {
<<
\sopranoVoicePart
\pianoPart
>>
\layout {
\context {
\RemoveEmptyStaffContext
\override VerticalAxisGroup #'remove-first = ##t
}
}
}


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


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-12 Thread Paul Morris
Here is another revision (hopefully the last?!).  The previous version would 
include the key name over a key cancellation[1], but it would often be an 
incorrect/unrelated key name (!).  

This version does not include the name of the key above a key-cancellation, 
unless the tonic note is the same in both keys, like a switch from G major to G 
minor.  (This is a glitch I haven't been able to work around.  It always gives 
the correct key name now at least.  I tried checking for natural signs as the 
type of accidental used in key cancellations, but this does not work.)

Cheers,
-Paul 

[1] http://www.lilypond.org/doc/v2.16/Documentation/internals/keycancellation



\version "2.16.0"

% tonic-semi: semitone of tonic note, 0-11 
% psn: vertical staff position of the last accidental sign in key signature
% accsign: the accidental sign type, 1/2=sharp, -1/2=flat
% Knowing these 3 things is enough to identify the key and whether it is 
major/minor

#(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 
(key-name   #{ \markup {} #})
  )
  (cond 
  ((= accsign 0) (cond
((= tonic-semi 0) (set! key-name #{ \markup \raise #3.4 
{C Major} #}))
((= tonic-semi 9) (set! key-name #{ \markup \raise #3.4 
{A Minor} #}))
(else (set! key-name #{\markup{}#}))
))
  ((= accsign 1/2)
(cond 
((= psn 3) (cond 
((= tonic-semi 7) (set! key-name #{ \markup {G Major} 
#}))
((= tonic-semi 4) (set! key-name #{ \markup {E Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 0) (cond
((= tonic-semi 2)   (set! key-name #{ \markup {D Major} 
#}))
((= tonic-semi 11) (set! key-name #{ \markup {B Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 4) (cond 
((= tonic-semi 9) (set! key-name #{ \markup {A Major} 
#}))
((= tonic-semi 6) (set! key-name #{ \markup {F\raise 
#.6 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 1) (cond 
((= tonic-semi 4) (set! key-name #{ \markup {E Major} 
#}))
((= tonic-semi 1) (set! key-name #{ \markup {C\raise 
#.6 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 5) (cond 
((= tonic-semi 11) (set! key-name #{ \markup {B Major} 
#}))
((= tonic-semi 8)   (set! key-name #{ \markup {G\raise 
#.6 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 2) (cond
((= tonic-semi 6) (set! key-name #{ \markup {F\raise 
#.6 {\sharp} Major} #}))
((= tonic-semi 3) (set! key-name #{ \markup {D\raise 
#.6 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
((= psn 6) (cond
((= tonic-semi 1)   (set! key-name #{ \markup {C\raise 
#.6 {\sharp} Major} #}))
((= tonic-semi 10) (set! key-name #{ \markup {A\raise 
#.6 {\sharp} Minor} #}))
(else (set! key-name #{\markup{}#}))
))
)
  )
  ((= accsign -1/2)
(cond
((= psn 6) (cond
((= tonic-semi 5) (set! key-name #{ \markup {F Major} 
#}))
((= tonic-semi 2) (set! key-name #{ \markup {D Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 2) (cond
((= tonic-semi 10) (set! key-name #{ \markup {B\raise 
#.4 {\flat} Major} #}))
((= tonic-semi 7)   (set! key-name #{ \markup {G Minor} 
#}))
(else (set! key-name #{\markup{}#}))
))
((= psn 5) (cond
((= tonic-semi 3) (set! key-name #{ \markup {E\raise 
#.4 {\flat} Major} #}))
((= tonic-semi 0) (set! key-name #{ \markup {C Minor} 
#}))
   

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-11 Thread Paul Morris
Here is an improved version.  It works the same as the last, 
but with much more streamlined and concise code.
-Paul


\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)) ;; 
semitone of tonic note, 0-11 
(acclist  (ly:grob-property grob 'alteration-alist))
(accsign   (if (null? acclist) 0 (cdr (list-ref acclist 0 
;; accidental sign type, 1/2=sharp, -1/2=flat
(psn  (if (null? acclist) 0 (car (list-ref acclist 
0 ;; vertical position of last accidental sign
(key-name  #{ \markup {} #})
  )
  (cond 
  ((= accsign 0) 
(if (= tonic-semi 0) 
(set! key-name #{ \markup \raise #3.4 {C Major} #})
(set! key-name #{ \markup \raise #3.4 {A Minor} #})
))
  ((= accsign 1/2)  ;; SHARP KEYS
(cond 
((= psn 3) 
(if (= tonic-semi 7) 
(set! key-name #{ \markup {G Major} #})
(set! key-name #{ \markup {E Minor} #})
))
((= psn 0) 
(if (= tonic-semi 2) 
(set! key-name #{ \markup {D Major} #})
(set! key-name #{ \markup {B Minor} #})
))
((= psn 4) 
(if (= tonic-semi 9) 
(set! key-name #{ \markup {A Major} #})
(set! key-name #{ \markup {F\raise #.6 {\sharp} 
Minor} #})
))
((= psn 1) 
(if (= tonic-semi 4) 
(set! key-name #{ \markup {E Major} #})
(set! key-name #{ \markup {C\raise #.6 {\sharp} 
Minor} #})
))
((= psn 5) 
(if (= tonic-semi 11)
(set! key-name #{ \markup {B Major} #})
(set! key-name #{ \markup {G\raise #.6 {\sharp} 
Minor} #})
))
((= psn 2) 
(if (= tonic-semi 6) 
(set! key-name #{ \markup {F\raise #.6 {\sharp} 
Major} #})  
(set! key-name #{ \markup {D\raise #.6 {\sharp} 
Minor} #})
))
((= psn 6) 
(if (= tonic-semi 1) 
(set! key-name #{ \markup {C\raise #.6 {\sharp} 
Major} #})
(set! key-name #{ \markup {A\raise #.6 {\sharp} 
Minor} #})
))
)
  )
  ((= accsign -1/2) ;; FLAT KEYS
(cond
((= psn 6) 
(if (= tonic-semi 5) 
(set! key-name #{ \markup {F Major} #})
(set! key-name #{ \markup {D Minor} #})
))
((= psn 2) 
(if (= tonic-semi 10) 
(set! key-name #{ \markup {B\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {G Minor} #})
))
((= psn 5) 
(if (= tonic-semi 3) 
(set! key-name #{ \markup {E\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {C Minor} #})
))
((= psn 1) 
(if (= tonic-semi 8) 
(set! key-name #{ \markup {A\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {F Minor} #})
))
((= psn 4) 
(if (= tonic-semi 1) 
(set! key-name #{ \markup {D\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {B\raise #.4 {\flat} 
Minor} #})
))
((= psn 0) 
(if (= tonic-semi 6) 
(set! key-name #{ \markup {G\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {E\raise #.4 {\flat} 
Minor} #})
))
((= psn 3) 
(if (= tonic-semi 11) 
(set! key-name #{ \markup {C\raise #.4 {\flat} 
Major} #})
(set! key-name #{ \markup {A\raise #.4 {\flat} 
Minor} #})
))
 

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-11 Thread Paul Morris
On Nov 11, 2012, at 7:38 AM, MING TSANG  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

Re: Custom key signature stencils, differentiating major and minor keys

2012-11-11 Thread MING TSANG
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.

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?


Thank you such useful custom key signature.  I definitely will use it.

 
Blessing in+,
Ming.
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Custom key signature stencils, differentiating major and minor keys

2012-11-10 Thread Paul Morris
Ok, I figured out a way to differentiate between major and minor keys.  I 
followed the example of this snippet which shows how to access the tonic note 
of the current key:
http://lsr.dsi.unimi.it/LSR/Item?id=818

By combining the tonic note with the type and position of the right-most 
accidental sign in the key signature, I could determine both the current key 
and whether it was major or minor.  (I guess I should allow for other modes as 
well, hmmm...)

See the code below which also now handles C Major / A Minor, and (for now) 
replaces the key signature stencil with the name of the key, as described here:
http://lilypond.org/doc/v2.16/Documentation/notation/modifying-stencils

A variation on this could come in handy if you wanted to automatically print 
the textual name of the key above the key signature.

Any advice or comments welcome.  There are probably ways to improve this or do 
it better.

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
)
(cond 
((= accsign 0) 
(if (= tonic-semi 0) 
(ly:grob-set-property! grob 
'text #{ \markup {C Major} #}) ;; C Major
(ly:grob-set-property! grob 
'text #{ \markup {A Minor} #}) ;; A Minor
))
((= accsign 1/2);; SHARP KEYS
  (cond 
((= psn 3) 
(if (= tonic-semi 7) 
(ly:grob-set-property! grob 
'text #{ \markup {G Major} #}) ;; G Major
(ly:grob-set-property! grob 
'text #{ \markup {E Minor} #}) ;; E Minor
))
((= psn 0) 
(if (= tonic-semi 2) 
(ly:grob-set-property! grob 
'text #{ \markup {D Major} #}) ;; D Major
(ly:grob-set-property! grob 
'text #{ \markup {B Minor} #}) ;; B Minor
))
((= psn 4) 
(if (= tonic-semi 9) 
(ly:grob-set-property! grob 
'text #{ \markup {A Major} #}) ;; A Major
(ly:grob-set-property! grob 
'text #{ \markup {Fis Minor} #}) ;; Fis Minor
))
((= psn 1) 
(if (= tonic-semi 4) 
(ly:grob-set-property! grob 
'text #{ \markup {E Major} #}) ;; E Major
(ly:grob-set-property! grob 
'text #{ \markup {Cis Minor} #}) ;; Cis Minor
))
((= psn 5) 
(if (= tonic-semi 11) 
(ly:grob-set-property! grob 
'text #{ \markup {B Major} #}) ;; B Major
(ly:grob-set-property! grob 
'text #{ \markup {Gis Minor} #}) ;; Gis Minor
))
((= psn 2) 
(if (= tonic-semi 6) 
(ly:grob-set-property! grob 
'text #{ \markup {Fis Major} #}) ;; Fis Major
(ly:grob-set-property! grob 
'text #{ \markup {Dis Minor} #}) ;; Dis Minor
))
((= psn 6) 
(if (= tonic-semi 1) 
(ly:grob-set-property! grob 
'text #{ \markup {Cis Major} #}) ;; Cis Major
(ly:grob-set-property! grob 
'text #{ \markup {Ais Minor} #}) ;; Ais Minor
))
  )
)
((= accsign -1/2)   ;; FLAT KEYS
  (cond
((= psn 6) 
(if (= tonic-semi