CLM "phrase" mechanism

Larry Troxler lt@westnet.com
Tue, 9 Sep 1997 21:40:42 -0400 (EDT)


I've got some probably confused questions about the CLM phrase mechanism.

First, is it true that in general, simply building on the "run*" mechanism
is not a replacement for phrases, because the latter doesn't take into
account concurrency, task-spawning, and out-of-time-order issues? It's not
clear to me under what circumstances "wait-for-phrase", for example, will
actually need to wait - I suppose this depends on whether "run" actually
launches a seperate thread, and whether the Lisp implementation is
multithreaded, etc. More to the point, when is the "wait-for-phrase"
mechanism actually needed? Only if events are called out of order? 

Next, the syntax of the use of phrases as described in the CLM manual,
seems a bit counter-intuitive to me, especially the second "pickup"
instrument example. I think this is because the handling of run-loop
phrase vars is completely different than the handling of vars outside the
run-loop, whereas I tend to think of that as a low-level implementation
distinction . Also, I think it may be a common case to have a number
of local
variables, each of which you would want to initialize to some value (as in
let), or use the current phrase value if a phrase is already in progress.

So, I'm thinking about something like the following:

ORIGINAL PICKUP EXAMPLE:

(definstrument pickup (phrase dur frq)
  (wait-for-phrase phrase)
  (let* ((s (or (phrase-value phrase 's)
                (make-oscil frq)))
         (amp (* .9 (or (phrase-value phrase 'amp) .5)))
         (start (or (phrase-value phrase nil) 0))
         (end (+ start (floor (* dur sampling-rate)))))
    (setf (phrase-value phrase nil) end)
    (run
      (loop for i from start below end do
        (outa i (* amp (oscil s)))))
    (end-run (phrase phrase 's 'amp))))

BRAINSTORMING, SUGGESTED SYNTAX:

(definstrument pickup (phrase dur frq)
  (using-phrase 
   phrase  ;; generates (wait-for-phrase phrase)

   ;; phrase vars. Like let, except that the initialization forms
   ;; are used only if the phrase is uninitialized. Otherwise,
   ;; the vars are assigned from the current phrase-values.
   ((s (make-oscil frq))
    (amp1 .5)
    (start 0))

   (let*
       ((amp (* .0 amp1))
	(end (+ start (floor (* dur sampling-rate)))))
     ;; Should be able to setf phrase-values regardless of whether
     ;; the vars are used in the run-loop :
     (setf (phrase-value phrase 'start) end) 
     (run
      (loop for i from start below end do
	    (outa i (* amp (oscil s)))))
     ;; The run loop above would magically know to resave 's and 'amp1
back into
     ;; the phrase, because of the var bindings specified as the
     ;; second arg to "using-phrase". Hence, no "end-run" needed.
    
     
      

 --  Larry Troxler  --  lt@westnet.com  --  Patterson, NY USA
--