lilypond-user
[Top][All Lists]
Advanced

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

Re: Colored note heads with black outline


From: Paul Morris
Subject: Re: Colored note heads with black outline
Date: Wed, 9 Oct 2013 13:03:39 -0700 (PDT)

Pierre Perol-Schneider wrote
> Thanks Paul, your code is much better than the one I was going to put.
> Looks like a Christmas tree :)

Thanks Pierre, and thanks for figuring out how to do the note heads in the
first place!  That was a clever solution.  

I've made the changes you suggested, and made it so that it's possible to
assign different colors to sharp, flat, double-sharp, and double-flat
alterations, if you want.  It's more verbose this way, but also more
flexible.  See below...

-Paul


%%%%%%%%%%%%%%%%%

\version "2.17.28"

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) green) ;; Dbb
                        ((-1/2) green) ;; Db
                        ((0) green) ;; D
                        ((1/2) green) ;; D#
                        ((1) green) ;; D##
                        (else black)))
                 ((2) (case alt
                        ((-1) blue) ;; Ebb
                        ((-1/2) blue) ;; Eb
                        ((0) blue) ;; E
                        ((1/2) blue) ;; E#
                        ((1) blue) ;; E##
                        (else black)))
                 ((3) (case alt
                        ((-1) red) ;; Fbb
                        ((-1/2) red) ;; Fb
                        ((0) red) ;; F
                        ((1/2) red) ;; F#
                        ((1) red) ;; F##
                        (else black)))
                 ((4) (case alt
                        ((-1) green) ;; Gbb
                        ((-1/2) green) ;; Gb
                        ((0) green) ;; G
                        ((1/2) green) ;; G#
                        ((1) green) ;; G##
                        (else black)))
                 ((5) (case alt
                        ((-1) blue) ;; Abb
                        ((-1/2) blue) ;; Ab
                        ((0) blue) ;; A
                        ((1/2) blue) ;; A#
                        ((1) blue) ;; A##
                        (else black)))
                 ((6) (case alt
                        ((-1) yellow) ;; Bbb
                        ((-1/2) yellow) ;; Bb
                        ((0) yellow) ;; B
                        ((1/2) yellow) ;; B#
                        ((1) yellow) ;; B##
                        (else black)))
                 (else black))))

     ;; just for dev work
     ;; (display dur-log) (newline)
     ;; (display nnm) (newline)
     ;; (display alt) (newline)

     (set! stl
           (cond
            ;; quarter notes and smaller
            ((> dur-log 1)
             (grob-interpret-markup grob
               #{ \markup {
                 \combine
                 \musicglyph #"noteheads.s2"
                 \translate-scaled #'(0.05 . 0)
                 \scale #'(1.03 . 0.98)
                 \rotate #'3
                 \magnify # 0.9 \with-color #clr
                 \musicglyph #"noteheads.s2"
               } #}
               ))
            ;; half notes
            ((= dur-log 1)
             (grob-interpret-markup grob
               #{ \markup {
                 \combine
                 \translate-scaled #'(0.11 . -0.01)
                 \scale #'(1 . 0.82)
                 \rotate #'7
                 \magnify # 0.85
                 \musicglyph #"noteheads.s1"
                 \combine
                 \musicglyph #"noteheads.s1"
                 \translate-scaled #'(0.07 . 0)
                 \scale #'(1.02 . 0.98)
                 \rotate #'2
                 \magnify # 0.9 \with-color #clr
                 \musicglyph #"noteheads.s1"
               } #}
               ))
            ;; whole notes
            ((< dur-log 1)
             (grob-interpret-markup grob
               #{ \markup {
                 \combine
                 \translate-scaled #'(0.2 . 0)
                 \magnify # 0.8
                 \musicglyph #"noteheads.s0"
                 \combine
                 \musicglyph #"noteheads.s0"
                 \translate-scaled #'(0.08 . 0)
                 \scale #'(1.03 . 1)
                 \magnify # 0.9 \with-color #clr
                 \musicglyph #"noteheads.s0"
               } #}
               ))))

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


music =
\relative f' {
  c4 d e f g a b c d e f g a b c d
  c,,2 d e f g a b c d e f g a b c d
  c,,1 d e f g a b c d e f g a b c
}

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




--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Colored-note-heads-with-black-outline-tp151821p152033.html
Sent from the User mailing list archive at Nabble.com.



reply via email to

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