CoCreate Modeling alarm clock: Beep whenever a long-running command terminates
Sometimes, a CoCreate Modeling command will take a while until it finishes all its calculations,
so you run the command, then turn your attention to a trade mag, start surfing,
or call home to discuss your dinner plans. However, you don't
really want to waste
time, so you'd like to make sure that you'll know when the command actually terminates.
The code below implements such a feature: After commands which run at least for a
user-definable number of seconds, it will play an arbitrary sound on the stereo
which is hooked up to your office PC. Pump up da volume.
;; -*-Lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Description: Triggers sounds when a long command terminates
;; Author: Claus Brod
;; Created: 7/17/2003 16:40
;; Language: Lisp
;;
;; (C) Copyright 2003 Claus Brod, all rights reserved
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(in-package :clausbrod.de)
(use-package :oli)
;; Usage:
;; - Configure path of WAV file (variable 'soundfile')
;; - Configure delay (only commands taking longer
;; than the configured delay will cause the sound
;; to be triggered; variable 'delay')
;; - Load LISP file
;; Note: The current implementation only works on Windows platforms.
;; Modify play-sound for other platforms. Use at your own risk.
(defun play-sound ()
(let ((soundfile "c:/temp/tada.wav"))
(sd-sys-background-job
(format nil "start ~A"
(sd-convert-filename-to-platform soundfile)))))
(let ((lastbusytime nil)
(delay 3))
(defun busy-handler (&rest args)
(declare (ignore args))
(setq lastbusytime (get-universal-time)))
(defun interactive-handler (&rest args)
(declare (ignore args))
(when lastbusytime
(when (> (- (get-universal-time) lastbusytime) delay)
(play-sound)))
(setq lastbusytime nil)))
;; Register busy and interactive handlers
(sd-unsubscribe-event *SD-BUSY-EVENT* 'busy-handler)
(sd-subscribe-event *SD-BUSY-EVENT* 'busy-handler)
(sd-unsubscribe-event *SD-INTERACTIVE-EVENT* 'interactive-handler)
(sd-subscribe-event *SD-INTERACTIVE-EVENT* 'interactive-handler)
This code illustrates the following techniques:
- How to subscribe a function for the
*SD-BUSY-EVENT*
and *SD-INTERACTIVE-EVENT*
events
- How to run an external command
Here's a rough description of how it works:
- The functions
busy-handler
and interactive-handler
are
subscribed to *SD-BUSY-EVENT*
and *SD-INTERACTIVE-EVENT*
.
- When the "busy" event is fired (i.e. when a command starts),
busy-handler
is called
and takes a note of the current time in lastbusytime
.
- When the system becomes interactive again, the "interactive"
event is fired and calls
interactive-handler
. This function
compares the current time against lastbusytime
. If the
current time deviates from the time at the start of the last
command by at least delay
seconds, the function play-sound
is called to, well, guess what .-)
--
ClausBrod
Revision: r1.7 - 06 Dec 2013 - 15:47 - ClausBrod