On Mon, May 4, 2015 at 10:04 PM, David Nalesnik <david.nales...@gmail.com>
wrote:

> Hi Kieren,
>
> On Sat, May 2, 2015 at 6:29 PM, Kieren MacMillan <
> kieren_macmil...@sympatico.ca> wrote:
>
>> Hi David,
>>
>> > > Out of curiosity, do you get results with color-tweaks2.ly (attached
>> somewhere above)?
>> > Same thing: the EE-added tweak gets executed, but doesn’t appear in the
>> log output.
>> > So it doesn't get colored?
>>
>> Sorry… let me be more clear. I \include-d the edition-engraver, and
>> compiled twice: once with an \editionMod to move the [initial] Clef, and
>> once without. The first time, the Clef moved (as expected) and was coloured
>> (as hoped); the second time, the Clef was neither moved nor coloured (both
>> as expected).
>
>
>> HOWEVER, the console output was identical in both cases: the tweak was
>> not recorded in the output (as I thought it should have been?).
>
>
> OK, then the modifying actual grobs approach is proving to be more useful
> on several counts.
>

And it works with that editionEngraver example.


>
> The attached file contains some improvements over color-tweaks2.ly.  The
> main difference is that it uses a simple Scheme engraver which must be
> \consists-ed.
>
> \voiceTwo and the like will result in colored objects (stems for example),
> but I don't think there's any help for that.  Call it a feature :)
>

oops, forgot the custom color settings.

Anyway, this should do the trick.  Let me know how it works out.

Best,
David

%%%%%%%%%%%%%%%%%%%%%%%%%%

override-color = #darkred

tweak-color = #blue

%tweak-color = #override-color

#(define (remove-first symbol alist)
   "Remove the first key-value pair of association list @var{alist}
whose key matches @var{symbol}."
   (let loop ((alist alist) (result '()))
     (cond
      ((null? alist) result)
      ((eq? (caar alist) symbol)
       (append result (cdr alist)))
      (else (loop (cdr alist)
              (append result (list (car alist))))))))

#(define (grob::has-default-prop grob prop)
   "Check all-grob-descriptions to see if symbol @var{grob} has
a default setting for symbol @var{prop}.  Either return the
setting or @code{#f}."
   (let ((description (assoc-get grob all-grob-descriptions)))
     (if description
         (assoc-get 'stencil description))))

#(define (mark-tweak grob)
   "Color @var{grob} if it has been tweaked.  The color to use is stored
in the global variables @var{override-color} and @var{tweak-color}."
   (let* ((default (assoc-get (grob::name grob) all-grob-descriptions))
          (props (ly:grob-basic-properties grob))
          ;; Our procedure has been added to the head of grob's basic
          ;; properties.  Let's not count it as a tweak!
          (props
           (remove
            (lambda (p)
              (and (procedure? (cdr p))
                   (eq? (procedure-name (cdr p)) 'mark-tweak)))
            props))
          ;; We're using after-line-breaking to set color of stencil, but
          ;; let's preserve its last setting
          (after-line-return (assoc-get 'after-line-breaking props))
          ;; Clef.glyph doesn't appear in all-grob-descriptions, but it
          ;; is set at some point automatically.  Don't mark it unless
          ;; it genuinely is a user override.  There may be other
          ;; such grobs.
          (props
           (if (eq? (grob::name grob) 'Clef)
               (reverse (remove-first 'glyph (reverse props)))
               props))
          (diff (lset-difference eq? props default)))
     ;; Tweaks will not appear in the "basic properties" alist of our grob,
but
     ;; we can find them through the music event which led to the grob.
This
     ;; is available through the stream-event which caused our grob.
     (if (null? diff)
         (let* ((cause (event-cause grob))
                (tweaks (and cause
                             (ly:music-property
                              (ly:event-property cause 'music-cause)
                              'tweaks))))
           (if (pair? tweaks)
               (set! (ly:grob-property grob 'color) tweak-color)))
         (set! (ly:grob-property grob 'color) override-color))

     ;; Return any default setting of after-line-breaking.
     after-line-return))

colorTweaksEngraver =
#(lambda (context)
   (make-engraver
    (acknowledgers
     ((grob-interface engraver grob source-engraver)
      (if (grob::has-default-prop grob 'stencil)
          (set! (ly:grob-property grob 'after-line-breaking)
                (mark-tweak grob)))))))


[...your music...]

\layout {
  \context {
    \Score
    \consists \colorTweaksEngraver
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to