From a1feb3a6fe9bdadbc39294ddaf3d07c8655fc9f4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 14 May 2023 21:48:05 +0200 Subject: Send selection via OSC --- guile/starlet/open-sound-control/utils.scm | 13 ++++++++++++- guile/starlet/selection.scm | 11 +++++++++++ guile/starlet/utils.scm | 10 +++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'guile') diff --git a/guile/starlet/open-sound-control/utils.scm b/guile/starlet/open-sound-control/utils.scm index 34c4127..4f0a60b 100644 --- a/guile/starlet/open-sound-control/utils.scm +++ b/guile/starlet/open-sound-control/utils.scm @@ -33,7 +33,8 @@ osc-playback-controls osc-select-button osc-parameter-encoder - osc-state-fader)) + osc-state-fader + send-selection-updates-to)) (define* (osc-playback-controls pb server go-method stop-method back-method @@ -151,3 +152,13 @@ (add-osc-method server fader "i" (lambda (v) (set! fader-val v))))) + + +(define (send-selection-updates-to addr) + (add-hook! + selection-hook + (lambda (sel) + (osc-send + addr + "/starlet/selection/update" + (get-selection-as-string))))) diff --git a/guile/starlet/selection.scm b/guile/starlet/selection.scm index d0f2c1d..7e5ca1a 100644 --- a/guile/starlet/selection.scm +++ b/guile/starlet/selection.scm @@ -20,6 +20,7 @@ ;; (define-module (starlet selection) #:use-module (starlet utils) + #:use-module (starlet fixture) #:use-module (srfi srfi-1) #:export (sel add-sel @@ -27,6 +28,7 @@ desel selection-hook get-selection + get-selection-as-string selected?)) @@ -39,6 +41,15 @@ selection) +(define (get-selection-as-string) + (cat-with-spaces + (map + (lambda (s) + (symbol->string + (get-fixture-name s))) + selection))) + + (define (sel . fixture-list) (if (nil? fixture-list) (set! selection '()) diff --git a/guile/starlet/utils.scm b/guile/starlet/utils.scm index e1b92a8..e0579ab 100644 --- a/guile/starlet/utils.scm +++ b/guile/starlet/utils.scm @@ -41,7 +41,8 @@ comment hash-table-empty? lookup - add-and-run-hook!)) + add-and-run-hook! + cat-with-spaces)) (define (print-hash-table ht) @@ -179,3 +180,10 @@ (define (add-and-run-hook! hook proc . initial-args) (add-hook! hook proc) (apply proc initial-args)) + + +(define (cat-with-spaces lst) + (reduce + (lambda (b a) + (string-append a " " b)) + "" lst)) -- cgit v1.2.3