lilypond-user
[Top][All Lists]
Advanced

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

scheme problem: colored background, layers


From: Big Noise
Subject: scheme problem: colored background, layers
Date: Sat, 29 Nov 2014 01:15:48 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

Hello everybody,

for analysis purposes, I'd like to put a colored background behind some notes.
Here's my first approach:


\version "2.18.0"

{
  << { R1 c'2 g' c' r R1 }
     \\
     {
       \override Voice.ClusterSpanner.color = #(rgb-color 0.5 0.6 1)
       \override Voice.ClusterSpanner.layer = #-1
       \makeClusters { s1 c'2 g' c' s s1 }
     }
     \\
     {
       \override Voice.ClusterSpanner.color = #(rgb-color 1.0 0.9 0.5)
       \override Voice.ClusterSpanner.layer = #-2
       \makeClusters { s1 <g c'''> q4 q2. s1 }
     }
  >>
}



Result: http://4.bp.blogspot.com/-h3plzLbjpdw/VHZZo4oVqlI/AAAAAAAAACY/6gL6EEf0JGk/s1600/ex01.gif

The blue line between the note heads is a cluster. To avoid covering the notes and staff lines, it's located in the layer "-1".
The yellow rectangle in the background (layer "-2") is achieved by a cluster as well. But as soon as the score gets longer, this can be quite a mess...

I would therefore prefer a (slightly modified) scheme function from Lilipond Snippet 726 "Coloring staves": http://lsr.di.unimi.it/LSR/Item?id=726


\version "2.18.0"

bgColor =
#(define-music-function (parser location y-lower y-upper color) (number? number? string?)
   #{\stopStaff
     \override Staff.StaffSymbol $'stencil =
     $(lambda (grob)
        (let* ((staff (ly:staff-symbol::print grob))
               (X-ext (ly:stencil-extent staff X))
               (Y-ext (ly:stencil-extent staff Y)))
          (set! Y-ext (cons
                       (- (car Y-ext) y-lower)
                       (+ (cdr Y-ext) y-upper)))
          (ly:grob-set-property! grob 'layer -10)
          (ly:stencil-add
           (ly:make-stencil (list 'color (eval-string color)
                              (ly:stencil-expr (ly:round-filled-box X-ext Y-ext 0))
                              X-ext Y-ext))
           staff)))
     \startStaff
   #})

{
  << { R1
       \bgColor #3 #3 "(rgb-color 1.0 0.9 0.5)" c'2 g' c'
       \bgColor #0 #0 "white" r R1 }
     \\
     {
       \override Voice.ClusterSpanner.color = #(rgb-color 0.5 0.6 1)
       \override Voice.ClusterSpanner.layer = #-1
       \makeClusters { s1 c'2 g' c' s s1 }
     }
  >>
}


Result: http://2.bp.blogspot.com/-tShfMsyLr04/VHZZo4nFNeI/AAAAAAAAACU/SDxqrHklKvk/s1600/ex02.gif

Here is my problem:
Now the staff lines and the yellow rectangle are located in the same layer, so it's not possible to place the blue cluster between them.
Is there a way to make the scheme function put the staff lines ("StaffSymbol") and the yellow rectangle into different layers?

Thanks in advance,
Klaus


reply via email to

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