From fead43e69edb5ea62b72a8b97c99efbd10403e68 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 23 Oct 2021 11:53:00 +0200 Subject: Handle controller=#f in 'set-midi-control-map!' --- guile/starlet/midi-control/faders.scm | 63 ++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'guile/starlet/midi-control/faders.scm') diff --git a/guile/starlet/midi-control/faders.scm b/guile/starlet/midi-control/faders.scm index 81764b5..e5f9cd4 100644 --- a/guile/starlet/midi-control/faders.scm +++ b/guile/starlet/midi-control/faders.scm @@ -327,34 +327,35 @@ (define (set-midi-control-map! controller new-control-map) - (let ((old-parameter-controller (get-parameter-controller controller))) - - ;; Remove the old parameter controller - (when old-parameter-controller - (scrub-parameter-controller! controller old-parameter-controller)) - - (set-parameter-controller! - controller - (make - #:callbacks '() - #:control-map new-control-map)) - - ;; If this is the first time, add the callbacks - (unless old-parameter-controller - - ;; Selection changed - (add-hook! - selection-hook - (lambda (fixture-list) - (update-midi-controls controller fixture-list))) - - ;; Value changed - (add-update-hook! programmer-state - (lambda (fix attr value source) - (unless (eq? source controller) - (update-midi-controls controller (get-selection)))))) - - ;; If there is a selection, run the callback now - (let ((current-selection (get-selection))) - (when current-selection - (update-midi-controls controller current-selection))))) + (when controller + (let ((old-parameter-controller (get-parameter-controller controller))) + + ;; Remove the old parameter controller + (when old-parameter-controller + (scrub-parameter-controller! controller old-parameter-controller)) + + (set-parameter-controller! + controller + (make + #:callbacks '() + #:control-map new-control-map)) + + ;; If this is the first time, add the callbacks + (unless old-parameter-controller + + ;; Selection changed + (add-hook! + selection-hook + (lambda (fixture-list) + (update-midi-controls controller fixture-list))) + + ;; Value changed + (add-update-hook! programmer-state + (lambda (fix attr value source) + (unless (eq? source controller) + (update-midi-controls controller (get-selection)))))) + + ;; If there is a selection, run the callback now + (let ((current-selection (get-selection))) + (when current-selection + (update-midi-controls controller current-selection)))))) -- cgit v1.2.3