@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,532 @@
1
+ /* Semantic palette — every colour in this sheet reads one of these vars.
2
+ * A theme is nothing but a set of assignments (see body.theme-terminal
3
+ * below); no per-rule colour overrides anywhere. */
4
+ :root {
5
+ --fg: white;
6
+ --bg: #332532;
7
+ --accent: #f87a52;
8
+ --muted: gray;
9
+ --playing: #9ece6a;
10
+ --sel-bg: #f87a52;
11
+ --sel-fg: black;
12
+ --border: #f87a52;
13
+ /* Chrome sizes JS sets every render (issues/066). */
14
+ --header-rows: 1px;
15
+ --footer-rows: 4px;
16
+ }
17
+
18
+ * {
19
+ box-sizing: border-box;
20
+ }
21
+
22
+ /* Layout: fixed header + fixed footer, body padding reserves their space.
23
+ * body's min-height keeps the document at least one viewport tall so the
24
+ * engine takes over the screen from row 0 (prompt pushed to scrollback) and
25
+ * the fixed bars stay pinned; shorter content would leave the frame anchored
26
+ * below the prompt and the fixed footer would paint past the screen bottom.
27
+ * Padding and both bars derive from the row counts JS sets (issues/066). */
28
+ body {
29
+ min-height: 100vh;
30
+ padding: var(--header-rows) 0 var(--footer-rows);
31
+ }
32
+
33
+ #header {
34
+ position: fixed;
35
+ top: 0;
36
+ right: 0;
37
+ left: 0;
38
+ height: var(--header-rows);
39
+ display: flex;
40
+ flex-direction: row;
41
+ justify-content: space-between;
42
+ padding: 0 1ch;
43
+ background-color: var(--bg);
44
+ color: var(--fg);
45
+ /* Chrome is not selectable text (TermDOM user-select) */
46
+ user-select: none;
47
+ }
48
+
49
+ #brand {
50
+ margin-right: 2ch;
51
+ font-weight: bold;
52
+ color: var(--accent);
53
+ }
54
+
55
+ /* The tab bar is a block so buttons break between lines on narrow screens.
56
+ * flex-start keeps its box the content's height, not the header's, so JS
57
+ * measures the row count from it. */
58
+ #tabs {
59
+ align-self: flex-start;
60
+ }
61
+
62
+ /* Info yields before the tabs wrap, then ellipsizes, then disappears. */
63
+ #headerInfo {
64
+ flex: 0 1000 auto;
65
+ overflow: hidden;
66
+ text-overflow: ellipsis;
67
+ white-space: nowrap;
68
+ margin-left: auto;
69
+ color: var(--muted);
70
+ }
71
+
72
+ .tabbar {
73
+ /*display: flex;
74
+ justify-content: between;*/
75
+ }
76
+
77
+ .tab {
78
+ margin: 0 1ch 0 0;
79
+ border: none;
80
+ padding: 0;
81
+ background-color: var(--bg);
82
+ color: var(--muted);
83
+ }
84
+
85
+ .tab.active {
86
+ color: var(--accent);
87
+ }
88
+
89
+ #content {
90
+ /*margin: 1px 0 3px;*/
91
+ padding: 0 1ch;
92
+ overflow: hidden;
93
+ border: 1px solid var(--border);
94
+ border-radius: 3px;
95
+ }
96
+
97
+ #footer {
98
+ position: fixed;
99
+ bottom: 0;
100
+ left: 0;
101
+ right: 0;
102
+ height: var(--footer-rows);
103
+ display: flex;
104
+ flex-direction: column;
105
+ /* Rows pin to the bottom: hiding the seek row (no track) leaves the
106
+ * old three-row footer instead of a blank top row (issues/038). */
107
+ justify-content: flex-end;
108
+ padding: 0 1ch;
109
+ background-color: var(--bg);
110
+ color: var(--muted);
111
+ /* Chrome is not selectable text (TermDOM user-select) */
112
+ user-select: none;
113
+ }
114
+
115
+ /* Key hints: TermDOM's UA style is bold + underline; keys are accelerators,
116
+ * not links — keep the weight, drop the underline. */
117
+ kbd {
118
+ text-decoration: none;
119
+ }
120
+
121
+ #footer div {
122
+ overflow: hidden;
123
+ }
124
+
125
+ #seekRow.hidden {
126
+ display: none;
127
+ }
128
+
129
+ #status {
130
+ color: var(--fg);
131
+ }
132
+
133
+ /* Seek bar row (issues/038): <progress> flexes to the width left beside
134
+ * the clock; the engine paints the track part at 1lh, so the whole row
135
+ * costs one cell. Plain DOM per timeUpdate — never canvas (issues/035).
136
+ * Fill/groove colours are theme vars through the progress pseudo-elements
137
+ * (the engine maps them onto its shadow parts; no colour literals here). */
138
+ #seekRow {
139
+ display: flex;
140
+ gap: 1ch;
141
+ }
142
+
143
+ #seekBar {
144
+ flex: 1 1 auto;
145
+ }
146
+
147
+ #seekBar::-webkit-progress-bar {
148
+ background-color: var(--muted);
149
+ }
150
+
151
+ #seekBar::-webkit-progress-value,
152
+ #seekBar::-moz-progress-bar {
153
+ background-color: var(--accent);
154
+ }
155
+
156
+ #seekClock {
157
+ color: var(--fg);
158
+ }
159
+
160
+ /* Panels: only the active one is visible (display toggle, no rebuild).
161
+ * Each panel is a non-scrolling flex column shell (title above the list;
162
+ * the sub-tab row below it when present): the scroll-container role lives
163
+ * on the inner .panel-scroll wrapper for every list-bearing panel, so the
164
+ * breadcrumbs sit outside the scrollable flow and can never move with it.
165
+ * Bounded height keeps the document exactly one viewport tall (the
166
+ * min-height invariant in body's rule) and the document camera never
167
+ * moves, so the fixed footer can't desync. */
168
+ .panel {
169
+ display: none;
170
+ /*border: 1px solid var(--accent);
171
+ border-radius: 3px;*/
172
+ padding: 0 1ch;
173
+ overflow: hidden;
174
+ }
175
+
176
+ .panel.active {
177
+ display: flex;
178
+ flex-direction: column;
179
+ height: calc(100vh - var(--footer-rows) - var(--header-rows) - 2px);
180
+ }
181
+
182
+ /* Panel breadcrumbs: pinned above the scroll port, structurally — rows
183
+ * live inside .panel-scroll and cannot enter the row the 1px margin
184
+ * reserves under the title (a full empty line of clearance at any scroll
185
+ * offset, unlike an in-flow list margin, which scrolls under pinned
186
+ * chrome). No background: nothing ever paints behind it. */
187
+ .panel-title {
188
+ color: var(--accent);
189
+ margin: 0 0 1px;
190
+ }
191
+
192
+ .subtabs {
193
+ flex: none;
194
+ margin: 0 0 1px;
195
+ overflow: hidden;
196
+ user-select: none;
197
+ }
198
+
199
+ .subtab {
200
+ /* No margin: the bracket glyphs already delimit adjacent buttons, and
201
+ * the narrower row keeps the view set on one line at 80 columns */
202
+ border: none;
203
+ padding: 0;
204
+ background-color: var(--bg);
205
+ color: var(--muted);
206
+ }
207
+
208
+ .subtab.active {
209
+ color: var(--accent);
210
+ }
211
+
212
+ .panel-scroll {
213
+ flex: 1 1 auto;
214
+ min-height: 0;
215
+ overflow-x: hidden;
216
+ overflow-y: scroll;
217
+ }
218
+
219
+ /* Lists: every item is exactly one row (nowrap + clip) so the virtualized
220
+ * window math in controller.js can assume fixed-height rows. The clip carries
221
+ * an ellipsis so a long name reads as truncated; TermDOM draws that marker in
222
+ * this element's own cell, so it follows the theme (--sel-fg on a selected
223
+ * row) with no extra colour. */
224
+ .list-item {
225
+ padding: 0 1ch;
226
+ color: var(--fg);
227
+ white-space: nowrap;
228
+ overflow: hidden;
229
+ text-overflow: ellipsis;
230
+ /* A row is an interactive target, not prose: double/triple click must not
231
+ * paint a text selection over it (TermDOM 0.1.9 word/paragraph select).
232
+ * Copyable text (browser path, playlist info) lives in .panel-title. */
233
+ user-select: none;
234
+ }
235
+
236
+ /* .list-spacer: plain div, height set inline by the windowed renderer
237
+ * (px == terminal rows). No rule needed — see controller.js. */
238
+
239
+ .list-item.selected,
240
+ .list-item.selected span {
241
+ background-color: var(--sel-bg);
242
+ color: var(--sel-fg);
243
+ }
244
+
245
+ .list-item.current {
246
+ color: var(--playing);
247
+ }
248
+
249
+ .list-item.selected.current {
250
+ color: var(--sel-fg);
251
+ }
252
+
253
+ .list-item.audio {
254
+ color: var(--playing);
255
+ }
256
+
257
+ .list-item.selected.audio {
258
+ color: var(--sel-fg);
259
+ }
260
+
261
+ /* Trailing row detail (playlist lengths, issues/046): stays at the default
262
+ * text colour while the row paints current/audio green. Selected rows keep
263
+ * the selection foreground via the broader .selected span rule above. */
264
+ .list-item .suffix {
265
+ color: var(--fg);
266
+ }
267
+
268
+ /* Main panel: flex column comes from .panel.active; this adds the centering
269
+ * (art + track meta centered in the row-less panel). ID would out-rank
270
+ * .panel/.panel.active, breaking tab hiding — class stays. */
271
+ .panel-main {
272
+ align-items: center;
273
+ }
274
+
275
+ /* Album art: a plain wrapper carries border + side padding (the engine's
276
+ * box model is unreliable on replaced elements); it holds the two role
277
+ * canvases (issues/035): #artCanvas is always a plain 2d context (the
278
+ * engine ships its bitmap as kitty pixels on kitty/Ghostty and rasterizes
279
+ * to half blocks elsewhere — no capability switching here), #vizCanvas is
280
+ * always the termdom-cellgrid and serves both the visualizer modes and
281
+ * the charset album-art styles. Art and viz are mutually exclusive modes;
282
+ * only one canvas is visible. The controller sets the wrapper's
283
+ * width inline: width snug around the art; the layout gives it every row
284
+ * left under the track meta (issues/066) and JS reads that height back.
285
+ * The art is drawn centered at its fitted size, never stretched. Cellgrid
286
+ * fillText defaults to the element's color. */
287
+ .art {
288
+ flex: 1 1 auto;
289
+ min-height: 0;
290
+ color: var(--muted);
291
+ border: 1px solid var(--border);
292
+ border-radius: 3px;
293
+ padding: 0 1px;
294
+ }
295
+
296
+ .art canvas {
297
+ display: block;
298
+ width: 100%;
299
+ height: 100%;
300
+ }
301
+
302
+ /* Beats .art canvas's display: block — .hidden alone is less specific */
303
+ .art canvas.hidden {
304
+ display: none;
305
+ }
306
+
307
+ .meta {
308
+ margin: 1px 0;
309
+ }
310
+
311
+ .meta-row {
312
+ display: flex;
313
+ gap: 1ch;
314
+ }
315
+
316
+ /* Two-column track info: column blocks give column 2 a fixed start */
317
+ .meta-cols {
318
+ display: flex;
319
+ gap: 3ch;
320
+ }
321
+
322
+ .meta-col {
323
+ display: flex;
324
+ flex-direction: column;
325
+ }
326
+
327
+ .meta-pair {
328
+ display: flex;
329
+ gap: 1ch;
330
+ }
331
+
332
+ .meta-label {
333
+ /* 7ch: "Artist" (longest label) + 1ch space */
334
+ width: 7ch;
335
+ color: var(--muted);
336
+ }
337
+
338
+ .meta-value {
339
+ color: var(--fg);
340
+ }
341
+
342
+ .placeholder {
343
+ color: var(--muted);
344
+ margin: 1px 0;
345
+ }
346
+
347
+ /* Idle splash (issues/049): no wrapper, border or padding — the cellgrid
348
+ * equals the box. The layout sizes it (issues/066): full inner width, every
349
+ * row left under the placeholder; splash.js reads the size back. */
350
+ .splash {
351
+ display: block;
352
+ flex: 1 1 auto;
353
+ min-height: 0;
354
+ width: 100%;
355
+ color: var(--muted);
356
+ user-select: none;
357
+ }
358
+
359
+ /* Utilities */
360
+ .hidden {
361
+ display: none;
362
+ }
363
+
364
+ /* Toast overlay */
365
+ .toast {
366
+ position: fixed;
367
+ top: calc(var(--header-rows) + 1px);
368
+ left: 0;
369
+ right: 0;
370
+ display: none;
371
+ justify-content: center;
372
+ }
373
+
374
+ .toast.show {
375
+ display: flex;
376
+ }
377
+
378
+ .toast-msg {
379
+ border: 1px solid var(--border);
380
+ border-radius: 3px;
381
+ background-color: var(--bg);
382
+ color: var(--fg);
383
+ padding: 0 2ch;
384
+ }
385
+
386
+ /* Onboarding modal (issues/041): a real top-layer <dialog> — termdom
387
+ * implements showModal() with the page behind inert (hit-testing and
388
+ * focus skip it), so the flow floats over whatever tab is active. The
389
+ * UA default ::backdrop is opaque Canvas; transparent keeps the app
390
+ * visible behind "Run setup again" mid-session. The picker list reuses
391
+ * .list-item rows; the engine centers the open dialog via the UA
392
+ * dialog:modal rule (fixed inset + margin auto). */
393
+ dialog.onboard {
394
+ background-color: var(--bg);
395
+ color: var(--fg);
396
+ border: 1px solid var(--border);
397
+ border-radius: 3px;
398
+ padding: 0 1ch;
399
+ max-width: calc(100vw - 4ch);
400
+ }
401
+
402
+ dialog.onboard::backdrop {
403
+ background-color: transparent;
404
+ }
405
+
406
+ .onboard-title {
407
+ color: var(--accent);
408
+ margin-bottom: 1px;
409
+ }
410
+
411
+ .onboard-dir {
412
+ color: var(--muted);
413
+ margin-bottom: 1px;
414
+ white-space: nowrap;
415
+ overflow: hidden;
416
+ user-select: none;
417
+ }
418
+
419
+ .onboard-hint {
420
+ color: var(--muted);
421
+ user-select: none;
422
+ }
423
+
424
+ /* Terminal theme: settings-panel option that swaps the palette for CSS
425
+ * system colours resolved from the user's terminal palette (TermDOM).
426
+ * Pure variable assignment — same channel as every other theme, so adding
427
+ * a theme means adding one block like this plus a controller cycle entry.
428
+ * Selection uses Highlight/HighlightText: the engine expresses a Highlight
429
+ * background as inverse video, and the terminal resolves inverse with its
430
+ * own foreground/background — a true palette-derived selection pair. The
431
+ * descendant background rule above is what makes it work: background-color
432
+ * is not inherited and the engine derives the inverse attribute per element
433
+ * from its own computed background, so the text spans must carry it too
434
+ * (otherwise the row inverts but the text runs paint un-flipped). */
435
+ body.theme-terminal {
436
+ --fg: CanvasText;
437
+ --bg: Canvas;
438
+ --accent: LinkText;
439
+ --muted: GrayText;
440
+ --playing: CanvasText;
441
+ --sel-bg: Highlight;
442
+ --sel-fg: HighlightText;
443
+ --border: GrayText;
444
+ }
445
+
446
+ /* Nord (nordtheme.github.io) — the 3rd-party palettes below follow the same
447
+ * pure-variable pattern; adding a theme is one block plus a controller
448
+ * cycle entry. Note: #000000 stores as 0 == engine "default fg", so dark
449
+ * selection foregrounds use the theme's bg colour instead of pure black. */
450
+ body.theme-nord {
451
+ --fg: #eceff4;
452
+ --bg: #2e3440;
453
+ --accent: #88c0d0;
454
+ --muted: #7b88a1;
455
+ --playing: #a3be8c;
456
+ --sel-bg: #88c0d0;
457
+ --sel-fg: #2e3440;
458
+ --border: #81a1c1;
459
+ }
460
+
461
+ /* Dracula (draculatheme.com) */
462
+ body.theme-dracula {
463
+ --fg: #f8f8f2;
464
+ --bg: #282a36;
465
+ --accent: #bd93f9;
466
+ --muted: #6272a4;
467
+ --playing: #50fa7b;
468
+ --sel-bg: #bd93f9;
469
+ --sel-fg: #282a36;
470
+ --border: #44475a;
471
+ }
472
+
473
+ /* Gruvbox dark (github.com/morhetz/gruvbox) */
474
+ body.theme-gruvbox {
475
+ --fg: #ebdbb2;
476
+ --bg: #282828;
477
+ --accent: #fe8019;
478
+ --muted: #928374;
479
+ --playing: #b8bb26;
480
+ --sel-bg: #ebdbb2;
481
+ --sel-fg: #282828;
482
+ --border: #504945;
483
+ }
484
+
485
+ /* Monokai — the classic Sublime Text palette */
486
+ body.theme-monokai {
487
+ --fg: #f8f8f2;
488
+ --bg: #272822;
489
+ --accent: #f92672;
490
+ --muted: #75715e;
491
+ --playing: #a6e22e;
492
+ --sel-bg: #f92672;
493
+ --sel-fg: #272822;
494
+ --border: #49483e;
495
+ }
496
+
497
+ /* Tokyo Night (github.com/tokyo-night/tokyo-night-vscode-theme) */
498
+ body.theme-tokyo-night {
499
+ --fg: #c0caf5;
500
+ --bg: #1a1b26;
501
+ --accent: #7aa2f7;
502
+ --muted: #787c99;
503
+ --playing: #9ece6a;
504
+ --sel-bg: #7aa2f7;
505
+ --sel-fg: #1a1b26;
506
+ --border: #3d59a1;
507
+ }
508
+
509
+ /* Solarized Dark (ethanschoonover.com/solarized) — base03 bg, base0 body
510
+ * text, base01 secondary, per the palette's own use table. */
511
+ body.theme-solarized-dark {
512
+ --fg: #839496;
513
+ --bg: #002b36;
514
+ --accent: #268bd2;
515
+ --muted: #586e75;
516
+ --playing: #859900;
517
+ --sel-bg: #268bd2;
518
+ --sel-fg: #002b36;
519
+ --border: #586e75;
520
+ }
521
+
522
+ /* Night Owl (github.com/sdras/night-owl-vscode-theme) */
523
+ body.theme-night-owl {
524
+ --fg: #d6deeb;
525
+ --bg: #011627;
526
+ --accent: #7fdbca;
527
+ --muted: #5f7e97;
528
+ --playing: #addb67;
529
+ --sel-bg: #7fdbca;
530
+ --sel-fg: #011627;
531
+ --border: #5f7e97;
532
+ }
@@ -0,0 +1,31 @@
1
+ // Reusable sub-screen tab row (issues/024): the pattern the Library panel
2
+ // introduced — a static row of buttons like the header tabs, click or the
3
+ // [ / ] keys switching between the views of one panel. render() keeps the
4
+ // .active class in step; onChange fires with the new index.
5
+ export function createSubtabs({ views, el, mount, onChange }) {
6
+ let index = 0;
7
+
8
+ const buttons = views.map((view, i) => {
9
+ const sub = el('button', 'subtab', view.label);
10
+ sub.dataset.view = view.key;
11
+ sub.addEventListener('click', () => set(i));
12
+ mount.appendChild(sub);
13
+ return sub;
14
+ });
15
+
16
+ function set(i) {
17
+ index = (i + views.length) % views.length;
18
+ onChange(index);
19
+ }
20
+
21
+ return {
22
+ render: () => {
23
+ const key = views[index].key;
24
+ buttons.forEach((sub) => {
25
+ sub.classList.toggle('active', sub.dataset.view === key);
26
+ });
27
+ },
28
+ active: () => index,
29
+ cycle: (delta) => set(index + delta),
30
+ };
31
+ }
@@ -0,0 +1,74 @@
1
+ import { bandAt, gradientBands } from './color.js';
2
+ import { emitHalfCells, makeHalfGrid } from './grid.js';
3
+ import { bandValues } from './spectrum.js';
4
+
5
+ // Bars: direct cell ops at whole-cell coords — crisp edges, uniform
6
+ // gaps, O(covered cells) per frame. Tops quantize to half rows; the
7
+ // vertical gradient quantizes to flat horizontal bands, accent at the
8
+ // bottom rising to playing at the top.
9
+ export const bars = {
10
+ needsSpectrum: true,
11
+ box: 'bars',
12
+ draw(grid, colors, viz) {
13
+ const { frequencyBins } = viz.data;
14
+ if (!frequencyBins || frequencyBins.length === 0) {
15
+ return;
16
+ }
17
+
18
+ const cols = grid.cols;
19
+ const rows = grid.rows;
20
+ if (cols < 4 || rows < 2) {
21
+ return;
22
+ }
23
+
24
+ // Standard stride: 2-cell bar + 1-cell gap; the cap stretches bars.
25
+ // Distribute cols exactly (Bresenham share, widths ±1): rounding
26
+ // stride×i made gaps 0-3 cells and floor(stride×⅔) flipped to
27
+ // 1-cell bars near the boundary (87-col vs 131-col terminals).
28
+ const fitBars = Math.max(1, Math.floor((cols + 1) / 3));
29
+ const numBars = Math.max(1, Math.min(viz.maxBars || fitBars, fitBars));
30
+ const gaps = numBars - 1;
31
+ const barCells = cols - gaps;
32
+ const maxRows = rows - 1;
33
+
34
+ const halfRows = rows * 2;
35
+ const heights = bandValues(frequencyBins, numBars).map((v) =>
36
+ Math.round(v * maxRows * 2),
37
+ );
38
+ const palette = gradientBands(
39
+ colors.accent,
40
+ colors.playing,
41
+ Math.min(rows, 12),
42
+ );
43
+ // Band k spans half-rows [bandBounds[k][0], bandBounds[k][1]);
44
+ // clip against each bar's top inside the loop.
45
+ const bandBounds = palette.map((_, k) => [
46
+ Math.round(halfRows - ((k + 1) * halfRows) / palette.length),
47
+ Math.round(halfRows - (k * halfRows) / palette.length),
48
+ ]);
49
+
50
+ const buf = makeHalfGrid(cols, rows);
51
+ // Width prefix of bars 0..i-1 — the Bresenham share each bar takes
52
+ // of barCells, so widths differ by at most one cell.
53
+ let cellsBefore = 0;
54
+ for (let i = 0; i < numBars; i++) {
55
+ const barHeight = heights[i];
56
+ const cellsThrough = Math.floor(((i + 1) * barCells) / numBars);
57
+ const width = Math.max(1, cellsThrough - cellsBefore);
58
+ const x = cellsBefore + i;
59
+ cellsBefore = cellsThrough;
60
+ if (barHeight <= 0) continue;
61
+ for (let b = 0; b < width; b++) {
62
+ for (let k = 0; k < palette.length; k++) {
63
+ const yH = Math.max(halfRows - barHeight, bandBounds[k][0]);
64
+ const bottom = bandBounds[k][1];
65
+ if (bottom <= yH) continue;
66
+ for (let y = yH; y < bottom; y++) {
67
+ buf.slots[y * cols + x + b] = bandAt(palette, k);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ emitHalfCells(grid, buf);
73
+ },
74
+ };
@@ -0,0 +1,64 @@
1
+ import { bandAt, fadeBands } from './color.js';
2
+ import { emitHalfCells, makeHalfGrid } from './grid.js';
3
+ import { updateCircles } from './onset.js';
4
+
5
+ // One ring into the half-grid: per-half distance test (d = 0 center,
6
+ // 1 on the ring), |d - 1| quantized against the fade width into a
7
+ // colour band. O(halves) tests; later writes win overlaps, so the
8
+ // caller paints the kick ring before the snare ring.
9
+ function paintRing(buf, r, cx, cy, ratio, fadeColors) {
10
+ const fade = Math.max(0.5, Math.min(2.5, 2 / Math.max(1, r)));
11
+ const ryH = (r / ratio) * 2; // vertical radius in half-rows
12
+ const x0 = Math.max(0, Math.floor(cx - r - 2));
13
+ const x1 = Math.min(buf.cols - 1, Math.ceil(cx + r + 2));
14
+ const y0 = Math.max(0, Math.floor(cy * 2 - ryH - 2));
15
+ const y1 = Math.min(buf.rows * 2 - 1, Math.ceil(cy * 2 + ryH + 2));
16
+ for (let yH = y0; yH <= y1; yH++) {
17
+ const dy = (yH - cy * 2) / ryH;
18
+ for (let x = x0; x <= x1; x++) {
19
+ const dx = (x - cx) / r;
20
+ const d = Math.sqrt(dx * dx + dy * dy);
21
+ const t = 1 - Math.abs(d - 1) / fade;
22
+ if (t > 0) {
23
+ buf.slots[yH * buf.cols + x] = bandAt(
24
+ fadeColors,
25
+ Math.floor(t * fadeColors.length),
26
+ );
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ export const circles = {
33
+ needsSpectrum: true,
34
+ box: 'square',
35
+ update(data, viz, now) {
36
+ return updateCircles(viz, data.frequencyBins, now, data.sampleRate);
37
+ },
38
+ // Two rings (kick accent, snare playing), radii from pulse levels,
39
+ // fading to bg over ~2 cells in three steps (no cellgrid alpha);
40
+ // arcs rasterize per half-row.
41
+ draw(grid, colors, viz) {
42
+ const cols = grid.cols;
43
+ const rows = grid.rows;
44
+ if (cols < 5 || rows < 5) {
45
+ return;
46
+ }
47
+
48
+ const cx = (cols - 1) / 2;
49
+ const cy = (rows - 1) / 2;
50
+ // Vertical radius = horizontal / cell aspect — round on tall cells;
51
+ // the widest ring spans half the height or width budget.
52
+ const ratio = Math.max(1, viz.cellRatio);
53
+ const maxR = Math.floor(Math.min((cols - 1) / 2, ((rows - 1) / 2) * ratio));
54
+ const base = 2;
55
+ const radius = (band) => base + band.pulse * (maxR - base);
56
+
57
+ const kickBands = fadeBands(colors.accent, colors.bg);
58
+ const snareBands = fadeBands(colors.playing, colors.bg);
59
+ const buf = makeHalfGrid(cols, rows);
60
+ paintRing(buf, radius(viz.circles.kick), cx, cy, ratio, kickBands);
61
+ paintRing(buf, radius(viz.circles.snare), cx, cy, ratio, snareBands);
62
+ emitHalfCells(grid, buf);
63
+ },
64
+ };