[Top][All Lists]

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

Re: Tweaking in an engraver

From: Timothy Lanfear
Subject: Re: Tweaking in an engraver
Date: Thu, 23 Jul 2015 21:59:09 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.8.0

On 19/07/15 18:27, Timothy Lanfear wrote:
On 19 Jul 2015, at 19:12, Peter Gentry <address@hidden> 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 

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)))
       ((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.

reply via email to

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