On Sun, 18 Jan 2015 19:34:24 -0800, Kieren MacMillan
<[email protected]> wrote:
This does have the variable reedPlayer storing written pitches, where we
recommend storing concert pitches
I would much rather code in concert pitches.
What I was suggesting, and what I put into the example, had all the typed input
in concert pitch.
By saying "reedPlayer stores written pitches", I meant only that the
\transpose{...} operations, to tell LilyPond which notes should be printed at which
transposition, were included in the variable reedPlayer.
Still, I think I must be missing something fundamental… It really seems to me
that \addInstrumentDefinition already has [almost?] everything we need: the
shortInstrumentName is there, the clef is there (in case a change is needed),
the cue name is there, the transposition is there, etc.
So what is stopping us from making something very similar to the OP’s original
code Do The Right Thing™?
LilyPond has the information, but it takes some work to teach her to
consistently use it differently than she does now, and differently than the
original poster still wants her to.
You could try the attached modification (to avoid transposition of cues) of
Jan-Peter's method.
LilyPond transposes your input by 'instrumentTransposition when generating cue
notes, so leave instrumentTransposition at its default.
Instead, the attached engraver uses a new property 'printTransposition to shift
your concert-pitch input to printed pitches. Key-signature changes are not
always appropriate, but you can type \key\default to reprint the current
key-signature and have it transposed for the instrument.
(This second *-Transposition setting would be confusing to new users of
LilyPond, so any real patch would require re-writing some internals of LilyPond
so we can select the desired behavior using just the old
'instrumentTransposition to describe the instrument pitch.)
part = { g'4 b' d'' fis'' R1
\instrumentSwitch "cl Bflat" \bar"||"\key\default
g'4 b' d'' fis'' R1
\instrumentSwitch "flute" \bar"||"\key\default
g'4 b' d'' fis'' R1 }
global = { \key g\major s1*4 }
\new Staff \with { \printTransposition }
\new Voice << \global \part >>\version "2.18.2"
% vim: filetype=lilypond:
% Substitute for \key\default that works with midi{}
reprintKey = \applyContext #(lambda (c)
(define (same-scale-step? a b) (= (car a) (car b)))
(let* ((pitch-alist (delete-duplicates!
(append (ly:context-property c 'keyAlterations)
major)
same-scale-step?))
(tonic (ly:context-property c 'tonic (ly:make-pitch 0 0 0)))
(sev (ly:make-stream-event `(key-change-event)
`((pitch-alist . ,pitch-alist)
(tonic . ,tonic)))))
(ly:broadcast (ly:context-event-source c) sev)))
% from "scm/define-context-properties.scm"
#(define (translator-property-description symbol type? description)
(if (not (and
(symbol? symbol)
(procedure? type?)
(string? description)))
(throw 'init-format-error))
(if (not (equal? #f (object-property symbol 'translation-doc)))
(ly:error (_ "symbol ~S redefined" symbol)))
(set-object-property! symbol 'translation-type? type?)
(set-object-property! symbol 'translation-doc description)
(set! all-translation-properties (cons symbol all-translation-properties))
symbol)
#(translator-property-description 'printTransposition ly:pitch? "transposition for printing with autoTransposeEngraver")
% adapted from Jan-Peter Voigt's autoTransposeEngraver at openlilylib
printTranspositionEngraver = #(lambda (context)
(let ((old-pitch-alist major)
(old-transp (ly:make-pitch 1 0 0)))
(make-engraver
(listeners
((melodic-event engraver ev)
(let ((transp (ly:context-property context 'printTransposition))
(pitch (ly:event-property ev 'pitch)))
(if (and (ly:pitch? pitch) (ly:pitch? transp))
(ly:event-set-property! ev 'pitch
(ly:pitch-diff pitch transp)))))
((key-change-event engraver ev)
(let ((transp (ly:context-property context 'printTransposition))
(tonic (ly:event-property ev 'tonic
(ly:context-property context 'tonic ;for \key\default
(ly:make-pitch 1 0 0))))
(pitch-alist (ly:event-property ev 'pitch-alist
old-pitch-alist)))
(if (ly:pitch? transp)
(begin
(ly:event-set-property! ev 'tonic
(ly:pitch-diff tonic transp))
(set! pitch-alist
(ly:transpose-key-alist pitch-alist
(ly:pitch-diff old-transp transp)))
(ly:event-set-property! ev 'pitch-alist pitch-alist)
(set! old-transp transp)))
(set! old-pitch-alist pitch-alist)))))))
printTransposition = \with {
\remove Key_engraver
\consists \printTranspositionEngraver
\consists Key_engraver
}
% ===================================================
\addInstrumentDefinition #"cl Bflat"
#`(
(printTransposition . ,(ly:make-pitch -1 6 FLAT))
(shortInstrumentName . "Cl. in Bb")
(clefGlyph . "clefs.G")
(middleCPosition . -6)
(clefPosition . -2)
(instrumentCueName . ,(make-bold-markup "Cl. in Bb"))
(midiInstrument . "clarinet")
)
\addInstrumentDefinition #"flute"
#`(
(printTransposition . ,(ly:make-pitch 0 0 0))
(shortInstrumentName . "Flute")
(clefGlyph . "clefs.G")
(middleCPosition . -6)
(clefPosition . -2)
(instrumentCueName . ,(make-bold-markup "Flute"))
(midiInstrument . "flute")
)
part = {
g'4 b' d'' fis'' R1
g'4 b' d'' fis'' R1
g'4 b' d'' fis'' R1
}
arrangement = {
s1*2 \instrumentSwitch "cl Bflat" \bar"||"\reprintKey
s1*2 \instrumentSwitch "flute" \bar"||"\reprintKey
s1*2
}
global = { \key g\major s1*4 }
\new Staff \with { \printTransposition }
\new Voice << \global \arrangement \part >>
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user