136 lines
6.3 KiB
Markdown
136 lines
6.3 KiB
Markdown
# ModFM (Web-based Tracker Music Player)
|
|
|
|
[](./LICENSE)
|
|
[](https://nuxt.com/)
|
|
[](https://lib.openmpt.org/)
|
|
|
|
---
|
|
# ModFM
|
|
ModFM is a web-based Tracker format music player built with Nuxt.js, WebAssembly (libopenmpt), and the Web Audio API (AudioWorklet). It supports playing various retro tracker formats (such as MOD, XM, S3M, IT, etc.) and integrates a SidWiz-style oscilloscope visualizer to display stable real-time waveforms for each channel.
|
|
|
|

|
|
|
|
---
|
|
|
|
## Tech Stack
|
|
- **Core Framework**: Nuxt.js (Vue 3 / TypeScript)
|
|
- **Audio Decoding**: `libopenmpt` compiled to WebAssembly
|
|
- **Audio Playback**: Web Audio API (AudioWorklet) running on an asynchronous rendering thread
|
|
- **Waveform Rendering**: Waveform extraction and Canvas real-time rendering based on the `SidWiz` algorithm
|
|
- **Styling**: Tailwind CSS
|
|
|
|
---
|
|
|
|
## Directory Structure
|
|
|
|
```
|
|
modfm/
|
|
├── app/ # Frontend views and interactive components (Vue 3 / Nuxt 3)
|
|
├── chiptune/ # AudioWorklet logic and WASM packaging scripts
|
|
├── data/ # Local data storage (ignored, containing .gitkeep)
|
|
│ └── music/ # Default local folder for music files
|
|
├── libopenmpt/ # C/C++ core decoding library with the ported SidWiz algorithm
|
|
├── public/ # Static assets (including compiled WASM glue files)
|
|
├── server/ # Backend API routes and SQLite database integration layer
|
|
│ ├── db.ts # Database initialization and schema setup
|
|
│ └── utils/
|
|
│ └── scanner.ts # Incremental music directory scanner
|
|
├── types/ # TypeScript declaration files
|
|
├── package.json # Project dependencies and scripts
|
|
├── LICENSE # MIT open-source license file
|
|
└── BUILD_libopenmpt.md # WebAssembly build instructions for the core library
|
|
```
|
|
|
|
---
|
|
|
|
## Prerequisites
|
|
|
|
- **Node.js**: `node >= 18.0.0`
|
|
- **Package Manager**: `npm` or `pnpm` is recommended
|
|
- **C/C++ Toolchain** (Optional): Only required if you modify and need to rebuild the `libopenmpt` WebAssembly binary. Local installation of [Emscripten SDK](https://emscripten.org/) is required.
|
|
|
|
---
|
|
|
|
## Environment Variables
|
|
|
|
The project supports runtime configuration via the following environment variables:
|
|
|
|
| Variable | Description | Default | Example |
|
|
| :--- | :--- | :--- | :--- |
|
|
| **`MUSIC_PATH`** | Custom absolute path to scan for music files. If not specified, it defaults to the local `data/music` directory. | `[Project Root]/data/music` | `/var/music/my_mods` |
|
|
| **`PORT`** | The listening port for production preview (`npm run preview`) or dev mode. | `3400` (preview) / `3401` (dev) | `8080` |
|
|
|
|
---
|
|
|
|
## Quick Start
|
|
|
|
### 1. Install Dependencies
|
|
```bash
|
|
# npm
|
|
npm install
|
|
|
|
# pnpm
|
|
pnpm install
|
|
```
|
|
|
|
### 2. Development Server
|
|
Start the development server (default port 3401):
|
|
```bash
|
|
npm run dev
|
|
```
|
|
Open `http://localhost:3401` in your browser.
|
|
|
|
### 3. Production Build & Preview
|
|
Build the application for production:
|
|
```bash
|
|
npm run build
|
|
```
|
|
Preview the production build (default port 3400):
|
|
```bash
|
|
npm run preview
|
|
```
|
|
|
|
---
|
|
|
|
## Development & Configuration Guide
|
|
|
|
### 1. Database Setup
|
|
The server uses SQLite (via the `better-sqlite3` driver):
|
|
- **Automated Setup**: On the first launch, the app automatically creates a `data/` directory and `app.sqlite` database file in the project root, initializing all schema tables (`users`, `songs`, `favorites`, etc.) and indexes. **No manual SQL scripts are required**.
|
|
|
|
### 2. Music Import & Scan
|
|
- **Default Path**: Place your music files (such as `mod`, `xm`, `it`, `s3m` tracker modules, or traditional `mp3`, `ogg`, `wav` files) in the local `data/music/` folder, or specify a custom directory using the `MUSIC_PATH` environment variable.
|
|
- **Scanning Mechanism**:
|
|
- **First-run Auto Scan**: If the database `songs` table is empty upon startup, a background incremental scanner automatically populates the database from the designated path.
|
|
- **Manual Trigger**: Send a `POST` request to `/api/admin/scan` to manually force an incremental scan and clean up obsolete records.
|
|
|
|
### 3. Custom Modifications to libopenmpt (Vendored Modifications)
|
|
To enable real-time, jitter-free oscilloscope rendering, we deeply integrated and customized the `libopenmpt` decoder. All modifications are in the `libopenmpt/` folder:
|
|
- **Waveform Processor**: Added [waveform_processor.c](libopenmpt/soundlib/waveform_processor.c) and [waveform_processor.h](libopenmpt/soundlib/waveform_processor.h) to implement the C version of the `PeakSpeedTrigger` alignment algorithm, 1-pole high-pass filter, and adaptive period tracking.
|
|
- **Mixer Interception**: Modified [Fastmix.cpp](libopenmpt/soundlib/Fastmix.cpp) to intercept raw PCM float outputs from each active channel and feed them into the waveform processor.
|
|
- **Interface Exposure**: Modified [Sndfile.cpp](libopenmpt/soundlib/Sndfile.cpp) to reset the processors when loading a track and export WASM bindings for the frontend AudioWorklet to read the stabilized waveform buffers.
|
|
|
|
> [!TIP]
|
|
> If you make changes to the C/C++ files under `libopenmpt/` and need to compile it, please refer to the [WASM Build Guide](./BUILD_libopenmpt.md).
|
|
|
|
---
|
|
|
|
## License & Third-Party Credits
|
|
|
|
The primary codebase of ModFM is licensed under the **[MIT License](./LICENSE)**.
|
|
|
|
This project vendors or links with several open-source subprojects:
|
|
1. **libopenmpt** (located at [libopenmpt/](./libopenmpt)) - **BSD-3-Clause License**. Copyright (c) 2004-2026 OpenMPT Developers. Used for tracker decoding.
|
|
2. **SidWiz** (algorithm reference) - **MIT License** reference. The waveform synchronization logic (PeakSpeedTrigger & adaptive width) is ported from Maxim's [SidWizPlus](https://github.com/maxim-zhao/SidWizPlus).
|
|
3. **chiptune3.worklet.js** (located at [chiptune/](./chiptune)) - **MIT License**. Custom fork based on DrSnuggles' chiptune3.js framework.
|
|
|
|
### NPM Dependency Licenses
|
|
- `@nuxtjs/color-mode`: MIT
|
|
- `bcryptjs`: BSD-3-Clause
|
|
- `better-sqlite3`: MIT
|
|
- `nuxt`: MIT
|
|
- `vue`: MIT
|
|
- `vue-router`: MIT
|
|
- `@nuxtjs/tailwindcss`: MIT
|
|
- `@types/node`: MIT
|