[CM] sprouts & closure in CM

Rick Taube taube@uiuc.edu
Sun, 12 Jun 2005 13:58:08 -0500


>>>   functions; and (2) be able to pass values back from the latter to 
>>> the
>>>   former. Condition (2) would enable me for example, to use the last
>>>   pitch in some random sprout as the starting pitch to the next 
>>> sprout
>>>   (thereby letting me form feedback chains etc).

you might be able to do what you want using co-routines. In this 
example. 'mus1' and 'mus2' represent different sections of music of 
arbitrary length that is not known ahead of time. The function 'main' 
is a little state machine that sprouts new sections based on a current 
section id and whatever results are passed in from previous sections.

Is this doing what you want?

(defun mus1 (id reps knum)
   ;; section 1 plays chromatic tones as some rate
   (process for i below reps
     with d = (pick .2 .4 .8)
     for k = (+ knum i)
     output (new midi :time (now) :keynum k :duration d)
     wait d
     finally (main id k d)))

(defun mus2 (id reps)
   ;; section 2 plays a high note
   (process repeat reps
     with d = .2
     with k = 98
     output (new midi :time (now) :keynum k :duration d)
     wait d
     finally (main id k)))

(defun main (id &rest args)
   (format t "~%sprouting section ~s"  id)
   (case id
     (0 (mus1 1 10 80))
     ((1 2 3 5) ;; scheduler is running so sprout
      (let ((last (car args)))
        (sprout (mus1 (+ id 1)
                      (between 5 10)
                      (- last 12))
                (now))))
     (4
      (sprout (mus2 5 12) (now)))))

(events (main 0) "test.mid")




On Jun 12, 2005, at 9:50 AM, Drew Krause wrote:

> taube@uiuc.edu wrote:  So I find myself wanting to (1) decouple the 
> calling and sprouted
>>>   functions; and (2) be able to pass values back from the latter to 
>>> the
>>>   former. Condition (2) would enable me for example, to use the last
>>>   pitch in some random sprout as the starting pitch to the next 
>>> sprout
>>>   (thereby letting me form feedback chains etc).
>>>
>> i think i see what you want to do: so your main process wants to 
>> sprout, then
>> wait until the sproutee stops and "returns" a value, then the main 
>> function
>> continues on using that value to sprout a new process, and so on?
>> ill have to think about this, currently processes are lisp functinos 
>> called by a
>> scheudler; ie there is no place to return values to.
>>
>
>  To provide side-by-side playback functionality, what if there was 
> some kind of process keyword like
>
>  sprout (process1 s1 s2)
> subsequently
> sprout (process s1 s2)
>
>  ... or does this run into the same problem with the scheduler? I'll 
> shut up now.
>
>  Drew