@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.
- package/LICENSE +21 -0
- package/README.md +294 -2
- package/assets/mixshell-screenshot.png +0 -0
- package/package.json +73 -5
- package/src/alsa-pulse.conf +20 -0
- package/src/alsa-setup.js +15 -0
- package/src/components/browser.js +193 -0
- package/src/components/config.js +168 -0
- package/src/components/durations.js +151 -0
- package/src/components/library.js +679 -0
- package/src/components/mediakeys.js +222 -0
- package/src/components/mpris.js +309 -0
- package/src/components/player.js +412 -0
- package/src/components/playlist.js +335 -0
- package/src/components/session.js +96 -0
- package/src/constants.js +164 -0
- package/src/engines/ffmpeg.js +601 -0
- package/src/engines/index.js +14 -0
- package/src/engines/webaudio.js +317 -0
- package/src/index.js +188 -0
- package/src/mediakeys/macos-nowplaying.js +227 -0
- package/src/ui/app.js +56 -0
- package/src/ui/artPane.js +314 -0
- package/src/ui/confirmPrompt.js +34 -0
- package/src/ui/constants.js +133 -0
- package/src/ui/controller.js +1641 -0
- package/src/ui/dom.js +9 -0
- package/src/ui/goToPrompt.js +105 -0
- package/src/ui/index.html +78 -0
- package/src/ui/libraryPanel.js +415 -0
- package/src/ui/listView.js +209 -0
- package/src/ui/onboarding.js +353 -0
- package/src/ui/playlistPanel.js +207 -0
- package/src/ui/settingsPanel.js +473 -0
- package/src/ui/shortcuts.js +30 -0
- package/src/ui/splash.js +302 -0
- package/src/ui/style.css +532 -0
- package/src/ui/subtabs.js +31 -0
- package/src/ui/visualizer/bars.js +74 -0
- package/src/ui/visualizer/circles.js +64 -0
- package/src/ui/visualizer/color.js +61 -0
- package/src/ui/visualizer/cube.js +105 -0
- package/src/ui/visualizer/grid.js +68 -0
- package/src/ui/visualizer/index.js +65 -0
- package/src/ui/visualizer/onset.js +130 -0
- package/src/ui/visualizer/spectrum.js +34 -0
- package/src/ui/visualizer/vu.js +71 -0
- package/src/ui/visualizer/waveform.js +58 -0
- package/src/utils/audioAnalyzer.js +362 -0
- package/src/utils/audioDevices.js +222 -0
- package/src/utils/cellart.js +75 -0
- package/src/utils/debug.js +7 -0
- package/src/utils/durationProbe.js +48 -0
- package/src/utils/folderArt.js +46 -0
- package/src/utils/format.js +20 -0
- package/src/utils/id3.js +84 -0
- package/src/utils/pathInput.js +76 -0
- package/src/utils/playlistIO.js +176 -0
- package/src/utils/terminalGraphics.js +47 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { isAudioFile, REPEAT_MODES } from '../constants.js';
|
|
5
|
+
|
|
6
|
+
function makeTrack(filePath) {
|
|
7
|
+
return { path: filePath, name: path.basename(filePath) };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Playlist extends EventEmitter {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.tracks = [];
|
|
14
|
+
this.currentIndex = -1;
|
|
15
|
+
this.shuffle = false;
|
|
16
|
+
// Repeat mode (issues/037): 'off' | 'all' | 'one'.
|
|
17
|
+
this.repeat = 'off';
|
|
18
|
+
this.shuffleOrder = null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get current() {
|
|
22
|
+
return this.tracks[this.currentIndex] || null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get isEmpty() {
|
|
26
|
+
return this.tracks.length === 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get length() {
|
|
30
|
+
return this.tracks.length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
buildShuffleOrder() {
|
|
34
|
+
const order = [...this.tracks];
|
|
35
|
+
for (let i = order.length - 1; i > 0; i--) {
|
|
36
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
37
|
+
[order[i], order[j]] = [order[j], order[i]];
|
|
38
|
+
}
|
|
39
|
+
if (this.current) {
|
|
40
|
+
order.splice(order.indexOf(this.current), 1);
|
|
41
|
+
order.unshift(this.current);
|
|
42
|
+
}
|
|
43
|
+
this.shuffleOrder = order;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Restore a saved session (issues/027): queue, current track and
|
|
47
|
+
// shuffle/repeat flags, without starting playback. shuffleOrder is
|
|
48
|
+
// rebuilt fresh — only validity is promised, not the previous order.
|
|
49
|
+
restoreSession({ tracks, currentIndex, shuffle, repeat }) {
|
|
50
|
+
this.tracks = tracks;
|
|
51
|
+
this.currentIndex = Math.min(Math.max(currentIndex, -1), tracks.length - 1);
|
|
52
|
+
this.shuffle = shuffle;
|
|
53
|
+
this.repeat = REPEAT_MODES.includes(repeat) ? repeat : 'off';
|
|
54
|
+
if (this.shuffle) {
|
|
55
|
+
this.buildShuffleOrder();
|
|
56
|
+
} else {
|
|
57
|
+
this.shuffleOrder = null;
|
|
58
|
+
}
|
|
59
|
+
this.emit('updated');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Queue loading (issues/028): replace the queue with prebuilt track
|
|
63
|
+
// objects ({path, name}) from the IO layer. "Open", not "merge" — and
|
|
64
|
+
// never starts playback; the cursor parks on track 1 and the user
|
|
65
|
+
// presses Enter/Space. Emits 'updated' only (not trackChanged) so the
|
|
66
|
+
// player stays quiet.
|
|
67
|
+
loadTracks(tracks) {
|
|
68
|
+
this.tracks = tracks;
|
|
69
|
+
this.currentIndex = tracks.length > 0 ? 0 : -1;
|
|
70
|
+
this.shuffleOrder = this.shuffle ? [...tracks] : null;
|
|
71
|
+
this.emit('updated');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
add(filePath) {
|
|
75
|
+
if (!isAudioFile(filePath)) return;
|
|
76
|
+
if (this.tracks.findIndex((track) => track.path === filePath) === -1) {
|
|
77
|
+
const track = makeTrack(filePath);
|
|
78
|
+
this.tracks.push(track);
|
|
79
|
+
|
|
80
|
+
// If this is the first track added, set current index
|
|
81
|
+
if (this.tracks.length === 1) {
|
|
82
|
+
this.currentIndex = 0;
|
|
83
|
+
this.emit('firstTrackQueued');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.shuffle) {
|
|
87
|
+
this.shuffleOrder.push(track);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.emit('updated');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Queue operations (issues/025): replace the queue with a new set of
|
|
95
|
+
// tracks. Playback is started explicitly by the caller, so this never
|
|
96
|
+
// emits firstTrackQueued.
|
|
97
|
+
replaceAll(filePaths) {
|
|
98
|
+
this.tracks = filePaths
|
|
99
|
+
.filter((filePath) => isAudioFile(filePath))
|
|
100
|
+
.map(makeTrack);
|
|
101
|
+
this.currentIndex = -1;
|
|
102
|
+
this.shuffleOrder = this.shuffle ? [] : null;
|
|
103
|
+
this.emit('updated');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Queue the track after the currently playing one, in both normal and
|
|
107
|
+
// shuffle order (the shuffle order is spliced, not rebuilt, so the
|
|
108
|
+
// insertion is visible in the upcoming sequence). With nothing playing
|
|
109
|
+
// this degrades to a plain append.
|
|
110
|
+
insertNext(filePath) {
|
|
111
|
+
if (!isAudioFile(filePath)) return;
|
|
112
|
+
if (this.tracks.some((track) => track.path === filePath)) return;
|
|
113
|
+
|
|
114
|
+
const track = makeTrack(filePath);
|
|
115
|
+
|
|
116
|
+
if (this.currentIndex === -1 || this.isEmpty) {
|
|
117
|
+
this.tracks.push(track);
|
|
118
|
+
if (this.shuffle) {
|
|
119
|
+
this.shuffleOrder.push(track);
|
|
120
|
+
}
|
|
121
|
+
this.emit('updated');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const insertAt = this.currentIndex + 1;
|
|
126
|
+
this.tracks.splice(insertAt, 0, track);
|
|
127
|
+
if (this.shuffle) {
|
|
128
|
+
const position = this.shuffleOrder.indexOf(this.current);
|
|
129
|
+
this.shuffleOrder.splice(position + 1, 0, track);
|
|
130
|
+
}
|
|
131
|
+
this.emit('updated');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
addMultiple(filePaths) {
|
|
135
|
+
const addedTracks = [];
|
|
136
|
+
filePaths.forEach((filePath) => {
|
|
137
|
+
if (
|
|
138
|
+
isAudioFile(filePath) &&
|
|
139
|
+
this.tracks.findIndex((track) => track.path === filePath) === -1
|
|
140
|
+
) {
|
|
141
|
+
const track = makeTrack(filePath);
|
|
142
|
+
this.tracks.push(track);
|
|
143
|
+
addedTracks.push(track);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// If these were the first tracks added, set current index
|
|
148
|
+
if (this.tracks.length > 0 && this.currentIndex === -1) {
|
|
149
|
+
this.currentIndex = 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (addedTracks.length) {
|
|
153
|
+
if (this.shuffle) {
|
|
154
|
+
this.shuffleOrder.push(...addedTracks);
|
|
155
|
+
}
|
|
156
|
+
this.emit('updated');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
remove(index) {
|
|
161
|
+
if (index >= 0 && index < this.tracks.length) {
|
|
162
|
+
// Adjust current index if needed
|
|
163
|
+
if (index === this.currentIndex) {
|
|
164
|
+
this.next();
|
|
165
|
+
if (this.currentIndex > index) {
|
|
166
|
+
this.currentIndex--;
|
|
167
|
+
}
|
|
168
|
+
} else if (index < this.currentIndex) {
|
|
169
|
+
this.currentIndex--;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const removedTrack = this.tracks[index];
|
|
173
|
+
this.tracks.splice(index, 1);
|
|
174
|
+
|
|
175
|
+
// If we removed the last track, adjust currentIndex
|
|
176
|
+
if (this.isEmpty) {
|
|
177
|
+
this.currentIndex = -1;
|
|
178
|
+
} else if (this.currentIndex >= this.tracks.length) {
|
|
179
|
+
this.currentIndex = this.tracks.length - 1;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this.shuffle) {
|
|
183
|
+
this.shuffleOrder = this.shuffleOrder.filter(
|
|
184
|
+
(track) => track !== removedTrack,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.emit('updated');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Reorder: swap the track at `index` with its neighbour at
|
|
193
|
+
// index + delta (delta -1 = up, +1 = down). Returns whether the swap
|
|
194
|
+
// happened. The shuffle order holds the same track objects, so the
|
|
195
|
+
// swap keeps it consistent untouched; currentIndex rides the moving
|
|
196
|
+
// track either way.
|
|
197
|
+
move(index, delta) {
|
|
198
|
+
const target = index + delta;
|
|
199
|
+
if (
|
|
200
|
+
index < 0 ||
|
|
201
|
+
index >= this.tracks.length ||
|
|
202
|
+
target < 0 ||
|
|
203
|
+
target >= this.tracks.length
|
|
204
|
+
) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const temp = this.tracks[index];
|
|
208
|
+
this.tracks[index] = this.tracks[target];
|
|
209
|
+
this.tracks[target] = temp;
|
|
210
|
+
if (this.currentIndex === index) {
|
|
211
|
+
this.currentIndex = target;
|
|
212
|
+
} else if (this.currentIndex === target) {
|
|
213
|
+
this.currentIndex = index;
|
|
214
|
+
}
|
|
215
|
+
this.emit('updated');
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
clear() {
|
|
220
|
+
this.tracks = [];
|
|
221
|
+
this.currentIndex = -1;
|
|
222
|
+
this.shuffleOrder = this.shuffle ? [] : null;
|
|
223
|
+
this.emit('updated');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// auto marks the end-of-track path (Player's 'ended' handler,
|
|
227
|
+
// issues/037): under repeat 'one' the current track is handed back for
|
|
228
|
+
// a restart. The check fires before the 'all' wrap-around. Manual
|
|
229
|
+
// next() (auto falsy) always moves to the neighbouring track — and
|
|
230
|
+
// skipFailed relies on that so a broken track cannot retry itself.
|
|
231
|
+
next(auto = false) {
|
|
232
|
+
if (this.isEmpty) return null;
|
|
233
|
+
|
|
234
|
+
if (auto && this.repeat === 'one' && this.current) {
|
|
235
|
+
this.emit('trackChanged', this.current);
|
|
236
|
+
return this.current;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (this.shuffle) {
|
|
240
|
+
const position = this.shuffleOrder.indexOf(this.current);
|
|
241
|
+
if (position < this.shuffleOrder.length - 1) {
|
|
242
|
+
this.currentIndex = this.tracks.indexOf(
|
|
243
|
+
this.shuffleOrder[position + 1],
|
|
244
|
+
);
|
|
245
|
+
} else if (this.repeat !== 'off') {
|
|
246
|
+
this.currentIndex = this.tracks.indexOf(this.shuffleOrder[0]);
|
|
247
|
+
} else {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
this.currentIndex++;
|
|
252
|
+
if (this.currentIndex >= this.tracks.length) {
|
|
253
|
+
if (this.repeat !== 'off') {
|
|
254
|
+
this.currentIndex = 0;
|
|
255
|
+
} else {
|
|
256
|
+
this.currentIndex = this.tracks.length - 1;
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.emit('trackChanged', this.current);
|
|
263
|
+
return this.current;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
previous() {
|
|
267
|
+
if (this.isEmpty) return null;
|
|
268
|
+
|
|
269
|
+
if (this.shuffle) {
|
|
270
|
+
const position = this.shuffleOrder.indexOf(this.current);
|
|
271
|
+
if (position > 0) {
|
|
272
|
+
this.currentIndex = this.tracks.indexOf(
|
|
273
|
+
this.shuffleOrder[position - 1],
|
|
274
|
+
);
|
|
275
|
+
} else if (this.repeat !== 'off') {
|
|
276
|
+
this.currentIndex = this.tracks.indexOf(
|
|
277
|
+
this.shuffleOrder[this.shuffleOrder.length - 1],
|
|
278
|
+
);
|
|
279
|
+
} else {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
this.currentIndex--;
|
|
284
|
+
if (this.currentIndex < 0) {
|
|
285
|
+
if (this.repeat !== 'off') {
|
|
286
|
+
this.currentIndex = this.tracks.length - 1;
|
|
287
|
+
} else {
|
|
288
|
+
this.currentIndex = 0;
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.emit('trackChanged', this.current);
|
|
295
|
+
return this.current;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
select(index) {
|
|
299
|
+
if (index >= 0 && index < this.tracks.length) {
|
|
300
|
+
this.currentIndex = index;
|
|
301
|
+
if (this.shuffle) {
|
|
302
|
+
this.buildShuffleOrder();
|
|
303
|
+
}
|
|
304
|
+
this.emit('trackChanged', this.current);
|
|
305
|
+
return this.current;
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
toggleShuffle() {
|
|
311
|
+
this.shuffle = !this.shuffle;
|
|
312
|
+
if (this.shuffle) {
|
|
313
|
+
this.buildShuffleOrder();
|
|
314
|
+
} else {
|
|
315
|
+
this.shuffleOrder = null;
|
|
316
|
+
}
|
|
317
|
+
this.emit('shuffleToggled', this.shuffle);
|
|
318
|
+
return this.shuffle;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Cycle off → all → one → off (issues/037); returns the new mode.
|
|
322
|
+
toggleRepeat() {
|
|
323
|
+
const index = REPEAT_MODES.indexOf(this.repeat);
|
|
324
|
+
this.repeat = REPEAT_MODES[(index + 1) % REPEAT_MODES.length];
|
|
325
|
+
this.emit('repeatToggled', this.repeat);
|
|
326
|
+
return this.repeat;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Set the mode directly (MPRIS LoopStatus setter, issues/037).
|
|
330
|
+
setRepeat(mode) {
|
|
331
|
+
if (!REPEAT_MODES.includes(mode) || mode === this.repeat) return;
|
|
332
|
+
this.repeat = mode;
|
|
333
|
+
this.emit('repeatToggled', this.repeat);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { SESSION_FILE } from '../constants.js';
|
|
3
|
+
import { DBG } from '../utils/debug.js';
|
|
4
|
+
|
|
5
|
+
// Read the stored position: an unconsumed pendingResume (session restored
|
|
6
|
+
// but the track was never started) beats the engine's byte counter, which
|
|
7
|
+
// is 0 until the first play. An explicit position wins over both — the
|
|
8
|
+
// trackChanged autosave passes 0 because the engine's counter still holds
|
|
9
|
+
// the previous track's offset at that moment.
|
|
10
|
+
function currentPosition(player, override = null) {
|
|
11
|
+
if (override !== null) return override;
|
|
12
|
+
if (player.pendingResume) {
|
|
13
|
+
return player.pendingResume.position;
|
|
14
|
+
}
|
|
15
|
+
return player.position;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Snapshot the listening session. Failures debug-log only — a session save
|
|
19
|
+
// must never take the player down (issues/026 posture).
|
|
20
|
+
export function saveSession(
|
|
21
|
+
{ player, playlist, position = null },
|
|
22
|
+
file = SESSION_FILE,
|
|
23
|
+
) {
|
|
24
|
+
try {
|
|
25
|
+
const session = {
|
|
26
|
+
tracks: playlist.tracks.map((track) => ({
|
|
27
|
+
path: track.path,
|
|
28
|
+
name: track.name,
|
|
29
|
+
})),
|
|
30
|
+
currentIndex: playlist.currentIndex,
|
|
31
|
+
position: currentPosition(player, position),
|
|
32
|
+
shuffle: playlist.shuffle,
|
|
33
|
+
repeat: playlist.repeat,
|
|
34
|
+
};
|
|
35
|
+
writeFileSync(file, `${JSON.stringify(session, null, 2)}\n`);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
DBG(`session save failed: ${error?.message ?? error}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Load the last session into playlist/player without starting playback.
|
|
42
|
+
// Returns true on a usable session. Missing, corrupt, or wholly-dead
|
|
43
|
+
// sessions fall back to today's defaults; files that no longer exist are
|
|
44
|
+
// dropped here with a debug count and an optional onDropped(count) callback
|
|
45
|
+
// (issues/027, :063).
|
|
46
|
+
export function restoreSession(
|
|
47
|
+
{ player, playlist, onDropped },
|
|
48
|
+
file = SESSION_FILE,
|
|
49
|
+
) {
|
|
50
|
+
try {
|
|
51
|
+
if (!existsSync(file)) return false;
|
|
52
|
+
|
|
53
|
+
const data = JSON.parse(readFileSync(file, 'utf8'));
|
|
54
|
+
if (!Array.isArray(data.tracks) || data.tracks.length === 0) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const alive = data.tracks.filter(
|
|
59
|
+
(track) => track.path && existsSync(track.path),
|
|
60
|
+
);
|
|
61
|
+
if (alive.length === 0) {
|
|
62
|
+
DBG('session restore: no track files remain, skipping');
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const dropped = data.tracks.length - alive.length;
|
|
66
|
+
|
|
67
|
+
// Fold the stored index down onto the surviving list (out-of-range
|
|
68
|
+
// or dead current track → -1, selecting none).
|
|
69
|
+
const currentIndex = Number.isInteger(data.currentIndex)
|
|
70
|
+
? alive.findIndex(
|
|
71
|
+
(track) => track.path === data.tracks[data.currentIndex]?.path,
|
|
72
|
+
)
|
|
73
|
+
: -1;
|
|
74
|
+
|
|
75
|
+
playlist.restoreSession({
|
|
76
|
+
tracks: alive,
|
|
77
|
+
currentIndex,
|
|
78
|
+
shuffle: Boolean(data.shuffle),
|
|
79
|
+
repeat: data.repeat,
|
|
80
|
+
});
|
|
81
|
+
if (dropped > 0) {
|
|
82
|
+
DBG(`session restore: dropped ${dropped} missing file(s)`);
|
|
83
|
+
onDropped?.(dropped);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const track = playlist.current;
|
|
87
|
+
const position = Number(data.position);
|
|
88
|
+
if (track && Number.isFinite(position) && position > 0) {
|
|
89
|
+
player.pendingResume = { path: track.path, position };
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
DBG(`session restore failed: ${error?.message ?? error}`);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const KEYS = {
|
|
5
|
+
PLAY_PAUSE: ' ',
|
|
6
|
+
NEXT: 'n',
|
|
7
|
+
PREVIOUS: 'p',
|
|
8
|
+
STOP: 's',
|
|
9
|
+
MUTE: 'm',
|
|
10
|
+
QUIT: 'q',
|
|
11
|
+
VOLUME_UP: 'ArrowUp',
|
|
12
|
+
VOLUME_DOWN: 'ArrowDown',
|
|
13
|
+
PAGE_UP: 'PageUp',
|
|
14
|
+
PAGE_DOWN: 'PageDown',
|
|
15
|
+
HOME: 'Home',
|
|
16
|
+
END: 'End',
|
|
17
|
+
NAVIGATE_LEFT: 'ArrowLeft',
|
|
18
|
+
NAVIGATE_RIGHT: 'ArrowRight',
|
|
19
|
+
SELECT: 'Enter',
|
|
20
|
+
DELETE: 'Delete',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const SCREENS = {
|
|
24
|
+
MAIN: 'main',
|
|
25
|
+
BROWSER: 'browser',
|
|
26
|
+
PLAYLIST: 'playlist',
|
|
27
|
+
LIBRARY: 'library',
|
|
28
|
+
SETTINGS: 'settings',
|
|
29
|
+
DEBUG: 'debug',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Everything the ffmpeg engine can decode and we accept from the
|
|
33
|
+
// browser/playlist. Membership drives the `isAudio` flag everywhere.
|
|
34
|
+
export const AUDIO_EXTENSIONS = new Set([
|
|
35
|
+
'mp3',
|
|
36
|
+
'flac',
|
|
37
|
+
'wav',
|
|
38
|
+
'ogg',
|
|
39
|
+
'oga',
|
|
40
|
+
'opus',
|
|
41
|
+
'm4a',
|
|
42
|
+
'm4b',
|
|
43
|
+
'aac',
|
|
44
|
+
'wma',
|
|
45
|
+
'aiff',
|
|
46
|
+
'aif',
|
|
47
|
+
'caf',
|
|
48
|
+
'ape',
|
|
49
|
+
'wv',
|
|
50
|
+
'tta',
|
|
51
|
+
'dsf',
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
export function extensionOf(name) {
|
|
55
|
+
return path.extname(name).slice(1).toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isAudioFile(name) {
|
|
59
|
+
return AUDIO_EXTENSIONS.has(extensionOf(name));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Playlist *container* formats (issues/028) — deliberately separate from
|
|
63
|
+
// AUDIO_EXTENSIONS, which gates decodeable audio. These are parse targets
|
|
64
|
+
// for load/save, never playable files.
|
|
65
|
+
export const PLAYLIST_EXTENSIONS = new Set(['m3u', 'm3u8', 'pls', 'json']);
|
|
66
|
+
|
|
67
|
+
export function isPlaylistFile(name) {
|
|
68
|
+
return PLAYLIST_EXTENSIONS.has(extensionOf(name));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Save formats offered in the UI (issues/028); JSON stays load-only.
|
|
72
|
+
export const PLAYLIST_FORMAT_OPTIONS = ['m3u', 'pls'];
|
|
73
|
+
|
|
74
|
+
// Settings-panel cycle options.
|
|
75
|
+
export const FPS_OPTIONS = [5, 7, 10, 15, 30, 60];
|
|
76
|
+
export const SMOOTHING_OPTIONS = [1, 0.9, 0.7, 0.5, 0.3, 0.1];
|
|
77
|
+
// Display names for SMOOTHING_OPTIONS (higher value = less smoothing).
|
|
78
|
+
export const SMOOTHING_LABELS = {
|
|
79
|
+
1: 'Off',
|
|
80
|
+
0.9: 'Very low',
|
|
81
|
+
0.7: 'Low',
|
|
82
|
+
0.5: 'Medium',
|
|
83
|
+
0.3: 'High',
|
|
84
|
+
0.1: 'Very high',
|
|
85
|
+
};
|
|
86
|
+
// Volume step is percent of full volume; seek step is seconds.
|
|
87
|
+
export const VOLUME_STEP_OPTIONS = [1, 2, 5, 10];
|
|
88
|
+
export const SEEK_STEP_OPTIONS = [5, 10, 15, 30];
|
|
89
|
+
// Audio backends (issues/020/021); takes effect on the next play.
|
|
90
|
+
export const AUDIO_ENGINES = ['ffmpeg', 'webaudio'];
|
|
91
|
+
|
|
92
|
+
// Repeat modes (issues/037): Playlist.repeat holds one of these strings;
|
|
93
|
+
// toggleRepeat() cycles through the array in this order.
|
|
94
|
+
export const REPEAT_MODES = ['off', 'all', 'one'];
|
|
95
|
+
export const REPEAT_LABELS = { off: 'OFF', all: 'ALL', one: 'ONE' };
|
|
96
|
+
|
|
97
|
+
export const DEFAULT_CONFIG = {
|
|
98
|
+
mediaDirectory: process.env.HOME || process.env.USERPROFILE || '.',
|
|
99
|
+
play_when_first_track_queued: true,
|
|
100
|
+
theme: 'default',
|
|
101
|
+
volume: 0.5,
|
|
102
|
+
volumeStep: 5,
|
|
103
|
+
seekStep: 5,
|
|
104
|
+
// Audio backend ('ffmpeg' | 'webaudio', issues/020/021).
|
|
105
|
+
audioEngine: 'ffmpeg',
|
|
106
|
+
// Output device (issues/042): speaker backend string (ALSA
|
|
107
|
+
// `hw:CARD=x,DEV=n` / `pulse:<sink>`), null = system default.
|
|
108
|
+
// MIXSHELL_AUDIO_DEVICE overrides (Player resolves both).
|
|
109
|
+
audioDevice: null,
|
|
110
|
+
visualizerMode: 'albumart', // vu, bars, waveform, circles, cube, albumart
|
|
111
|
+
// Album art style: 'blocks' drawImage's the bitmap onto the art
|
|
112
|
+
// canvas's plain 2d context — the engine ships that bitmap as a kitty
|
|
113
|
+
// graphics image on kitty/Ghostty and rasterizes it to half blocks
|
|
114
|
+
// elsewhere (issues/035; there is no renderer setting — TermDOM's
|
|
115
|
+
// auto fallback is the capability layer). The charset styles are
|
|
116
|
+
// luminance glyphs drawn per cell on the shared cellgrid canvas.
|
|
117
|
+
albumArtStyle: 'blocks',
|
|
118
|
+
|
|
119
|
+
// Phase 2.1: Performance settings for visualizer
|
|
120
|
+
visualizerQuality: 'high', // 'low', 'medium', 'high' - controls FFT size and bar count
|
|
121
|
+
visualizerFPS: 60, // Frame rate: 5, 7, 10, 15, 30, or 60 FPS. 30 suits the ~43Hz spectrum refresh (bars, waveform); 60 matches desktop monitors and feeds VU off the ~86Hz analysis stream
|
|
122
|
+
visualizerSmoothing: 1, // Bar smoothing (SMOOTHING_LABELS): 1 = Off (instant) to 0.1 = Very high (slow, very smooth)
|
|
123
|
+
showFPS: false, // FPS counter overlay on the visualizer canvas
|
|
124
|
+
|
|
125
|
+
// Media library (issues/023): scanned roots and whether startup triggers
|
|
126
|
+
// a scan of them.
|
|
127
|
+
libraryDirs: [],
|
|
128
|
+
libraryScanOnStart: false,
|
|
129
|
+
|
|
130
|
+
// Playlist export container (issues/028): 'm3u' | 'pls'.
|
|
131
|
+
playlistSaveFormat: 'm3u',
|
|
132
|
+
|
|
133
|
+
// Media keys + Now Playing on macOS (issues/048): opt-in while the
|
|
134
|
+
// bundled helper awaits validation on real hardware. Linux is served
|
|
135
|
+
// by MPRIS regardless; Windows has no helper yet.
|
|
136
|
+
mediaKeys: false,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Luminance ramps, dark to bright, for the charset art modes. Block
|
|
140
|
+
// characters (░▒▓█) measure one cell on most Latin-configured terminals; if a
|
|
141
|
+
// font reports them ambiguous-wide the art's column alignment will skew.
|
|
142
|
+
// 'complex' is the classic 70-level density ramp plus 100% block.
|
|
143
|
+
export const CHARSETS = {
|
|
144
|
+
binary: ' 10',
|
|
145
|
+
basic: ' .:-=+*#%@',
|
|
146
|
+
braille: ' ⠁⠒⠩⠷⡿',
|
|
147
|
+
braille_plus: ' ⠁⠒⠩⠷⡿░▒▓█',
|
|
148
|
+
medium: ` .·,-':;I=+"^/\\|_░*xoO0XH8#▒$@▓█`,
|
|
149
|
+
complex:
|
|
150
|
+
' .\'^":,;Il!i><~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$█',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// All user state lives in one directory (issues/030). MIXSHELL_DIR
|
|
154
|
+
// overrides it for tests, CI and portable setups.
|
|
155
|
+
export const STATE_DIR =
|
|
156
|
+
process.env.MIXSHELL_DIR ?? path.join(os.homedir(), 'mixshell');
|
|
157
|
+
|
|
158
|
+
export const CONFIG_FILE = path.join(STATE_DIR, 'config.json');
|
|
159
|
+
|
|
160
|
+
// Session persistence (issues/027): queue + playback state across runs.
|
|
161
|
+
export const SESSION_FILE = path.join(STATE_DIR, 'session.json');
|
|
162
|
+
|
|
163
|
+
// SQLite index for the media library (issues/023).
|
|
164
|
+
export const LIBRARY_DB_FILE = path.join(STATE_DIR, 'library.db');
|