(rts [to] {keyword value}*)

Starts the real time scheduler according to optional and keyword arguments. Returns no values. You must load the RTS system before calling the function.

rts supports the following optional arguments:

to {stream | false}
The default destination output stream, defaults to *out*. If the value is a stream then it must already be open and initialized. If the value is false then no output stream is assumed and the caller is expected to manage stream IO directly using the :to argument to output.

rts supports the following keywor arguments:

:time-format {:sec | :msec | :usec}
The format of time values returned by now . If the value is :sec then floating point seconds are returned, :msec returns integer milliseconds (1000 msec equals 1 sec) and :usec returns microseconds (1000000 usec equals 1 sec). The default value is :sec. Use :msec or :usec to avoid float consing in some Lisps. Note that event durations and wait values must agree with the time format.
:resolution {usecs}
The duty cycle of the scheduling loop in microseconds (usec), where 1000000 usec equals 1 second. The default value is 100, or 1/10 of a millisecond.
:priority {number}
The pthread priorty that the scheduler runs under. The value should be an integer between 1 and 100. The default value is 20.
:policy {number}
The pthread policy that the scheduler runs under. The value 2 is SCHED_RR and 4 is SCHED_FIFO. This value is currently ignored.


Example 1. Starting rts and sprouting from the REPL.

(define *pm*
  (portmidi-open :output 3 :latency 0))

(define (zzz len lb ub wai amp)
  (process repeat len
           output (new midi :time (now)
                       :duration .1 :amplitude amp
                       :keynum (between lb ub))
           wait wai))

(rts *pm*)
;;; eval to add stuff

(let ((k (between 20 100))
      (n (pick 3 5 7 11)))
  (sprout (zzz (* n (pick 2 3 4))
               (+ k 7)
               (/ 1 n)

;;; stop when you are done.


Example 2. Endless Fluff. Stops only when rts-stop is called. (Todd Ingalls)

(define fluff '(60 62 64 67 72 65 69 48 50))

(define (endless-fluff num dur knums)
  (process repeat num for i from 0 
           (new midi :time (now) 
                :duration (* 2 dur)
                :amplitude .5
                :keynum (pickl fluff))
	   wait (pick dur (/ dur 2) (/ dur 4))
	   when (= i (1- num))
	   sprout (process repeat 4
                           output (new midi :time (now) 
                                       :duration 5
                                       :amplitude .5 
                                       :keynum (pickl knums)))
	   sprout (endless-fluff 20 1 knums)))

(rts *pm*)

(sprout (endless-fluff 20 1 fluff))

;;; stop when you are done.


Example 3. Sprouting into the scheduler from a receive hook.

(define *pm* (portmidi-open :input 1 :output 3 :latency 0))

(define (major-thirds len knum)
  (process with d = .1
           for i below len
           for k = (+ knum (* (mod i 5) 4))
           output (make-note-on 0 k 90) at (now)
           sprout (make-note-off 0 k 125) at (+ (now) .5)
           wait d))

(rts *pm*)

(set-receiver! (lambda (mm ms) ms
                 (if (note-on-p mm)
                   (sprout (major-thirds 20 (note-on-key mm)))))

;;; stop receiving and scheduling.

(remove-receiver! *pm*)




See also:

$Name: $
($Revision: 1.14 $, $Date: 2006/05/14 20:09:57 $)