[CM] help with case statement

2016-01-26 Thread Lynn Artas
Hello list,

   I’m working on translating some old CM code and am stumbling on how to
do a case statement in Grace. I’m giving a pared-down example. Currently
the problems (likely all related) are:

1. I do get one note out (yay) in addition to the error:

>>> Error: attempt to apply the integer 1 to ({s7-error}-11 80 8.1
# 8.1 8.1 {s7-error}-11 {s7-error}-11)?

casethejoint: (ffi_cm_print args) ; args: ("attempt to
apply ~A ~S t...

casethejoint: ((set! {v}-567 (+ {v}-567 1)) {w...

casethejoint: (call-with-exit (lambda (return)... ; thecase: 0, newdur: 8.1

   ; newkeynum: 80

   ; waittime: 8.1

   ; thetime: 8.1

casethejoint: (sprout (casethejoint))

No success single quoting.

2. It seems to always pick the second case, whether “thecase” picks 0 or 1,
or whether I switch the numbers (make case 1 come first and case 0 second).

3. When I use the commented line (process while (<= theme 100) to control
the length of the process, it is clear that time doesn’t update. (This
update method works fine when not part of the attempted case statement.)

Any leads on documentation appreciated—I’ve been through the examples that
come with Grace, and of course, the online documentation, without success.

Please pardon the formatting and many thanks for any tips.

;;; -*- syntax: Lisp; font-size: 16; line-numbers: no; -*-
(define speeds (make-cycle '(0.2 0.3 0.4 0.2 4 3.5 1 1.2 2.4 3.9 0.3 8.2
7.8 5.2 0.2 5.4 3.4 5.8 6.1 2.2 4.8 2.4 0.3 4.7 4.4 4.4 0.1
7.2 3.7 9 1.8 10.1 4.2 4.6 4.9 4.8 1.9 4.8 0.9 5.6 3.5 3 3.6 3 4.3 2.8 5.5
5.6 5.1 1.2 1.2 7.6 5.6 5
3.5 3.1 4.6 3 4.2 4.4 4.4 5.8 3.4 4.9 3.9 0.2 9.2 12.5 5 0.5 3.6 6.2 11.9
11.3 1.2 0.3 2.3 1.9 2.5 4.7
3.6 3.9 3.6 0.4 6.9 2.3 2.6 2.5 4.3 4 4.1 1 0.7 8 3.3 2 5.8 3.4 2 4.8 0.4
8.8 1.6 0.4 6.6 5.1 2.5 6.2
6.3 0.3 7.1 8.3 10.7 13.3 3.8 6.3 0.4 2.8 5.6 1.1 10.5 4.3 0.2 4.2 2.8 1.8
6 5.5 3 7.7 1.7 8.4 11.5
5.5 1.3 2.4 0.1 8 5.2 2.8 2.1 5.4 2.8 3.9 4.9 3.2 0.4 5.8 0.4 6 4.5 4.4 1.7
4.6 3.4 1.2 6.1 7.1 0.1 2
1.3 0.8 1.6 5.1 5.9 6 0.5 3.3 0.8 3.9 2.2 5 5.4 4 1.8 4.1 5.6 2.5 4 5 2.7
0.6 8.1 2.2 3.2 3.9 4.1 3.1
1.5 0.3 0 0.1 0.4 0.4 2.3 3.3 2.3 1.5 4.3 4.4 3.9 2 4.8 4.1 3.8 1.7 5.6 4.5
2.5 1.8 7.1 2.1 2.3 1.5 0.5
1 0.9 3.2 0.3 0.1 0.2 0 )))

(define (casethejoint)
(let* (
  (currenttime 0)
   (newkeynum 0)
   (waittime 0)
   (thetime 0)
   (newdur 0)
   (thecase 0)
  )

 ;(process  while (<= thetime 100) ;-->time not currently updating, making
this potentially dangerous

(process repeat 50
 do
 (set! thecase (pick 0 1))
 (print "thecase is") (print thecase)
 (set! newdur (next speeds))
;append ;-->was necessary in the old code
 (case thecase
   (
   (0
 (print "case is 0")
 (set! newkeynum (between 40 42))
 (set! waittime newdur)
 (mp:midi :key  newkeynum)
 (wait waittime)
 (set! thetime (+ thetime waittime))
 (print "thetime is")  (print thetime)
 )

(1
 (print "case is 1")
 (set! newkeynum  (between 80 82))
 (set! waittime newdur)
 (mp:midi :key  newkeynum)
 (wait waittime)
 (set! thetime (+ thetime waittime))
 (print "thetime is")  (print thetime)
 )
   )
   )
 )
)
)


(sprout (casethejoint))
___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist


Re: [CM] help with case statement

2016-01-26 Thread bil

In case, the keys are in a list, so the syntax
is (case the-case
 ((0) ...)
 ((1) ...)))
You're currently missing the extra parens around the
0 and 1.  For Scheme, "The Scheme Programming Language"
by Dybvig is clear, but try to find the second edition --
I think the newer edition describes r6rs scheme which
has been abandoned.  Scheme is very
close to Common Lisp, so the best intro of all is
probably Peter Seibel's Practical Common Lisp,
available online.


___
Cmdist mailing list
Cmdist@ccrma.stanford.edu
https://cm-mail.stanford.edu/mailman/listinfo/cmdist