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: David Kastrup
Subject: Re: Change color after a line break
Date: Sun, 19 Jul 2015 10:04:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Marc Hohl <address@hidden> writes:

> Am 17.07.2015 um 18:59 schrieb Marc Hohl:
>> Hi list,
>>
>> for strange reasons, I have to color complete lines in different colors.
>>
>> I found http://lsr.di.unimi.it/LSR/Item?id=443 which works
>> great for complete scores, but if I call \applyContext ...
>> after a line break, the color of the Staff lines does not change.
>> I tried \stopStaff/\startStaff with no visible difference.
>>
>> How can I change the definition of override-color-for-all-grobs
>> to make the second staff line completely red?

The definition is fine.  The application isn't.

>> #(define (override-color-for-all-grobs color)
>>    (lambda (context)
>>     (let loop ((x all-grob-descriptions))
>>      (if (not (null? x))
>>       (let ((grob-name (caar x)))
>>        (display grob-name)
>>        (ly:context-pushpop-property context grob-name 'color color)
>>        (loop (cdr x)))))))
>>
>> \relative c' {
>>    \applyContext #(override-color-for-all-grobs (x11-color 'blue))

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\!
>> }
>
> 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.  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.

> 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).  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.

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)
#})

\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\!
}

-- 
David Kastrup



reply via email to

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