@trippnology/mixshell 0.0.0-stage → 0.7.0

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 +294 -2
  3. package/assets/mixshell-screenshot.png +0 -0
  4. package/package.json +73 -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 +412 -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 +601 -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 +1641 -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
@@ -0,0 +1,168 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+
3
+ import { CONFIG_FILE, DEFAULT_CONFIG, SMOOTHING_LABELS } from '../constants.js';
4
+ import { friendlyDeviceName } from '../utils/audioDevices.js';
5
+
6
+ export class Config {
7
+ constructor({ platform = process.platform } = {}) {
8
+ this.data = { ...DEFAULT_CONFIG };
9
+ // Injectable for the settings rows that depend on the OS (issues/048).
10
+ this.platform = platform;
11
+ // True when load() created the file fresh — the first-run gate
12
+ // (issues/041) keys on this, not merely on the onboarded flag, so
13
+ // legacy installs that already have a config.json are never nagged.
14
+ this.fresh = false;
15
+ }
16
+
17
+ load() {
18
+ try {
19
+ if (existsSync(CONFIG_FILE)) {
20
+ const configData = JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));
21
+ this.data = { ...DEFAULT_CONFIG, ...configData };
22
+ } else {
23
+ this.fresh = true;
24
+ this.save(); // Create default config file if it doesn't exist
25
+ }
26
+ } catch (error) {
27
+ console.error('Error loading config:', error);
28
+ }
29
+ return this.data;
30
+ }
31
+
32
+ // First-run onboarding gate (issues/041): run when the config file was
33
+ // just created, or when an explicit `onboarded: false` re-arms the
34
+ // flow ("Run setup again" sets it). An absent flag on an existing file
35
+ // means a legacy install — keep the defaults, never nag.
36
+ needsOnboarding() {
37
+ return this.fresh || this.get('onboarded') === false;
38
+ }
39
+
40
+ save() {
41
+ try {
42
+ writeFileSync(CONFIG_FILE, `${JSON.stringify(this.data, null, 2)}\n`);
43
+ } catch (error) {
44
+ console.error('Error saving config:', error);
45
+ }
46
+ }
47
+
48
+ get(key) {
49
+ return this.data[key];
50
+ }
51
+
52
+ set(key, value) {
53
+ this.data[key] = value;
54
+ return value;
55
+ }
56
+
57
+ // Cycle a setting through its option list (wraps), persist, return the
58
+ // new value. Unknown/missing current lands on options[0].
59
+ cycle(key, options) {
60
+ return this.step(key, options, 1);
61
+ }
62
+
63
+ // Step a setting through its options, wrapping in either direction.
64
+ // Missing/stale values land on the first option forward, the last back.
65
+ step(key, options, direction = 1) {
66
+ const index = options.indexOf(this.get(key));
67
+ const next =
68
+ index === -1
69
+ ? direction > 0
70
+ ? 0
71
+ : options.length - 1
72
+ : (index + direction + options.length) % options.length;
73
+ const value = options[next];
74
+ this.set(key, value);
75
+ this.save();
76
+ return value;
77
+ }
78
+
79
+ // Settings sub-screens (issues/024): grouped rows per view. Rows are
80
+ // [path, name] pairs; interpolated labels re-evaluate on each access, so
81
+ // cycled values show up on the next render. Paths key the applySetting
82
+ // switch, not positions.
83
+ get settingsViews() {
84
+ return [
85
+ {
86
+ key: 'general',
87
+ label: 'General',
88
+ rows: [
89
+ // First item under Settings > General (issues/042). Stored
90
+ // value is the speaker backend string; the label shows the
91
+ // friendly enumeration name, falling back to the raw string
92
+ // when the cache has not warmed yet.
93
+ [
94
+ 'audio_device',
95
+ `Output device: ${
96
+ this.get('audioDevice')
97
+ ? (friendlyDeviceName(this.get('audioDevice')) ??
98
+ this.get('audioDevice'))
99
+ : 'Default'
100
+ }`,
101
+ ],
102
+ ['default_dir', `Media Directory: ${this.get('mediaDirectory')}`],
103
+ ['audio_engine', `Audio Engine: ${this.get('audioEngine')}`],
104
+ ['volume_step', `Volume Step: ${this.get('volumeStep')}%`],
105
+ ['seek_step', `Seek Step: ${this.get('seekStep')}s`],
106
+ [
107
+ 'playlist_save_format',
108
+ `Playlist Save Format: ${this.get('playlistSaveFormat')}`,
109
+ ],
110
+ [
111
+ 'auto_play_first',
112
+ `Auto-play First Queued: ${this.get('play_when_first_track_queued') ? 'ON' : 'OFF'}`,
113
+ ],
114
+ // Only where a helper is bundled (issues/048); Linux media
115
+ // keys ride MPRIS and need no setting.
116
+ ...(this.platform === 'darwin'
117
+ ? [
118
+ [
119
+ 'media_keys',
120
+ `Media Keys: ${this.get('mediaKeys') ? 'ON' : 'OFF'}`,
121
+ ],
122
+ ]
123
+ : []),
124
+ ],
125
+ },
126
+ {
127
+ key: 'ui',
128
+ label: 'UI',
129
+ rows: [
130
+ ['theme', `Theme: ${this.get('theme')}`],
131
+ ['albumart_style', `Album Art Style: ${this.get('albumArtStyle')}`],
132
+ ],
133
+ },
134
+ {
135
+ key: 'visualizer',
136
+ label: 'Visualiser',
137
+ rows: [
138
+ [
139
+ 'visualizer_quality',
140
+ `Visualizer Quality: ${this.get('visualizerQuality')}`,
141
+ ],
142
+ ['visualizer_fps', `Visualizer FPS: ${this.get('visualizerFPS')}`],
143
+ [
144
+ 'visualizer_smoothing',
145
+ `Visualizer Smoothing: ${
146
+ SMOOTHING_LABELS[this.get('visualizerSmoothing')] ??
147
+ this.get('visualizerSmoothing')
148
+ }`,
149
+ ],
150
+ ['show_fps', `FPS Counter: ${this.get('showFPS') ? 'ON' : 'OFF'}`],
151
+ ],
152
+ },
153
+ {
154
+ key: 'library',
155
+ label: 'Library',
156
+ rows: [
157
+ ['library_rescan', 'Rescan Library Now'],
158
+ [
159
+ 'library_scan_start',
160
+ `Scan on Start: ${this.get('libraryScanOnStart') ? 'ON' : 'OFF'}`,
161
+ ],
162
+ ['library_dirs', `Library Dirs: ${this.get('libraryDirs').length}`],
163
+ ['run_setup', 'Run setup again'],
164
+ ],
165
+ },
166
+ ];
167
+ }
168
+ }
@@ -0,0 +1,151 @@
1
+ import { DBG } from '../utils/debug.js';
2
+ import { probeDuration } from '../utils/durationProbe.js';
3
+
4
+ // Playlist duration totals (issues/046). Two halves:
5
+ //
6
+ // - totals() is a synchronous read: durations come from the library DB
7
+ // cache only (path-keyed; scanned tracks carry theirs from the tag
8
+ // parse, everything else is filled in below). Never touches a file.
9
+ // - The background pass probes exactly the tracks currently queued —
10
+ // nothing else, no library walk. It rides the playlist 'updated'
11
+ // event (add/replaceAll/loadTracks all emit it), so a file is probed
12
+ // when it lands in the queue and never again (learned values persist
13
+ // in the cache; one-shot failures are remembered for the session so
14
+ // a broken file is not re-probed on every queue edit).
15
+ //
16
+ // Learned durations are written through Library.learnDurations, whose
17
+ // single 'updated' per batch is what refreshes the header — this
18
+ // service adds no UI event of its own.
19
+
20
+ // Debounce so addMultiple / folder `a` Add all bursts probe once.
21
+ const DEBOUNCE_MS = 300;
22
+ const CONCURRENCY = 3;
23
+
24
+ export function createDurationService({
25
+ library,
26
+ playlist,
27
+ probe = probeDuration,
28
+ debounceMs = DEBOUNCE_MS,
29
+ }) {
30
+ // Paths that came back without a usable duration this session —
31
+ // never re-probed (the header counts them as "unknown").
32
+ const failed = new Set();
33
+ let timer = null;
34
+ let draining = false;
35
+ let rerun = false;
36
+ let stopped = false;
37
+
38
+ // Queue changed: fill the header's duration gaps. Debounced; a pass
39
+ // still running reruns once at the end instead of interleaving.
40
+ function refresh() {
41
+ if (stopped) return;
42
+ if (draining) {
43
+ rerun = true;
44
+ return;
45
+ }
46
+ if (timer) clearTimeout(timer);
47
+ timer = setTimeout(run, debounceMs);
48
+ timer.unref?.();
49
+ }
50
+
51
+ async function run() {
52
+ timer = null;
53
+ draining = true;
54
+ try {
55
+ do {
56
+ rerun = false;
57
+ await pass();
58
+ } while (rerun && !stopped);
59
+ } finally {
60
+ draining = false;
61
+ }
62
+ }
63
+
64
+ async function pass() {
65
+ const paths = playlist.tracks.map((track) => track.path);
66
+ if (paths.length === 0) return;
67
+ const known = library.durationsByPaths(paths);
68
+ const todo = [
69
+ ...new Set(paths.filter((p) => !known.has(p) && !failed.has(p))),
70
+ ];
71
+ if (todo.length === 0) return;
72
+ DBG(`duration probe: ${todo.length} queued file(s) unknown`);
73
+
74
+ const found = [];
75
+ let next = 0;
76
+ const worker = async () => {
77
+ while (next < todo.length && !stopped) {
78
+ const filePath = todo[next++];
79
+ let seconds = null;
80
+ try {
81
+ seconds = await probe(filePath);
82
+ } catch (error) {
83
+ DBG(`duration probe error: ${filePath}: ${error?.message ?? error}`);
84
+ }
85
+ if (stopped) return;
86
+ if (seconds > 0) {
87
+ found.push({ path: filePath, seconds });
88
+ } else {
89
+ failed.add(filePath);
90
+ }
91
+ }
92
+ };
93
+ await Promise.all(
94
+ Array.from({ length: Math.min(CONCURRENCY, todo.length) }, worker),
95
+ );
96
+ if (stopped || found.length === 0) return;
97
+ library.learnDurations(found);
98
+ }
99
+
100
+ function onUpdated() {
101
+ refresh();
102
+ }
103
+ playlist.on('updated', onUpdated);
104
+
105
+ // Aggregate for the playlist header (issues/046). Order follows what
106
+ // will actually play next — the shuffle order when shuffle is on —
107
+ // and `left` walks that order from the current track to the end of
108
+ // the pass, minus the elapsed part of the playing track. Unknown
109
+ // durations contribute nothing and are counted, not guessed.
110
+ function totals({ elapsed = 0 } = {}) {
111
+ const order =
112
+ playlist.shuffle && playlist.shuffleOrder?.length
113
+ ? playlist.shuffleOrder
114
+ : playlist.tracks;
115
+ const durations = library.durationsByPaths(
116
+ order.map((track) => track.path),
117
+ );
118
+ let total = 0;
119
+ let unknown = 0;
120
+ for (const track of order) {
121
+ const seconds = durations.get(track.path);
122
+ if (seconds > 0) total += seconds;
123
+ else unknown++;
124
+ }
125
+ const position = playlist.current ? order.indexOf(playlist.current) : -1;
126
+ let left = total;
127
+ if (position >= 0) {
128
+ left = 0;
129
+ for (let i = position; i < order.length; i++) {
130
+ const seconds = durations.get(order[i].path);
131
+ if (seconds > 0) left += seconds;
132
+ }
133
+ }
134
+ return {
135
+ total,
136
+ left: Math.max(0, left - Math.max(0, elapsed)),
137
+ unknown,
138
+ };
139
+ }
140
+
141
+ function stop() {
142
+ stopped = true;
143
+ if (timer) {
144
+ clearTimeout(timer);
145
+ timer = null;
146
+ }
147
+ playlist.off('updated', onUpdated);
148
+ }
149
+
150
+ return { refresh, totals, stop };
151
+ }