On 19/07/15 18:27, Timothy Lanfear wrote:
On 19 Jul 2015, at 19:12, Peter Gentry <[email protected]> wrote:

The OP described wanting to tweak a note property depending on its pitch. Now I 
may be missing something but do you need to create
an engraver for this.

I am after something like your solution. Part of my motivation was to learn how 
engravers work. I can follow up with more detail in a few days when I return 
home.

I mostly use LilyPond to transcribe and arrange music for my recorder group. Being fed up with repeating the same boiler plate for each piece, I set up some infrastructure to help.

Loosely inspired by \addInstrumentDefinition, I create definitions for each size of recorder like this,

#(add-instrument-definition 'Descant
   `((instrumentName      . "Descant Recorder")
     (shortInstrumentName . "D")
     (instrumentCueName   . "Descant")
     (clef                . "treble^8")
(range . (,(ly:make-pitch 0 6 1/2) ,(ly:make-pitch 3 1 0)))
     (midiInstrument      . "recorder")))

which is enough to calculate the additional arcana like clefPosition, middleCPosition and build pre-defined contexts for each size of recorder, and a RecorderConsort context that accepts them. So I can now write

\new RecorderConsort <<
  \new Descant { ... }
  \new Treble { ... }
  \new Tenor { ... }
  \new Bass { ... }
>>

and automatically get the right clef, midi instrument and labels like instrumentName.

When arranging it is handy to be able to spot notes outside the range of the instrument by colouring them, e.g.

\new RecorderConsort <<
  \new Descant \with { \outOfRange } { ... }
  \new Treble { ... }
  \new Tenor { ... }
  \new Bass { ... }
>>

An engraver to do this could be

outOfRangeEngraver =
#(lambda (context)
 (let* ((instrument (ly:context-name context))
        (inst-def   (ly:assoc-get instrument instrument-definitions))
        (range      (ly:assoc-get 'range inst-def))
        (low        (first  range))
        (high       (second range)))
   (make-engraver
     (acknowledgers
       ((note-head-interface engraver grob source-engraver)
        (let* ((cause (ly:grob-property  grob  'cause))
               (pitch (ly:event-property cause 'pitch)))
          (if (or (ly:pitch<? pitch low) (ly:pitch<? high pitch))
            (ly:grob-set-property! grob 'color red))))))))

outOfRange = \with { \consists \outOfRangeEngraver }

--
Timothy Lanfear, Bristol, UK.


_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to