Changing every grob's color in a staff

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing every grob's color in a staff

Maurizio Tomasi
Hello to everybody,

  I am writing separate parts of Schubert's "Salve Regina"
for my chorus. I would like to include every staff in the
scores, but use a black color for the part itself and a
gray color for the others.

So, for instance, the score for tenor voices should use a
black color for the tenor staff and gray color for sopranos,
altos and basses.

My first try was to write a function that set manually the
color for each possible grob in the Staff and Voice context,
but this is boring and not elegant at all.

My next idea was to write a Scheme function which changes
the color property of each grob in a Staff, but I have
problem in implementing it. I used something like:

#(define (gray-grob grob grob-origin context)
  (set! (ly:grob-property grob 'color) (x11-color 'grey)))

...

\new Staff {

        \set Staff.instrument = "Contralti"

        \applyoutput #gray-grob

        (notes...)
}

but unfortunately \applyoutput works on the first grob
only. How could I tell Lilypond to use "gray-grob" on
every grob on the staff?

Thanks in advance,
  Maurizio Tomasi.




_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Changing every grob's color in a staff

Han-Wen Nienhuys
Maurizio Tomasi wrote:
> My first try was to write a function that set manually the
> color for each possible grob in the Staff and Voice context,
> but this is boring and not elegant at all.

> but unfortunately \applyoutput works on the first grob
> only. How could I tell Lilypond to use "gray-grob" on
> every grob on the staff?

A couple of options:

- write an "all_grob_property_engraver", which takes a list like

   allGrobProperties =  #`(color ,gray)

and applies that to every grob.

- Use scheme code to set #'color in all grobs. You can get a list of
grob names from the all-grob-descriptions variable.



--
  Han-Wen Nienhuys - [hidden email] - http://www.xs4all.nl/~hanwen


_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Changing every grob's color in a staff

Maurizio Tomasi
In reply to this post by Maurizio Tomasi
Thanks a lot for your suggestions, Han-Wen. I finally managed to get what I
wanted. I post my solution here:

--------------------------------------------------------------------
\version "2.6.4"

#(define (override-color-for-all-grobs color)
  (lambda (context)
   (let loop ((x all-grob-descriptions))
    (if (not (null? x))
     (let ((grob-name (car (car x))))
      (ly:context-pushpop-property context grob-name 'color color)
      (loop (cdr x)))))))

\new Staff \relative c' {
    \applycontext #(override-color-for-all-grobs (x11-color 'gray))

    c4-\pp-\< d e f | \grace { g16[( a g fis]) } g1-\ff-\!
}
--------------------------------------------------------------------

I am quite proud of this: it's my first try using Scheme functions in a Lilypond
file!

Maurizio.



_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Changing every grob's color in a staff

Graham Percival-2

On 14-Nov-05, at 2:56 AM, Maurizio Tomasi wrote:

> Thanks a lot for your suggestions, Han-Wen. I finally managed to get
> what I
> wanted. I post my solution here:

Thanks!  Could you also add this snippet to the Lilypond Snippet
Repository?  I think it could be useful for other people to see it.

Cheers,
- Graham



_______________________________________________
lilypond-user mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/lilypond-user