lilypond-user
[Top][All Lists]
Advanced

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

Re: Change color after a line break


From: Marc Hohl
Subject: Re: Change color after a line break
Date: Sun, 19 Jul 2015 10:38:23 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

Am 19.07.2015 um 10:04 schrieb David Kastrup:
Marc Hohl <address@hidden> writes:
[...]

This \applyContext is executed at Score level as no other contexts have
yet been created.

    c4\pp\< d e f
    \break \stopStaff
    \applyContext #(override-color-for-all-grobs (x11-color 'red))

This \applyContext is executed at Voice level.  Try

\context Score \applyContext ...

here.  You want Score level rather than Staff level in order to also
catch stuff like marks, bar numbers and so on.  You might want to use
\context Staff for the first \applyContext, just to make sure that you
don't get it executed in some other context due to unrelated stuff.

    \startStaff
    \grace { g16[( a g fis]) } g1\ff\!
}

I merely copied the example from lsr, where no explicit contexts are given, but I think I understand ...

Addendum:

I am using the bleeding edge self-compiled lilypond version 2.19.24
and tried

#(define (override-color-for-all-grobs color)
   (lambda (context)
    (let loop ((x all-grob-descriptions))
     (if (not (null? x))
      (let ((grob-name (caar x)))
       #{ \override #(list 'Staff grob-name 'color) = #color #}
       (loop (cdr x)))))))

Well, you indend this to be the same thing, but evaluating some music
expression and then throwing it away is not going to cause any visible
results.

Ah, the same mistake again – I had that before, and you corrected me in another thread. I *really* should be more careful.

  By the way, you can write

   #{ \override Staff . #grob-name . color = #color #}

instead in cases where an override music expression is actually needed.
Probably #{ \override Staff.#grob-name .color = #color #} would also
work but it seems nicer not to overdo the compression when putting
Scheme in the middle.

Ah, ok. I fiddled with the old "Grob #'property" syntax and ended with the list construct. Your proposal look quite better.


as well as the new overrideProperty command provided by David Kastrup
in one of the latest patch series:

#(define (override-color-for-all-grobs color)
   (lambda (context)
    (let loop ((x all-grob-descriptions))
     (if (not (null? x))
      (let ((grob-name (caar x)))
        (overrideProperty (list 'Score grob-name 'color) color)
       (loop (cdr x)))))))

No, overrideProperty is a real old thing (and also returns a music
expression which will use a different mechanism when interpreted).  What
I provided was propertyOverride (yes, that's a really fabulous naming
choice that will never cause anybody to confuse the two).

Ah, that's the culprit! I remembered that you provided (override ...)
at Scheme level and renamed the command shortly after that, but somehow
I confused overrideProperty and propertyOverride.


 Which again
is just another alias for what you wrote above, and as it is returning a
music expression, will not do the trick for you in the same way than the
other overrides.

Yes, I understand.

Now let's for exercise sake actually try going through a music
expression here.  If we do that, we cannot go through an \applyContext
hook since then no iterator will get to see our override any more.  We
could try creating Override stream events and sending them to the
context ourselves (that's how the respective iterators work) but that's
sort of pointless.  Instead, just let us create and use overrides
directly:

overrideColorForAll =
#(define-music-function (color) (color?)
#{ #@(map (lambda (dsc)
             #{ \override Score . #(car dsc) . color = #color
             #})
      all-grob-descriptions)
#})

Thanks a lot! Just to check that I have understood the underlying mechanism, I rewrote that according to

overrideColorForAll =
#(define-music-function (color) (color?)
#{ #@(map (lambda (dsc)
            (propertyOverride (list 'Score (car dsc) 'color) color))
     all-grob-descriptions)
#})

which seems to do the trick as well without switching between Scheme and LilyPond whithin overrideColorForAll.


\relative c' {
    \overrideColorForAll #(x11-color 'blue)
    c4\pp\< d e f
    \break \stopStaff
    \overrideColorForAll #(x11-color 'red)
    \startStaff
    \grace { g16[( a g fis]) } g1\ff\!
}

Thanks for your detailed explanations!

Marc





reply via email to

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