[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Please help with Lilypond calling Scheme
From: |
Malte Meyn |
Subject: |
Re: Please help with Lilypond calling Scheme |
Date: |
Tue, 20 Sep 2016 23:30:22 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
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'
}