lilypond-user
[Top][All Lists]
Advanced

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

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


From: Paul Morris
Subject: Re: Custom key signature stencils, differentiating major and minor keys
Date: Mon, 16 Dec 2013 09:55:53 -0800 (PST)

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.



reply via email to

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