Made remote playing possible.

This commit is contained in:
2026-07-06 14:28:28 +02:00
parent de443aad9d
commit c8494e289e
2 changed files with 63 additions and 14 deletions
+23 -2
View File
@@ -4,6 +4,7 @@
racket/contract
racket/async-channel
racket/runtime-path
racket/string
uni-channel
"audio-placed-player.rkt"
"opusfile-decoder.rkt"
@@ -88,6 +89,23 @@
(define (evt-data evt)
(cadr evt))
(define (correct-to-os-path h replacements)
(let ((file (hash-ref h 'file #f)))
(letrec ((f (λ (l fl)
(if (null? l)
fl
(let ((bp-remote (cdar l))
(bp-local (caar l)))
(f (cdr l) (string-replace fl bp-remote bp-local)))))))
(unless (eq? file #f)
(let* ((delim (if (eq? (system-type 'os) 'windows) "\\" "/"))
(file* (string-replace
(string-replace
(f replacements (format "~a" file)) "/" delim)
"\\" delim)))
(hash-set! h 'file (build-path file*))))
h)))
(define-syntax assert
(syntax-rules ()
((_ cond message ...)
@@ -190,8 +208,10 @@
(let ((e (evt-get 500)))
(cond ((eq? e #f) (void))
((is-event? e 'state)
(let ((data (evt-data e)))
(set-audio-play-state! handle (car data))
(let* ((data (evt-data e))
(h (car data)))
(correct-to-os-path h replace-base-paths)
(set-audio-play-state! handle h)
(cb-state* (cadr data) (car data))))
((is-event? e 'audio-done) (cb-eof*))
((is-event? e 'exception)
@@ -214,6 +234,7 @@
(when (hash? (audio-play-state handle))
(let ((h (hash-copy (audio-play-state handle))))
(hash-set! h 'state 'invalid)
(correct-to-os-path h replace-base-paths)
(set-audio-play-state! handle h)))
(dbg-sound "audio-play handle invalidated and cleaned of references")
))