;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;;  RANDOMLY PLACE EACH MOVIE FRAME ON TWO CANVASES

;;

;;  Try moving the top canvas.

;;

;;  Download a medium sized quicktime trailer from apple

;;  Load it into quicktime-pro and export it at its current

;;  size but in TIFF format.  Use that file in gfx:load-movie.

;; 

;;  Impromptu does not currently support any format

;;  other than TIFF

;;

;;  This example plays the movie frame by frame but randomises

;;  the frame location. And for good measure does it on two 

;;  canvases at once. Graphical polyphony is possible.

;;

;;  NOTE: The two canvases start on top of each other

;;  drag one to another section of the screen.

;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(define canvas1 (gfx:make-canvas))

(define canvas2 (gfx:make-canvas))


; make sure you set the string to a movie location on your system

(define movie (gfx:load-movie "/tmp/myfilm.mov"))

(define frame-length (* *second* 0.041))


(define mlgth (- (gfx:get-movie-duration movie) 1.0))


(define loop

   (lambda (time mtime)

      (let ((image (gfx:get-movie-frame movie mtime)))

         (gfx:draw-image time canvas1 image 0.5 (list (random -100 500) 

                                                  (random -100 500)

                                                  (random 0 500)

                                                  (random 0 500)))

         (gfx:draw-image time canvas2 image 0.5 (list (random -100 500) 

                                                  (random -100 500)

                                                  (random 0 500)

                                                  (random 0 500)))

         ; advance time by a 24th of a second

         (set! time (+ time frame-length))

         (if (< mtime mlgth)

             (callback (- time 500) 'loop time (+ mtime 0.041))))))


(loop (now) 0.0)