(require (lib "rscT.ss" "rscT")) ;; Create a tempo based schedule. (define U (ceiling (utc))) (define T (make-tschedule! 120.0 0.0 U)) ;; Conversion fron pulse <-> utc. (map (lambda (p) (pulse->utc T p)) (list 0.0 1.0 4.0 -1.0)) (map (lambda (p) (utc->pulse T p)) (list U (+ U 4.0) (- U 1.0))) ;; Schedule at exact pulses. (define (print . l) (for-each display l) (newline)) (tschedule-at! T (+ 1.0 (ceiling (utc->pulse T (utc)))) (lambda (p f) (print "Pulse is " p) (f 1.0))) (tschedule-clear! T) ;; Change tempo (this can be *while* the the tschedule is busy). (tschedule-reset*! T (choose! (list 60.0 120.0 30.0 240.0))) ;; Special case insertion tests. (let ((f (lambda (n) (lambda (p f) (print p n)))) (p (ceiling (utc->pulse T (utc))))) (tschedule-at! T (+ p 2) (f 1)) ; Empty special case. (tschedule-at! T (+ p 4) (f 2)) ; At end special case. (tschedule-at! T (+ p 1) (f 3)) ; At front special case. (tschedule-at! T (+ p 2) (f 4)) ; At same time special case. (tschedule-at! T (+ p 3) (f 5))) ; => ORDER IS 3,{1,4},5,2 ;; Schedule to next actual pulse then reschedule to each subsequent ;; pulse. (tschedule-at! T (ceiling (utc->pulse T (utc))) (lambda (p f) (print "The time is" p) (f 1.0))) (tschedule-reset*! T (* 60.0 5.0)) ;; Clear the scheduler. (tschedule-clear! T) ;; Test a tschedule that is identical to the UTC scheduler. To make ;; such a schedule set the tempo to sixty and the utc and the pulse ;; values to zero. (begin! (define Z (ceiling (utc))) (define Z_2 (+ Z 2.0)) (define T (make-tschedule! 60.0 0.0 0.0)) (schedule-at! Q Z_2 (lambda (t f) (print "The time is:" t) (f 1.0))) (tschedule-at! T Z_2 (lambda (p f) (print "The pulse is:" p) (f 1.0)))) (begin! (schedule-clear! Q) (tschedule-clear! T)) ;; Test multiple synchronized tschedules. This is the test from SC3. (begin (define Z (ceiling (utc))) (define T (make-tschedule! 60.0 0.0 Z)) (define U (make-tschedule! (* 60.0 (/ 2.0 5.0)) 0.0 Z)) (define L (list T U)) (define (scale-tempo T s) (tschedule-reset*! T (* (spp->ppm (tschedule-spp T)) s))) (tschedule-at! T 0 (lambda (p f) (print "T" p) (f 1.0))) (tschedule-at! U 0 (lambda (p f) (print "U" p) (f 1.0)))) (for-each (lambda (Q) (scale-tempo Q 3)) L) (for-each (lambda (Q) (scale-tempo Q 1/4)) L) (for-each (lambda (Q) (tschedule-clear! Q)) L)