7.0 KiB
Convert JavaScript to Parenscript with Enhanced Spectrum Analyzer
Overview
This PR converts all frontend JavaScript files to Parenscript (Common Lisp that compiles to JavaScript), improving maintainability and code consistency across the Asteroid Radio codebase. Additionally, it includes significant enhancements to the spectrum analyzer with theming, multiple visualization styles, and improved stream reliability.
Major Changes
1. Parenscript Conversion
-
Converted 7 JavaScript files to Parenscript:
admin.js→parenscript/admin.lispauth-ui.js→parenscript/auth-ui.lispfront-page.js→parenscript/front-page.lispplayer.js→parenscript/player.lispprofile.js→parenscript/profile.lispusers.js→parenscript/users.lisprecently-played.js→parenscript/recently-played.lisp
-
Original JavaScript files renamed to
.js.originalfor reference -
Added
parenscript-utils.lispfor shared compilation utilities -
Parenscript files are now the source of truth; JavaScript is generated dynamically on request
2. Stream Reliability Improvements
- Automatic reconnection logic for live stream after long pauses (>10 seconds)
- Improved spectrum analyzer audio context handling with proper reset functionality
- Fixed stream pause detection to prevent unnecessary "now playing" updates during paused playback
- Better error handling for stream stalls and connection issues
3. Spectrum Analyzer Enhancements
Color Themes (6 options)
- Monotone - Deep blue to cobalt gradient matching site aesthetic
- Green - Classic bright green gradient (default)
- Blue - Cyan to deep blue
- Purple - Magenta to deep purple
- Red - Bright red to dark red
- Amber - Orange to brown
Visualization Styles (3 options)
- Bars - Traditional bar graph (default)
- Wave - Continuous line/waveform
- Dots - Particle/dot visualization
UI Features
- Dropdown controls for real-time theme and style selection
- Persistent preferences saved to localStorage
- Dynamic border color that changes to match selected theme
- Dynamic dropdown styling - dropdown boxes update their colors to match the selected theme
- Mute detection with visual "MUTED" indicator overlay
4. UX Improvements
- Live indicator animation changed from blinking to smooth pulse (inspired by old MacBook sleep indicator)
- Removed verbose debug logging from console output
- Cleaner, more professional user experience throughout
5. Documentation & Scripts
- Added
docs/PARENSCRIPT-EXPERIMENT.orgdocumenting the conversion process and rationale - Added helper scripts for music library management:
scripts/music-library-tree.py- Generate library tree structurescripts/fix-m3u-paths.py- Fix playlist pathsscripts/scan.py- Library scanning utilities
- Added sample playlists and playlist documentation
Technical Details
Parenscript Integration
- All Parenscript files compile to JavaScript on-the-fly via custom route handlers in
asteroid.lisp - Compilation happens at request time, allowing for rapid development iteration
- No build step required for JavaScript changes
- Full access to Common Lisp macros and language features for frontend code
Backward Compatibility
- ✅ Maintains full backward compatibility with existing functionality
- ✅ No breaking changes to API or user-facing features
- ✅ All existing routes and endpoints remain unchanged
- ✅ Original JavaScript preserved as
.originalfiles for reference
Code Quality
- Removed generated
asteroid.cssfrom repository (auto-generated on build) - Consistent code style across frontend and backend (all Lisp)
- Better type safety and error handling through Lisp's condition system
- Easier refactoring and maintenance with unified language
Testing
- ✅ All existing functionality verified working
- ✅ Stream reconnection tested with long pauses (>10 seconds)
- ✅ Spectrum analyzer themes and styles tested across all pages (front page, player, admin)
- ✅ Preferences persistence verified across browser sessions
- ✅ Cross-browser compatibility maintained
- ✅ Audio context handling tested with multiple audio elements
- ✅ Mute detection working correctly
Migration Notes
For Developers
- Frontend changes should now be made in
parenscript/*.lispfiles - JavaScript is generated automatically - no need to edit
.jsfiles - Use
make clean && maketo rebuild after Parenscript changes - Original JavaScript files kept as
.js.originalfor reference during transition
For Deployment
- No changes to deployment process
- Server generates JavaScript on-the-fly from Parenscript
- No additional dependencies beyond existing Common Lisp setup
Files Changed
Added
parenscript-utils.lisp- Parenscript compilation utilitiesparenscript/admin.lisp- Admin interface logicparenscript/auth-ui.lisp- Authentication UIparenscript/front-page.lisp- Front page and live streamparenscript/player.lisp- Audio player controlsparenscript/profile.lisp- User profile managementparenscript/recently-played.lisp- Recently played tracksparenscript/users.lisp- User managementdocs/PARENSCRIPT-EXPERIMENT.org- Documentationscripts/*- Helper scripts for library management
Modified
asteroid.lisp- Added Parenscript compilation routes, removed debug loggingfrontend-partials.lisp- Removed debug logging from Icecast statsstatic/asteroid.lass- Updated live indicator animationtemplate/*.ctml- Added spectrum analyzer controls
Renamed
static/js/admin.js→static/js/admin.js.originalstatic/js/auth-ui.js→static/js/auth-ui.js.originalstatic/js/front-page.js→static/js/front-page.js.originalstatic/js/player.js→static/js/player.js.originalstatic/js/profile.js→static/js/profile.js.originalstatic/js/users.js→static/js/users.js.originalstatic/js/recently-played.js→static/js/recently-played.js.original
Deleted
static/asteroid.css- Now auto-generated, removed from repository
Screenshots
The spectrum analyzer now features:
- Multiple color themes with dynamic border matching
- Three distinct visualization styles (bars, wave, dots)
- Clean dropdown UI for easy customization
- Smooth animations and transitions
Future Enhancements
Potential future improvements building on this foundation:
- Additional visualization styles (spectrogram, circular, etc.)
- More color themes
- Customizable color picker for user-defined themes
- Visualization presets tied to music genres
- WebGL-accelerated rendering for complex visualizations
Conclusion
This PR represents a significant modernization of the Asteroid Radio frontend while maintaining full backward compatibility. The move to Parenscript unifies the codebase under Common Lisp, making it easier to maintain and extend. The enhanced spectrum analyzer provides users with a more engaging and customizable listening experience.
Ready to merge ✅