Am 20.09.2016 um 19:12 schrieb PMA:
(define (colorNote n)
  (cond ((eq? (- n) 1) 'red )
        ((eq? (- n) 2) 'blue)))

This returns the symbol 'red or the symbol 'blue, not the constant named red (value (1.0 0.0 0.0)) or the constant named blue.

    \override NoteHead.font-size = #offset  % This line works.

Here you use # to switch from LilyPond to Scheme so you can use the Scheme variable offset.

    \override NoteHead.color = #(colorNote #offset) % *ERRORS*.

Here the first # switches to Scheme so the second # isn’t necessary anymore.

Slightly off-topic: your colorNote function is more complicated than necessary. (eq? (- n) 1) can be simplified to (eq? n -1) and I would recommend to use case instead of cond and eq?.


\version "2.18.2"

#(define (colorNote n)
  (case n
    ((-1) red)
    ((-2) blue)
    (else '())))
% the else case isn’t really necessary here but it prevents warnings or % errors if colorNote (or FS) is called with another value like 5
% (see example below)

FS =
#(define-music-function (parser location offset) (number?)
     \override NoteHead.font-size = #offset
     \override NoteHead.color = #(colorNote offset)

% example usage
  \FS -1 c' d' \FS -2 e' f' \FS 5 g' a'

lilypond-user mailing list

Reply via email to