[CM] About the implementation of sturms function in Notes from the Metalevel

Emre Sevinc emres@bilgi.edu.tr
Fri, 28 Oct 2005 22:41:13 +0300


This is a multi-part message in MIME format.

------_=_NextPart_001_01C5DBF7.8DC9A8AC
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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)
;; `-- =3D=3D>
;;       -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 =3D 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=20
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=20
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.


------_=_NextPart_001_01C5DBF7.8DC9A8AC
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7638.1">
<TITLE>About the implementation of sturms function in Notes from the =
Metalevel</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=3D2>I came to the 12. Chapter of Notes from the =
Metalevel<BR>
book and while I was trying to compile the sturms function<BR>
I had some warning from SBCL:<BR>
<BR>
The details are at:<BR>
<BR>
<A =
HREF=3D"http://paste.lisp.org/display/12980">http://paste.lisp.org/displa=
y/12980</A><BR>
<BR>
;; the code below (which is taken from Common Music<BR>
;; application produces an error:<BR>
;;<BR>
;;-+&nbsp; Warnings (1)<BR>
;; `-- =3D=3D&gt;<BR>
;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -1<BR>
;;&nbsp;&nbsp;&nbsp;&nbsp; This is not a (OR (SINGLE-FLOAT (0.0)) =
(DOUBLE-FLOAT (0.0d0)) (RATIONAL (0))):<BR>
;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -1<BR>
;;&nbsp;&nbsp;&nbsp;&nbsp; See also:<BR>
;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SBCL Manual, Handling of Types =
[node]<BR>
<BR>
<BR>
(define (strums key1 key2 rate dur amp)<BR>
&nbsp; (let ((step (if (&lt; key2 key1) -1 1)) ;; e.g. 1 2 gives no =
warn.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (diff (abs (- key1 =
key2))))<BR>
&nbsp;&nbsp;&nbsp; (loop repeat (+ diff 1)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for key from key1 =
by step<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for beg from 0 by =
rate<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collect (new =
midi<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :time beg<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :duration dur<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :amplitude amp<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :keynum key))))<BR>
<BR>
<BR>
<BR>
One of the possible solutions was to use a slightly different for in<BR>
the loop:<BR>
<BR>
<BR>
; this seems to solve the problem of<BR>
;; a potential *negative* stepping value<BR>
<BR>
(define (strums key1 key2 rate dur amp)<BR>
&nbsp; (let ((step (if (&lt; key2 key1) -1 1))<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (diff (abs (- key1 =
key2))))<BR>
&nbsp;&nbsp;&nbsp; (loop repeat (+ diff 1)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for key =3D key1 =
then (+ key step)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for beg from 0 by =
rate<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; collect (new =
midi<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :time beg<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :duration dur<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :amplitude amp<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :keynum key))))<BR>
<BR>
Another proposed solution is to to do a conditional rotatef of key1 and =
key2<BR>
and then do a for key from key1 to key2.<BR>
<BR>
PS: Maybe this is already corrected in the CD that came with the<BR>
book (I couldn't find scores.cm in CVS version of CM) but I'm just the =
type of<BR>
guy who likes to type code from the book and I just wanted to share =
this<BR>
just in case somebody else is stuck in the same place.<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C5DBF7.8DC9A8AC--