[CM] rhythm durations and rests

Rick Taube taube@uiuc.edu
Fri, 27 Feb 2004 09:11:26 -0600


> is there a way that i can update the *rhythms* in my code to include 
> such a symbol?
> the only way i can currently figure out how to get negative rhythms is 
> to do something like:
> (rhythm 'q-w) -> -2.0

first, if you use ratios to mark your "rests" you can already do what 
you want:

? (rhythm -1/4)
-1.0
? (rhythm '(q w -2 e q... -1/16 ))
(1.0 4.0 -8.0 0.5 1.875 -0.25)


if you want to only use symbols then this new definition of
the rhythm method for symbols ("cm/src/data.scm") is probably what you 
want:
---
(define %rest-char #\-)
(define-method (rhythm (val <symbol>) . args)
   (with-args (args &optional (tempo *tempo*) (beat *beat*))
     (let ((n (hash-ref *rhythms* val)))
       (if n
         (rhythm n tempo beat)
         (let* ((str (symbol->string val))
                (num (if (char-ci=? (string-ref str 0) %rest-char)
                       (- (parse-rhythm-string (substring str 1)))
                       (parse-rhythm-string str ))))
           (hash-set! *rhythms* val num)
           (rhythm (hash-ref *rhythms* val) tempo beat))))))---

after replacing the existing rhythm method with the snippit above, do
	$ cd /path/to/cm
	$ bin/cm.sh
that will regenerate data.lisp (if you are using cltl) and reload the 
system with the new definition in effect. once thats done you can do

? (rhythm '-q)
-1.0
? (rhythm '-w-q)
(rhythm '-w-q)
-3.0

note that resting must be applied to the entire expression so -w-q = 
-(w-q) = -3 not -5...so im not sure if I should use - or R to denote 
rhythmic "rests" -- minus is consistent with using ratios but then 
rhythm exprs may seem weird.  if you want to use R do (define 
%rest-char #\R) and away you go. if you (or anyone) has an opinion on R 
vs - let me know.

ive already  made these changes to the cm-2.5 branch