@trippnology/mixshell 0.0.0-stage → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +320 -2
  3. package/assets/mixshell-screenshot.png +0 -0
  4. package/package.json +74 -5
  5. package/src/alsa-pulse.conf +20 -0
  6. package/src/alsa-setup.js +15 -0
  7. package/src/components/browser.js +193 -0
  8. package/src/components/config.js +168 -0
  9. package/src/components/durations.js +151 -0
  10. package/src/components/library.js +679 -0
  11. package/src/components/mediakeys.js +222 -0
  12. package/src/components/mpris.js +309 -0
  13. package/src/components/player.js +436 -0
  14. package/src/components/playlist.js +335 -0
  15. package/src/components/session.js +96 -0
  16. package/src/constants.js +164 -0
  17. package/src/engines/ffmpeg.js +610 -0
  18. package/src/engines/index.js +14 -0
  19. package/src/engines/webaudio.js +317 -0
  20. package/src/index.js +188 -0
  21. package/src/mediakeys/macos-nowplaying.js +227 -0
  22. package/src/ui/app.js +56 -0
  23. package/src/ui/artPane.js +314 -0
  24. package/src/ui/confirmPrompt.js +34 -0
  25. package/src/ui/constants.js +133 -0
  26. package/src/ui/controller.js +1654 -0
  27. package/src/ui/dom.js +9 -0
  28. package/src/ui/goToPrompt.js +105 -0
  29. package/src/ui/index.html +78 -0
  30. package/src/ui/libraryPanel.js +415 -0
  31. package/src/ui/listView.js +209 -0
  32. package/src/ui/onboarding.js +353 -0
  33. package/src/ui/playlistPanel.js +207 -0
  34. package/src/ui/settingsPanel.js +473 -0
  35. package/src/ui/shortcuts.js +30 -0
  36. package/src/ui/splash.js +302 -0
  37. package/src/ui/style.css +532 -0
  38. package/src/ui/subtabs.js +31 -0
  39. package/src/ui/visualizer/bars.js +74 -0
  40. package/src/ui/visualizer/circles.js +64 -0
  41. package/src/ui/visualizer/color.js +61 -0
  42. package/src/ui/visualizer/cube.js +105 -0
  43. package/src/ui/visualizer/grid.js +68 -0
  44. package/src/ui/visualizer/index.js +65 -0
  45. package/src/ui/visualizer/onset.js +130 -0
  46. package/src/ui/visualizer/spectrum.js +34 -0
  47. package/src/ui/visualizer/vu.js +71 -0
  48. package/src/ui/visualizer/waveform.js +58 -0
  49. package/src/utils/audioAnalyzer.js +362 -0
  50. package/src/utils/audioDevices.js +222 -0
  51. package/src/utils/cellart.js +75 -0
  52. package/src/utils/debug.js +7 -0
  53. package/src/utils/durationProbe.js +48 -0
  54. package/src/utils/folderArt.js +46 -0
  55. package/src/utils/format.js +20 -0
  56. package/src/utils/id3.js +84 -0
  57. package/src/utils/pathInput.js +76 -0
  58. package/src/utils/playlistIO.js +176 -0
  59. package/src/utils/terminalGraphics.js +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rikki Tripp - Trippnology
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,321 @@
1
- # Temporary Holding Version
1
+ # MixShell
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A console-based music player that is deliberately easy to use. No vim
4
+ keybindings, no command language, no modes to learn — browse with the
5
+ arrow keys, press `Enter` to play, and every shortcut is labelled in the
6
+ footer. If you can use a file manager, you already know how to drive it.
7
+
8
+ Under the hood it renders a full terminal UI
9
+ ([@b9g/termdom](https://github.com/bikeshaving/termdom)): plays everything
10
+ ffmpeg can decode (MP3, FLAC, WAV, OGG, m4a, …), shows
11
+ [album art](#album-art), and runs a live visualizer — all in the terminal.
12
+
13
+ ![MixShell's Main tab showing album art and keyboard shortcuts in the footer](assets/mixshell-screenshot.png)
14
+
15
+ MixShell is in beta. It works well for its author on Linux, but has had few
16
+ other users yet. Feedback, bug reports, and macOS reports (see
17
+ [Media keys](#macos)) are very welcome at
18
+ [github.com/Trippnology/mixshell/issues](https://github.com/Trippnology/mixshell/issues).
19
+
20
+ One thing to know before you ask, though: MixShell is deliberately simple
21
+ and will stay that way. It plays music and gets out of the way, and it
22
+ will not gain advanced features such as tag editing, an equaliser,
23
+ scrobbling, or smart playlists — requests for them will be politely
24
+ declined. Bugs and small improvements to what's already there are another
25
+ matter; those are very welcome.
26
+
27
+ ## Installation
28
+
29
+ You'll need [Node.js](https://nodejs.org) 22.12.0 or newer (check with
30
+ `node --version`). Then:
31
+
32
+ ```sh
33
+ npm install -g @trippnology/mixshell
34
+ ```
35
+
36
+ That's it — everything else MixShell needs, including its own copy of
37
+ ffmpeg, is downloaded automatically during install. One exception: the
38
+ default engine's `speaker` module compiles from source at install time.
39
+ On Windows that needs a C++ compiler: install the "Desktop development
40
+ with C++" workload of [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
41
+ (or tick "Tools for Native Modules" in the Node.js installer). Without
42
+ it the install still succeeds and MixShell plays through WebAudio
43
+ instead, with a message at first play. See Troubleshooting below.
44
+
45
+ ## Usage
46
+
47
+ ```sh
48
+ mixshell # start in your saved media directory, or home on first run
49
+ mixshell -d /path/to/music # start in a media directory
50
+ mixshell -p ./playlist.json # load a saved playlist
51
+ ```
52
+
53
+ Everything on screen can be reached with the arrow keys and `Enter`, and
54
+ the keys you can press are always listed in the footer. The global keys:
55
+ `Space` play/pause, `n`/`p` next/previous, `s` stop, `m` mute. `1`–`5`
56
+ switch tabs in the order shown in the header (`6` with `--debug`); `q`
57
+ quits. The arrow keys depend on the tab: `↑`/`↓` volume and `←`/`→` seek
58
+ on Main; `↑`/`↓` select on Playlist, Library, Browser and Settings;
59
+ `←`/`→` Back/Open on Browser, step ±1 on Settings. `w` save playlist is
60
+ on Playlist only.
61
+
62
+ `Enter` plays what's under the cursor; `Alt+Enter` adds it to the queue
63
+ instead. In the browser, `a` adds every audio file under the browsed
64
+ directory — including subdirectories. Press `g` to type a directory path
65
+ (relative paths start from the directory you're viewing), `←` to go back or
66
+ up, and `→` to open the highlighted folder.
67
+
68
+ By default, queueing the first track into an empty queue starts it playing
69
+ straight away. To queue tracks without playback starting, switch off
70
+ **Settings → General → Auto-play First Queued** (or set
71
+ `"play_when_first_track_queued": false` in `~/mixshell/config.json`). The
72
+ change takes effect immediately.
73
+
74
+ ## Sound
75
+
76
+ MixShell ships two ways to play sound. The default works everywhere with
77
+ no extra setup, so you can skip this section unless something won't play
78
+ or you like tinkering. Switch in **Settings → General → Audio Engine** —
79
+ the choice is saved and takes effect the next time you press play.
80
+
81
+ | | `ffmpeg` (default) | `webaudio` |
82
+ | ------------ | ----------------------------------------------- | --------------------------------------------- |
83
+ | Extra setup | Windows: C++ build tools (or WebAudio fallback) | Linux: needs `pipewire-jack` (see below) |
84
+ | File types | anything ffmpeg can decode | MP3, FLAC, WAV, OGG, m4a |
85
+ | Memory use | streams the file, stays constant | loads the whole file into memory (~21 MB/min) |
86
+ | Sound device | pick any output device in Settings | system default only |
87
+
88
+ Which to pick? The default is the safe choice: no system dependencies,
89
+ small memory footprint, and any output device. The `webaudio` option can
90
+ play a little more smoothly when the terminal is busy, and it's the
91
+ automatic fallback on unusual platforms where the default's audio library
92
+ won't build. Both engines pass the same test suite, and holding down a
93
+ key to scroll fast through your library is glitch-free on both.
94
+
95
+ If `webaudio` can't start a sound session (for example, its optional
96
+ package didn't install), the current track is skipped with an error
97
+ message and playback carries on — switch back to `ffmpeg` and nothing
98
+ else changes.
99
+
100
+ ## Album art
101
+
102
+ Nothing to set up. MixShell checks what your terminal can draw when it
103
+ starts, and shows the cover the best way it can:
104
+
105
+ - In **kitty** or **Ghostty**, the cover is a real image, drawn at the
106
+ full resolution of the space it takes up.
107
+ - In every other terminal, the same cover is drawn with block characters
108
+ instead — the same picture in the same colours, just chunkier. Nothing
109
+ else changes.
110
+
111
+ Inside tmux, the real image needs tmux's `allow-passthrough` option
112
+ (`set -g allow-passthrough on`); with it off you get the block version.
113
+
114
+ Prefer the classic character look? **Settings → UI → Album Art Style**
115
+ (`"albumArtStyle"` in `config.json`) swaps the cover for a rendition in
116
+ plain characters — shade ramps, ones and zeros, or Braille — that doesn't
117
+ depend on which terminal you use. The change applies immediately.
118
+ `blocks`, the default, is the style that becomes a real image in kitty
119
+ and Ghostty.
120
+
121
+ ## Media keys and desktop remote control
122
+
123
+ ### Linux
124
+
125
+ On a Linux desktop your keyboard's media keys (play/pause, next,
126
+ previous), `playerctl`, and desktop tray controls work while MixShell is
127
+ running:
128
+
129
+ ```sh
130
+ playerctl -p mixshell status
131
+ playerctl -p mixshell play-pause
132
+ playerctl -p mixshell next
133
+ playerctl -p mixshell volume 0.8
134
+ ```
135
+
136
+ This uses the optional `dbus-next` package, which normally installs
137
+ automatically. If it's missing — or you're on a headless machine —
138
+ MixShell simply runs without it. Nothing else changes.
139
+
140
+ ### macOS
141
+
142
+ Your keyboard's media keys and the Control Center playback controls
143
+ drive MixShell while it runs, and Now Playing shows the current track.
144
+
145
+ It's off by default. Switch it on in **Settings → General → Media Keys**
146
+ (or set `"mediaKeys": true` in `~/mixshell/config.json`) and restart
147
+ MixShell. The setting only appears on macOS; elsewhere the
148
+ `"mediaKeys": false` line in `config.json` does nothing.
149
+
150
+ There's nothing to install — no npm package and no compiler. MixShell
151
+ runs a small built-in helper through macOS's own `osascript`. If the
152
+ helper can't start, MixShell logs one debug line and runs as usual.
153
+
154
+ This was written without access to a Mac and is untested on real
155
+ hardware. Reports from macOS users — working or not — are very welcome.
156
+
157
+ ### Windows
158
+
159
+ Not supported yet. The API to target is SMTC (System Media Transport
160
+ Controls); pull requests welcome.
161
+
162
+ ## Where MixShell keeps its data
163
+
164
+ All your settings and library data live in one folder, `~/mixshell/`.
165
+ Back it up, move it, or delete it as a unit. To put it somewhere else,
166
+ set the `MIXSHELL_DIR` environment variable.
167
+
168
+ ## Configuration
169
+
170
+ Every option below can be changed in Settings — you don't need to edit
171
+ `config.json` by hand. The headings match the Settings screens, and each
172
+ row names the setting you want. Changes are saved as soon as you make them
173
+ (except Media Keys, which takes effect on the next start).
174
+
175
+ ### General
176
+
177
+ - **Media Directory** — `mediaDirectory`: a path (default: your home dir).
178
+ - **Output device** — `audioDevice`: a device id, or `null` for the system
179
+ default. The `MIXSHELL_AUDIO_DEVICE` environment variable overrides it.
180
+ - **Audio Engine** — `audioEngine`: `ffmpeg` (default) or `webaudio`.
181
+ - **Volume Step** — `volumeStep`: `1`, `2`, `5` (default) or `10`, in percent.
182
+ - **Seek Step** — `seekStep`: `5` (default), `10`, `15` or `30` seconds.
183
+ - **Playlist Save Format** — `playlistSaveFormat`: `m3u` (default) or `pls`.
184
+ - **Auto-play First Queued** — `play_when_first_track_queued`: `true`
185
+ (default) or `false`.
186
+ - **Media Keys** (macOS only) — `mediaKeys`: `false` (default) or `true`.
187
+
188
+ ### UI
189
+
190
+ - **Theme** — `theme`: `default` (default), `terminal`, `nord`, `dracula`,
191
+ `gruvbox`, `monokai`, `tokyo-night`, `solarized-dark` or `night-owl`.
192
+ `terminal` has no palette of its own: it uses the colours of whatever
193
+ colour scheme your terminal is configured with (its default foreground
194
+ and background, plus blue and bright black).
195
+ - **Album Art Style** — `albumArtStyle`: `blocks` (default), `basic`,
196
+ `binary`, `braille`, `braille_plus`, `medium` or `complex`.
197
+
198
+ ### Visualiser
199
+
200
+ - **Visualizer Quality** — `visualizerQuality`: `low`, `medium` or `high`
201
+ (default).
202
+ - **Visualizer FPS** — `visualizerFPS`: `5`, `7`, `10`, `15`, `30` or `60`
203
+ (default).
204
+ - **Visualizer Smoothing** — `visualizerSmoothing`: `1` (Off, default),
205
+ `0.9`, `0.7`, `0.5`, `0.3` or `0.1`.
206
+ - **FPS Counter** — `showFPS`: `false` (default) or `true`.
207
+
208
+ ### Library
209
+
210
+ - **Library Dirs** — `libraryDirs`: a list of paths to scan (default:
211
+ empty). Add one with `Shift+L` in the Browser; remove one in Settings.
212
+ - **Scan on Start** — `libraryScanOnStart`: `false` (default) or `true`.
213
+
214
+ MixShell also writes a few values to `config.json` as you use it, rather
215
+ than offering them as Settings rows: `volume` (0–1) and `visualizerMode`
216
+ (`vu`, `bars`, `waveform`, `circles`, `cube`, `albumart`, the default).
217
+ Volume changes with `↑`/`↓` on Main; visualizer mode changes with `v`.
218
+ The `onboarded` flag tracks first-run setup and is maintained by
219
+ **Settings → Library → Run setup again**.
220
+
221
+ ## Troubleshooting and advanced setup
222
+
223
+ **Node version.** Below Node 22.12.0, npm only _warns_ during install —
224
+ it finishes anyway, and MixShell then fails at startup with a module
225
+ error. If you see that, update Node rather than debugging the error.
226
+
227
+ **`speaker` failed to build on Windows.** At first play, a message says
228
+ the default audio engine did not install and WebAudio output is being
229
+ used. That means the native `speaker` module could not compile. To get
230
+ the default engine back:
231
+
232
+ 1. Install the [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
233
+ with the "Desktop development with C++" workload, or tick "Tools for
234
+ Native Modules" in the Node.js installer.
235
+ 2. Reinstall: `npm install -g @trippnology/mixshell`.
236
+
237
+ Use the **2022** Build Tools, not only Visual Studio 2026: releases
238
+ before this fix ship a build helper (`node-gyp`) that predates VS 2026
239
+ and reports `could not find a version of Visual Studio 2017 or newer`
240
+ even when 2026 is installed. Newer releases bundle a helper that
241
+ recognises it. If npm also reports `EPERM` while removing a folder such
242
+ as `node_modules\speaker\deps`, add an exclusion for `AppData\Roaming\npm`
243
+ in your antivirus, remove
244
+ `C:\Users\<you>\AppData\Roaming\npm\node_modules\@trippnology`, then
245
+ reinstall.
246
+
247
+ **Optional dependencies.** Two npm packages MixShell uses are marked
248
+ optional — npm tolerates their install failing and MixShell runs without
249
+ them: `dbus-next` (media keys, above) and `node-web-audio-api` (the
250
+ `webaudio` engine, above).
251
+
252
+ **Keys in different terminals.** kitty, Ghostty, tmux, and xterm (via its
253
+ extended-keys protocol) also accept `Shift+Enter` (queue at bottom) and
254
+ `Ctrl+Enter` (queue after current track); `Ctrl+J` works as
255
+ queue-after-current in any terminal. Other terminals can't tell
256
+ `Shift+Enter` from plain `Enter`, so MixShell doesn't guess — use the
257
+ `Alt` spellings there.
258
+
259
+ **Choosing a sound device.** Settings → General → Output device opens a list
260
+ of your output devices; pick one with `↑`/`↓` and `Enter`. `←`/`→` on the row
261
+ step through devices directly. As an override (for scripts and launchers),
262
+ the default engine also honours the `MIXSHELL_AUDIO_DEVICE` environment
263
+ variable, e.g. `MIXSHELL_AUDIO_DEVICE=pulse:my-sink mixshell`.
264
+
265
+ **`webaudio` on Linux (JACK).** The `webaudio` prebuilts use the JACK
266
+ audio API. Most desktops running PipeWire just need the `pipewire-jack`
267
+ package. On Debian/Ubuntu that package installs its `libjack` outside the
268
+ dynamic loader's search path, so starting a session fails with
269
+ `DeviceUnavailable` until you either launch under the wrapper:
270
+
271
+ ```sh
272
+ pw-jack mixshell
273
+ ```
274
+
275
+ or make it permanent:
276
+
277
+ ```sh
278
+ sudo cp /usr/share/doc/pipewire/examples/ld.so.conf.d/pipewire-jack-x86_64-linux-gnu.conf /etc/ld.so.conf.d/
279
+ sudo ldconfig
280
+ ```
281
+
282
+ ## Contributing
283
+
284
+ Start with [DEVELOPMENT.md](DEVELOPMENT.md) — it covers setup, testing,
285
+ architecture, and the conventions (and gotchas) that keep changes from
286
+ breaking things silently. Coding agents should read [AGENTS.md](AGENTS.md),
287
+ the condensed version of the same document.
288
+
289
+ 1. Fork it!
290
+ 2. Create your feature branch: `git checkout -b my-new-feature develop`
291
+ 3. Commit your changes: `git commit -am 'Add some feature'`
292
+ 4. Push to the branch: `git push origin my-new-feature`
293
+ 5. Submit a pull request :D
294
+
295
+ ## History
296
+
297
+ MixShell began on 2 March 2025 as a small terminal MP3 player built on
298
+ [terminal-kit](https://github.com/cronvel/terminal-kit), with album art
299
+ drawn as ASCII. terminal-kit served it well for a year and a half, but
300
+ TermDOM came along and was a lot more enjoyable to work with: HTML, CSS and
301
+ a real DOM, in the terminal. The UI was rewritten on TermDOM in August 2026.
302
+
303
+ The rest followed quickly: ffmpeg decoding and a SQLite library (October
304
+ 2026), MPRIS and media keys, a second audio engine, native album art, and
305
+ five visualizer modes.
306
+
307
+ ## Credits
308
+
309
+ MixShell was created by [Trippnology](https://trippnology.com/), but it would not be possible without:
310
+
311
+ - **[Brian Kim](https://github.com/brainkim)** — author of
312
+ [TermDOM](https://github.com/bikeshaving/termdom), the terminal UI engine
313
+ MixShell is built on.
314
+ - **[titanism](https://github.com/titanism)** ([Forward Email](https://forwardemail.net)) —
315
+ TermDOM's `<img>` and `<canvas>` support
316
+ ([PR #125](https://github.com/bikeshaving/termdom/pull/125)), which
317
+ MixShell's album art is drawn with.
318
+
319
+ ## License
320
+
321
+ MIT — see [LICENSE](LICENSE).
Binary file
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
- "name": "@trippnology/mixshell",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@trippnology/mixshell",
3
+ "version": "0.7.1",
4
+ "description": "Terminal-based music player",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "mixshell": "src/index.js"
9
+ },
10
+ "engines": {
11
+ "node": ">=22.12.0"
12
+ },
13
+ "scripts": {
14
+ "start": "node src/index.js",
15
+ "test": "node node_modules/mocha/bin/mocha.js",
16
+ "lint": "node node_modules/@biomejs/biome/bin/biome check .",
17
+ "lint:fix": "node node_modules/@biomejs/biome/bin/biome check --write ."
18
+ },
19
+ "prepublishOnly": "npm test && npm run lint",
20
+ "files": [
21
+ "src",
22
+ "assets"
23
+ ],
24
+ "keywords": [
25
+ "music",
26
+ "player",
27
+ "terminal",
28
+ "console",
29
+ "tui"
30
+ ],
31
+ "author": "Rikki Tripp - Trippnology",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/Trippnology/mixshell.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/Trippnology/mixshell/issues"
39
+ },
40
+ "homepage": "https://github.com/Trippnology/mixshell#readme",
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/"
43
+ },
44
+ "dependencies": {
45
+ "@b9g/termdom": "0.2.7",
46
+ "@ffmpeg-installer/ffmpeg": "1.1.0",
47
+ "better-sqlite3": "13.2.0",
48
+ "commander": "15.1.0",
49
+ "fft.js": "4.0.4",
50
+ "music-metadata": "12.7.0",
51
+ "node-gyp": "13.1.0"
52
+ },
53
+ "devDependencies": {
54
+ "@biomejs/biome": "2.6.8",
55
+ "chai": "6.3.0",
56
+ "mocha": "12.0.3"
57
+ },
58
+ "optionalDependencies": {
59
+ "dbus-next": "0.10.2",
60
+ "node-web-audio-api": "2.2.0",
61
+ "speaker": "0.5.5"
62
+ },
63
+ "overrides": {
64
+ "node-gyp": "13.1.0"
65
+ },
66
+ "allowScripts": {
67
+ "@ffmpeg-installer/linux-x64@4.1.0": true,
68
+ "@ffmpeg-installer/linux-arm64@4.1.0": true,
69
+ "@ffmpeg-installer/darwin-x64@4.1.0": true,
70
+ "@ffmpeg-installer/darwin-arm64@4.1.0": true,
71
+ "@ffmpeg-installer/win32-x64@4.1.0": true,
72
+ "speaker@0.5.5": true,
73
+ "better-sqlite3@13.2.0": true
74
+ }
75
+ }
@@ -0,0 +1,20 @@
1
+ # Load the distro's full ALSA configuration first, then override the
2
+ # default PCM to PulseAudio. Without the include, standard device-name
3
+ # syntaxes (`hw:CARD=x,DEV=n`, `default:CARD=x`, …) are unknown — ALSA_CONFIG_PATH
4
+ # replaces the top-level config entirely.
5
+ </usr/share/alsa/alsa.conf>
6
+ pcm.!default {
7
+ type pulse
8
+ }
9
+ pcm.pulse {
10
+ @args [ DEVICE ]
11
+ @args.DEVICE {
12
+ type string
13
+ default ""
14
+ }
15
+ type pulse
16
+ device $DEVICE
17
+ }
18
+ ctl.!default {
19
+ type pulse
20
+ }
@@ -0,0 +1,15 @@
1
+ // Must be the first import in index.js: sets ALSA_CONFIG_PATH before any
2
+ // module (e.g. `speaker`) loads native ALSA bindings. The `speaker` binding
3
+ // opens the ALSA "default" device at module load time; on systems where
4
+ // "default" is broken (e.g. card 0 is a capture-only USB camera), that probe
5
+ // crashes with an ALSA assertion. Routing default through PulseAudio fixes it.
6
+ // Skipped when the user provides an explicit ALSA_CONFIG_PATH.
7
+ import { existsSync } from 'node:fs';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ if (process.platform === 'linux' && !process.env.ALSA_CONFIG_PATH) {
11
+ const conf = fileURLToPath(new URL('./alsa-pulse.conf', import.meta.url));
12
+ if (existsSync(conf)) {
13
+ process.env.ALSA_CONFIG_PATH = conf;
14
+ }
15
+ }
@@ -0,0 +1,193 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ import { setImmediate as nextTask } from 'node:timers/promises';
6
+
7
+ import { isAudioFile, isPlaylistFile } from '../constants.js';
8
+ import { DBG } from '../utils/debug.js';
9
+ import { resolveDirectoryInput } from '../utils/pathInput.js';
10
+
11
+ // Entries walked between event-loop yields. Mirrors the library scan
12
+ // walker (issues/031) so a big collectAudioFiles() pass keeps the TUI
13
+ // painting instead of freezing on one synchronous traversal.
14
+ const WALK_YIELD = 50;
15
+
16
+ export class Browser extends EventEmitter {
17
+ constructor(initialDirectory) {
18
+ super();
19
+ this.currentDirectory = initialDirectory || process.cwd();
20
+ this.entries = [];
21
+ this.selectedIndex = 0;
22
+ this.history = [];
23
+ this.previousDirectoryName = null;
24
+ // Reason for the last failed loadDirectory, as { path, error };
25
+ // null after a success (issues/054).
26
+ this.lastError = null;
27
+
28
+ // Load the initial directory
29
+ this.loadDirectory(this.currentDirectory);
30
+ }
31
+
32
+ loadDirectory(dirPath, skipHistory = false) {
33
+ this.lastError = null;
34
+ try {
35
+ // Reuse the shared validation so failures carry the same reason
36
+ // as the Go to prompt (issues/054).
37
+ const { error } = resolveDirectoryInput(dirPath);
38
+ if (error) {
39
+ DBG(`browser: invalid directory: ${dirPath}`);
40
+ this.lastError = { path: dirPath, error };
41
+ return false;
42
+ }
43
+
44
+ // Read and build the listing before mutating state: a failure
45
+ // keeps the current directory, entries and cursor intact.
46
+ const items = fs.readdirSync(dirPath, { withFileTypes: true });
47
+ const entries = items.map((item) => {
48
+ const fullPath = path.join(dirPath, item.name);
49
+ // Dirent.isDirectory() is false for symlinks; a guarded stat
50
+ // follows the link so linked folders list and open like real
51
+ // ones (issues/051). Broken links stay plain rows.
52
+ let isDirectory = item.isDirectory();
53
+ if (item.isSymbolicLink()) {
54
+ try {
55
+ isDirectory = fs.statSync(fullPath).isDirectory();
56
+ } catch {
57
+ isDirectory = false;
58
+ }
59
+ }
60
+ const isAudio = !isDirectory && isAudioFile(item.name);
61
+ // Playlist containers (issues/028) are listed and loadable but
62
+ // never decode as audio.
63
+ const isPlaylist = !isDirectory && isPlaylistFile(item.name);
64
+
65
+ return {
66
+ name: item.name,
67
+ path: fullPath,
68
+ isDirectory,
69
+ isAudio,
70
+ isPlaylist,
71
+ };
72
+ });
73
+
74
+ // Sort: directories first, then files
75
+ entries.sort((a, b) => {
76
+ if (a.isDirectory && !b.isDirectory) return -1;
77
+ if (!a.isDirectory && b.isDirectory) return 1;
78
+ return a.name.localeCompare(b.name);
79
+ });
80
+
81
+ // Add parent directory entry at the top (except for root paths)
82
+ if (path.resolve(dirPath) !== path.resolve('/')) {
83
+ entries.unshift({
84
+ name: '..',
85
+ path: path.join(dirPath, '..'),
86
+ isDirectory: true,
87
+ isAudio: false,
88
+ });
89
+ }
90
+
91
+ const oldDirectory = this.currentDirectory;
92
+ const goingUp = this.isParentDirectory(oldDirectory, dirPath);
93
+ if (oldDirectory !== dirPath && !skipHistory) {
94
+ this.history.push(oldDirectory);
95
+ }
96
+ if (oldDirectory && (skipHistory || !goingUp)) {
97
+ this.previousDirectoryName = path.basename(oldDirectory);
98
+ }
99
+ this.currentDirectory = dirPath;
100
+ this.entries = entries;
101
+ if (this.previousDirectoryName && goingUp) {
102
+ const previousIndex = entries.findIndex(
103
+ (entry) => entry.name === this.previousDirectoryName,
104
+ );
105
+ this.selectedIndex = Math.max(previousIndex, 0);
106
+ this.previousDirectoryName = null; // Clear after use
107
+ } else {
108
+ this.selectedIndex = 0;
109
+ }
110
+ this.emit('directoryLoaded', dirPath, this.entries);
111
+ return true;
112
+ } catch (error) {
113
+ DBG(`browser: load failed: ${error.message}`);
114
+ this.lastError = { path: dirPath, error: error.message };
115
+ return false;
116
+ }
117
+ }
118
+
119
+ goBack() {
120
+ if (this.history.length > 0) {
121
+ const previousDir = this.history.pop();
122
+ this.loadDirectory(previousDir, true); // true = skipHistory
123
+ return true;
124
+ }
125
+ // Fresh launch: ← climbs to the parent, same as the onboarding
126
+ // picker. At the filesystem root there is nowhere to go (issues/051).
127
+ const parent = path.resolve(this.currentDirectory, '..');
128
+ if (parent === path.resolve(this.currentDirectory)) return false;
129
+ return this.loadDirectory(parent, true);
130
+ }
131
+
132
+ isParentDirectory(child, parent) {
133
+ if (!parent) return false;
134
+ const resolvedChild = path.resolve(child);
135
+ const resolvedParent = path.resolve(parent);
136
+ const relative = path.relative(resolvedParent, resolvedChild);
137
+ // Parent if relative path doesn't start with '..'
138
+ return !relative.startsWith('..');
139
+ }
140
+
141
+ getSelected() {
142
+ return this.entries[this.selectedIndex] || null;
143
+ }
144
+
145
+ openSelected() {
146
+ const selected = this.getSelected();
147
+ if (!selected) return null;
148
+
149
+ if (selected.isDirectory) {
150
+ this.loadDirectory(selected.path);
151
+ return { type: 'directory', path: selected.path };
152
+ } else if (selected.isAudio) {
153
+ this.emit('fileSelected', selected);
154
+ return { type: 'file', path: selected.path };
155
+ }
156
+
157
+ return null;
158
+ }
159
+
160
+ findAudioFiles() {
161
+ return this.entries.filter((entry) => entry.isAudio);
162
+ }
163
+
164
+ // Recursive collector (issues/039): every audio file under dirPath,
165
+ // per-directory alphabetical, depth first, so repeated actions give
166
+ // stable queues. Traversal rules mirror the library scan walker
167
+ // (library.js #walk): only real directories are descended (Dirent
168
+ // isDirectory() is false for symlinks, so links never escape the
169
+ // tree), unreadable directories are skipped, and dot-prefixed
170
+ // files/directories are ignored. Playlist containers are parse
171
+ // targets, never decodeable audio.
172
+ async collectAudioFiles(dirPath = this.currentDirectory, out = []) {
173
+ let entries;
174
+ try {
175
+ entries = fs.readdirSync(dirPath, { withFileTypes: true });
176
+ } catch {
177
+ return out; // unreadable/missing directory — skip, don't fail
178
+ }
179
+ entries.sort((a, b) => a.name.localeCompare(b.name));
180
+ let walked = 0;
181
+ for (const entry of entries) {
182
+ if (entry.name.startsWith('.')) continue;
183
+ const fullPath = path.join(dirPath, entry.name);
184
+ if (entry.isDirectory()) {
185
+ await this.collectAudioFiles(fullPath, out);
186
+ } else if (entry.isFile() && isAudioFile(entry.name)) {
187
+ out.push({ path: fullPath });
188
+ }
189
+ if (++walked % WALK_YIELD === 0) await nextTask();
190
+ }
191
+ return out;
192
+ }
193
+ }