lilypond-user
[Top][All Lists]
Advanced

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

Re: instrumentSwitch and addInstrumentDefinition use


From: Keith OHara
Subject: Re: instrumentSwitch and addInstrumentDefinition use
Date: Sun, 11 Jan 2015 21:28:39 -0800
User-agent: Opera Mail/12.16 (Win32)

On Sun, 11 Jan 2015 12:36:43 -0800, Kieren MacMillan <address@hidden> wrote:

So LilyPond does not store a global key signature.

No, but as you well know, many (most?) Lilypounders abstract the key signature 
(etc.)
into their own global [variable](s).

Right, but LilyPond doesn't know if that is the concert-pitch key (nor does she 
require all instruments to be playing in the same concert-pitch key).  I 
thought that would make automatic generation of key signature hard, but...
We could, I think, keep this organization, and write a
"\tranpositionUpdateKey bes"  that looks up the old key-signature and old
transposition on the Staff, figures the concert key, applies the new
transposition, figures the new key-signature for the new transposition
and sets that new key signature.

Why can that not be rolled into an improved instrumentSwitch?

It could.  The old instrumentDefinition, however, had no advantage over just 
collecting the instrument-switch settings in a variable, and was harder to use.

I just write an explicit \key d\major at the instrument switch when needed

This is one of the great banes of my current Lilypond existence — as a writer 
of musical theatre and band/orchestral music, I need to change instruments and 
keys all the time, very often in the middle of a section (w.r.t. key 
signature). Trying to remember to explicitly add key signatures etc. — and tag 
them as necessary — is quite frustrating, time-consuming, and error-prone.


I guess you enter the notes in concert pitch, then ?
Do you use the \quoteDuring mechanism (as below) or Jan-Peter's 
auto-transposing engraver to generate the engraved pitches for each instrument?


\version "2.19.15"
transpositionUpdateKey =
#(define-music-function (parser location new-transposition) (ly:pitch?)
   (_i "Set instrument transposition and, based on the previous
transposition and key, generate the key-change to keep the sounding key.")
   (define (generate-key-change c)
     (define (same-scale-step? a b) (= (car a) (car b)))
     (let* ((old-alt (delete-duplicates!
                        (append (ly:context-property c 'keyAlterations)
                                major)
                        same-scale-step?))
            (old-tonic (ly:context-property c 'tonic (ly:make-pitch 0 0 0)))
            (old-transp (ly:context-property c 'instrumentTransposition
                           (ly:make-pitch 0 0 0)))
            (delta (ly:pitch-diff old-transp new-transposition))
            (new-alt (ly:transpose-key-alist old-alt delta))
            (new-tonic (ly:pitch-transpose old-tonic delta))
            (sev (ly:make-stream-event `(key-change-event)
                    `((pitch-alist . ,new-alt)
                      (tonic . ,new-tonic)))))
     (ly:broadcast (ly:context-event-source c) sev)))
   #{
     \applyContext #generate-key-change
     \transposition $new-transposition
   #} )


prepClarinet = { \set Staff.shortInstrumentName="Clar"
                <>^\markup\italic\center-align "pick up clarinet" }
clarinet = { <>^\markup\bold"Clarinet"
             \once\set Staff.whichBar = "||"
             \transpositionUpdateKey bes }

concertBandEdition = {
  s1*3 \tag#'Sue \prepClarinet
  s1 \mark"All Reeds" \tag#'Sue \clarinet}

tune =  { \key c\major \repeat unfold 4 {c'4 e' g' b' R1} }
backup = { \key c\major \repeat unfold 8 {c'4 e' g' b' } }
\addQuote "tune" \tune

<< \new Staff \with { instrumentName="horn in F" }
   \keepWithTag#'Sue <<
      \concertBandEdition \transposition f
      \quoteDuring "tune" #(skip-of-length tune) >>
   \new Staff \with { instrumentName="alto clarinet" }
   \keepWithTag#'Joe <<
      \concertBandEdition \transposition es
      \transpose es c' \backup >>>>




reply via email to

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