[Top][All Lists]

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

Re: Tweaking in an engraver

From: tisimst
Subject: Re: Tweaking in an engraver
Date: Thu, 23 Jul 2015 14:03:06 -0700 (MST)


That is absolutely fantastic! What a great way to set up and use instruments! Great work!

- Abraham

On 7/23/2015 2:59 PM, Timothy Lanfear-2 [via Lilypond] wrote:
On 19/07/15 18:27, Timothy Lanfear wrote:
>> On 19 Jul 2015, at 19:12, Peter Gentry <[hidden email]> 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

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

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

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.

lilypond-user mailing list
[hidden email]

If you reply to this email, your message will be added to the discussion below:
To start a new topic under User, email [hidden email]
To unsubscribe from Lilypond, click here.

View this message in context: Re: Tweaking in an engraver
Sent from the User mailing list archive at

reply via email to

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