From 094e72b0e6215aa002a6a68951ba28521448185f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 5 Apr 2021 10:21:46 +0200 Subject: When using jogwheel control, clamp values to end of range --- guile/starlet/midi-control/faders.scm | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'guile/starlet/midi-control') diff --git a/guile/starlet/midi-control/faders.scm b/guile/starlet/midi-control/faders.scm index 34d9ddb..0b8f3d7 100644 --- a/guile/starlet/midi-control/faders.scm +++ b/guile/starlet/midi-control/faders.scm @@ -72,6 +72,11 @@ (cons '() '()) fixture-list attrs))) +(define (clamp-to-attr-range attr-obj val) + (let ((r (get-attr-range attr-obj))) + (max (car r) + (min (cadr r) + val)))) (define* (at-midi-jogwheel fixture-list attr cc-number #:key (led #f)) @@ -90,15 +95,20 @@ (let ((old-vals (current-values fixtures attr)) (offset 0)) (register-midi-cc-callback! - #:cc-number cc-number - #:func (lambda (prev-cc-val new-cc-value) - (set! offset (+ offset (ccval->offset new-cc-value))) - (for-each (lambda (fix old-val) - (set-in-state! programmer-state - fix - attr - (+ old-val offset))) - fixtures old-vals))))))) + #:cc-number cc-number + #:func (lambda (prev-cc-val new-cc-value) + (set! offset (+ offset (ccval->offset new-cc-value))) + (for-each (lambda (fix old-val) + (let ((attr-obj (find-attr fix attr))) + (when (and attr-obj + (continuous-attribute? attr-obj)) + (set-in-state! programmer-state + fix + attr + (clamp-to-attr-range + attr-obj + (+ old-val offset)))))) + fixtures old-vals))))))) -- cgit v1.2.3