[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: utility: \interpolate
From: |
Nicolas Sceaux |
Subject: |
Re: utility: \interpolate |
Date: |
Sat, 25 Feb 2006 09:42:05 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) |
May I nitpick about style?
Erik Sandberg <address@hidden> writes:
> #(define (make-rel-music-function sig fun)
> (let ((newfun (lambda args
> (make-music 'SequentialMusic
the indentation is broken here.
> 'elements (list (primitive-eval (cons fun args)))
Are you sure you want primitive-eval here?
(apply fun args)
> 'arguments args
> 'to-relative-callback (lambda (m r)
> (ly:music-set-property! m 'elements (ly:music-property m 'arguments))
The idomatic way of setting music properties is:
(set! (ly:music-property m 'elements) value)
> (let
Usually, you don't skip a line after let.
> ((ret (ly:music-sequence::simultaneous-relative-callback m r)))
> (ly:music-set-property! m 'elements
> (list (primitive-eval (cons fun (ly:music-property m 'elements)))))
> ret))))))
same remarks about primitive-eval and ly:music-set-property!
> (ly:make-music-function sig newfun)))
#(define (make-rel-music-function sig fun)
(let ((newfun (lambda args
(make-music 'SequentialMusic
'elements (list (apply fun args))
'arguments args
'to-relative-callback
(lambda (m r)
(set! (ly:music-property m 'elements)
(ly:music-property m 'arguments))
(let ((ret
(ly:music-sequence::simultaneous-relative-callback m r)))
(set! (ly:music-property m 'elements)
(list (apply fun (ly:music-property m
'elements))))
ret))))))
(ly:make-music-function sig newfun)))
> #(defmacro def-rel-music-function (args signature . body)
Actually, it was my mistake to call the macro def-music-function: it
should have been called define-music-function. Maybe you should call
your macro define-relative-music-function, or whatever makes the "rel"
clearer about what it means, and the same for make-rel-music-function.
> "As def-music-function, but the function arguments are affected by
> \\relative.
>
> The function may NOT have any side-effects.
> "
> `(make-rel-music-function (list ,@signature)
> (lambda (,@args)
> ,@body)))
>
> #(define (first-note chord)
> "Find the first element in an EventChord, which is a note event."
> (let first ((els (ly:music-property chord 'elements)))
> (cond
Usually, you don't skip a line after cond. first is not really a well
chosen name for what is done here, as in srfi-1, first is synonym to
car. I actually thought that in the else case, you were returning the
second element of elts, and to comment: use (second elts).
> ((not (pair? els)) '())
((null? els) #f)
> ((eq? (ly:music-property (car els) 'name) 'NoteEvent) (car els))
> (else (first (cdr els))))))
>
> #(define (simple-interpolate acc first last)
Note: first and last are function names in srfi-1.
> "Interpolates pitches from first to last, and appends to acc"
> (let* ((p1 (ly:music-property (first-note first) 'pitch))
> (p2 (ly:music-property (first-note last) 'pitch))
> (pitch-diff (- (ly:pitch-steps p2) (ly:pitch-steps p1)))
> (new-pitch (ly:make-pitch
> 0
> ((if (< 0 pitch-diff) + -) (ly:pitch-steps p1) 1)
> 0))
> )
Don't let closing parens alone on a line, and don't leave blank lines
inside functions.
(+ (ly:pitch-steps p1) (if (< 0 pitch-diff) 1 -1))
You can also use then functions 1+ and 1-.
> (if (and (<= pitch-diff 1) (>= pitch-diff -1))
(if (<= -1 pitch-diff 1)
makes the relation clearer.
nicolas