@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.
- package/LICENSE +21 -0
- package/README.md +320 -2
- package/assets/mixshell-screenshot.png +0 -0
- package/package.json +74 -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 +436 -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 +610 -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 +1654 -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
package/src/ui/dom.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Element helper bound to a document (each UI module gets its own).
|
|
2
|
+
export function makeEl(document) {
|
|
3
|
+
return (tag, cls, text) => {
|
|
4
|
+
const node = document.createElement(tag);
|
|
5
|
+
if (cls) node.className = cls;
|
|
6
|
+
if (text != null) node.textContent = text;
|
|
7
|
+
return node;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { resolveDirectoryInput } from '../utils/pathInput.js';
|
|
2
|
+
|
|
3
|
+
// One prompt, three hosts (onboarding picker, browser tab, Settings row).
|
|
4
|
+
// Owns its own text cursor; the host supplies the base directory for
|
|
5
|
+
// relative paths and the callback for a confirmed directory. key() returns
|
|
6
|
+
// true when the prompt consumed the event (invariant 5: above digits and
|
|
7
|
+
// global shortcuts). Editing keys mirror the playlist save prompt.
|
|
8
|
+
export function createGoToPrompt() {
|
|
9
|
+
let prompt = null;
|
|
10
|
+
|
|
11
|
+
function start({ base, onConfirm }) {
|
|
12
|
+
prompt = { text: '', pos: 0, base, onConfirm, error: null };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function key(e) {
|
|
16
|
+
if (!prompt) return false;
|
|
17
|
+
const keyName = e.key;
|
|
18
|
+
if (keyName === 'Enter') {
|
|
19
|
+
if (!prompt.text.trim()) {
|
|
20
|
+
prompt = null;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const { path, error } = resolveDirectoryInput(prompt.text, {
|
|
24
|
+
base: prompt.base,
|
|
25
|
+
});
|
|
26
|
+
if (error) {
|
|
27
|
+
prompt.error = error;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const onConfirm = prompt.onConfirm;
|
|
31
|
+
// A host that cannot open the directory returns the reason; keep
|
|
32
|
+
// the prompt open so it can be corrected in place (issues/054).
|
|
33
|
+
const confirmError = onConfirm(path);
|
|
34
|
+
if (confirmError) {
|
|
35
|
+
prompt.error = confirmError;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
prompt = null;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (keyName === 'Escape') {
|
|
42
|
+
prompt = null;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (keyName === 'Backspace') {
|
|
46
|
+
if (prompt.pos > 0) {
|
|
47
|
+
prompt.text =
|
|
48
|
+
prompt.text.slice(0, prompt.pos - 1) + prompt.text.slice(prompt.pos);
|
|
49
|
+
prompt.pos--;
|
|
50
|
+
prompt.error = null;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (keyName === 'Delete') {
|
|
55
|
+
if (prompt.pos < prompt.text.length) {
|
|
56
|
+
prompt.text =
|
|
57
|
+
prompt.text.slice(0, prompt.pos) + prompt.text.slice(prompt.pos + 1);
|
|
58
|
+
prompt.error = null;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (keyName === 'ArrowLeft') {
|
|
63
|
+
prompt.pos = Math.max(0, prompt.pos - 1);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (keyName === 'ArrowRight') {
|
|
67
|
+
prompt.pos = Math.min(prompt.text.length, prompt.pos + 1);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (keyName === 'Home') {
|
|
71
|
+
prompt.pos = 0;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (keyName === 'End') {
|
|
75
|
+
prompt.pos = prompt.text.length;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// Don't scroll the panel or open the browser filter mid-prompt.
|
|
79
|
+
if (keyName === 'PageUp' || keyName === 'PageDown') return true;
|
|
80
|
+
if (e.ctrlKey && !e.metaKey && !e.altKey && keyName.toLowerCase() === 'f')
|
|
81
|
+
return true;
|
|
82
|
+
if (keyName.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
83
|
+
prompt.text =
|
|
84
|
+
prompt.text.slice(0, prompt.pos) +
|
|
85
|
+
keyName +
|
|
86
|
+
prompt.text.slice(prompt.pos);
|
|
87
|
+
prompt.pos++;
|
|
88
|
+
prompt.error = null;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Appended to whatever the host already shows, so the cursor and the
|
|
95
|
+
// rejection message land on the same line (footer height never changes).
|
|
96
|
+
function suffix() {
|
|
97
|
+
if (!prompt) return '';
|
|
98
|
+
const text = `${prompt.text.slice(0, prompt.pos)}▌${prompt.text.slice(prompt.pos)}`;
|
|
99
|
+
return ` · Go to (from ${prompt.base}): "${text}"${
|
|
100
|
+
prompt.error ? ` — ${prompt.error}` : ''
|
|
101
|
+
}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { start, key, suffix, isOpen: () => !!prompt };
|
|
105
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<header id="header">
|
|
2
|
+
<div id="brand">MixShell</div>
|
|
3
|
+
<div class="tabbar" id="tabs">
|
|
4
|
+
<button type="button" class="tab active" data-tab="main">Main</button>
|
|
5
|
+
<button type="button" class="tab" data-tab="playlist">Playlist</button>
|
|
6
|
+
<button type="button" class="tab" data-tab="library">Library</button>
|
|
7
|
+
<button type="button" class="tab" data-tab="browser">Browser</button>
|
|
8
|
+
<button type="button" class="tab" data-tab="settings">Settings</button>
|
|
9
|
+
<button type="button" class="tab" data-tab="debug">Debug</button>
|
|
10
|
+
</div>
|
|
11
|
+
<div id="headerInfo" class="muted"></div>
|
|
12
|
+
</header>
|
|
13
|
+
|
|
14
|
+
<main id="content">
|
|
15
|
+
<section class="panel panel-main active" id="panel-main">
|
|
16
|
+
<div class="art hidden" id="artBox">
|
|
17
|
+
<canvas id="artCanvas"></canvas>
|
|
18
|
+
<canvas id="vizCanvas" class="hidden"></canvas>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="meta hidden" id="trackMeta"></div>
|
|
21
|
+
<canvas id="splashCanvas" class="splash hidden"></canvas>
|
|
22
|
+
<div class="placeholder" id="noTrack">No song playing.</div>
|
|
23
|
+
</section>
|
|
24
|
+
|
|
25
|
+
<section class="panel" id="panel-browser">
|
|
26
|
+
<div class="panel-title" id="browserPath"></div>
|
|
27
|
+
<div class="panel-scroll">
|
|
28
|
+
<div class="list" id="browserList"></div>
|
|
29
|
+
</div>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
<section class="panel" id="panel-playlist">
|
|
33
|
+
<div class="panel-title" id="playlistInfo"></div>
|
|
34
|
+
<div class="panel-scroll">
|
|
35
|
+
<div class="list" id="playlistList"></div>
|
|
36
|
+
<div class="placeholder hidden" id="playlistEmpty">Playlist is empty — visit the Library or Browser to load music.</div>
|
|
37
|
+
</div>
|
|
38
|
+
</section>
|
|
39
|
+
|
|
40
|
+
<section class="panel panel-subtabs" id="panel-library">
|
|
41
|
+
<div class="subtabs" id="librarySubtabs"></div>
|
|
42
|
+
<div class="panel-title" id="libraryPath"></div>
|
|
43
|
+
<div class="panel-scroll">
|
|
44
|
+
<div class="list" id="libraryList"></div>
|
|
45
|
+
<div class="placeholder hidden" id="libraryEmpty"></div>
|
|
46
|
+
</div>
|
|
47
|
+
</section>
|
|
48
|
+
|
|
49
|
+
<section class="panel panel-subtabs" id="panel-settings">
|
|
50
|
+
<div class="subtabs" id="settingsSubtabs"></div>
|
|
51
|
+
<div class="panel-title" id="settingsPath"></div>
|
|
52
|
+
<div class="panel-scroll">
|
|
53
|
+
<div class="list" id="settingsList"></div>
|
|
54
|
+
</div>
|
|
55
|
+
</section>
|
|
56
|
+
|
|
57
|
+
<section class="panel" id="panel-debug">
|
|
58
|
+
<div class="panel-title">Debug</div>
|
|
59
|
+
<div class="panel-scroll">
|
|
60
|
+
<div class="meta" id="systemInfo"></div>
|
|
61
|
+
<div class="list" id="debugList"></div>
|
|
62
|
+
</div>
|
|
63
|
+
</section>
|
|
64
|
+
</main>
|
|
65
|
+
|
|
66
|
+
<div class="toast" id="toast">
|
|
67
|
+
<div class="toast-msg" id="toastMsg"></div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<footer id="footer">
|
|
71
|
+
<div id="shortcutsLocal"></div>
|
|
72
|
+
<div id="shortcutsGlobal"></div>
|
|
73
|
+
<div id="seekRow" class="hidden">
|
|
74
|
+
<progress id="seekBar"></progress>
|
|
75
|
+
<span id="seekClock"></span>
|
|
76
|
+
</div>
|
|
77
|
+
<div id="status"></div>
|
|
78
|
+
</footer>
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GROUP_SORTS,
|
|
3
|
+
LIB_SMART,
|
|
4
|
+
LIBRARY_VIEWS,
|
|
5
|
+
PLAY_WINDOWS,
|
|
6
|
+
TRACK_SORTS,
|
|
7
|
+
} from '../components/library.js';
|
|
8
|
+
import { createSubtabs } from './subtabs.js';
|
|
9
|
+
|
|
10
|
+
// Library panel: views, drill navigation and the search input; listing
|
|
11
|
+
// data comes from the Library component's SQLite backend (issues/023).
|
|
12
|
+
export function createLibraryPanel({
|
|
13
|
+
library,
|
|
14
|
+
player,
|
|
15
|
+
playlist,
|
|
16
|
+
els,
|
|
17
|
+
el,
|
|
18
|
+
getCursor,
|
|
19
|
+
setCursor,
|
|
20
|
+
selectedRow: getSelectedRow,
|
|
21
|
+
showMessage,
|
|
22
|
+
refreshShortcuts,
|
|
23
|
+
renderList,
|
|
24
|
+
pathSuffix = () => '',
|
|
25
|
+
filterRows = (rows) => rows,
|
|
26
|
+
}) {
|
|
27
|
+
const lib = {
|
|
28
|
+
// Drilled levels: { baseLabel, query, rows, cursor } — the track list
|
|
29
|
+
// snapshots at descend time (`query` remembers the view/group so a
|
|
30
|
+
// sort cycle can re-query, issues/033); cursor is the position to
|
|
31
|
+
// restore when this level becomes visible again. rootCursor plays
|
|
32
|
+
// that role for the view root (whose live cursor is the controller's
|
|
33
|
+
// per-tab state).
|
|
34
|
+
stack: [],
|
|
35
|
+
rootCursor: 0,
|
|
36
|
+
};
|
|
37
|
+
let libQuery = '';
|
|
38
|
+
// Most Played time window (issues/032). Session-only — no config key.
|
|
39
|
+
let libWindow = 'all';
|
|
40
|
+
// Sort state (issues/033): one spec per view-kind — group roots vs every
|
|
41
|
+
// track list. Session-only; survives view switches, drills and rescans
|
|
42
|
+
// (sort is a lens, not navigation). Defaults reproduce the historical
|
|
43
|
+
// hard-coded orders.
|
|
44
|
+
let trackSort = { key: 'album', dir: 'asc' };
|
|
45
|
+
let groupSort = { key: 'name', dir: 'asc' };
|
|
46
|
+
|
|
47
|
+
// The active view lives entirely in the subtabs factory; this re-reads it.
|
|
48
|
+
function libView() {
|
|
49
|
+
return LIBRARY_VIEWS[subtabs.active()];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function trackRows(tracks) {
|
|
53
|
+
return tracks.map((track) => ({
|
|
54
|
+
kind: 'track',
|
|
55
|
+
path: track.path,
|
|
56
|
+
// Star glyph replaces ♪ on starred tracks (issues/045).
|
|
57
|
+
icon: track.favourite ? '★' : '♪',
|
|
58
|
+
audio: true,
|
|
59
|
+
text: `${track.artist} - ${track.title}`,
|
|
60
|
+
current: playlist.current?.path === track.path,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Rows + breadcrumb label for the level currently on screen. Root level
|
|
65
|
+
// derives from the view (groups for the grouping views, tracks for the
|
|
66
|
+
// smart views and search); drilled levels replay their snapshot.
|
|
67
|
+
function libraryLevel() {
|
|
68
|
+
const view = libView();
|
|
69
|
+
if (lib.stack.length > 0) {
|
|
70
|
+
const top = lib.stack[lib.stack.length - 1];
|
|
71
|
+
return { label: top.baseLabel, rows: top.rows };
|
|
72
|
+
}
|
|
73
|
+
if (LIB_SMART[view.key]) {
|
|
74
|
+
const isMostPlayed = view.key === 'mostplayed';
|
|
75
|
+
return {
|
|
76
|
+
label: isMostPlayed
|
|
77
|
+
? `${view.label} · ${
|
|
78
|
+
PLAY_WINDOWS.find((w) => w.key === libWindow)?.label
|
|
79
|
+
}`
|
|
80
|
+
: view.label,
|
|
81
|
+
rows: trackRows(
|
|
82
|
+
library[LIB_SMART[view.key]](
|
|
83
|
+
isMostPlayed ? libWindow : undefined,
|
|
84
|
+
trackSort,
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
switch (view.key) {
|
|
90
|
+
case 'artists':
|
|
91
|
+
case 'albums':
|
|
92
|
+
case 'genres':
|
|
93
|
+
case 'years':
|
|
94
|
+
return {
|
|
95
|
+
label: view.label,
|
|
96
|
+
rows: library.groupBy(view.key, groupSort).map((group) => ({
|
|
97
|
+
kind: 'group',
|
|
98
|
+
value: group.value,
|
|
99
|
+
icon: '▸',
|
|
100
|
+
text: `${group.value} (${group.count})`,
|
|
101
|
+
})),
|
|
102
|
+
};
|
|
103
|
+
case 'search':
|
|
104
|
+
return {
|
|
105
|
+
label: libQuery ? `Search: "${libQuery}"` : 'Search (type to filter)',
|
|
106
|
+
rows: libQuery ? trackRows(library.search(libQuery, trackSort)) : [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function descend(row) {
|
|
112
|
+
const view = libView();
|
|
113
|
+
const cursor = getCursor();
|
|
114
|
+
// Remember where we sat on the level we're leaving so ascend()
|
|
115
|
+
// can put the selection back on the group we drilled out of.
|
|
116
|
+
if (lib.stack.length > 0) {
|
|
117
|
+
lib.stack[lib.stack.length - 1].cursor = cursor;
|
|
118
|
+
} else {
|
|
119
|
+
lib.rootCursor = cursor;
|
|
120
|
+
}
|
|
121
|
+
lib.stack.push({
|
|
122
|
+
baseLabel: `${view.label} › ${row.value}`,
|
|
123
|
+
query: { viewKey: view.key, value: row.value },
|
|
124
|
+
rows: trackRows(library.tracksWhere(view.key, row.value, trackSort)),
|
|
125
|
+
cursor: 0,
|
|
126
|
+
});
|
|
127
|
+
setCursor(0);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function ascend() {
|
|
131
|
+
if (lib.stack.length === 0) return;
|
|
132
|
+
lib.stack.pop();
|
|
133
|
+
const parent = lib.stack[lib.stack.length - 1];
|
|
134
|
+
setCursor(parent ? parent.cursor : lib.rootCursor);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Cycle the Most Played time window (issues/032, `t` in the Library
|
|
138
|
+
// tab). Only meaningful on that view; switching drops the drill stack
|
|
139
|
+
// and parks the cursor, like a subtab change.
|
|
140
|
+
function cycleWindow() {
|
|
141
|
+
if (libView().key !== 'mostplayed') return;
|
|
142
|
+
const next =
|
|
143
|
+
PLAY_WINDOWS[
|
|
144
|
+
(PLAY_WINDOWS.findIndex((w) => w.key === libWindow) + 1) %
|
|
145
|
+
PLAY_WINDOWS.length
|
|
146
|
+
];
|
|
147
|
+
libWindow = next.key;
|
|
148
|
+
lib.stack = [];
|
|
149
|
+
lib.rootCursor = 0;
|
|
150
|
+
setCursor(0);
|
|
151
|
+
render();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// True while the screen shows a grouping view's root (the only place
|
|
155
|
+
// GROUP_SORTS apply); every other level — smart views, search, drilled
|
|
156
|
+
// group members — is a track list.
|
|
157
|
+
function currentLevelIsGroup() {
|
|
158
|
+
if (lib.stack.length > 0) return false;
|
|
159
|
+
return ['artists', 'albums', 'genres', 'years'].includes(libView().key);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Sort cycling (issues/033, S/D in the Library tab): S cycles the key,
|
|
163
|
+
// landing on its natural direction, D flips it. Group roots cycle
|
|
164
|
+
// Name·Count; every track list shares the track sort. Sort is a lens,
|
|
165
|
+
// not navigation — the drill stack survives and the visible level
|
|
166
|
+
// re-queries; the cursor parks at 0 because the old selection's
|
|
167
|
+
// position is meaningless under a new order.
|
|
168
|
+
function cycleSort() {
|
|
169
|
+
const group = currentLevelIsGroup();
|
|
170
|
+
const sorts = group ? GROUP_SORTS : TRACK_SORTS;
|
|
171
|
+
const keys = Object.keys(sorts);
|
|
172
|
+
const state = group ? groupSort : trackSort;
|
|
173
|
+
const key = keys[(keys.indexOf(state.key) + 1) % keys.length];
|
|
174
|
+
applySort({ key, dir: sorts[key].natural });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function flipSortDir() {
|
|
178
|
+
const group = currentLevelIsGroup();
|
|
179
|
+
const state = group ? groupSort : trackSort;
|
|
180
|
+
applySort({ ...state, dir: state.dir === 'desc' ? 'asc' : 'desc' });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function applySort(next) {
|
|
184
|
+
if (currentLevelIsGroup()) {
|
|
185
|
+
groupSort = next;
|
|
186
|
+
} else {
|
|
187
|
+
trackSort = next;
|
|
188
|
+
resliceTopLevel();
|
|
189
|
+
}
|
|
190
|
+
setCursor(0);
|
|
191
|
+
render();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Re-query the drilled level's snapshot under the new track sort. Root
|
|
195
|
+
// levels re-query inside libraryLevel() on the next render.
|
|
196
|
+
function resliceTopLevel() {
|
|
197
|
+
const top = lib.stack[lib.stack.length - 1];
|
|
198
|
+
if (!top) return;
|
|
199
|
+
top.rows = trackRows(
|
|
200
|
+
library.tracksWhere(top.query.viewKey, top.query.value, trackSort),
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Breadcrumb suffix (issues/033): the active sort must always be
|
|
205
|
+
// visible — `Library › Pink Floyd · ↓ Year`. Skipped on the search
|
|
206
|
+
// view's empty pre-query state.
|
|
207
|
+
function sortSuffix() {
|
|
208
|
+
if (isSearchRoot() && !libQuery) return '';
|
|
209
|
+
const group = currentLevelIsGroup();
|
|
210
|
+
const sort = group ? groupSort : trackSort;
|
|
211
|
+
const spec = (group ? GROUP_SORTS : TRACK_SORTS)[sort.key];
|
|
212
|
+
return ` · ${sort.dir === 'desc' ? '↓' : '↑'} ${spec?.label ?? sort.key}`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Queue operations (issues/025): Enter replaces the queue with every
|
|
216
|
+
// track in the current view and plays the selection; Alt+Enter queues at
|
|
217
|
+
// the bottom; Alt+J queues after the playing track; Shift+Enter /
|
|
218
|
+
// Ctrl+Enter / Ctrl+J mirror them (issues/036). replaceAll clears
|
|
219
|
+
// the queue, so the selection's index is its position among the view's
|
|
220
|
+
// track rows.
|
|
221
|
+
function trackPaths(rows) {
|
|
222
|
+
return rows.filter((row) => row.path).map((row) => row.path);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function selectedRow() {
|
|
226
|
+
return getSelectedRow() ?? libraryLevel().rows[getCursor()];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Selected queueable row, or null after toasting "Already queued"
|
|
230
|
+
// (add()/insertNext() dedup silently otherwise).
|
|
231
|
+
function selectedTrack() {
|
|
232
|
+
const row = selectedRow();
|
|
233
|
+
if (!row?.path) return null;
|
|
234
|
+
if (playlist.tracks.some((track) => track.path === row.path)) {
|
|
235
|
+
showMessage('Already queued');
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
return row;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function playViewSelection() {
|
|
242
|
+
const row = selectedRow();
|
|
243
|
+
if (!row?.path) return;
|
|
244
|
+
const paths = trackPaths(libraryLevel().rows);
|
|
245
|
+
playlist.replaceAll(paths);
|
|
246
|
+
playlist.select(paths.indexOf(row.path));
|
|
247
|
+
// When playing, the playlist trackChanged listener already restarts
|
|
248
|
+
// the player; playing again here would emit a second 'play' event and
|
|
249
|
+
// count the track twice in the library log.
|
|
250
|
+
if (!player.isPlaying) player.play();
|
|
251
|
+
showMessage(`Now playing: ${row.text}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function queueSelection() {
|
|
255
|
+
const row = selectedTrack();
|
|
256
|
+
if (!row) return;
|
|
257
|
+
playlist.add(row.path);
|
|
258
|
+
showMessage(`Queued: ${row.text}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function queueNext() {
|
|
262
|
+
const row = selectedTrack();
|
|
263
|
+
if (!row) return;
|
|
264
|
+
const playing = playlist.currentIndex !== -1;
|
|
265
|
+
playlist.insertNext(row.path);
|
|
266
|
+
showMessage(playing ? `Playing next: ${row.text}` : `Queued: ${row.text}`);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Star the selected track (issues/045, `f` in the Library tab).
|
|
270
|
+
function toggleFavourite() {
|
|
271
|
+
const row = selectedRow();
|
|
272
|
+
if (!row?.path) return;
|
|
273
|
+
const starred = library.toggleFavourite(row.path);
|
|
274
|
+
showMessage(starred ? `★ ${row.text}` : `Unstarred ${row.text}`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function openEntry() {
|
|
278
|
+
const row = selectedRow();
|
|
279
|
+
if (!row) return;
|
|
280
|
+
if (row.kind === 'group') {
|
|
281
|
+
descend(row);
|
|
282
|
+
} else if (row.path) {
|
|
283
|
+
playViewSelection();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Right arrow mirrors Enter only on group rows; on a track list Enter
|
|
288
|
+
// already plays, so → stays inert.
|
|
289
|
+
function openGroup() {
|
|
290
|
+
const row = selectedRow();
|
|
291
|
+
if (row?.kind === 'group') descend(row);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function addAll() {
|
|
295
|
+
// Group roots show group rows, not tracks; empty search is the
|
|
296
|
+
// existing all-tracks query (all tag columns are NOT NULL).
|
|
297
|
+
// ponytail: add Library.all() if search semantics ever narrow.
|
|
298
|
+
const paths = trackPaths(
|
|
299
|
+
currentLevelIsGroup()
|
|
300
|
+
? library.search('', trackSort)
|
|
301
|
+
: libraryLevel().rows,
|
|
302
|
+
);
|
|
303
|
+
if (paths.length === 0) {
|
|
304
|
+
showMessage('Nothing to add');
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
playlist.addMultiple(paths);
|
|
308
|
+
showMessage(`Added ${paths.length} tracks to playlist`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function render() {
|
|
312
|
+
const level = libraryLevel();
|
|
313
|
+
const viewKey = libView().key;
|
|
314
|
+
subtabs.render();
|
|
315
|
+
els.libraryPath.textContent = `Library › ${level.label}${sortSuffix()}${pathSuffix()}`;
|
|
316
|
+
els.libraryEmpty.textContent =
|
|
317
|
+
viewKey === 'search'
|
|
318
|
+
? 'Type to search the library.'
|
|
319
|
+
: viewKey === 'favourites'
|
|
320
|
+
? 'No favourites yet. Press f on a track to star it.'
|
|
321
|
+
: !library.isConfigured()
|
|
322
|
+
? 'No library dirs. Press L in the browser to add one.'
|
|
323
|
+
: library.scanning
|
|
324
|
+
? 'Scanning library…'
|
|
325
|
+
: 'Library is empty.';
|
|
326
|
+
els.libraryEmpty.classList.toggle('hidden', level.rows.length > 0);
|
|
327
|
+
renderList(els.libraryList, filterRows(level.rows));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Library sub-tab row (shared factory, issues/024): click or the [ / ]
|
|
331
|
+
// keys switch views; render() keeps .active in step. Every switch —
|
|
332
|
+
// click or key — drops the drill stack and parks the cursor.
|
|
333
|
+
const subtabs = createSubtabs({
|
|
334
|
+
views: LIBRARY_VIEWS,
|
|
335
|
+
el,
|
|
336
|
+
mount: els.librarySubtabs,
|
|
337
|
+
onChange: () => {
|
|
338
|
+
lib.stack = [];
|
|
339
|
+
lib.rootCursor = 0;
|
|
340
|
+
setCursor(0);
|
|
341
|
+
render();
|
|
342
|
+
// Footer carries `t` only on Most Played (issues/032).
|
|
343
|
+
refreshShortcuts();
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// Search input mode: printable keys build the query instead of firing
|
|
348
|
+
// shortcuts ([ and ] still switch views; Backspace edits, Esc clears or
|
|
349
|
+
// exits when the query is empty).
|
|
350
|
+
// Returns whether the key was consumed; everything else — Enter, arrows,
|
|
351
|
+
// page keys — falls through to the controller's normal handling.
|
|
352
|
+
function searchKey(e) {
|
|
353
|
+
const key = e.key;
|
|
354
|
+
if (key === 'Backspace') {
|
|
355
|
+
libQuery = libQuery.slice(0, -1);
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
if (key === 'Escape') {
|
|
359
|
+
if (libQuery) {
|
|
360
|
+
libQuery = '';
|
|
361
|
+
} else {
|
|
362
|
+
// ponytail: wraps to the first view; remember the previous one
|
|
363
|
+
// only if exiting Search ever needs to land back there.
|
|
364
|
+
subtabs.cycle(1);
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
if (
|
|
369
|
+
key.length === 1 &&
|
|
370
|
+
!e.ctrlKey &&
|
|
371
|
+
!e.metaKey &&
|
|
372
|
+
!e.altKey &&
|
|
373
|
+
key !== '[' &&
|
|
374
|
+
key !== ']'
|
|
375
|
+
) {
|
|
376
|
+
libQuery += key;
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function isSearchRoot() {
|
|
383
|
+
return lib.stack.length === 0 && libView().key === 'search';
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return {
|
|
387
|
+
render,
|
|
388
|
+
rows: () => libraryLevel().rows,
|
|
389
|
+
isSearchRoot,
|
|
390
|
+
isMostPlayedView: () => libView().key === 'mostplayed',
|
|
391
|
+
searchKey,
|
|
392
|
+
cycleView: (delta) => subtabs.cycle(delta),
|
|
393
|
+
cycleWindow,
|
|
394
|
+
cycleSort,
|
|
395
|
+
flipSortDir,
|
|
396
|
+
ascend,
|
|
397
|
+
openEntry,
|
|
398
|
+
openGroup,
|
|
399
|
+
playViewSelection,
|
|
400
|
+
queueSelection,
|
|
401
|
+
queueNext,
|
|
402
|
+
toggleFavourite,
|
|
403
|
+
addAll,
|
|
404
|
+
// Index changed under us (scan finished, play counted, star toggled —
|
|
405
|
+
// issues/045): track rows now carry the favourite flag, so drilled
|
|
406
|
+
// snapshots re-slice; the cursor position stays meaningful (sort and
|
|
407
|
+
// membership rarely shift on a play count), unlike reset().
|
|
408
|
+
reslice: resliceTopLevel,
|
|
409
|
+
reset: () => {
|
|
410
|
+
lib.stack = [];
|
|
411
|
+
lib.rootCursor = 0;
|
|
412
|
+
setCursor(0);
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|