lilypond-user
[Top][All Lists]
Advanced

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

Re: writing custom engravers in scheme - defining context properties?


From: Paul
Subject: Re: writing custom engravers in scheme - defining context properties?
Date: Mon, 10 Oct 2016 13:25:38 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0

Welcome to LilyPond!  More below...

On 10/10/2016 12:00 PM, Maxwell Phillips wrote:
I'm experimenting with writing custom scheme engravers, for example to deal with groups of staffs with complex rules about when each staff should be visible or hidden.

I can't figure out how to define the properties that engravers pass on to the contexts they "consist" (sorry if not using the right terminology).

For example, I want to define an engraver with property my-prop such that
\new Staff \with { \consists My_engraver }
allows me to \set Staff.my-prop to change the behavior of My_engraver.

Looks like you got a long way before asking on the list, kudos! What you're trying to do is not documented or in the LSR as far as I know.

The context properties you're talking about are not properties of engravers -- so you don't define them as part of creating an engraver -- but they can be accessed, modified, and used by engravers. (Engravers do their work in contexts and are added to them with \consists.)

All the source code I can find for engraver definitions is in C++, not scheme, and the examples of scheme engravers I've found online don't seem to include user-settable properties. Is it possible to accomplish this?

It is possible to define custom context properties as follows:

%%%%

% modified version of translator-property-description procedure
% from "scm/define-context-properties.scm"

#(define (add-context-prop symbol type?)
  (set-object-property! symbol 'translation-type? type?)
  (set-object-property! symbol 'translation-doc "custom context property")
(set! all-translation-properties (cons symbol all-translation-properties))
  symbol)

#(add-context-prop 'customProp number?)
#(add-context-prop 'anotherCustomProp list?)

%%%%

Then you can use them like any other context property (e.g. \set Staff.customProp), access them with a custom engraver, etc.

Note that custom context properties are not a supported feature of LilyPond (at least not yet[1]). I have not had any problems using them, but the way they work may change. (Apparently in the current implementation they persist beyond the processing of a given file, so be sure to set them to what you want before you use them.)

[1] http://lists.gnu.org/archive/html/lilypond-devel/2016-09/msg00116.html

-Paul




reply via email to

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