[CM] About the implementation of sturms function in Notes from the Metalevel
Emre Sevinc
emres at bilgi.edu.tr
Fri Oct 28 12:41:13 PDT 2005
I came to the 12. Chapter of Notes from the Metalevel
book and while I was trying to compile the sturms function
I had some warning from SBCL:
The details are at:
http://paste.lisp.org/display/12980
;; the code below (which is taken from Common Music
;; application produces an error:
;;
;;-+ Warnings (1)
;; `-- ==>
;; -1
;; This is not a (OR (SINGLE-FLOAT (0.0)) (DOUBLE-FLOAT (0.0d0)) (RATIONAL (0))):
;; -1
;; See also:
;; SBCL Manual, Handling of Types [node]
(define (strums key1 key2 rate dur amp)
(let ((step (if (< key2 key1) -1 1)) ;; e.g. 1 2 gives no warn.
(diff (abs (- key1 key2))))
(loop repeat (+ diff 1)
for key from key1 by step
for beg from 0 by rate
collect (new midi
:time beg
:duration dur
:amplitude amp
:keynum key))))
One of the possible solutions was to use a slightly different for in
the loop:
; this seems to solve the problem of
;; a potential *negative* stepping value
(define (strums key1 key2 rate dur amp)
(let ((step (if (< key2 key1) -1 1))
(diff (abs (- key1 key2))))
(loop repeat (+ diff 1)
for key = key1 then (+ key step)
for beg from 0 by rate
collect (new midi
:time beg
:duration dur
:amplitude amp
:keynum key))))
Another proposed solution is to to do a conditional rotatef of key1 and key2
and then do a for key from key1 to key2.
PS: Maybe this is already corrected in the CD that came with the
book (I couldn't find scores.cm in CVS version of CM) but I'm just the type of
guy who likes to type code from the book and I just wanted to share this
just in case somebody else is stuck in the same place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20051028/6d383dee/attachment.html>
More information about the Cmdist
mailing list