lilypond-user
[Top][All Lists]
Advanced

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

Re: Catch direction operators


From: David Kastrup
Subject: Re: Catch direction operators
Date: Sun, 29 Sep 2013 09:44:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

David Nalesnik <address@hidden> writes:

> Hi Urs,
>
>
> On Sat, Sep 28, 2013 at 12:13 PM, Urs Liska <address@hidden> wrote:
>
>> Hi,
>>
>> I have a 'function' that redefines commands like \slurUp to color the
>> corresponding grob (highlighting manual interventions during score
>> development).
>>
>> Is it possible to 'catch' instances of grobs whose direction has been set
>> by the ^ and _ operators and call a music function on the affected object.
>> I'd like to write
>>
>> a^(
>>
>> and as a result get
>>
>> \once \override Slur #'color = red
>> a^(
>>
>> Any ideas?
>>
>
> I couldn't get any results with a music function, but a little
> experimenting got me a tiny engraver which responds to the directional
> operators.  Not sure how useful this is, but here goes:
>
> \version "2.17.25"
>
> #(define (Color_explicit_direction_engraver ctx)
>     (make-engraver
>      (acknowledgers
>       ((slur-interface trans grob source)
>        (let* ((event (event-cause grob))
>               (dir (ly:event-property event 'direction)))
>          (if (not (null? dir))
>              (set! (ly:grob-property grob 'color) red)))))))
>
> \new Staff {
>   c''^(
>   d'')
>   c''(
>   d'')
>   c''_(
>   d'')
>   <c'' e''>^(
>   <d'' f''>)
> }
>
> \layout {
>   \context {
>     \Staff
>     \consists #Color_explicit_direction_engraver
>   }
> }

Well, that triggers the "it's easier to manipulate grobs than music
expression" complaint of Harm.

Now actually, in this case the simplest and most versatile course to me
seems like using _neither_ an engraver _nor_ a music expression
manipulation.  Instead something like

colorizeDir =
#(define-music-function (parser location item)
  (symbol-list-or-music?)
  (define (grob-colorize-dir grob)
    (let ((ev (event-cause grob)))
      (and ev (ly:event-property ev 'direction #f)
              red)))
  #{ \tweak color #grob-colorize-dir #item #})

\new Staff \with { \colorizeDir Slur } {
  c''^(
  d'')
  c''(
  d'')
  \undo \colorizeDir Staff.Slur
  c''_(
  d'')
  <c'' e''>-\once \colorizeDir ^(
  <d'' f''>)
}
It's easy to use on multiple grob types, individual music expressions
and other stuff.

-- 
David Kastrup

reply via email to

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