[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing \tweak-s to engravers
From: |
David Kastrup |
Subject: |
Re: Passing \tweak-s to engravers |
Date: |
Thu, 14 Jun 2018 13:32:36 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Urs Liska <address@hidden> writes:
> I have been banging my head against the wall for quite some time now,
> but finally I'm at least at a point where I can ask a question here.
>
> I am programmatically attaching a custom grob property to some music
> and want to later act upon that in an engraver.
"later" is the key. To do something "later" than something else, that
something else has to happen _earlier_.
> When I tried to switch the attachment process from \once \override to
> \tweak the engraver suddenly didn't recognize the property
> anymore.
It did. _After_ you looked.
> First I thought I got it wrong with where the property was attached in
> the music expression, but now I've realized the following behaviour:
>
> When an engraver is consisted to a Voice or Staff or similar context
> only properties created through overrides are visible to the
> acknowledger while tweaks seem to be hidden. However, if I consist the
> engraver to Score also tweaks are recognized.
>
> The following MWE shows this behaviour with a common grob property,
> but it's the same with my custom grob property. For my use case in
> scholarLY it's neither an option to switch back to \once \override
> (because also \tweak-able post-events have to be supported) nor to
> consist the engraver to Score (because I need to know from which
> context the annotations come).
>
> So what do I have to do to make a Voice/Staff-consisted engraver aware
> of \tweak-s and not only of \override-s?
> And why is that behaviour as it is?
>
> %%%
> \version "2.19.80"
>
> testEngr =
> #(lambda (context)
> (make-engraver
> (acknowledgers
> ((note-head-interface engraver grob source-engraver)
> (ly:message "Notehead color: ~a" (ly:grob-property grob 'color))
> ))))
>
> \layout {
> \context {
> % uncomment *one* of the following two lines
> \Staff
> %\Score
> \consists #testEngr
> }
> }
>
> \relative {
> \once \override NoteHead.color = #red c'
> \tweak color #red c'
> }
> %%%
>From the Engraver tutorial in the Contributor's Guide (Acknowledging grobs):
Acknowledge functions are called in the order engravers are
‘\consist’-ed (the only exception is if you set ‘must-be-last’ to ‘#t’).
There will always be a call to ‘process-acknowledged ()’ whenever
grobs have been created, and _reading_ stuff from grobs should be
delayed until then since other acknowledgers might _write_ stuff into a
grob even after your acknowledger has been called. So the basic
workflow is to use the various acknowledgers to _record_ the grobs you
are interested in and _write_ stuff into them (or do read/write stuff
that more or less is accumulative and/or really unrelated to other
engravers), and then use the ‘process-acknowledged ()’ hook for
processing (including _reading_) the grobs you had recorded.
You can create new grobs in ‘process-acknowledged ()’. That will
lead to a new cycle of ‘acknowledger ()’ calls followed by a new cycle
of ‘process-acknowledged ()’ calls.
Note that tweaks are applied by the acknowledger in the Tweak_engraver.
I repeat my advice to read the Engraver tutorial. Really. In this
case, the central paragraph I quoted is very, very relevant.
--
David Kastrup