The new Livecoding Error Hook in Impromptu


Impromptu 2.5 has been out for a while now, but I never realized it contained this handy new feature: an 'error hook'.

The interpreter will now throw to an error hook providing you with greater control over exception handling. You initiate the livecoding error hook by calling (sys:livecoding-error-hook #t). Errors are then passed to the *livecoding-error-hook* function, which you may rebind. By default, the function simply returns 1 but can be modified for more specialized behavior.

This feature is extremely useful if you're performing live and want to avoid situations in which a simple typo or parenthesis error could derail your entire performance. The error hook will often prevent your looping function from crashing, giving you time to fix the error while the music continues to play. This is a game-changer for live coding performances where maintaining flow is crucial.

Impromptu: livecoding error hook

Here's an example from the official release notes:

;; turn on livecoding error hook
(sys:livecoding-error-hook #t)

;; with livecoding-error-hook on
;; this temporal recursion will continue
;; to play the second note even though 'pitch
;; is an unbound symbol
(define loop
   (lambda (beat) 
      ;; symbol a is not bound but loop continues to function
      (play piano pitch 80 1)
      (play piano 63 80 1)
      (callback (*metro* (+ beat (* 1/2 1))) 'loop (+ beat 1))))

(loop (*metro* 'get-beat 4))

;; by redefining the error hook we can provide
;; additional specialization - such as replacing
;; any unbound symbol with 60!
;;
;; eval below and both notes will play
;; 'pitch being replaced by 60
(define *livecoding-error-hook* 
   (lambda (msg a) 
      (cond ((symbol? a) 60)
            (else 0))))

Happy (and safer) livecoding!

Cite this blog post:


Michele Pasin. The new Livecoding Error Hook in Impromptu. Blog post on www.michelepasin.org. Published on May 2, 2011.

Comments via Github:


See also: