home *** CD-ROM | disk | FTP | other *** search
- (in-package :oou)
- (oou-provide :video-player)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; video-player.lisp
- ;;
- ;; Copyright ⌐ 1992 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;;
- ;; object for controling video players
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (oou-dependencies
- :serial-port
- )
-
- (export '(video-player
- vp-init vp-dispose vp-load vp-loaded-p vp-features
- vp-max-frame vp-min-frame vp-current-frame
- vp-seek vp-play vp-play-clip vp-limit
- vp-stop vp-freeze vp-step vp-scan vp-jump))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defclass video-player ()
- ((framehook-fn :initarg :framehook-fn
- :reader framehook-fn)
- (fh-install-fn :accessor fh-install-fn)
- (fh-remove-fn :accessor fh-remove-fn)
- (frame-limit-p :initform nil
- :accessor frame-limit-p)
- (min-frame-limit :accessor min-frame-limit)
- (max-frame-limit :accessor max-frame-limit))
- )
-
- (defmethod initialize-instance :after ((vp video-player) &rest initargs)
- (declare (ignore initargs))
- (framehook-init vp))
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;
-
- (defmethod vp-init ((vp video-player)) t)
- (defmethod vp-dispose ((vp video-player)) t)
-
- (defgeneric vp-load (vp &key &allow-other-keys))
- (defgeneric vp-loaded-p (vp))
-
- (defmethod vp-features ((vp video-player)) nil)
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;core feature control methods
-
- (defgeneric vp-max-frame (vp))
- (defgeneric vp-min-frame (vp))
- (defgeneric vp-current-frame (vp))
-
- (defmethod vp-seek :around ((vp video-player) frame &key &allow-other-keys)
- (declare (ignore frame))
- (with-cursor *watch-cursor*
- (call-next-method)))
-
- (defmethod vp-play :around ((vp video-player))
- (when (vp-limit-check-p vp :forward) (call-next-method)))
-
- (defmethod vp-play :after ((vp video-player))
- (vp-framehook-install vp))
-
- (defmethod vp-stop :after ((vp video-player))
- (vp-framehook-remove vp)
- (vp-fix-overshoot vp)
- (vp-framehook vp))
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;optional feature control methods
-
- (defmethod vp-freeze :after ((vp video-player))
- (vp-framehook-remove vp)
- (vp-fix-overshoot vp)
- (vp-framehook vp))
-
- (defmethod vp-step :around ((vp video-player) direction)
- (when (vp-limit-check-p vp direction) (call-next-method)))
-
- (defmethod vp-step :after ((vp video-player) direction)
- (declare (ignore direction))
- (vp-framehook vp))
-
- (defmethod vp-scan :around ((vp video-player) direction speed-x)
- (declare (ignore speed-x))
- (when (vp-limit-check-p vp direction) (call-next-method)))
-
- (defmethod vp-scan :after ((vp video-player) direction speed-x)
- (declare (ignore direction speed-x))
- (vp-framehook-install vp))
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;high level feature control methods
-
- (defmethod vp-jump :around ((vp video-player) direction frame-count)
- (let ((max-jump (ecase direction
- (:forward
- (- (if (frame-limit-p vp) (max-frame-limit vp) (vp-max-frame vp))
- (vp-current-frame vp)))
- (:reverse
- (- (vp-current-frame vp)
- (if (frame-limit-p vp) (min-frame-limit vp) (vp-min-frame vp)))))))
- (when (plusp max-jump)
- (call-next-method vp direction frame-count))))
-
- (defmethod vp-jump :after ((vp video-player) direction frame-count)
- (declare (ignore direction frame-count))
- (vp-fix-overshoot vp)
- (vp-framehook vp))
-
- (defmethod vp-jump ((vp video-player) direction frame-count)
- (vp-seek vp (ecase direction
- (:forward (+ (vp-current-frame vp) frame-count))
- (:reverse (- (vp-current-frame vp) frame-count)))))
-
- (defmethod vp-play-clip :around ((vp video-player) start-frame end-frame &rest rest &key &allow-other-keys)
- (declare (ignore rest))
- (let ((old-min-limit (when (frame-limit-p vp) (min-frame-limit vp)))
- (old-max-limit (when (frame-limit-p vp) (max-frame-limit vp))))
- (prog2
- (vp-limit vp start-frame end-frame)
- (call-next-method)
- (vp-limit vp old-min-limit old-max-limit))))
-
- (defmethod vp-play-clip ((vp video-player) start-frame end-frame &rest rest &key &allow-other-keys)
- (declare (ignore end-frame))
- (apply 'vp-seek vp start-frame rest)
- (vp-play vp)
- t)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; frame limit methods
-
- (defmethod vp-limit ((vp video-player) min-frame max-frame)
- (if (or min-frame max-frame)
- (setf (min-frame-limit vp) (or min-frame (vp-min-frame vp))
- (max-frame-limit vp) (or max-frame (vp-max-frame vp))
- (frame-limit-p vp) t)
- (setf (frame-limit-p vp) nil)))
-
- (defmethod vp-limit-check-p ((vp video-player) direction)
- (or (not (frame-limit-p vp))
- (let ((cur-frame (vp-current-frame vp)))
- (with-slots (max-frame-limit min-frame-limit) vp
- (ecase direction
- (:forward (< cur-frame max-frame-limit))
- (:reverse (> cur-frame min-frame-limit)))))))
-
- (defmethod vp-fix-overshoot ((vp video-player))
- (when (frame-limit-p vp)
- (with-slots (max-frame-limit min-frame-limit) vp
- (let ((cur-frame (vp-current-frame vp)))
- (if (> cur-frame max-frame-limit)
- (vp-seek vp max-frame-limit)
- (when (< cur-frame min-frame-limit)
- (vp-seek vp min-frame-limit)))))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; framehook mechanism
-
- (defmethod framehook-init ((vp video-player))
- (let ((eventhook-save nil)
- (installed-p nil)
- (last-frame -1)
- (min-frame 0)
- (max-frame most-positive-fixnum)
- (freeze-p nil))
- (flet ((fh-limit ()
- (let ((cur-frame (vp-current-frame vp)))
- (unless (= cur-frame last-frame)
- (setf last-frame cur-frame)
- (if (or (<= cur-frame min-frame) (>= cur-frame max-frame))
- (if freeze-p (vp-freeze vp) (vp-stop vp))
- (vp-framehook vp cur-frame)))
- (when eventhook-save (funcall eventhook-save))))
- (fh-update ()
- (let ((cur-frame (vp-current-frame vp)))
- (unless (= cur-frame last-frame)
- (setf last-frame cur-frame)
- (vp-framehook vp cur-frame))
- (when eventhook-save (funcall eventhook-save)))))
- (flet ((fh-install ()
- (unless installed-p
- (setf installed-p t)
- (setf eventhook-save *eventhook*)
- (setf last-frame -1)
- (setf freeze-p (find :freeze (vp-features vp)))
- (if (frame-limit-p vp)
- (setf min-frame (min-frame-limit vp)
- max-frame (max-frame-limit vp)
- *eventhook* #'fh-limit)
- (setf *eventhook* #'fh-update))))
- (fh-remove ()
- (when installed-p
- (setf *eventhook* eventhook-save)
- (setf installed-p nil))))
- (setf (fh-install-fn vp) #'fh-install
- (fh-remove-fn vp) #'fh-remove)))))
-
- (defmethod vp-framehook ((vp video-player) &optional (current-frame (vp-current-frame vp)))
- (when (slot-boundp vp 'framehook-fn)
- (funcall (framehook-fn vp) current-frame)))
-
- (defmethod vp-framehook-install ((vp video-player))
- (when (or (slot-boundp vp 'framehook-fn) (frame-limit-p vp))
- (funcall (fh-install-fn vp))))
-
- (defmethod vp-framehook-remove ((vp video-player))
- (funcall (fh-remove-fn vp)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- #|
- examples can be found in the player specific -vp files
- |#