From 090e8e98986e91228d45d9174dd3c90613142193 Mon Sep 17 00:00:00 2001 From: Glenn Thompson Date: Tue, 2 Dec 2025 09:34:41 +0300 Subject: [PATCH] fix: Serve spectrum analyzer JavaScript dynamically via API Changed from static file generation to Radiance API endpoint. Parenscript now generates JavaScript in-memory at runtime when the /api/asteroid/spectrum-analyzer.js endpoint is requested. This is the correct approach for Parenscript integration with Radiance. --- module.lisp | 7 ------- spectrum-analyzer.lisp | 15 ++++----------- template/front-page.ctml | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/module.lisp b/module.lisp index 5a2239c..f9bafef 100644 --- a/module.lisp +++ b/module.lisp @@ -4,10 +4,3 @@ (:use #:cl #:radiance #:lass #:r-clip #:asteroid.app-utils) (:domain "asteroid") (:export #:-main)) - -;; Generate Parenscript files at compile time -(eval-when (:compile-toplevel :load-toplevel :execute) - (when (find-package :asteroid) - (let ((pkg (find-package :asteroid))) - (when (fboundp (find-symbol "WRITE-SPECTRUM-ANALYZER-JS" pkg)) - (funcall (find-symbol "WRITE-SPECTRUM-ANALYZER-JS" pkg)))))) diff --git a/spectrum-analyzer.lisp b/spectrum-analyzer.lisp index f0b8640..1190536 100644 --- a/spectrum-analyzer.lisp +++ b/spectrum-analyzer.lisp @@ -3,8 +3,9 @@ ;;; Spectrum Analyzer - Parenscript Implementation ;;; Generates JavaScript for real-time audio visualization -(defun generate-spectrum-analyzer-js () - "Generate JavaScript code for the spectrum analyzer using Parenscript" +(define-api asteroid/spectrum-analyzer.js () () + "Serve the spectrum analyzer JavaScript generated from Parenscript" + (setf (content-type *response*) "application/javascript") (ps:ps (defvar *audio-context* nil) (defvar *analyser* nil) @@ -85,12 +86,4 @@ (let ((audio-element (chain document (get-element-by-id "live-audio")))) (when audio-element (chain audio-element (add-event-listener "play" init-spectrum-analyzer)) - (chain audio-element (add-event-listener "pause" stop-spectrum-analyzer))))))))) - -(defun write-spectrum-analyzer-js () - "Write the generated JavaScript to a file" - (with-open-file (stream (asdf:system-relative-pathname :asteroid "static/js/spectrum-analyzer.js") - :direction :output - :if-exists :supersede - :if-does-not-exist :create) - (write-string (generate-spectrum-analyzer-js) stream))) + (chain audio-element (add-event-listener "pause" stop-spectrum-analyzer)))))))) diff --git a/template/front-page.ctml b/template/front-page.ctml index c10c3d9..7144efe 100644 --- a/template/front-page.ctml +++ b/template/front-page.ctml @@ -11,7 +11,7 @@ - +