On 2018-09-27 10:54 pm, Federico Bruni wrote:
Il giorno gio 27 set 2018 alle 21:29, Tim Meier <timmeie...@yahoo.com>
ha scritto:
Hello,

unfortunately I'm not that well versed in the lillypond/scheme syntax. What I want to do is basically this (in pseudocode):

if (noteDuration is quarter) => make noteHead blue
if (noteDuration is half) => make noteHead red
...

Can someone tell me how I would write that in Scheme?


You may adapt this snippet to work on durations instead of pitches:
http://lilypond.org/doc/v2.19/Documentation/snippets/pitches#pitches-coloring-notes-depending-on-their-pitch

IMO a new coloring-notes-depending-on-their-duration.ly file should be
added to the Snippets manual if someone comes up with the required
code.

Here's a quick adaptation:

%%%%
\version "2.19.82"

#(define color-mapping
  (list
    (cons (ly:make-duration -1 0 1 1) (x11-color 'red))
    (cons (ly:make-duration 0 0 1 1) (x11-color 'orange))
    (cons (ly:make-duration 1 1 1 1) (x11-color 'yellow))
    (cons (ly:make-duration 2 0 1 1) (x11-color 'green))
    (cons (ly:make-duration 1 0 1 1) (x11-color 'blue))
    (cons (ly:make-duration 2 1 1 1) (x11-color 'violet))
    (cons (ly:make-duration 3 0 1 1) (x11-color 'red))
    (cons (ly:make-duration 3 1 1 1) (x11-color 'orange))
    (cons (ly:make-duration 4 0 1 1) (x11-color 'yellow))
    (cons (ly:make-duration 1 0 2 3) (x11-color 'green))
    (cons (ly:make-duration 2 0 2 3) (x11-color 'blue))))

#(define (duration-equals? d1 d2)
  (and (not (ly:duration<? d1 d2)) (not (ly:duration<? d2 d1))))

#(define (duration-to-color duration)
  (let ((color (assoc duration color-mapping duration-equals?)))
    (if color (cdr color))))

#(define (color-notehead grob)
  (duration-to-color
    (ly:event-property (event-cause grob) 'duration)))

\score {
  \new Staff \relative b' {
    \override NoteHead.color = #color-notehead
    b \breve 1 2. 4 2 4. 8 8. 16 \tuplet 3/2 { 2 4 } r4 |
  }
}
%%%%

Don't know if this is up to snippet standards, though.

-- Aaron Hill
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to