lilypond-user
[Top][All Lists]
Advanced

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

[LSR] Colored notes with black outlines (enhancement).


From: Pierre Perol-Schneider
Subject: [LSR] Colored notes with black outlines (enhancement).
Date: Tue, 17 Mar 2015 09:00:59 +0100

Hi List, Hi Paul,

Paul, do you remember this snippet we committed something like 2 years ago: http://lsr.di.unimi.it/LSR/Item?id=890 ?
Well, a recent discussion regarding the '\path' command made me think about the following changes.
Major advantages :
- one can modify the outline thickness.
- one can choose whether the noteheads or the outlines is coloured.
Minor effect : the output seems much better to me, not sure though ;)

So, here it goes:

\version "2.18.2"

coloredNoteHeads =
#(lambda (grob)
   (let* ((fsz  (ly:grob-property grob 'font-size 0.0))
          (mult (magstep fsz))
          (stl '())
          (dur-log (ly:grob-property grob 'duration-log))
          (pch (ly:event-property (event-cause grob) 'pitch))
          (nnm (ly:pitch-notename pch))
          (alt (ly:pitch-alteration pch))
          (clr (case nnm
                 ((0) (case alt
                        ((-1) red) ;; Cbb
                        ((-1/2) red) ;; Cb
                        ((0) red) ;; C
                        ((1/2) red) ;; C#
                        ((1) red) ;; C##
                        (else black)))
                 ((1) (case alt
                        ((-1) (x11-color 'orange)) ;; Dbb
                        ((-1/2) (x11-color 'orange)) ;; Db
                        ((0) (x11-color 'orange)) ;; D
                        ((1/2) (x11-color 'orange)) ;; D#
                        ((1) (x11-color 'orange)) ;; D##
                        (else black)))
                 ((2) (case alt
                        ((-1) yellow) ;; Ebb
                        ((-1/2) yellow) ;; Eb
                        ((0) yellow) ;; E
                        ((1/2) yellow) ;; E#
                        ((1) yellow) ;; E##
                        (else black)))
                 ((3) (case alt
                        ((-1) green) ;; Fbb
                        ((-1/2) green) ;; Fb
                        ((0) green) ;; F
                        ((1/2) green) ;; F#
                        ((1) green) ;; F##
                        (else black)))
                 ((4) (case alt
                        ((-1) blue) ;; Gbb
                        ((-1/2) blue) ;; Gb
                        ((0) blue) ;; G
                        ((1/2) blue) ;; G#
                        ((1) blue) ;; G##
                        (else blue)))
                 ((5) (case alt
                        ((-1) (x11-color 'purple)) ;; Abb
                        ((-1/2) (x11-color 'purple)) ;; Ab
                        ((0) (x11-color 'purple)) ;; A
                        ((1/2) (x11-color 'purple)) ;; A#
                        ((1) (x11-color 'purple)) ;; A##
                        (else black)))
                 ((6) (case alt
                        ((-1) (x11-color 'brown)) ;; Bbb
                        ((-1/2) (x11-color 'brown)) ;; Bb
                        ((0) (x11-color 'brown)) ;; B
                        ((1/2) (x11-color 'brown)) ;; B#
                        ((1) (x11-color 'brown)) ;; B##
                        (else black)))
                 (else black))))

     (set! stl
           (cond
            ;; quarter notes and smaller
            ((> dur-log 1)
             (grob-interpret-markup grob
                #{
                  \markup {
                    \combine
                    \with-color #clr
                    \musicglyph #"noteheads.s2"
                    %% optional:
                    %\with-color #clr  
                    %% change edge thickness:
                    \path #0.07 #'(
                       (moveto   0.00   -0.20)
                       (curveto  0.00   -0.20    0.00   -0.69    0.69   -0.50)
                       (curveto  0.69   -0.50    1.08   -0.38    1.27   -0.01)
                       (curveto  1.27   -0.01    1.44    0.34    1.14    0.49)
                       (curveto  1.14    0.49    0.90    0.61    0.60    0.49)
                       (curveto  0.60    0.49   -0.02    0.25    0.00   -0.20))
                  }
                #}
               ))
            ;; half notes
            ((= dur-log 1)
             (grob-interpret-markup grob
               #{
                 \markup {
                    \combine
                    \with-color #clr  
                    \musicglyph #"noteheads.s1"
                    %% optional:
                    %\with-color #clr  
                    %% change edge thickness:  
                    \path #0.07 #'(
                       (moveto  0.130   -0.200)
                       (curveto 0.130   -0.200    0.070   -0.341    0.200   -0.410)
                       (curveto 0.200   -0.410    0.270   -0.460    0.400   -0.400)
                       (curveto 0.400   -0.400    0.850   -0.160    1.100    0.040)
                       (curveto 1.100    0.040    1.390    0.225    1.210    0.395)
                       (curveto 1.210    0.395    1.130    0.470    1.000    0.410)
                       (curveto 1.000    0.410    0.540    0.190    0.240   -0.070)
                       (curveto 0.240   -0.070    0.140   -0.160    0.130   -0.200)
                       (moveto  0.060    0.000)
                       (curveto 0.060    0.000   -0.220   -0.610    0.450   -0.540)
                       (curveto 0.450   -0.540    0.800   -0.530    1.100   -0.320)
                       (curveto 1.100   -0.320    1.250   -0.230    1.360    0.110)
                       (curveto 1.360    0.110    1.490    0.490    1.150    0.540)
                       (curveto 1.150    0.540    0.900    0.580    0.550    0.465)
                       (curveto 0.550    0.465    0.200    0.380    0.060    0.000))
                  }
               #}
               ))
            ;; whole notes
            ((= dur-log 0)
             (grob-interpret-markup grob
              #{
                \markup {
                  \combine
                  \with-color #clr  
                  \musicglyph #"noteheads.s0"
                  %% optional:
                  %\with-color #clr  
                  %% change edge thickness:  
                  \path #0.07 #'(
                     (moveto  0.610   0.260)
                     (curveto 0.610   0.260    0.460   -0.190    0.920   -0.410)
                     (curveto 0.920  -0.410    1.330   -0.600    1.410   -0.200)
                     (curveto 1.410  -0.200    1.500    0.290    1.000    0.440)
                     (curveto 1.000   0.440    0.700    0.535    0.610    0.260)
                     (moveto  0.300   0.390)
                     (curveto 0.300   0.390   -0.380    0.030    0.300   -0.390)
                     (curveto 0.300  -0.390    0.900   -0.740    1.700   -0.390)
                     (curveto 1.700  -0.390    2.400   -0.030    1.690    0.400)
                     (curveto 1.690   0.400    1.050    0.750    0.300    0.390))
                }
              #}
               ))
            ;; breve notes
            ((< dur-log 0)
             (grob-interpret-markup grob
               #{
                  \markup {
                    \combine
                    \with-color #clr  
                    \musicglyph #"noteheads.sM1"
                    %% optional:
                    %\with-color #clr  
                    %% change edge thickness:   
                    \path #0.07 #'(
                       (moveto  -0.160   0.000)
                       (lineto  -0.160   0.620)
                       (curveto -0.160   0.620   -0.160    0.690   -0.080    0.700)
                       (curveto -0.080   0.700    0.010    0.710    0.015    0.620)
                       (lineto   0.015   0.100)
                       (curveto  0.015   0.100    0.080    0.500    0.950    0.550)
                       (curveto  0.950   0.550    1.740    0.575    1.940    0.100)
                       (lineto   1.940   0.620)
                       (curveto  1.940   0.620    1.940    0.690    2.020    0.700)
                       (curveto  2.020   0.700    2.110    0.710    2.115    0.620)
                       (lineto   2.115  -0.620)
                       (curveto  2.115  -0.620    2.110   -0.700    2.020   -0.700)
                       (curveto  2.020  -0.700    1.940   -0.690    1.940   -0.620)
                       (lineto   1.940  -0.090)
                       (curveto  1.940  -0.090    1.820   -0.540    0.950   -0.545)
                       (curveto  0.950  -0.545    0.110   -0.500    0.015   -0.090)
                       (lineto   0.015  -0.620)
                       (curveto  0.015  -0.620    0.010   -0.700   -0.080   -0.700)
                       (curveto -0.080  -0.700   -0.160   -0.690   -0.160   -0.620)
                       (lineto  -0.160   0.000)
                       (moveto   0.585   0.260)
                       (curveto  0.585   0.260    0.435   -0.190    0.895   -0.410)
                       (curveto  0.895  -0.410    1.305   -0.600    1.385   -0.200)
                       (curveto  1.385  -0.200    1.475    0.290    0.975    0.440)
                       (curveto  0.975   0.440    0.675    0.535    0.585    0.260))
                  }                 
               #}
               ))
            ))

     (set! (ly:grob-property grob 'stencil)
           (ly:stencil-scale stl mult mult))))

%%%% USAGE EXAMPLE %%%%

music =
\relative f' {
  c4 d e f
  g4 a b c
  d2 e f2 g
  a1 b
  \set Timing.measureLength = #(ly:make-moment 2/1)
  c\breve
}

\new Staff
  \with {
    \override NoteHead.layer = #2
    \override NoteHead.before-line-breaking = \coloredNoteHeads
  }
  { \music }



It shouldn't be very difficult to add those two new variables in the code, should it? But since 'coloredNoteHeads' is a property value, I cannot find any handy way.

Any idea ?


TIA,

Pierre






reply via email to

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