mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-09-11 13:44:31 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bfe508642 | ||
|
|
2a15f6e757 |
@@ -8,13 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- **The v3 Songs grid is now DOM-virtualized — card-node count stays bounded no matter how big the library is or how far you scroll.** The grid used to append every scrolled page and never let go, so a 2000-song library grew the DOM from 24 → 624 → 2001 card nodes as you scrolled (layout/memory cost scaling with depth). It now renders only the **visible window** of cards (± a small overscan); a sizer element sized to the whole library (`ceil(total/cols) × rowH`) gives the scrollbar its full geometry while the grid is absolutely positioned to the first visible row. `state.songs` is a sparse, absolutely-indexed store fetched a page at a time on demand — using the stage-1 **keyset cursor** for contiguous forward scroll (O(page)) and falling back to `OFFSET page=` for jumps/restore/non-keyset providers (collections, remote). Verified bounded (~60 nodes for a 2001-song library while the count still reads "2001 songs"). The **A–Z rail now seeks directly**: `sort_letters` gives a letter's first-row index (cumulative of prior buckets), converted to a scrollTop in O(1) — no more paging through every intervening row (a bounded forward scan covers the rare legacy provider without `sort_letters`). Select-mode selections, accuracy badges, the ⋮ card menu, plugin card actions, scroll-restore (now scrollTop-based, since geometry is stable), and the tree/folder views all survive cards leaving and re-entering the DOM. Plugins that decorate cards get a stable `window.v3Songs.visibleCards()` accessor + a `v3:library-window-rendered` event instead of assuming every card is present (the highway-stutter lesson). Stage 2 of the virtualized-grid project (got-feedback/feedBack#636 item 3), building on the stage-1 keyset data layer below. Frontend-only: `static/v3/songs.js`, `static/v3/v3.css`. Tests: `tests/browser/v3-grid-virtualization.spec.ts` (bounded-DOM invariant across a 2001-song scroll + direct rail jump), updated `tests/js/v3_az_rail.test.js` + `tests/js/v3_songs_scroll.test.js`.
|
||||
- **Keyset (cursor) pagination for the library grid — the data layer for an upcoming virtualized grid, and a latent paging bug fixed along the way.** Every library sort now carries a unique `filename` tiebreak, making the order **total** — which fixes a latent bug where rows sharing a sort key (e.g. two songs by the same artist) could be skipped or duplicated across `OFFSET` pages. `GET /api/library` gains an opaque `after` cursor + a `next_cursor` in the response: passing the cursor back fetches the next page with a **WHERE-seek** instead of `OFFSET`, so deep paging is O(page) regardless of depth. The seek is NULL-aware and exactly `OFFSET`-equivalent (verified across artist/title/recent, ascending + descending, including the legacy `dir=desc` shape and NULL sort keys); unknown/compound sorts and bad cursors fall back to `OFFSET`, and only the local provider is handed a cursor (collections/remote page by `OFFSET`). New composite `(artist NOCASE, filename)` / `(title NOCASE, filename)` / `(mtime, filename)` indexes cover the order. This is stage 1 of the virtualized-grid project (got-feedback/feedBack#636 item 3); the DOM-recycling render window builds on it next. Tests: `tests/test_library_keyset.py` (keyset==OFFSET parity, stable tiebreak, dir=desc, NULL keys, cursor fallback).
|
||||
- **Smart collections — save a set of library filters as a live, auto-updating source.** A collection is a saved `/api/library` query (e.g. "Drop-D tunings", "sloppak only", "recently added") that stays live: it's registered as a **library provider**, so it shows up in the v3 Songs source picker and inherits the whole grid UI — paging, stats, the A–Z rail, art — for free, with **no new screen**. Storage reuses the playlist subsystem (a `playlists.rules` JSON blob = a smart collection; membership is the live filter result, not stored songs, and collections are excluded from the manual-playlist list + read-only to playlist mutations). New `GET`/`POST`/`PUT`/`DELETE /api/collections`; a per-collection `SmartCollectionProvider` delegates `query_page`/`query_stats`/`query_artists` to the local DB with the stored rules applied; providers are re-registered from a boot scan so collections survive a restart. Rules mirror the raw `/api/library` query params (unknown keys dropped, never 500). Frontend: a "+ Save as collection" action in the v3 filter drawer (shown when filters are active) names the current filter set and switches to it. The charrette's "the homelab primitive FeedBack was missing" pick (got-feedback/feedBack#636 item 2); richer rule fields (accuracy, genre, difficulty) follow as the metadata work lands. Tests: `tests/test_collections_api.py`, `tests/js/v3_collections.test.js`.
|
||||
- **The settings backup now includes your library database + custom art — your scores, favorites, playlists, and play history are no longer the one thing a backup can't save.** `GET /api/settings/export` gains an additive `core_server_files` section carrying a **consistent snapshot of `web_library.db`** (taken via the SQLite online-backup API, so it's a complete single file even while the server is running) plus any custom **playlist covers** and **avatar** (`CONFIG_DIR/playlist_covers/`, `CONFIG_DIR/avatars/`). On `POST /api/settings/import` the database is **staged** to `web_library.db.restore` rather than written over the live, open DB; it's swapped in at the next startup (`_apply_pending_db_restore`, before the connection opens), which also clears the old WAL sidecars so a stale `-wal` can't be replayed onto the restored file — the import response sets `restart_required: true` and warns accordingly. Custom art is written immediately. The bundle stays backward-compatible (older servers ignore the new section). Came out of the library design charrette (dev-ops lens's top "protect irreplaceable data" pick, got-feedback/feedBack#636). _Known gap:_ custom uploaded **song** art is still commingled with the rebuildable thumbnail cache in `art_cache/`, so it isn't bundled yet (a tracked follow-up). Tests: `tests/test_settings_export_library_db.py` (snapshot consistency, staged-not-live restore, sidecar clearing, traversal rejection, full round-trip).
|
||||
- **A persisted wishlist — keep a list of songs you want but don't own yet.** New `wanted` table + `GET`/`POST`/`DELETE /api/wanted` give FeedBack the *arr-style "Wanted/Monitored" primitive it was missing: an entry is a *not-owned* song (artist/title/source/source_ref/note), so it lives in its own table rather than the playlist subsystem (which references owned local files). The API is idempotent on identity (case-insensitive artist+title, plus source+source_ref), so a producer — the `find_more` ownership-diff, or a manual add — can re-post without duplicating. Newest-first. Backend primitive for the charrette's wishlist finding (got-feedback/feedBack#636 item 4); the consuming UI lives in the producing plugin. Tests: `tests/test_wanted_api.py`.
|
||||
- **Practice-aware library home — a "Repertoire" meter + a "Keep practicing" shelf on the v3 Songs page.** The library opened cold into a flat sorted grid; now the unfiltered grid front door leads with two practice-aware surfaces built entirely from data already on hand (no new endpoints or stored state). A **Repertoire meter** shows how much of your library you can actually play — *"Repertoire: 12 of 80 songs · 7 in progress"* with a progress bar — counting songs at or above the same mastery threshold the green accuracy badge uses (≥ 90% best accuracy) over the unfiltered library total. A **"Keep practicing" shelf** is a horizontal row of your recently-played-but-not-yet-mastered songs (newest first, click to play) — the practice-accuracy-driven "continue" rail a media server can't do. Both reuse `/api/stats/best` (already loaded for the card badges) + `/api/stats/recent`; they show **only** on the grid view when you aren't searching/filtering/selecting, refresh after a song is scored, and collapse to nothing on an empty library. Soft-gamification only — descriptive encouragement (goal-gradient / endowed-progress), never content-gating, decay, or nagging. Frontend-only: `static/v3/songs.js` (`renderLibraryHome`/`_repertoireCounts`), `static/v3/v3.css`. Came out of the library design charrette (the UX + gamification lenses' top pick). Tests: `tests/js/v3_keep_practicing.test.js`.
|
||||
- **A–Z fast-scroll rail on the v3 Songs grid.** A vertical letter rail (Plex/Radarr/iOS-contacts pattern) pinned to the right edge next to the scrollbar lets you jump the library to a starting letter — tap a letter, drag to scrub with a live letter bubble, or arrow-key between letters. It shows **only** for the grid view + alphabetical (artist/title) sorts, and only offers letters actually present in the current sort **and filter set**, so a tap always lands on a real card (absent letters are dimmed + non-interactive). Because the grid is forward-only, server-paged infinite scroll, a jump pages through to the target card and scrolls to it (a newer jump supersedes an in-flight one); a keyset-seek + virtualized window is the noted scaling follow-up for very large libraries. Backend: `/api/library/stats` now accepts `sort` and returns an additive `sort_letters` map (songs-per-first-letter of the active sort column — artist or title), filter-synced; the legacy `letters` (distinct-artist) field is unchanged for the dashboard + classic tree. Frontend: `static/v3/songs.js` (`refreshRail`/`jumpToLetter`, cards tagged with `data-letter`), `static/v3/v3.css` (`.v3-azrail`). The classic (v2) tree already had letter selection; this brings the new grid to parity. Tests: `tests/test_library_filters.py` (sort_letters artist/title + song-vs-artist counting), `tests/test_library_providers.py` (sort forwarded to providers), `tests/js/v3_az_rail.test.js`.
|
||||
- **Playlists get content-dependent covers + custom art.** Playlist cards were a tiny `🎵` emoji on an empty square. Now a playlist's cover reflects its contents: **empty → the icon**, **a few songs → the first song's album art**, **4+ songs → a 2×2 art mosaic**. You can also **upload a custom cover** (a "Cover" button in the playlist detail view → image picker; "Remove cover" reverts to the content view). `MetadataDB.list_playlists()` now returns each playlist's first few song `art_urls`; `GET /api/playlists` and `GET /api/playlists/{id}` add `cover_url` when a custom cover exists. New routes `POST` / `GET` / `DELETE /api/playlists/{id}/cover` store a small PNG thumbnail under `CONFIG_DIR/playlist_covers/` (PIL-converted, like song-art upload); the cover is removed with the playlist. Frontend: `playlistCoverHtml(p)` in `static/v3/playlists.js`. Tests: `tests/test_playlists_api.py` (art_urls + cover roundtrip / reject-non-image / delete-cleanup), `tests/js/v3_playlist_cover.test.js`.
|
||||
- **v3 Songs: "Add to playlist" is now on each song's ⋮ "More" menu.** Previously a song could only be added to a playlist through select-mode (the checkbox → batch bar). The per-card overflow menu now has an **Add to playlist** row that targets that one song, reusing the same picker (choose a listed number or type a new name to create it). The select-mode batch flow and the single-song menu now share one extracted `addFilenamesToPlaylist(filenames)` helper in `static/v3/songs.js` (both grid and tree rows, since they share `openCardMenu`). Tests: `tests/js/v3_add_to_playlist_menu.test.js`.
|
||||
- **Resume where you left off — leaving a song now snapshots your place so an exit is recoverable, not a restart-from-zero.** Exiting the player (`showScreen()` teardown, before audio unload) writes `{song, arrangement, position, speed}` to `localStorage` (`feedBack.resumeSession`), and a non-blocking **"Resume practice"** pill offers it back on the next non-player screen (and on the next app launch). Clicking Resume re-enters the song, restores the arrangement + playback speed, and seeks to the saved position via the existing `_audioSeek` funnel; `playSong()` gains a `{ resume: {position, speed} }` option that arms a `song:ready`-consumed restore instead of the normal autostart, so the two never fight over playback. The snapshot is deliberately conservative — ignored for a song you barely started (< 3s) or had basically finished (within 5s of the end), cleared on natural song-end and once consumed, and expired after 24h. The pill is self-contained (inline-styled, body-appended, works identically in the classic and v3 shells with no Tailwind rebuild), never blocks, and a dismiss forgets the current snapshot for the session. This pairs with the Escape focus fix: now that Escape reliably leaves regardless of focus, an *accidental* exit is one tap to undo. Public surface: `window.resumeLastSession()` / `window.feedBack.resumeLastSession`. (The broader nav-state work — returning to a song after wandering into Settings → Tone Builder — is a separate, larger track; this lands the player-session slice.) Tests: `tests/browser/resume-session.spec.ts` (snapshot guards, staleness, pill show/hide/dismiss, resume consumption).
|
||||
@@ -47,11 +40,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **v3 library: exact artist/album filters + scroll/page-depth restore** (feedBack#857). The v3 Songs toolbar gains Artist and Album dropdowns (Album populates from the selected artist and stays disabled until one is chosen), backed by new exact, case-insensitive (`COLLATE NOCASE`) `artist` / `album` query params threaded through `MetadataDB._build_where` → `query_page` / `query_artists` / `query_stats` and the `/api/library`, `/api/library/artists`, `/api/library/stats` endpoints (the free-text `q` search stays fuzzy and composes with the exact filters). The artist/album catalog is fetched independently of the active artist/album selection so the dropdowns always list the full set for the current provider/search. The toolbar is now sticky so filter controls stay reachable when browsing deep libraries, and returning from the player restores the previous scroll position **and** the loaded infinite-scroll page depth via a `sessionStorage` snapshot keyed by a filter/sort/view state hash (invalidated whenever those change, so a filter change still resets to the top). Tests: `tests/test_library_filters.py` (backend artist/album filters), `tests/js/v3_songs_scroll.test.js` (state-hash + snapshot helpers).
|
||||
|
||||
### Fixed
|
||||
- **v3 player: opening another rail popover now closes the Section Practice popover (no more two stacked popovers).** Opening the **Practice** pill's popover and then clicking a different player-rail icon (e.g. **Plugins**) left the Practice popover open underneath the new one — looked broken (reported on macOS, 0.3.0 / 2026-06-28). The rail icons call `e.stopPropagation()` in their click handler (`static/v3/player-chrome.js`), which killed bubbling before it reached the Practice popover's outside-click dismiss bound on `document`. The dismiss (`_installSectionPracticeDismiss` in `static/app.js`) now binds in the **capture phase**, which runs before the target's handler so a descendant's `stopPropagation()` can't swallow it — mirroring how the audio-mixer popover already dismisses. Esc handling stays bubble-phase (the player's Escape-to-exit ordering is unchanged). v2 shares `app.js` and is only hardened (no rail `stopPropagation` there). Tests: `tests/js/section_practice_dismiss.test.js`.
|
||||
- **v3 UI no longer lets you accidentally text-select the chrome.** Dragging or double-clicking across the interface used to marquee-highlight buttons, labels, the sidebar, the transport, and the note-highway HUD — which looks broken (reported on Mac + Windows). The v3 shell now defaults to `user-select: none` on `html` (`static/v3/v3.css`), then opts *content* back in — so chrome is non-selectable but the text you actually copy still works. Decided by a 4-lens panel (UX / accessibility / dev-ops / plugin-ecosystem); the guardrails are deliberate: **form fields are always re-enabled** (never break the caret / IME — no `* { user-select:none }`, which trips a WebKit input bug); **plugin screens (`.screen[id^="plugin-"]`) stay selectable by default** so a plugin's copyable text (lyrics, chord names, results) — including community plugins that don't know about this — isn't silently locked; and **core read-only content opts back in by container** via a new hand-authored **`.fb-selectable`** class — applied to the whole **Settings** panel (paths, device names, version, diagnostics, About — answering "is settings still copyable?": yes), the **now-playing song metadata** (with `pointer-events` re-enabled so the HUD text is actually reachable), and the focused **modals / dialogs / toasts / scan banner** that carry copyable errors, IDs, paths, and file names. It's cosmetic only (it protects nothing) and never used to lock copy-worthy text — errors, IDs, paths, versions, and metadata stay selectable per WCAG 2.2 (copy-paste as a permitted mechanism). Dense card lists (library grid, dashboard, profile) stay non-selectable by design — making them selectable would reintroduce the marquee-mess across cards. **v3-only** (v2 unchanged); plain CSS, no Tailwind rebuild; no desktop changes (standard OS-framed window). Plugin authors: `.fb-selectable` is documented in `CLAUDE.md` for re-enabling copyable content rendered outside a plugin screen. Tests: `tests/js/v3_user_select_policy.test.js`.
|
||||
- **Input-setup wizard no longer collapses an audio device's driver-type variants into one entry.** On Windows the desktop engine enumerates the same interface once per host API (ASIO / Windows Audio / DirectSound), and the wizard's audio picker (`plugins/input_setup/screen.js`) de-duped the source list by display **label** — so the variants (which share a name) collapsed to a single choice, silently keeping whichever sorted first (often *not* the low-latency ASIO one the player wants). The audio-input capability already collapses true duplicates by `logicalSourceKey` (`_visibleInputSources` in `static/capabilities/audio-session.js`), and the variants each have a **distinct** key, so the wizard's extra label-collapse was redundant for real dupes and destructive for these — it also could drop the variant that was actually `selected`. Removed it; the picker now lists every selectable input. Pairs with feedBack-desktop's change to label each source with its driver type (e.g. "Focusrite (ASIO)") so the now-distinct entries are legible.
|
||||
- **3D Highway FPS counter no longer hides behind the v3 "Up Next" pill.** The on-highway FPS readout (Settings → Graphics → 3D Highway → Show FPS counter) is pinned to the top-right of the highway overlay — the same corner the v3 player chrome stacks its persistent **Up Next** pill and live-performance HUD into, on a higher layer that paints over the canvas. So the readout sat *behind* that chrome and couldn't be read — precisely when a tester had turned it on to judge performance (it also made the separate "Up Next won't turn off" complaint worse, since the default-on pill covered the counter regardless). The counter now stays top-right but drops just **below** whichever of that chrome is showing: `highway_3d`'s `screen.js` measures the lowest visible top-right v3 HUD element (`#v3-upnext` / `#v3-live-performance-hud` / `#hud-time`) and floors the FPS box's Y beneath it. Element refs are resolved once and cached (no per-frame `querySelector`, per the plugin perf rules) and only consulted while the counter is actually drawn; gated on `window.feedBack.uiVersion === 'v3'` so the classic (v2) UI is byte-for-byte unaffected. `plugins/highway_3d/plugin.json` version → `3.30.1` (cache-buster). (For reading raw perf numbers unobstructed, the core perf HUD — `localStorage.highwayPerfHud='1'` — still renders above all chrome and additionally shows the adaptive render-scale.)
|
||||
- **3D Highway fret-number row no longer clips off the bottom edge when the camera zooms in on a centred span.** The heat-coloured fret-number row is drawn as a band *below* the board (`sY(lowest) − S_GAP*1.4`), but the camera's self-correcting framing only anchors the board **centre** to the lower third of the screen — it reserved no headroom for that row. So a tight zoom on a centred active span (worst around mid-neck; fine when the span sits at either end of the neck, which is why testers saw it "only when centered" and "not every song") dropped the numbers past the bottom edge. Tilt can't fix it there (it would only trade a bottom clip for a top clip), so `camUpdate()` now **dollies the camera back just enough to bring the row back into frame**: it projects the row band with the final camera and, when it falls below a safe NDC line (`FRET_ROW_FIT_NDC_MIN`), raises a capped, hysteretic `_fretRowFitBoost` applied to the `curDist` lerp target (the span-driven zoom still owns zooming *in*). The boost rises promptly (proportional to the deficit), relaxes lazily past a deadband, and is capped (`FRET_ROW_FIT_BOOST_MAX`, +60%) so the zoom can't pop or hunt; it cooperates with the tilt loop (pull-back shrinks the scene, tilt keeps the centre anchored) and yields entirely to the Camera Director free-cam. Surgical: passages where the row is already visible never trigger it, so framing is unchanged everywhere it already worked. `plugins/highway_3d/plugin.json` version → `3.30.2` (cache-buster). Tests: `tests/js/highway_3d_camera_framing.test.js` (guard constants, the boosted `curDist` lerp, the projected-row hysteresis, free-cam yield).
|
||||
- **v3 Songs grid now refreshes after a Settings rescan / DLC-folder change — no app restart needed.** On a fresh install, pointing at a DLC folder in Settings and running a scan left the Songs section empty until a restart (the scan *did* populate the library — `_background_scan` re-reads `config.json` fresh — but the v3 grid never reloaded). The Settings **Rescan / Full Rescan** handlers only refreshed the classic (v2) library via `loadLibrary()`; the v3 grid (`static/v3/songs.js`) had no listener for a scan it didn't start itself (only its own upload path self-refreshed via `watchUploadScan`), so its cached, pre-DLC (empty) DOM/snapshot survived a sidebar return until a full reload. The rescan handlers now emit a **`library:changed`** event (`static/app.js`); the v3 grid listens and **reloads if it's the active screen, else marks itself dirty** so the next entry does a full re-fetch instead of restoring the stale snapshot (a `_libraryDirty` short-circuit ahead of every cached-DOM fast-path in `onV3SongsScreenEnter`). Tests: `tests/js/v3_library_refresh.test.js` (the emit + the reload/dirty wiring).
|
||||
- **Edit Metadata modal: the Year is now editable.** You could set a year when authoring a pak but the Songs → Edit Metadata modal had no Year field, so it could never be changed afterward. The backend (`POST /api/song/<f>/meta`) already accepted and normalized `year` (writes it into the file via `songmeta`, survives a rescan) — only the UI omitted it. Added a **Year** input to `openEditModal()` (populated from the song's existing year) and included `year` in `saveEditModal()`'s POST body (`static/app.js`). Both the v3 card menu and the legacy edit button already pass the year through, so both surfaces get the field.
|
||||
- **Edit Metadata modal no longer closes when a click-drag is released on the backdrop.** Selecting text inside a field and releasing the mouse past the modal's edge dismissed the form without warning (the `click` event's target resolved to the backdrop), discarding the edit. Backdrop dismissal now requires the **mousedown to have started on the backdrop** too — tracked per-modal and decided by a new pure `_editModalShouldClose(clickTarget, modalEl, downOnBackdrop)` helper (`static/app.js`). Cancel / ✕ still close on a normal click. Tests: `tests/js/edit_metadata_modal.test.js` (year in the POST body + the backdrop-close decision table).
|
||||
|
||||
@@ -552,7 +552,6 @@ a local pointer + code map.
|
||||
- **Storage** — `localStorage` for all user preferences
|
||||
- **Styling** — Tailwind CSS utility classes, dark theme (`bg-dark-600`, `text-gray-300`, accent `#4080e0`, gold `#e8c040`). Tailwind is served as a **prebuilt** stylesheet (`static/tailwind.min.css`, regenerated by `bash scripts/build-tailwind.sh`), **never** the runtime Play CDN — the CDN's on-the-fly JIT rescanned the DOM on the main thread and dropped ~26% of frames with the 3D highway (feedBack-desktop#110). The committed CSS only contains classes the build scanner saw, so CI (`tailwind-fresh`) rebuilds and diffs it; run the build script and commit when you add new classes. A plugin that uses classes not guaranteed in core (notably arbitrary values like `w-[37px]`) MUST ship its own compiled stylesheet via the `styles` manifest key, built with `corePlugins.preflight = false` (utilities only — core ships the one base reset). Plugins MUST NOT load the Tailwind Play CDN or any runtime CSS JIT. See constitution Principle II.
|
||||
- **Naming** — camelCase for JS functions, kebab-case for CSS classes, snake_case for plugin IDs
|
||||
- **Text selection (v3)** — the v3 UI defaults to `user-select: none` on `html` (in `static/v3/v3.css`) so accidental drag/double-click selection of chrome never looks broken. Form fields are always re-enabled, and a **plugin's mounted screen subtree (`.screen[id^="plugin-"]`) stays selectable by default**, so a plugin's copy-worthy text (lyrics, chord names, results, diagnostics) is unaffected — *unless your plugin renders copyable content OUTSIDE its `plugin-<id>` screen* (e.g. injected into the player chrome / a HUD overlay), which inherits the non-select default. Opt such content back in with the core-served **`.fb-selectable`** class (it sets `user-select: text` on the element + descendants; works for runtime-installed plugins since it's hand-authored in core CSS, not a scanned Tailwind utility). Never use a `* { user-select: none }` rule (breaks input carets/IME), and never use `user-select: none` to "lock" text — keep errors, IDs, paths, versions, and metadata selectable. (v2 is unchanged.)
|
||||
- **Player layout** — `#player` is `display:flex; flex-direction:column; position:fixed; inset:0`. `#highway` is `flex:1`. `#player-controls` sits at the bottom. Hiding the highway collapses the layout — use `margin-top: auto` on controls if you need to hide it.
|
||||
|
||||
## Backend Conventions
|
||||
|
||||
+56
-116
@@ -55,94 +55,59 @@ The host writes default `--fb-*` role tokens on `:root` **unconditionally** (not
|
||||
`[data-fb-theme]`), seeded from the canonical `fb` palette, so `var(--fb-accent, …)` always
|
||||
resolves — themed or not. Roles:
|
||||
|
||||
**Namespace (normative).** The public contract lives under one prefix, **`--fb-*`**, written on
|
||||
`:root` by a host-owned *contract stylesheet* (see §6 / §8) so it is present **themed or not**.
|
||||
The existing `--fbv-*` vars stay **internal plumbing** — `theme-core.js` uses them only to
|
||||
recolour the Tailwind `.bg-fb-*/.text-fb-*/.border-fb-*` utilities under `html[data-fb-theme]`;
|
||||
they are **not** part of this contract and plugins must not read them. (Implementation may seed
|
||||
`--fb-*` from the same source the `--fbv-*` overrides use, so an equipped theme moves both.)
|
||||
`surface · card · border · text · text-dim · accent · accent-2 · good · warn · bad`
|
||||
plus two **new keystones**:
|
||||
|
||||
**Value grammar (normative).** Colour roles are a **space-separated `r g b` triplet** (matching
|
||||
today's `--fbv-*` and the Tailwind utilities), consumed as `rgb(var(--fb-accent))` with optional
|
||||
alpha `rgb(var(--fb-accent) / .5)`. Recipe slots (Layer 2) hold **full CSS values** for their
|
||||
device (a `box-shadow`, a `border` shorthand, a length, a paint), with `none` legal **except**
|
||||
where noted.
|
||||
- **`on-accent`** — foreground legible *on* an accent fill. (Rule: any role used as a fill
|
||||
behind text gets a paired `on-*`.) Fixes white-on-amber.
|
||||
- **`focus-ring`** — focus indicator independent of accent, so focus stays visible when
|
||||
`accent ≈ surface`.
|
||||
|
||||
**Normative role tokens** (all `--fb-*`, all always present):
|
||||
|
||||
| Role | Token | Notes |
|
||||
| --- | --- | --- |
|
||||
| surface / card / border | `--fb-surface` `--fb-card` `--fb-border` | structural |
|
||||
| text / dim | `--fb-text` `--fb-text-dim` | |
|
||||
| accent / second hue | `--fb-accent` `--fb-accent-2` | `accent-2` is **just a second hue** — never an assumed gradient end |
|
||||
| status | `--fb-good` `--fb-warn` `--fb-bad` | maps onto today's palette `good / mid / low` (mid→warn, low→bad) — implementation aliases both |
|
||||
| **on-fill (new)** | `--fb-on-accent` `--fb-on-good` `--fb-on-warn` `--fb-on-bad` | **Rule: every role used as a fill behind text gets a paired `--fb-on-*`** (fixes white-on-amber). Required + contrast-linted (§6). |
|
||||
| **focus (new)** | `--fb-focus-ring` | focus indicator independent of `accent`, so focus stays visible when `accent ≈ surface` |
|
||||
`accent-2` is demoted to "just a second hue" — **never** an assumed gradient end.
|
||||
|
||||
### Layer 2 — Capability **recipes** (intent-named slots; "off" is legal)
|
||||
|
||||
A theme declares its design *language* by filling intent-named slots (all `--fb-*`-prefixed,
|
||||
same namespace as the roles). A feature applies the slot bundle **unconditionally**; it never
|
||||
branches on "is this theme glowy?". Atomic slots (renames-by-intent of today's tokens):
|
||||
`--fb-corner-radius`, `--fb-corner-clip`, `--fb-panel-shadow`, `--fb-text-emph-shadow`,
|
||||
`--fb-panel-texture`, `--fb-motion-decorative` (reduced-motion-gated). For these, `none` is legal.
|
||||
A theme declares its design *language* by filling intent-named slots. A feature applies the
|
||||
slot bundle **unconditionally**; it never branches on "is this theme glowy?". Atomic slots
|
||||
(renames-by-intent of today's tokens): `corner-radius`, `corner-clip`, `panel-shadow`,
|
||||
`text-emph-shadow`, `panel-texture`, `motion-decorative` (reduced-motion-gated).
|
||||
|
||||
Two **composite recipes** carry the load:
|
||||
|
||||
- **EMPHASIS** — how this theme makes a primary action special:
|
||||
`--fb-emph-fill / --fb-emph-border / --fb-emph-halo / --fb-emph-on`.
|
||||
`--emph-fill / --emph-border / --emph-halo / --emph-on`.
|
||||
neon → halo (glow ring); esports → border (solid accent); metal → fill + drop-shadow.
|
||||
Any individual slot may be `none` — but a theme **must** emphasise *somehow* (at least one of
|
||||
fill/border/halo non-`none`), so a primary action is never visually flat.
|
||||
- **ACCENT-TEXT** — how this theme fills a big accent number: `--fb-acc-text-fill`
|
||||
None empty — each emphasises in its own language.
|
||||
- **ACCENT-TEXT** — how this theme fills a big accent number: `--acc-text-fill`
|
||||
(decoupled from `accent-2`). neon/metal → a gradient; esports → a solid accent.
|
||||
**`--fb-acc-text-fill` is the one slot where `none` is illegal** — it is always a valid paint
|
||||
(solid colour or gradient), defaulting to `rgb(var(--fb-accent))`. Reason: the number is
|
||||
rendered with `background-clip: text` + transparent text-fill, so a `none` paint would make
|
||||
the digits **invisible** (transparent fill, nothing to clip) — which would violate the DoD
|
||||
"a device stays legible when its slot resolves to `none`". The feature also feature-detects
|
||||
`background-clip: text` and keeps a solid `color` base (see §5), so the digits are legible
|
||||
even where clip-text is unsupported.
|
||||
|
||||
> These generalize the interim per-skin tokens already shipped in `note_detect`
|
||||
> (`--nd-hero-ring-idle/on`, `--nd-hero-border`, `--nd-acc-fill`).
|
||||
|
||||
### Layer 3 — JS read API + reconciliation
|
||||
|
||||
**The JS API is only for renderers that can't use CSS (canvas / WebGL), never for DOM/CSS
|
||||
consumers** — those use the tokens and slots directly (§5). Critically, it exposes *resolved
|
||||
token values*, **not** theme-style booleans: a `glow:false` flag can't tell a canvas whether to
|
||||
draw a border, a bevel, a drop-shadow, or flat text, so there is **no** `capabilities()` of
|
||||
booleans. On the existing `window.feedBack` bus:
|
||||
On the existing `window.feedBack` bus:
|
||||
|
||||
- `feedBack.theme.get()` → `{ id, isThemed, tokens }` where `tokens` is the **resolved** map of
|
||||
every `--fb-*` role + recipe slot (the computed values, so a canvas reads the actual device,
|
||||
e.g. the gradient stops for `--fb-acc-text-fill`, not a boolean).
|
||||
- `feedBack.theme.prefersReducedMotion()` → boolean (host wraps `matchMedia` once). **This is the
|
||||
single approved JS reduced-motion gate going forward** — existing direct `matchMedia` callers
|
||||
(`venue-mood-fx.js`, `pedal-cables.js`) migrate to it; `--fb-motion-decorative` covers the
|
||||
CSS-authored decorative motion.
|
||||
- `theme:changed` event → `{ id, tokens }`.
|
||||
- `feedBack.theme.get()` → `{ id, tokens, isThemed }`
|
||||
- `feedBack.theme.capabilities()` → `{ glow, gradients, motion }` (the device-affordance signal)
|
||||
- `feedBack.theme.prefersReducedMotion()` → boolean (host wraps `matchMedia` once)
|
||||
- `theme:changed` event → `{ id, tokens, capabilities }` (emitted at theme-core's existing
|
||||
apply chokepoint; analogous to `note_detect`'s `notedetect:skin`)
|
||||
|
||||
**Lifecycle (normative).** `get()` always returns the **current effective theme synchronously**
|
||||
and is valid at any time — before any theme is applied it returns the default/unthemed roles
|
||||
(which always exist on `:root`). Theme application is async (it follows a `/api/profile` refresh);
|
||||
`theme:changed` fires **only after** the DOM vars/classes are committed, and **once on initial
|
||||
hydration** so a late-mounting plugin isn't stuck on stale state. **Plugin rule:** read `get()`
|
||||
on mount, then subscribe to `theme:changed` — never assume an order between your mount and the
|
||||
first theme apply.
|
||||
**Reconciliation rule (ends the two-disconnected-systems problem) — depends on whether the
|
||||
plugin has its own identity:**
|
||||
|
||||
**Reconciliation rule (ends the two-disconnected-systems problem):** a plugin skin
|
||||
**derives surface/text/border from host tokens** (`--nd-bg: rgb(var(--fb-card))`, etc.) and
|
||||
**owns only its accent + its devices**, selecting the device via the recipe. A host theme then
|
||||
pulls plugin chrome along (one truth for surfaces), while the plugin layers identity on top and
|
||||
never imposes a device the active theme neutralizes.
|
||||
|
||||
**Propagation scope (normative).** The contract is **same-document light-DOM**: `:root` `--fb-*`
|
||||
inheritance and the central focus/motion rules (§6) reach any normal plugin screen. A plugin that
|
||||
renders into a **shadow root or iframe** is responsible for bridging — copy the resolved
|
||||
`get().tokens` into its sub-root and re-subscribe to `theme:changed` (host `:root` vars don't
|
||||
cross those boundaries).
|
||||
- **A plugin *without* its own skin** should **derive surface/text/border from host tokens**
|
||||
(`background: var(--fbv-card)`, etc.) and **own only its accent + its devices**, selecting the
|
||||
device via the recipe. A host theme then pulls its chrome along — one truth for surfaces — and
|
||||
it never imposes a device the active theme neutralizes. This is the common case.
|
||||
- **A plugin *with* deliberate skins** (e.g. `note_detect`'s neon / esports / metal, which are
|
||||
full design languages) **owns its surfaces** — deriving them from the host theme would *erase*
|
||||
the skin's identity (metal's brushed steel becomes a flat host colour). Such a plugin adopts the
|
||||
**role + recipe *pattern*** (per-skin device tokens, `on-accent`, `focus-ring`, "off" is legal)
|
||||
and verifies across **its own** skin matrix, but does not blindly inherit host surfaces.
|
||||
*(Decided 2026-06-29: keep note_detect's skins self-owned + their current button text — so the
|
||||
fix is the per-skin device pattern + the verification gate, not surface-derivation.)*
|
||||
|
||||
## 5. Consumption pattern (the rule for feature authors)
|
||||
|
||||
@@ -152,47 +117,28 @@ cross those boundaries).
|
||||
|
||||
```css
|
||||
.hero-cta {
|
||||
background: var(--fb-emph-fill);
|
||||
border: var(--fb-emph-border);
|
||||
box-shadow: var(--fb-emph-halo); /* neon→ring · esports→none · metal→drop-shadow */
|
||||
color: var(--fb-emph-on); /* never hardcoded #fff again */
|
||||
border-radius: var(--fb-corner-radius);
|
||||
background: var(--emph-fill);
|
||||
border: var(--emph-border);
|
||||
box-shadow: var(--emph-halo); /* neon→ring · esports→none · metal→drop-shadow */
|
||||
color: var(--emph-on); /* never hardcoded #fff again */
|
||||
border-radius: var(--corner-radius);
|
||||
}
|
||||
.accuracy-number {
|
||||
/* Always-legible solid base; survives no-clip-text support too. */
|
||||
color: rgb(var(--fb-accent));
|
||||
}
|
||||
/* Apply the clipped paint ONLY where supported — and --fb-acc-text-fill is
|
||||
guaranteed a real paint (never `none`, per Layer 2), so the digits can't go
|
||||
invisible. */
|
||||
@supports ((background-clip: text) or (-webkit-background-clip: text)) {
|
||||
.accuracy-number {
|
||||
background: var(--fb-acc-text-fill);
|
||||
-webkit-background-clip: text; background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
color: var(--accent); /* legible solid fallback FIRST */
|
||||
background: var(--acc-text-fill);
|
||||
background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
|
||||
}
|
||||
```
|
||||
|
||||
**Where the contract physically lives.** A **host-owned static contract stylesheet** (e.g.
|
||||
`static/v3/theme-contract.css`, hand-authored, linked from `static/v3/index.html`) holds the
|
||||
always-present `:root --fb-*` defaults **plus** the two central a11y rules below. It is **not** a
|
||||
Tailwind file, so it never touches the prebuilt `static/tailwind.min.css` artifact the
|
||||
`tailwind-fresh` CI check diffs (and it's independent of `theme-core.js`, which keeps
|
||||
runtime-injecting only the `--fbv-*` utility overrides under `[data-fb-theme]`).
|
||||
## 6. Accessibility (baked into the contract, not per-feature)
|
||||
|
||||
- **Reduced motion:** `--fb-motion-decorative` is the *only* place CSS decorative animation is
|
||||
named; one central rule in the contract sheet sets it to `none` under
|
||||
`@media (prefers-reduced-motion: reduce)`, so no theme can forget the gate. (JS-driven motion
|
||||
uses `feedBack.theme.prefersReducedMotion()` — §4.3.)
|
||||
- **Focus parity:** one contract-level `:focus-visible { outline: 2px solid rgb(var(--fb-focus-ring)) }`
|
||||
for contract consumers; themes recolour `--fb-focus-ring` but may not author their own focus
|
||||
styling. *Migration:* v3 already ships component-specific focus + reduced-motion rules in
|
||||
`v3.css`; those are reconciled onto the contract token (not magically replaced) as a tracked
|
||||
cleanup — "one rule" describes the end state, not day one.
|
||||
- **On-fill contrast:** every `--fb-on-*` is required and **lintable**
|
||||
(`contrast(on-X, X) ≥ 4.5:1`, 3:1 large) for each fill role (`accent / good / warn / bad`).
|
||||
Contrast is the theme's job, computed once — not re-judged per feature.
|
||||
- **Reduced motion:** `motion-decorative` is the *only* place decorative animation is named;
|
||||
one central rule sets it to `none` under `@media (prefers-reduced-motion: reduce)`, so no
|
||||
theme can forget the gate.
|
||||
- **Focus parity:** exactly one contract-level `:focus-visible { outline: 2px solid var(--focus-ring) }`;
|
||||
themes recolour `focus-ring` but may not author their own focus styling.
|
||||
- **On-accent contrast:** `on-accent` is required and **lintable** (`contrast(on-accent, accent) ≥ 4.5:1`,
|
||||
3:1 large). Contrast is the theme's job, computed once — not re-judged per feature.
|
||||
|
||||
## 7. Verification gate (prevent recurrence)
|
||||
|
||||
@@ -211,15 +157,13 @@ stays legible when its slot resolves to `none`** · reduced-motion + focus parit
|
||||
|
||||
## 8. Back-compat & rollout
|
||||
|
||||
All additive: the new always-present `--fb-*` tokens (in the contract sheet, §6) + a new
|
||||
`feedBack.theme` namespace + a new event with no current listeners. Existing plugins (those
|
||||
reading `fb-*` Tailwind utility classes, or shipping their own skins) are untouched unless they
|
||||
opt in. On a host too old to ship the contract sheet, a consumer still degrades cleanly: the
|
||||
two-arg fallback `rgb(var(--fb-accent, 224 128 32))` resolves to the literal, and
|
||||
`window.feedBack?.theme?.get?.()` is feature-detected — so older hosts behave exactly as today.
|
||||
All additive: new `--fb-*` runtime vars + a new `feedBack.theme` namespace + a new event with no
|
||||
current listeners. Existing plugins (those reading `fb-*` utility classes, or shipping their own
|
||||
skins) are untouched unless they opt in; two-arg `var(--fb-x, fallback)` + `window.feedBack?.theme?.get`
|
||||
feature-detection means older hosts behave exactly as today.
|
||||
|
||||
**Workstream (sub-tasks):**
|
||||
1. **Host minimal surface** — the contract stylesheet's always-present default `--fb-*` tokens + `feedBack.theme.{get, prefersReducedMotion}` (`get().tokens` = resolved values; no boolean `capabilities()`) + `theme:changed`. *(the smallest thing that would have prevented the incident)*
|
||||
1. **Host minimal surface** — always-present default `--fb-*` tokens + `feedBack.theme.{get,capabilities,prefersReducedMotion}` + `theme:changed`. *(the smallest thing that would have prevented the incident)*
|
||||
2. **note_detect refactor** — rename device tokens by intent (EMPHASIS + ACCENT-TEXT recipes), add `on-accent` + `focus-ring`, derive surfaces from host tokens.
|
||||
3. **Verification gate** — commit the render-matrix + DoD checklist; add the canvas share-card surface.
|
||||
4. **Ecosystem migration guide** — document the contract + the consumption rule for community plugin authors.
|
||||
@@ -238,9 +182,5 @@ two-arg fallback `rgb(var(--fb-accent, 224 128 32))` resolves to the literal, an
|
||||
plugin-local forever? (This proposal assumes plugin-local + contract-implementing.)
|
||||
- Component-recipe **bundles** (per named component) are the richer end-state; intent-named
|
||||
slots are the right seed. When/whether to graduate.
|
||||
|
||||
*(Resolved during review and folded into the sections above: the token namespace + value grammar
|
||||
and normative role table (§4.1); the `none`-is-illegal carve-out for `--fb-acc-text-fill` (§4.2);
|
||||
JS exposes resolved tokens, not booleans (§4.3); `theme:changed` lifecycle + shadow/iframe
|
||||
propagation (§4.3); the physical home of the role tokens + central focus/motion rules — a
|
||||
host-owned contract stylesheet outside Tailwind (§6).)*
|
||||
- Where the central reduced-motion + focus rules physically live (core base layer vs a shared
|
||||
plugin import) and how the host injects role tokens into plugin roots.
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
# Theming a plugin so it works in every theme
|
||||
|
||||
This is the how-to for plugin authors. It exists because of one recurring bug:
|
||||
a plugin's UI is built and eyeballed against the **default** look, ships, and
|
||||
then a user switches themes and the feature's *colours adapt but its visual
|
||||
devices vanish* — a glow ring, a colour gradient — because the active theme
|
||||
doesn't speak that visual language.
|
||||
|
||||
**The golden rule:** themes are different **design languages**, not palettes.
|
||||
Reference **roles** and **recipe slots**; never hardcode a *device* (a literal
|
||||
`box-shadow` glow, a literal `linear-gradient`, a hex colour). Then your feature
|
||||
renders correctly in a theme nobody has invented yet — and **verify it across
|
||||
the whole theme set before you merge.**
|
||||
|
||||
(Design + rationale: [host-theme-contract.md](host-theme-contract.md), got-feedback/feedBack#644.)
|
||||
|
||||
## What the host gives you
|
||||
|
||||
Always-present CSS role tokens on `:root` (resolve themed *or* un-themed):
|
||||
`--fbv-bg / sidebar / card / cardMuted / primary / primaryHi / accent / text /
|
||||
textDim / border / good / mid / low / gold`, plus **`--fbv-on-accent`** (a
|
||||
foreground legible *on* an accent fill) and **`--fbv-focus-ring`**. Use as
|
||||
`color: rgb(var(--fbv-text))`, `background: rgb(var(--fbv-card))`, etc.
|
||||
|
||||
A JS read surface on the event bus:
|
||||
|
||||
```js
|
||||
const t = window.feedBack?.theme;
|
||||
t?.get(); // { id, isThemed, tokens }
|
||||
t?.capabilities(); // { glow, gradients, motion } — what devices this theme permits
|
||||
t?.prefersReducedMotion(); // boolean (one central matchMedia)
|
||||
window.feedBack.on('theme:changed', (e) => { /* e.detail = {id, tokens, capabilities} */ });
|
||||
```
|
||||
|
||||
Feature-detect everything (`window.feedBack?.theme?.get`) and pass a fallback to
|
||||
every `var(--fbv-x, <fallback>)` so you degrade cleanly on an older host.
|
||||
|
||||
## Pick your path
|
||||
|
||||
### Path A — you do NOT have your own skins (most plugins)
|
||||
|
||||
Look like the host. **Derive surfaces from host tokens** and **choose devices
|
||||
from capabilities** instead of hardcoding them:
|
||||
|
||||
```js
|
||||
const caps = window.feedBack?.theme?.capabilities?.() ?? { glow: true, motion: true };
|
||||
heroEl.classList.toggle('use-glow', caps.glow && !window.feedBack.theme.prefersReducedMotion());
|
||||
```
|
||||
```css
|
||||
.hero { background: rgb(var(--fbv-primary)); color: rgb(var(--fbv-on-accent, #fff)); }
|
||||
.hero:focus-visible { outline: 2px solid rgb(var(--fbv-focus-ring)); outline-offset: 2px; }
|
||||
.hero.use-glow { box-shadow: 0 0 16px -2px rgb(var(--fbv-primary)); } /* only where the theme allows it */
|
||||
```
|
||||
Re-read on `theme:changed` if you cache anything (e.g. a canvas palette).
|
||||
|
||||
### Path B — you HAVE your own deliberate skins (like the scoring UI)
|
||||
|
||||
Your skins are an identity (neon vs steel vs clean) — **own your surfaces**;
|
||||
don't inherit host surfaces or you'll erase that identity. Adopt only the
|
||||
**pattern**: make every visual *device* a **per-skin token whose "off" value is
|
||||
legal**, so each skin authors its own version and a glow-less skin simply
|
||||
doesn't glow. Example (the "make the hero special" device):
|
||||
|
||||
```css
|
||||
/* base / neon */ :root { --hero-ring: .5; --hero-border: transparent; --acc-fill: linear-gradient(135deg, var(--accent), var(--accent2)); }
|
||||
/* glow-less skin */ [data-skin="clean"] { --hero-ring: 0; --hero-border: var(--accent); --acc-fill: var(--accent); }
|
||||
.hero { background: var(--acc-fill); border-color: var(--hero-border); }
|
||||
.hero::after { opacity: var(--hero-ring); /* the glow ring; 0 = off */ }
|
||||
```
|
||||
Neon emphasises with the ring, the clean skin with a solid border — **neither is
|
||||
empty of emphasis; each speaks its own language.** Same idea for an accent-filled
|
||||
number (`--acc-fill` = a gradient in one skin, a solid in another so it doesn't
|
||||
wash out to white). Add `on-accent` + `focus-ring` per skin too.
|
||||
|
||||
## Accessibility (part of the contract, not an afterthought)
|
||||
|
||||
- **Reduced motion:** gate decorative animation on `prefers-reduced-motion`
|
||||
(CSS `@media`, or `theme.prefersReducedMotion()`); functional transitions are fine.
|
||||
- **Focus:** always a visible `:focus-visible` outline using `focus-ring` — don't
|
||||
bind focus only to `accent` (it can ≈ the surface in some themes).
|
||||
- **On-accent contrast:** text on an accent fill uses `on-accent`; watch light
|
||||
accents (a mid-amber needs dark text, not white).
|
||||
|
||||
## Before you merge — verify across the matrix
|
||||
|
||||
Render your UI in **every** theme/skin and look at them together. If you ship
|
||||
your own skins, do this with a render-matrix in CI/local (reference: the scoring
|
||||
UI's `npm run render-skins` + `theme-matrix-checklist.md`). The checklist that
|
||||
catches this bug class:
|
||||
|
||||
- [ ] colours via tokens, no hardcoded hexes
|
||||
- [ ] rendered in **all** themes/skins (not just the default)
|
||||
- [ ] every new *device* is per-skin / capability-gated and **legible when its token is `none`**
|
||||
- [ ] reduced-motion + visible focus in every theme
|
||||
- [ ] text on accent stays legible everywhere
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "highway_3d",
|
||||
"name": "3D Highway",
|
||||
"version": "3.30.2",
|
||||
"version": "3.30.0",
|
||||
"type": "visualization",
|
||||
"bundled": true,
|
||||
"script": "screen.js",
|
||||
|
||||
@@ -1083,22 +1083,6 @@
|
||||
const FOCUS_D = 600 * K;
|
||||
const CAM_LERP_BASE = 0.02;
|
||||
|
||||
// Base vertical field of view (deg). THREE's PerspectiveCamera fov is the
|
||||
// VERTICAL angle; horizontal follows from the aspect ratio. At a normal
|
||||
// ~16:9 pane this gives a ~102° horizontal cone. On an ultra-wide pane
|
||||
// (top/bottom 2-player split → full-width/half-height → ~32:9) that
|
||||
// horizontal cone balloons past 130° and squeezes the fixed-width neck into
|
||||
// a central sliver. The optional horizontal-FOV-hold path below counters
|
||||
// that by lowering the effective vertical fov as the pane widens.
|
||||
const BASE_VFOV = 70;
|
||||
// Horizontal-FOV-hold ("Hor+") defaults. At/under HORPLUS_START_ASPECT the
|
||||
// effective vertical fov equals BASE_VFOV (exact no-op); past it the
|
||||
// vertical fov drops to keep the horizontal cone ~constant so the neck
|
||||
// fills a wide pane. HORPLUS_MIN_VFOV floors the result on pathological
|
||||
// aspects. Engaged only via the window.__h3dAspectTune bridge (default off).
|
||||
const HORPLUS_START_ASPECT = 16 / 9;
|
||||
const HORPLUS_MIN_VFOV = 28;
|
||||
|
||||
// Zoom-dependent framing — height (h*) and depth (dist*) multipliers
|
||||
// applied to cam.position. Interpolated by `dist`:
|
||||
// NEAR = tight view (nut position, span<=4 -> dist~=93*K): lower/closer.
|
||||
@@ -1111,16 +1095,6 @@
|
||||
const CAM_FRAME_H_FAR = 1.00;
|
||||
const CAM_FRAME_D_NEAR = 0.575;
|
||||
const CAM_FRAME_D_FAR = 0.60;
|
||||
// Fret-row fit guard. The heat-coloured fret-number row is a band drawn
|
||||
// BELOW the board (at sY(lowest) - S_GAP*1.4). The lower-third framing
|
||||
// anchors the board CENTRE, not that row, so a tight zoom on a centred span
|
||||
// (worst mid-neck — fine pushed to either end of the neck) drops the row off
|
||||
// the bottom edge. Tilt can't add vertical room there (it would only trade a
|
||||
// bottom clip for a top clip), so camUpdate dollies the camera back just
|
||||
// enough to bring the row back into frame — auto-sized, capped, hysteretic.
|
||||
const FRET_ROW_FIT_NDC_MIN = -0.86; // keep the row anchor at/above this NDC y (>-1 = on screen)
|
||||
const FRET_ROW_FIT_DEADBAND = 0.06; // headroom past the min before the dolly relaxes (anti-hunt)
|
||||
const FRET_ROW_FIT_BOOST_MAX = 1.6; // cap the pull-back so the zoom can't pop (never dolly back > +60%)
|
||||
|
||||
// Camera-X targeting (issue #34). The visible AHEAD = 4.0 s window is
|
||||
// far too coarse for picking where the camera should sit — a single
|
||||
@@ -1607,257 +1581,6 @@
|
||||
ss.isCanvasFocused(highwayCanvas));
|
||||
}
|
||||
|
||||
// A/B toggle for the wide-pane horizontal-FOV-hold. Flips
|
||||
// window.__h3dAspectTune.enabled so the running app can switch between the
|
||||
// current framing (off, the baseline) and the Hor+ framing (on) with one
|
||||
// keypress, across all panes at once. Registered once per session via a
|
||||
// module-level guard (it toggles a shared global, so per-instance
|
||||
// registration would stack duplicate handlers and cancel itself out); it's
|
||||
// a harmless debug control, so it is never unregistered. No-ops where the
|
||||
// core shortcut API isn't present (older core / borrowed contexts).
|
||||
let _abShortcutRegistered = false;
|
||||
function _registerAspectAbShortcut() {
|
||||
if (_abShortcutRegistered) return;
|
||||
if (typeof window.registerShortcut !== 'function') return;
|
||||
_abShortcutRegistered = true;
|
||||
try {
|
||||
window.registerShortcut({
|
||||
key: 'A', // uppercase e.key → produced with Shift held (Shift+A)
|
||||
description: '3D Highway: toggle wide-pane framing A/B (Shift+A)',
|
||||
scope: 'player',
|
||||
handler: () => {
|
||||
const t = _aspectTune();
|
||||
t.enabled = !t.enabled;
|
||||
try { console.log('[h3d] wide-pane framing', t.enabled ? 'ON' : 'OFF'); } catch (e) {}
|
||||
// Surface the live tuner panel whenever the feature is on,
|
||||
// hide it when off. Built lazily on first use.
|
||||
_ensureAspectPanel();
|
||||
_setAspectPanelVisible(t.enabled);
|
||||
_syncAspectPanel();
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
_abShortcutRegistered = false; // allow a later retry if it threw
|
||||
}
|
||||
}
|
||||
|
||||
// ── Wide-pane framing: live tuner bridge + panel ──────────────────────────
|
||||
// window.__h3dAspectTune is the single source of truth the renderer reads
|
||||
// each frame (see effectiveVfov + camUpdate). The defaults reproduce the
|
||||
// current framing exactly (enabled:false). Values persist to localStorage so
|
||||
// a tuning session survives reloads; the floating panel (Shift+A) writes the
|
||||
// same object live. All of this is a debug aid — none of it runs unless the
|
||||
// user opts in.
|
||||
// Versioned key: the first iteration shipped a broken default (enabled:true,
|
||||
// baseVfov:30) and may have persisted it. Bumping the key ignores that stale
|
||||
// state so the corrected default-off config actually takes effect.
|
||||
const _ASPECT_LS = 'h3d_aspect_tune2';
|
||||
// Working defaults. Default OFF, so out of the box this is an exact no-op —
|
||||
// every pane renders byte-for-byte as before (effectiveVfov returns
|
||||
// BASE_VFOV and the pose nudges gate off). The config is also coherent when
|
||||
// a tester turns it ON via Shift+A: baseVfov == BASE_VFOV so normal ~16:9
|
||||
// panes (single-player, most 2x2) stay at 70° even enabled, and only panes
|
||||
// wider than startAspect (2.25) engage the Hor+ hold; blend:1 makes that
|
||||
// hold actually take effect; minVfovDeg (28) sits below baseVfov so the floor
|
||||
// is a real floor. The pose nudges are the in-progress wide-pane look a
|
||||
// tester sees once enabled. localStorage overrides all of this per machine.
|
||||
const _ASPECT_DEFAULTS = {
|
||||
enabled: false, baseVfov: BASE_VFOV, startAspect: 2.25, hfovDeg: null,
|
||||
blend: 1, minVfovDeg: HORPLUS_MIN_VFOV, splitOnly: false,
|
||||
heightMul: 0.30, distMul: 0.95, pitchAdd: -1.5, lookDepthMul: 1,
|
||||
};
|
||||
// Slider specs (numeric fields). Checkboxes (enabled/splitOnly) + the hfov
|
||||
// override are handled separately in the panel builder. Ranges are wide on
|
||||
// purpose — this is a tuning aid, the no-op default sits mid-range.
|
||||
const _ASPECT_FIELDS = [
|
||||
{ k: 'baseVfov', label: 'Base vFOV°', min: 18, max: 90, step: 1 },
|
||||
{ k: 'startAspect', label: 'Start aspect', min: 1.0, max: 4.0, step: 0.05 },
|
||||
{ k: 'blend', label: 'Blend', min: 0, max: 1, step: 0.05 },
|
||||
{ k: 'minVfovDeg', label: 'Min vFOV°', min: 10, max: 60, step: 1 },
|
||||
{ k: 'heightMul', label: 'Height ×', min: 0.1, max: 2.5, step: 0.05 },
|
||||
{ k: 'distMul', label: 'Dolly ×', min: 0.2, max: 3.0, step: 0.05 },
|
||||
{ k: 'pitchAdd', label: 'Pitch +', min: -40, max: 40, step: 0.5 },
|
||||
// Aims the camera further down the neck (>1) or pulls the aim back (<1).
|
||||
// This is the lever that flattens the mid-distance "hump" toward a
|
||||
// straight gradual recede.
|
||||
{ k: 'lookDepthMul', label: 'Look depth', min: 0.2, max: 3.0, step: 0.05 },
|
||||
];
|
||||
let _aspectPanelEl = null; // the floating panel root (built once)
|
||||
let _aspectPanelRO = null; // readout <div>
|
||||
let _aspectPanelRAF = 0; // readout poll handle
|
||||
|
||||
// Get-or-create the live bridge object, seeded from defaults + localStorage.
|
||||
function _aspectTune() {
|
||||
let t = window.__h3dAspectTune;
|
||||
if (!t || typeof t !== 'object') {
|
||||
t = Object.assign({}, _ASPECT_DEFAULTS);
|
||||
try {
|
||||
const raw = localStorage.getItem(_ASPECT_LS);
|
||||
if (raw) Object.assign(t, JSON.parse(raw));
|
||||
} catch (e) {}
|
||||
window.__h3dAspectTune = t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function _aspectPersist() {
|
||||
try {
|
||||
const t = _aspectTune(), out = {};
|
||||
Object.keys(_ASPECT_DEFAULTS).forEach((k) => { out[k] = t[k]; });
|
||||
localStorage.setItem(_ASPECT_LS, JSON.stringify(out));
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function _ensureAspectPanel() {
|
||||
if (_aspectPanelEl || typeof document === 'undefined') return;
|
||||
const t = _aspectTune();
|
||||
const wrap = document.createElement('div');
|
||||
wrap.id = 'h3d-aspect-tuner';
|
||||
wrap.style.cssText = [
|
||||
'position:fixed', 'top:64px', 'right:12px', 'z-index:99999',
|
||||
'width:230px', 'padding:10px 12px', 'border-radius:8px',
|
||||
'background:rgba(12,18,28,0.92)', 'border:1px solid rgba(120,150,200,0.35)',
|
||||
'box-shadow:0 6px 24px rgba(0,0,0,0.5)', 'color:#cfe0f5',
|
||||
'font:11px/1.35 system-ui,sans-serif', 'user-select:none',
|
||||
'pointer-events:auto',
|
||||
].join(';');
|
||||
|
||||
const title = document.createElement('div');
|
||||
title.textContent = 'Wide-pane framing (A/B)';
|
||||
title.style.cssText = 'font-weight:700;margin-bottom:6px;color:#e8c040;';
|
||||
wrap.appendChild(title);
|
||||
|
||||
// enabled + splitOnly checkboxes
|
||||
[['enabled', 'Enabled (Shift+A)'], ['splitOnly', 'Split panes only']].forEach(([k, lbl]) => {
|
||||
const row = document.createElement('label');
|
||||
row.style.cssText = 'display:flex;align-items:center;gap:6px;margin:2px 0;cursor:pointer;';
|
||||
const cb = document.createElement('input');
|
||||
cb.type = 'checkbox'; cb.checked = !!t[k]; cb.dataset.k = k;
|
||||
cb.addEventListener('change', () => {
|
||||
_aspectTune()[k] = cb.checked; _aspectPersist();
|
||||
if (k === 'enabled') _setAspectPanelVisible(cb.checked);
|
||||
});
|
||||
const span = document.createElement('span'); span.textContent = lbl;
|
||||
row.appendChild(cb); row.appendChild(span); wrap.appendChild(row);
|
||||
});
|
||||
|
||||
// numeric sliders
|
||||
_ASPECT_FIELDS.forEach((f) => {
|
||||
const row = document.createElement('div');
|
||||
row.style.cssText = 'margin:5px 0;';
|
||||
const head = document.createElement('div');
|
||||
head.style.cssText = 'display:flex;justify-content:space-between;';
|
||||
const lab = document.createElement('span'); lab.textContent = f.label;
|
||||
const val = document.createElement('span');
|
||||
val.style.cssText = 'color:#8fb6ff;font-variant-numeric:tabular-nums;';
|
||||
head.appendChild(lab); head.appendChild(val); row.appendChild(head);
|
||||
const sl = document.createElement('input');
|
||||
sl.type = 'range'; sl.min = f.min; sl.max = f.max; sl.step = f.step;
|
||||
sl.value = Number.isFinite(t[f.k]) ? t[f.k] : _ASPECT_DEFAULTS[f.k];
|
||||
sl.dataset.k = f.k;
|
||||
sl.style.cssText = 'width:100%;';
|
||||
const show = () => { val.textContent = (+sl.value).toFixed(f.step < 1 ? 2 : 0); };
|
||||
show();
|
||||
sl.addEventListener('input', () => {
|
||||
_aspectTune()[f.k] = parseFloat(sl.value); show(); _aspectPersist();
|
||||
});
|
||||
row.appendChild(sl); wrap.appendChild(row);
|
||||
});
|
||||
|
||||
// hfov override (checkbox enables a slider; off → hfovDeg=null = auto)
|
||||
{
|
||||
const row = document.createElement('div'); row.style.cssText = 'margin:5px 0;';
|
||||
const head = document.createElement('label');
|
||||
head.style.cssText = 'display:flex;align-items:center;gap:6px;cursor:pointer;';
|
||||
const cb = document.createElement('input');
|
||||
cb.type = 'checkbox'; cb.checked = Number.isFinite(t.hfovDeg);
|
||||
const lbl = document.createElement('span'); lbl.textContent = 'Override held hFOV°';
|
||||
head.appendChild(cb); head.appendChild(lbl); row.appendChild(head);
|
||||
const sl = document.createElement('input');
|
||||
sl.type = 'range'; sl.min = 40; sl.max = 160; sl.step = 1;
|
||||
sl.value = Number.isFinite(t.hfovDeg) ? t.hfovDeg : 102;
|
||||
sl.disabled = !cb.checked;
|
||||
sl.style.cssText = 'width:100%;';
|
||||
cb.addEventListener('change', () => {
|
||||
sl.disabled = !cb.checked;
|
||||
_aspectTune().hfovDeg = cb.checked ? parseFloat(sl.value) : null;
|
||||
_aspectPersist();
|
||||
});
|
||||
sl.addEventListener('input', () => {
|
||||
if (cb.checked) { _aspectTune().hfovDeg = parseFloat(sl.value); _aspectPersist(); }
|
||||
});
|
||||
row.appendChild(sl); wrap.appendChild(row);
|
||||
}
|
||||
|
||||
// live readout
|
||||
_aspectPanelRO = document.createElement('div');
|
||||
_aspectPanelRO.style.cssText = 'margin-top:6px;padding-top:6px;border-top:1px solid rgba(120,150,200,0.25);color:#9fb;font-variant-numeric:tabular-nums;';
|
||||
_aspectPanelRO.textContent = 'aspect — · vFOV —';
|
||||
wrap.appendChild(_aspectPanelRO);
|
||||
|
||||
// buttons
|
||||
const btnRow = document.createElement('div');
|
||||
btnRow.style.cssText = 'display:flex;gap:6px;margin-top:8px;';
|
||||
const mkBtn = (txt, fn) => {
|
||||
const b = document.createElement('button');
|
||||
b.textContent = txt;
|
||||
b.style.cssText = 'flex:1;padding:4px 0;border-radius:5px;border:1px solid rgba(120,150,200,0.4);background:rgba(40,60,90,0.6);color:#cfe0f5;cursor:pointer;font:11px system-ui;';
|
||||
b.addEventListener('click', fn);
|
||||
return b;
|
||||
};
|
||||
btnRow.appendChild(mkBtn('Reset', () => {
|
||||
const t2 = _aspectTune();
|
||||
Object.keys(_ASPECT_DEFAULTS).forEach((k) => { t2[k] = _ASPECT_DEFAULTS[k]; });
|
||||
t2.enabled = true; // keep panel up after reset
|
||||
_aspectPersist(); _syncAspectPanel();
|
||||
}));
|
||||
btnRow.appendChild(mkBtn('Copy', () => {
|
||||
const t2 = _aspectTune(), out = {};
|
||||
Object.keys(_ASPECT_DEFAULTS).forEach((k) => { out[k] = t2[k]; });
|
||||
const json = JSON.stringify(out, null, 2);
|
||||
try { console.log('[h3d] wide-pane framing values:\n' + json); } catch (e) {}
|
||||
try { if (navigator.clipboard) navigator.clipboard.writeText(json); } catch (e) {}
|
||||
}));
|
||||
wrap.appendChild(btnRow);
|
||||
|
||||
document.body.appendChild(wrap);
|
||||
_aspectPanelEl = wrap;
|
||||
_aspectPanelEl.style.display = 'none';
|
||||
}
|
||||
|
||||
// Push current bridge values back into the panel controls (after Reset or an
|
||||
// external edit). Cheap; only runs on demand.
|
||||
function _syncAspectPanel() {
|
||||
if (!_aspectPanelEl) return;
|
||||
const t = _aspectTune();
|
||||
_aspectPanelEl.querySelectorAll('input[type=checkbox][data-k]').forEach((cb) => {
|
||||
cb.checked = !!t[cb.dataset.k];
|
||||
});
|
||||
_aspectPanelEl.querySelectorAll('input[type=range][data-k]').forEach((sl) => {
|
||||
const k = sl.dataset.k;
|
||||
if (Number.isFinite(t[k])) sl.value = t[k];
|
||||
sl.dispatchEvent(new Event('input')); // refresh the value label
|
||||
});
|
||||
}
|
||||
|
||||
function _setAspectPanelVisible(on) {
|
||||
_ensureAspectPanel();
|
||||
if (!_aspectPanelEl) return;
|
||||
_aspectPanelEl.style.display = on ? 'block' : 'none';
|
||||
window.__h3dAspectPanelOpen = !!on; // gates the per-frame readout publish
|
||||
if (on && !_aspectPanelRAF) {
|
||||
const tick = () => {
|
||||
if (!window.__h3dAspectPanelOpen) { _aspectPanelRAF = 0; return; }
|
||||
const ro = window.__h3dAspectReadout;
|
||||
if (_aspectPanelRO && ro && Number.isFinite(ro.aspect)) {
|
||||
_aspectPanelRO.textContent =
|
||||
'aspect ' + ro.aspect.toFixed(2) + ' · vFOV ' + ro.vfov.toFixed(1) + '°';
|
||||
}
|
||||
_aspectPanelRAF = requestAnimationFrame(tick);
|
||||
};
|
||||
_aspectPanelRAF = requestAnimationFrame(tick);
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================================================
|
||||
* Background animations (issue #13)
|
||||
*
|
||||
@@ -3602,42 +3325,6 @@
|
||||
let _fpsEma = 0;
|
||||
let _fpsDisplay = 0;
|
||||
let _fpsLastSampleT = 0;
|
||||
// The FPS readout is pinned top-right of the highway overlay — the same
|
||||
// corner the v3 player chrome stacks its persistent "Up Next" pill and
|
||||
// live-performance HUD into, on a higher layer that paints over the
|
||||
// canvas. So out of the box the readout sits *behind* that chrome and
|
||||
// can't be read (exactly when you've turned it on to judge perf). Rather
|
||||
// than relocate it (testers look top-right), we drop it just BELOW
|
||||
// whichever of that chrome is showing. Refs are resolved once and cached
|
||||
// — never a per-frame querySelector (see CLAUDE.md "never run DOM queries
|
||||
// on a per-frame path") — and re-resolved only when a node detaches.
|
||||
let _v3HudEls = null;
|
||||
// Returns the bottom edge (in overlay-canvas px, which are 1:1 CSS px on
|
||||
// this overlay) of the lowest visible top-right v3 chrome element, or 0
|
||||
// when none apply (classic v2 UI, or all hidden). Only called while the
|
||||
// FPS readout is actually drawn, so the layout reads cost nothing in the
|
||||
// common (counter-off) case.
|
||||
function _v3TopRightChromeBottom() {
|
||||
if (typeof document === 'undefined' || !highwayCanvas) return 0;
|
||||
// Only the v3 chrome stacks persistent HUD elements over the canvas's
|
||||
// top-right. Gate on the documented detector so this is a strict no-op
|
||||
// in classic v2 (where 'hud-time' also exists but sits elsewhere).
|
||||
if (!(window.feedBack && window.feedBack.uiVersion === 'v3')) return 0;
|
||||
if (!_v3HudEls || _v3HudEls.some((el) => el && !el.isConnected)) {
|
||||
_v3HudEls = ['v3-upnext', 'v3-live-performance-hud', 'hud-time']
|
||||
.map((id) => document.getElementById(id));
|
||||
}
|
||||
const top = highwayCanvas.getBoundingClientRect().top;
|
||||
let maxBottom = 0;
|
||||
for (const el of _v3HudEls) {
|
||||
// offsetParent === null ⇒ display:none (a `.hidden` pill/HUD) or
|
||||
// not laid out — don't duck under something that isn't shown.
|
||||
if (!el || el.offsetParent === null) continue;
|
||||
const b = el.getBoundingClientRect().bottom - top;
|
||||
if (b > maxBottom) maxBottom = b;
|
||||
}
|
||||
return maxBottom;
|
||||
}
|
||||
let _diagChord = null;
|
||||
// Chord diagram render cache. Keys: static layout inputs joined as a
|
||||
// string. Values: OffscreenCanvas (or <canvas>) rendered at opacity=1
|
||||
@@ -3765,11 +3452,6 @@
|
||||
// that CSS-box drift and re-frame, instead of the user having to
|
||||
// un/re-maximize the window.
|
||||
let _appliedW = 0, _appliedH = 0;
|
||||
// Last pane aspect (w/h) handed to the camera, cached so camUpdate can
|
||||
// recompute the horizontal-FOV-hold each frame (and react to live
|
||||
// __h3dAspectTune edits) without waiting for a resize. 0 until first
|
||||
// applySize().
|
||||
let _paneAspect = 0;
|
||||
// True once applySize() has pinned the .h3d-wrap overlay to the
|
||||
// highway canvas's offset box. Stays false while the canvas has no
|
||||
// layout yet (init() can run before #highway has a real box, where
|
||||
@@ -4373,11 +4055,6 @@
|
||||
|
||||
let tgtX = xFretMid(CAM_LOCK_CENTER_FRET), curX = xFretMid(CAM_LOCK_CENTER_FRET);
|
||||
let tgtDist = CAM_DIST_BASE, curDist = CAM_DIST_BASE;
|
||||
// Dolly-back multiplier applied to the curDist lerp target by camUpdate's
|
||||
// fret-row fit guard. 1 = no extra pull-back (the common case); rises
|
||||
// toward FRET_ROW_FIT_BOOST_MAX only when a tight, centred zoom would push
|
||||
// the fret-number row past the bottom edge, then relaxes back to 1.
|
||||
let _fretRowFitBoost = 1;
|
||||
// Last committed lowFretBonus contribution baked into tgtDist
|
||||
// (see candidateDist block — bonus is applied on top of the
|
||||
// hysteresis-gated base).
|
||||
@@ -6248,7 +5925,7 @@
|
||||
scene = new T.Scene();
|
||||
scene.fog = new T.Fog(0x101820, FOG_START * 0.8, FOG_END * 1.2);
|
||||
|
||||
cam = new T.PerspectiveCamera(BASE_VFOV, 1, 0.01, FOG_END * 3);
|
||||
cam = new T.PerspectiveCamera(70, 1, 0.01, FOG_END * 3);
|
||||
|
||||
ambLight = new T.AmbientLight(0xffffff, 0.85);
|
||||
scene.add(ambLight);
|
||||
@@ -14187,81 +13864,13 @@
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// Horizontal-FOV-hold ("Hor+"). Returns the vertical fov (deg) the
|
||||
// camera should use for the given pane aspect. With the bridge off (or
|
||||
// absent), or at/under the start aspect, it returns the base vertical
|
||||
// fov unchanged — an exact no-op, so normal panes render identically to
|
||||
// before. Past the start aspect it lowers the vertical fov to keep the
|
||||
// horizontal cone ~constant, so the neck fills an ultra-wide pane
|
||||
// instead of collapsing into a central sliver. Pure + finite-guarded.
|
||||
function effectiveVfov(aspect, tune) {
|
||||
const base = (tune && Number.isFinite(tune.baseVfov)) ? tune.baseVfov : BASE_VFOV;
|
||||
if (!tune || !tune.enabled || !Number.isFinite(aspect) || aspect <= 0) return base;
|
||||
const start = (Number.isFinite(tune.startAspect) && tune.startAspect > 0)
|
||||
? tune.startAspect : HORPLUS_START_ASPECT;
|
||||
if (aspect <= start) return base;
|
||||
const floor = Number.isFinite(tune.minVfovDeg) ? tune.minVfovDeg : HORPLUS_MIN_VFOV;
|
||||
const DEG = Math.PI / 180;
|
||||
// Held horizontal fov: explicit hfovDeg if given, else the horizontal
|
||||
// cone the base vertical fov produces at the start aspect.
|
||||
const hfov = (Number.isFinite(tune.hfovDeg) && tune.hfovDeg > 0)
|
||||
? tune.hfovDeg * DEG
|
||||
: 2 * Math.atan(Math.tan(base * DEG / 2) * start);
|
||||
// Vertical fov that reproduces that horizontal cone at this aspect.
|
||||
let vfov = 2 * Math.atan(Math.tan(hfov / 2) / aspect) / DEG;
|
||||
const blend = Number.isFinite(tune.blend) ? Math.max(0, Math.min(1, tune.blend)) : 1;
|
||||
vfov = base + (vfov - base) * blend; // 0 = base, 1 = full Hor+
|
||||
if (!Number.isFinite(vfov)) return base;
|
||||
return Math.max(floor, Math.min(base, vfov));
|
||||
}
|
||||
|
||||
/* ── Camera smooth lerp ──────────────────────────────────────────── */
|
||||
function camUpdate(bundle) {
|
||||
const bpm = computeBPM(bundle.beats, bundle.currentTime);
|
||||
const lerp = CAM_LERP_BASE * Math.max(bpm, 60) / 120;
|
||||
|
||||
// ── Horizontal-FOV-hold + optional wide-pane pose nudges ──
|
||||
// Driven by window.__h3dAspectTune (default off → exact no-op).
|
||||
// _aspectTune() returns the live bridge object, seeded from defaults
|
||||
// + localStorage on first read so a persisted tuning session applies
|
||||
// on load without opening the panel. Every field is finite-coerced.
|
||||
// When disabled (or splitOnly and not in a split) the tune is treated
|
||||
// as null, so effectiveVfov returns the base vertical fov and cam.fov
|
||||
// is restored to it. The fov write is guarded on an actual change so
|
||||
// a steady pane costs nothing.
|
||||
const _aspTune = _aspectTune();
|
||||
const _aspActive = !!(_aspTune && _aspTune.enabled
|
||||
&& !(_aspTune.splitOnly && !_ssActive()));
|
||||
const _tune = _aspActive ? _aspTune : null;
|
||||
const _vfov = effectiveVfov(_paneAspect, _tune);
|
||||
if (Number.isFinite(_vfov) && Math.abs(_vfov - cam.fov) > 1e-4) {
|
||||
cam.fov = _vfov;
|
||||
cam.updateProjectionMatrix();
|
||||
}
|
||||
// Publish a live readout for the tuner panel (only while it's open,
|
||||
// so the steady path stays allocation-free). Last pane to render wins
|
||||
// the slot — fine, all panes share the same aspect in a split layout.
|
||||
if (window.__h3dAspectPanelOpen) {
|
||||
const _ro = window.__h3dAspectReadout || (window.__h3dAspectReadout = {});
|
||||
_ro.aspect = _paneAspect; _ro.vfov = _vfov;
|
||||
}
|
||||
// Optional pose nudges (height / dolly / pitch) to chase a low-flat
|
||||
// wide-pane look if fov alone isn't enough. Gated to wide panes and
|
||||
// suppressed while the Camera Director owns the view (it wins).
|
||||
const _startAspect = (_tune && Number.isFinite(_tune.startAspect) && _tune.startAspect > 0)
|
||||
? _tune.startAspect : HORPLUS_START_ASPECT;
|
||||
const _dirActive = !!(window.__h3dCamCtl && window.__h3dCamCtl.enabled);
|
||||
const _wide = !!(_tune && _paneAspect > _startAspect) && !_dirActive;
|
||||
const _poseHMul = (_wide && Number.isFinite(_tune.heightMul)) ? _tune.heightMul : 1;
|
||||
const _poseDMul = (_wide && Number.isFinite(_tune.distMul)) ? _tune.distMul : 1;
|
||||
const _poseLookYAdd = (_wide && Number.isFinite(_tune.pitchAdd)) ? _tune.pitchAdd * K : 0;
|
||||
const _poseLookZMul = (_wide && Number.isFinite(_tune.lookDepthMul) && _tune.lookDepthMul > 0)
|
||||
? _tune.lookDepthMul : 1;
|
||||
|
||||
curX += (tgtX - curX) * lerp;
|
||||
// The fret-row fit guard (end of camUpdate) may dolly the camera back
|
||||
// via _fretRowFitBoost; the span-driven tgtDist still owns zooming IN.
|
||||
curDist += (tgtDist * _fretRowFitBoost - curDist) * lerp;
|
||||
curDist += (tgtDist - curDist) * lerp;
|
||||
const dist = curDist * aspectScale;
|
||||
const h = CAM_H_BASE * (dist / CAM_DIST_BASE);
|
||||
|
||||
@@ -14273,9 +13882,6 @@
|
||||
const _dMul = CAM_FRAME_D_NEAR + (CAM_FRAME_D_FAR - CAM_FRAME_D_NEAR) * _zt;
|
||||
const shoulderOffset = (_leftyCached ? -1 : 1) * 10 * K;
|
||||
let _camX = curX + shoulderOffset, _camY = h * _hMul, _camZ = dist * _dMul;
|
||||
// Optional wide-pane pose nudges (default identity → no-op).
|
||||
if (_poseHMul !== 1) _camY *= _poseHMul;
|
||||
if (_poseDMul !== 1) _camZ *= _poseDMul;
|
||||
// ── Free-camera user tweaks (orbit / height / zoom / pan) ──
|
||||
// Driven by the Camera Director plugin via window.__h3dCamCtl.
|
||||
// Layered ON TOP of the auto-framing so note tracking still works.
|
||||
@@ -14284,7 +13890,7 @@
|
||||
// finite number before use so a malformed object can never feed NaN
|
||||
// into cam.position / cam.lookAt.
|
||||
const _freeCam = window.__h3dCamCtl;
|
||||
const _lookAtZ = -FOCUS_D * 0.35 * _poseLookZMul;
|
||||
const _lookAtZ = -FOCUS_D * 0.35;
|
||||
if (_freeCam && _freeCam.enabled) {
|
||||
const _distMul = Number.isFinite(_freeCam.distMul) ? _freeCam.distMul : 1;
|
||||
const _heightMul = Number.isFinite(_freeCam.heightMul) ? _freeCam.heightMul : 1;
|
||||
@@ -14305,7 +13911,7 @@
|
||||
// This lets the camera adapt to any panel aspect ratio automatically.
|
||||
const fretMidY = (sY(0) + sY(nStr - 1)) / 2;
|
||||
_probe.set(curX, fretMidY, 0); // play-line fretboard centre
|
||||
cam.lookAt(curX, curLookY + _poseLookYAdd, _lookAtZ); // tentative look — needed for project()
|
||||
cam.lookAt(curX, curLookY, -FOCUS_D * 0.35); // tentative look — needed for project()
|
||||
cam.updateMatrixWorld();
|
||||
_probe.project(cam); // _probe.y → NDC in [-1, 1]
|
||||
|
||||
@@ -14334,39 +13940,7 @@
|
||||
const _pitch = Number.isFinite(_freeCam.pitch) ? _freeCam.pitch : 0;
|
||||
cam.lookAt(curX + _panX * K, curLookY + (_pitch + _panY) * K, _lookAtZ);
|
||||
} else {
|
||||
cam.lookAt(curX, curLookY + _poseLookYAdd, _lookAtZ);
|
||||
}
|
||||
|
||||
// ── Fret-row fit guard ────────────────────────────────────────────
|
||||
// Project the fret-number-row band (just below the lowest string, at
|
||||
// the play line) with the final camera. If it sits below the safe
|
||||
// bottom line, dolly back (raise _fretRowFitBoost → applied to the
|
||||
// curDist lerp target next frame) until it clears; relax lazily once
|
||||
// there's comfortable headroom. Asymmetric + deadbanded so it
|
||||
// converges without hunting, and capped so the zoom can't pop. It
|
||||
// cooperates with the tilt loop above rather than fighting it: pulling
|
||||
// back shrinks the scene, the tilt loop keeps the board centre anchored
|
||||
// at DESIRED_NDC_Y, so only the row's bottom headroom changes. Skipped
|
||||
// while the free-cam (Camera Director) owns the view.
|
||||
if (_freeCam && _freeCam.enabled) {
|
||||
if (_fretRowFitBoost !== 1) _fretRowFitBoost = 1;
|
||||
} else {
|
||||
cam.updateMatrixWorld();
|
||||
const _rowY = Math.min(sY(0), sY(nStr - 1)) - S_GAP * 1.4;
|
||||
_probe.set(curX, _rowY, 0.5 * K);
|
||||
_probe.project(cam); // _probe.y → NDC; < -1 = off the bottom
|
||||
const _rowNdcY = _probe.y;
|
||||
if (_rowNdcY < FRET_ROW_FIT_NDC_MIN) {
|
||||
// Row below the safe line → pull back promptly, proportional to
|
||||
// the deficit so it converges in a few frames without overshoot.
|
||||
const _need = FRET_ROW_FIT_NDC_MIN - _rowNdcY;
|
||||
_fretRowFitBoost = Math.min(FRET_ROW_FIT_BOOST_MAX,
|
||||
_fretRowFitBoost + Math.min(0.05, _need * 0.4));
|
||||
} else if (_rowNdcY > FRET_ROW_FIT_NDC_MIN + FRET_ROW_FIT_DEADBAND
|
||||
&& _fretRowFitBoost > 1) {
|
||||
// Comfortable headroom → relax the dolly back toward normal, lazily.
|
||||
_fretRowFitBoost = Math.max(1, _fretRowFitBoost - 0.01);
|
||||
}
|
||||
cam.lookAt(curX, curLookY, _lookAtZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14431,10 +14005,6 @@
|
||||
cam.aspect = w / h;
|
||||
cam.updateProjectionMatrix();
|
||||
aspectScale = Math.max(1, REF_ASPECT / Math.max(cam.aspect, 0.5));
|
||||
// Cache the pane aspect for the horizontal-FOV-hold in camUpdate.
|
||||
// cam.fov itself is owned by camUpdate (not set here) so live
|
||||
// __h3dAspectTune edits apply every frame without a resize.
|
||||
_paneAspect = cam.aspect;
|
||||
_appliedW = w; _appliedH = h;
|
||||
}
|
||||
|
||||
@@ -14628,7 +14198,7 @@
|
||||
pFretColMarker = null;
|
||||
_fretMarkerWaveCache.clear();
|
||||
gNote = gSus = gBeat = gTapChevron = null;
|
||||
tgtX = curX = xFretMid(CAM_LOCK_CENTER_FRET); tgtDist = curDist = CAM_DIST_BASE; tgtLookY = curLookY = 0; _fretRowFitBoost = 1; nStr = NSTR; _oobStringWarned = false;
|
||||
tgtX = curX = xFretMid(CAM_LOCK_CENTER_FRET); tgtDist = curDist = CAM_DIST_BASE; tgtLookY = curLookY = 0; nStr = NSTR; _oobStringWarned = false;
|
||||
_lookaheadCamX = xFretMid(CAM_LOCK_CENTER_FRET);
|
||||
_lookaheadFretSpan = DEFAULT_LOOKAHEAD_FRET_SPAN;
|
||||
_lookaheadCamPrevNow = null;
|
||||
@@ -14678,7 +14248,6 @@
|
||||
}
|
||||
_destroyed = _isReady = false;
|
||||
_isFocused = true;
|
||||
_registerAspectAbShortcut(); // session-global A/B toggle (self-guarded)
|
||||
const myToken = ++_initToken;
|
||||
highwayCanvas = canvas;
|
||||
_invertedCached = !!(bundle && bundle.inverted);
|
||||
@@ -14988,13 +14557,7 @@
|
||||
const _fpsBoxW = Math.ceil(_fpsMetrics.width) + _fpsPadX * 2;
|
||||
const _fpsBoxH = 14 + _fpsPadY * 2;
|
||||
const _fpsE = 8;
|
||||
// Keep it top-right but below the v3 Up Next pill / live HUD
|
||||
// (whichever is showing) so the readout is never occluded.
|
||||
const _fpsBaseY = Math.round(Math.max(
|
||||
_fpsE + H * 0.06,
|
||||
lyricsBottom + _fpsE,
|
||||
_v3TopRightChromeBottom() + _fpsE,
|
||||
));
|
||||
const _fpsBaseY = Math.round(Math.max(_fpsE + H * 0.06, lyricsBottom + _fpsE));
|
||||
const _fpsX = W - 8 - _fpsBoxW;
|
||||
const _fpsY = _fpsBaseY + cornerStack['tr'];
|
||||
lyricsCtx.fillStyle = 'rgba(0,0,0,0.55)';
|
||||
@@ -15097,8 +14660,6 @@
|
||||
_destroyed = true; _isReady = false; _diagChord = null; _diagPrev = null; _diagLastKey = null; _diagRenderCache.clear();
|
||||
_lastHwW = 0; _lastHwH = 0;
|
||||
_appliedW = 0; _appliedH = 0;
|
||||
_paneAspect = 0;
|
||||
if (cam && cam.fov !== BASE_VFOV) { cam.fov = BASE_VFOV; cam.updateProjectionMatrix(); }
|
||||
_wrapPinned = false;
|
||||
_unsubscribeFocus(); teardown();
|
||||
highwayCanvas = null;
|
||||
|
||||
@@ -51,16 +51,15 @@
|
||||
sources = sources.filter((s) => s
|
||||
&& !/midi/i.test(String(s.providerId || ''))
|
||||
&& !/^midi-input/i.test(String(s.label || '')));
|
||||
// No label de-dupe here. The audio-input capability already
|
||||
// collapses exact duplicates by logicalSourceKey
|
||||
// (_visibleInputSources), so nothing it returns shares a key. A
|
||||
// device that enumerates under several driver types (ASIO / Windows
|
||||
// Audio / DirectSound) has a DISTINCT key per type and is now
|
||||
// labelled with its driver type (e.g. "Focusrite (ASIO)") — each is
|
||||
// a real, separately-selectable input the user must be able to see.
|
||||
// The old bare-label collapse also kept whichever variant sorted
|
||||
// first, which could silently drop the one that was actually
|
||||
// `selected` below.
|
||||
// De-dupe by display label — the desktop engine enumerates the same
|
||||
// device under several driver types, so the same name can repeat.
|
||||
const seen = new Set();
|
||||
sources = sources.filter((s) => {
|
||||
const key = String(s.label || '').toLowerCase();
|
||||
if (seen.has(key)) return false;
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
const selected = sources.find((s) => s && s.selected) || null;
|
||||
return { sources, selected };
|
||||
} catch (_) { return { sources: [], selected: null }; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "tuner",
|
||||
"name": "Guitar/Bass Tuner",
|
||||
"version": "1.3.2",
|
||||
"version": "1.3.1",
|
||||
"bundled": true,
|
||||
"private": false,
|
||||
"script": "screen.js",
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
// ── Constants ─────────────────────────────────────────────────────
|
||||
var _TUNER_LABEL_H = 12; // px height of each drum label
|
||||
var _TUNER_NEEDLE_HALF_SWEEP = 90; // degrees — ±50 cents = horizontal (180° apart)
|
||||
var _SETTLE_A = 0.05; // deg — needle "settled" threshold (sub-visible)
|
||||
var _SETTLE_Y = 0.1; // px — drum-strip "settled" threshold
|
||||
var _TUNER_IN_TUNE_THRESHOLD = 2;
|
||||
var _TUNER_STRIP_START_MIDI = 14; // ~18 Hz — covers 20 Hz minimum
|
||||
var _TUNER_STRIP_END_MIDI = 84; // ~1047 Hz C6
|
||||
@@ -323,34 +321,9 @@
|
||||
currentAngle += (targetAngle - currentAngle) * lf;
|
||||
_setNeedle(currentAngle);
|
||||
|
||||
// Stop once the needle has settled on its target — a static needle
|
||||
// needs no repaint. update() re-kicks the loop when a new reading
|
||||
// moves the target, so this idles the always-on tuner (no signal /
|
||||
// steady pitch) instead of pinning a core at 60 fps forever.
|
||||
if (Math.abs(targetDrumY - currentDrumY) <= _SETTLE_Y
|
||||
&& Math.abs(targetAngle - currentAngle) <= _SETTLE_A) {
|
||||
currentDrumY = targetDrumY; currentAngle = targetAngle;
|
||||
freqStrip.style.transform = 'translateY(' + currentDrumY + 'px)';
|
||||
noteStrip.style.transform = 'translateY(' + currentDrumY + 'px)';
|
||||
_setNeedle(currentAngle);
|
||||
rafId = null;
|
||||
return;
|
||||
}
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
|
||||
// Restart the loop only when there's actually something to animate toward
|
||||
// (a new target). Reset lastTime so the first frame after an idle gap
|
||||
// doesn't take one big easing step.
|
||||
function _kick() {
|
||||
if (rafId === null
|
||||
&& (Math.abs(targetDrumY - currentDrumY) > _SETTLE_Y
|
||||
|| Math.abs(targetAngle - currentAngle) > _SETTLE_A)) {
|
||||
lastTime = performance.now();
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
|
||||
// ── Public API ────────────────────────────────────────────────
|
||||
@@ -387,7 +360,6 @@
|
||||
bulbEl.style.backgroundColor = '#2a1010';
|
||||
bulbEl.style.border = '2px solid #4a2020';
|
||||
bulbEl.style.boxShadow = 'none';
|
||||
_kick(); // animate back to rest, then the loop self-stops
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -404,7 +376,6 @@
|
||||
bulbEl.style.border = '2px solid #4a2020';
|
||||
bulbEl.style.boxShadow = 'none';
|
||||
}
|
||||
_kick(); // a new reading moved the target → run until it settles
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
|
||||
@@ -620,20 +620,8 @@
|
||||
if (_mt3Mode === 'strobe') { _computeStrobeStates(); }
|
||||
|
||||
_applyTickStates();
|
||||
|
||||
// No signal and both the glow and strobe drift have fully settled →
|
||||
// idle the loop. update() re-kicks it on the next note.
|
||||
if (!_mt3HasSignal && _mt3GlowOpacity < 0.004
|
||||
&& Math.abs(_mt3SmoothedCents) <= 0.1) {
|
||||
_mt3RafId = null;
|
||||
_mt3LastTime = null;
|
||||
return;
|
||||
}
|
||||
_mt3RafId = requestAnimationFrame(_animateStrobe);
|
||||
}
|
||||
function _kick() {
|
||||
if (_mt3RafId === null) { _mt3LastTime = null; _mt3RafId = requestAnimationFrame(_animateStrobe); }
|
||||
}
|
||||
_mt3RafId = requestAnimationFrame(_animateStrobe);
|
||||
|
||||
// ── MODE button ───────────────────────────────────────────────
|
||||
@@ -689,7 +677,6 @@
|
||||
_renderNote(' ');
|
||||
_applyAccidental();
|
||||
}
|
||||
if (hasNote) { _kick(); } // new signal → restart the strobe loop if idled
|
||||
}
|
||||
|
||||
// ── Public: destroy ───────────────────────────────────────────
|
||||
|
||||
@@ -354,19 +354,10 @@
|
||||
if (_smoothedCents > 0) { speed = -speed; }
|
||||
_strobeOffset = ((_strobeOffset + speed * dt) % _totalDash + _totalDash) % _totalDash;
|
||||
arcPath.setAttribute('stroke-dashoffset', String(_strobeOffset));
|
||||
} else if (_currentCents === 0) {
|
||||
// Fully decelerated and no live signal → idle the loop instead of
|
||||
// rescheduling forever. update() re-kicks it on the next note.
|
||||
_rafId = null;
|
||||
_lastTime = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_rafId = requestAnimationFrame(_animateStrobe);
|
||||
}
|
||||
function _kick() {
|
||||
if (_rafId === null) { _lastTime = null; _rafId = requestAnimationFrame(_animateStrobe); }
|
||||
}
|
||||
_rafId = requestAnimationFrame(_animateStrobe);
|
||||
|
||||
// ── Helper: derive octave number from frequency ───────────────
|
||||
@@ -448,7 +439,6 @@
|
||||
|
||||
// Strobe state — smoothed animation decelerates naturally when _currentCents → 0
|
||||
_currentCents = hasNote ? cents : 0;
|
||||
if (hasNote) { _kick(); } // new signal → restart the decel loop if idled
|
||||
}
|
||||
|
||||
// ── Public: destroy ───────────────────────────────────────────
|
||||
|
||||
@@ -142,20 +142,9 @@ window._tunerViz_strobe = function (container) {
|
||||
strobeEl.style.opacity = '0';
|
||||
}
|
||||
|
||||
// Idle the loop when there's no live signal — the strobe only needs to
|
||||
// paint while a note is sounding. update() re-kicks it on the next note,
|
||||
// so a silent tuner stops repainting instead of spinning at 60 fps.
|
||||
if (!strobeActive) { rafId = null; return; }
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
|
||||
function _kick() {
|
||||
if (rafId === null) {
|
||||
lastAnimateTime = performance.now();
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
}
|
||||
|
||||
rafId = requestAnimationFrame(_animate);
|
||||
|
||||
// ── Public API ────────────────────────────────────────────────────
|
||||
@@ -199,7 +188,6 @@ window._tunerViz_strobe = function (container) {
|
||||
const inTune = Math.abs(cents) < 5;
|
||||
strobeEl.style.opacity = inTune ? '1' : '0.6';
|
||||
strobeEl.style.filter = inTune ? _STROBE_GLOW_IN_TUNE : _STROBE_GLOW_OUT;
|
||||
_kick();
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
|
||||
@@ -122,26 +122,6 @@
|
||||
plungerEl.style.left = _leftPct.toFixed(2) + '%';
|
||||
plungerEl.style.top = _topPct.toFixed(2) + '%';
|
||||
|
||||
// No live signal and the plunger has eased back to its resting centre
|
||||
// → idle the loop. update() re-kicks it on the next note.
|
||||
if (_currentNote === null && !_plungerDipped
|
||||
&& Math.abs(targetLeft - _leftPct) < 0.05) {
|
||||
_leftPct = targetLeft;
|
||||
plungerEl.style.left = _leftPct.toFixed(2) + '%';
|
||||
_rafId = null;
|
||||
_lastTime = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
|
||||
function _kick() {
|
||||
if (_rafId !== null) return;
|
||||
// Already parked at rest with no signal → nothing to animate, stay idle.
|
||||
if (_currentNote === null && !_plungerDipped
|
||||
&& Math.abs(_TUNER_TT_CENTRE_PCT - _leftPct) < 0.05) return;
|
||||
_lastTime = null;
|
||||
_rafId = requestAnimationFrame(_animate);
|
||||
}
|
||||
|
||||
@@ -150,7 +130,6 @@
|
||||
_currentNote = note;
|
||||
_currentCents = note === null ? 0 : cents;
|
||||
if (!_plungerDipped) { noteEl.textContent = note || '–'; }
|
||||
_kick(); // a new reading may move the plunger → ensure the loop runs
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
|
||||
+2
-156
@@ -5993,45 +5993,11 @@ let _pendingAutostart = false;
|
||||
window.feedBack.on('song:ready', () => {
|
||||
if (!_pendingAutostart) return;
|
||||
_pendingAutostart = false;
|
||||
if (isPlaying) return;
|
||||
// Feedpak contributor credits: only real feedpak plays carry authors
|
||||
// (loose/archive and minigames get []), so a non-empty list is the gate.
|
||||
// Shown over the highway and dismissed the moment real playback begins
|
||||
// (song:play). This fresh-load path is the only place it fires —
|
||||
// arrangement switches / seeks / manual replays never arm _pendingAutostart,
|
||||
// and minigames never get here. Decoupled from autoplay below so credits
|
||||
// show on load even when autoplay-exit is disabled.
|
||||
const authors = (window.feedBack.currentSong && window.feedBack.currentSong.authors) || [];
|
||||
if (authors.length) {
|
||||
showSongCreditsOverlay(authors);
|
||||
_creditsHideOnPlay = () => { _creditsHideOnPlay = null; hideSongCreditsOverlay(); };
|
||||
window.feedBack.on('song:play', _creditsHideOnPlay, { once: true });
|
||||
}
|
||||
// Autoplay-exit disabled: don't auto-start. Still let the credits dwell a
|
||||
// couple seconds on the freshly-loaded song, then clear them (they also
|
||||
// clear early if the user manually presses Play, via _creditsHideOnPlay).
|
||||
if (!_autoplayExitEnabled()) {
|
||||
if (authors.length) _creditsTimer = setTimeout(hideSongCreditsOverlay, _CREDITS_HOLD_MS);
|
||||
return;
|
||||
}
|
||||
if (!_autoplayExitEnabled() || isPlaying) return;
|
||||
// "Countdown before song": play a 4-beat count-in, then start. Otherwise
|
||||
// reuse the Play button's start path directly (handles HTML5 + _juceMode).
|
||||
if (_countdownBeforeSongEnabled()) {
|
||||
// The count-in (~2.5s) gives the credits their on-screen dwell.
|
||||
Promise.resolve(startSongCountIn()).catch((err) => console.warn('[app] song count-in failed:', err));
|
||||
} else if (authors.length) {
|
||||
// No count-in window — hold the credits a couple seconds, then start.
|
||||
// _cancelCountIn() and changeArrangement() both clear _creditsTimer, so
|
||||
// a teardown / arrangement switch during the hold cancels this play.
|
||||
_creditsTimer = setTimeout(() => {
|
||||
_creditsTimer = null;
|
||||
// If playback doesn't actually start (e.g. HTML5 autoplay rejection),
|
||||
// song:play never fires — clear the credits promptly rather than
|
||||
// waiting for the backstop. On success the song:play listener owns it.
|
||||
Promise.resolve(togglePlay())
|
||||
.then(() => { if (!isPlaying) hideSongCreditsOverlay(); })
|
||||
.catch((err) => { console.warn('[app] autoplay failed:', err); hideSongCreditsOverlay(); });
|
||||
}, _CREDITS_HOLD_MS);
|
||||
} else {
|
||||
Promise.resolve(togglePlay()).catch((err) => console.warn('[app] autoplay failed:', err));
|
||||
}
|
||||
@@ -6429,11 +6395,6 @@ let _arrBusyTimeout = null;
|
||||
|
||||
async function changeArrangement(index) {
|
||||
if (currentFilename) {
|
||||
// Tear down any pending fresh-load credits before switching: the
|
||||
// no-count-in hold timer would otherwise fire togglePlay() against the
|
||||
// incoming (still-loading) arrangement. hideSongCreditsOverlay() clears
|
||||
// the timer, the song:play listener, and the overlay node.
|
||||
hideSongCreditsOverlay();
|
||||
window.feedBack.emit('song:arrangement-changed', { filename: currentFilename, arrangement: index });
|
||||
const wasPlaying = isPlaying;
|
||||
const time = _audioTime();
|
||||
@@ -8714,24 +8675,12 @@ function _installSectionPracticeDismiss() {
|
||||
// inside #section-practice-control so it never self-closes. Listeners added
|
||||
// mid-dispatch don't fire for the opening click, so there's no immediate
|
||||
// close race.
|
||||
//
|
||||
// The click listener uses the CAPTURE phase: the v3 player rail's icon
|
||||
// buttons call e.stopPropagation() in their click handler (player-chrome.js
|
||||
// wireRail), which kills bubbling before it reaches document. A bubble-phase
|
||||
// outside-click dismiss would therefore never fire when the user clicks a
|
||||
// rail icon (Plugins, Audio, …) to open another popover, leaving this
|
||||
// popover stranded open on top of it. Capture runs before the target's
|
||||
// handler, so the stopPropagation can't swallow it. This mirrors the audio
|
||||
// mixer popover (audio-mixer.js), which dismisses outside-clicks the same
|
||||
// way. (Esc stays bubble-phase — no rail handler stops keydown propagation,
|
||||
// so it already reaches us, and capturing it would reorder it ahead of the
|
||||
// player's Escape-to-exit handling.)
|
||||
document.addEventListener('click', (e) => {
|
||||
if (!_sectionPracticePopoverOpen()) return;
|
||||
const ctrl = document.getElementById('section-practice-control');
|
||||
if (ctrl && ctrl.contains(e.target)) return;
|
||||
_closeSectionPracticePopover();
|
||||
}, true);
|
||||
});
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && _sectionPracticePopoverOpen()) _closeSectionPracticePopover();
|
||||
});
|
||||
@@ -9336,27 +9285,10 @@ let _countOverlay = null;
|
||||
let _countInGen = 0;
|
||||
let _countInTimer = null;
|
||||
let _countInRaf = 0;
|
||||
// Feedpak credits overlay (manifest `authors:`, spec §5.4): shown on the
|
||||
// highway when a song is loaded, alongside the count-in. Torn down together
|
||||
// with the count-in via _cancelCountIn().
|
||||
let _creditsOverlay = null;
|
||||
let _creditsTimer = null;
|
||||
let _creditsHideOnPlay = null;
|
||||
let _creditsMaxTimer = null;
|
||||
const _CREDITS_HOLD_MS = 3000;
|
||||
// Backstop: the overlay's primary dismiss is song:play, but playback can fail
|
||||
// to start without emitting it (HTML5 autoplay rejection, JUCE start failure,
|
||||
// a count-in handoff that never plays). This hard cap guarantees the credits
|
||||
// never linger over the highway. Generous enough to outlast a normal count-in.
|
||||
const _CREDITS_MAX_MS = 12000;
|
||||
function _cancelCountIn() {
|
||||
_countInGen++;
|
||||
_countingIn = false;
|
||||
hideCountOverlay();
|
||||
// The credits overlay rides the count-in lifecycle (and its no-count-in
|
||||
// hold timer), so a teardown — leaving the player, loading another song —
|
||||
// must clear it too, or it lingers on the next screen.
|
||||
hideSongCreditsOverlay();
|
||||
if (_countInTimer) { clearTimeout(_countInTimer); _countInTimer = null; }
|
||||
if (_countInRaf) { cancelAnimationFrame(_countInRaf); _countInRaf = 0; }
|
||||
}
|
||||
@@ -9374,92 +9306,6 @@ function hideCountOverlay() {
|
||||
if (_countOverlay) { _countOverlay.remove(); _countOverlay = null; }
|
||||
}
|
||||
|
||||
// Map a feedpak author `role` to a friendly "<verb> by" credit line. The
|
||||
// recommended vocabulary is from feedpak spec §5.4; unknown roles are
|
||||
// title-cased ("foo" → "Foo by"); a missing role shows the bare name.
|
||||
const _CREDIT_ROLE_VERBS = {
|
||||
charter: 'Charted by',
|
||||
transcriber: 'Transcribed by',
|
||||
arranger: 'Arranged by',
|
||||
editor: 'Edited by',
|
||||
mixer: 'Mixed by',
|
||||
engineer: 'Engineered by',
|
||||
proofreader: 'Proofread by',
|
||||
};
|
||||
|
||||
function _creditLineLabel(role) {
|
||||
if (!role) return '';
|
||||
const key = String(role).trim().toLowerCase();
|
||||
if (_CREDIT_ROLE_VERBS[key]) return _CREDIT_ROLE_VERBS[key];
|
||||
return key.charAt(0).toUpperCase() + key.slice(1) + ' by';
|
||||
}
|
||||
|
||||
// Show the feedpak contributor credits over the highway. `authors` is the
|
||||
// sanitized [{name, role}] list from window.feedBack.currentSong.authors.
|
||||
// Anchored to the lower third (bottom-center) so it never collides with the
|
||||
// vertically-centered count-in number, and pointer-events-none so it never
|
||||
// intercepts clicks. No-op when there are no contributors to show.
|
||||
function showSongCreditsOverlay(authors) {
|
||||
if (!Array.isArray(authors) || authors.length === 0) return;
|
||||
if (!_creditsOverlay) {
|
||||
_creditsOverlay = document.createElement('div');
|
||||
_creditsOverlay.className = 'song-credits-overlay';
|
||||
document.body.appendChild(_creditsOverlay);
|
||||
}
|
||||
// Build via DOM + textContent — author names are untrusted pack data and
|
||||
// must never be interpolated as HTML.
|
||||
_creditsOverlay.replaceChildren();
|
||||
const card = document.createElement('div');
|
||||
card.className = 'song-credits-card';
|
||||
|
||||
const eyebrow = document.createElement('div');
|
||||
eyebrow.className = 'song-credits-eyebrow';
|
||||
eyebrow.textContent = 'Credits';
|
||||
card.appendChild(eyebrow);
|
||||
|
||||
const title = (window.feedBack && window.feedBack.currentSong
|
||||
&& window.feedBack.currentSong.title) || '';
|
||||
if (title) {
|
||||
const heading = document.createElement('div');
|
||||
heading.className = 'song-credits-heading';
|
||||
heading.textContent = title;
|
||||
card.appendChild(heading);
|
||||
}
|
||||
|
||||
for (const a of authors) {
|
||||
if (!a || !a.name) continue;
|
||||
const row = document.createElement('div');
|
||||
row.className = 'song-credits-line';
|
||||
const label = _creditLineLabel(a.role);
|
||||
if (label) {
|
||||
const lab = document.createElement('span');
|
||||
lab.className = 'song-credits-role';
|
||||
lab.textContent = label + ' ';
|
||||
row.appendChild(lab);
|
||||
}
|
||||
const nm = document.createElement('span');
|
||||
nm.className = 'song-credits-name';
|
||||
nm.textContent = a.name;
|
||||
row.appendChild(nm);
|
||||
card.appendChild(row);
|
||||
}
|
||||
_creditsOverlay.appendChild(card);
|
||||
// Arm the backstop so the overlay self-clears even if playback never starts
|
||||
// / never emits song:play. song:play (or any teardown) clears it earlier.
|
||||
if (_creditsMaxTimer) clearTimeout(_creditsMaxTimer);
|
||||
_creditsMaxTimer = setTimeout(hideSongCreditsOverlay, _CREDITS_MAX_MS);
|
||||
}
|
||||
|
||||
function hideSongCreditsOverlay() {
|
||||
if (_creditsTimer) { clearTimeout(_creditsTimer); _creditsTimer = null; }
|
||||
if (_creditsMaxTimer) { clearTimeout(_creditsMaxTimer); _creditsMaxTimer = null; }
|
||||
if (_creditsHideOnPlay) {
|
||||
window.feedBack.off('song:play', _creditsHideOnPlay);
|
||||
_creditsHideOnPlay = null;
|
||||
}
|
||||
if (_creditsOverlay) { _creditsOverlay.remove(); _creditsOverlay = null; }
|
||||
}
|
||||
|
||||
async function startCountIn(opts = {}) {
|
||||
if (_countingIn) return;
|
||||
_countingIn = true;
|
||||
|
||||
@@ -3530,13 +3530,6 @@ function createHighway() {
|
||||
// matchesArrangement on this rather than the
|
||||
// arrangement name.
|
||||
hasNotation: Boolean(msg.has_notation),
|
||||
// Feedpak contributor credits (manifest
|
||||
// `authors:`, spec §5.4): [{name, role}].
|
||||
// Only real feedpak plays carry these; loose/
|
||||
// archive sources and synthetic highway uses
|
||||
// (minigames) get []. app.js shows a credits
|
||||
// overlay on song load when this is non-empty.
|
||||
authors: Array.isArray(msg.authors) ? msg.authors : [],
|
||||
};
|
||||
window.feedBack.emit('song:loaded', window.feedBack.currentSong);
|
||||
}
|
||||
|
||||
@@ -863,93 +863,3 @@ html { scroll-behavior: smooth; }
|
||||
box-shadow: 0 0 0 2px rgba(64, 128, 224, 0.7);
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
/* Feedpak contributor credits shown over the highway when a song loads
|
||||
(manifest `authors:`, spec §5.4). Anchored to the upper third so it sits
|
||||
ABOVE the vertically-centered count-in number; click-through. */
|
||||
.song-credits-overlay {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 15%;
|
||||
/* Above the modal layer (z-[200], incl. the "Loading audio" backdrop) and
|
||||
the count-in number (z-[100]) so the credits stay prominent through the
|
||||
whole load → count-in → play window. */
|
||||
z-index: 205;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
animation: song-credits-fade-in 0.45s cubic-bezier(0.16, 1, 0.3, 1);
|
||||
}
|
||||
|
||||
.song-credits-card {
|
||||
position: relative;
|
||||
min-width: 16rem;
|
||||
max-width: min(90vw, 34rem);
|
||||
padding: 1.4rem 2.5rem 1.5rem;
|
||||
text-align: center;
|
||||
background:
|
||||
radial-gradient(120% 140% at 50% 0%, rgb(56 78 130 / 0.45) 0%, transparent 60%),
|
||||
linear-gradient(165deg, rgb(23 30 48 / 0.92) 0%, rgb(11 15 26 / 0.94) 100%);
|
||||
border: 1px solid rgb(129 140 248 / 0.28);
|
||||
border-radius: 1rem;
|
||||
box-shadow:
|
||||
0 18px 50px rgb(0 0 0 / 0.55),
|
||||
0 0 0 1px rgb(0 0 0 / 0.35),
|
||||
inset 0 1px 0 rgb(255 255 255 / 0.07);
|
||||
backdrop-filter: blur(10px);
|
||||
-webkit-backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
/* Accent bar across the top edge of the card. */
|
||||
.song-credits-card::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 3.25rem;
|
||||
height: 3px;
|
||||
border-radius: 0 0 3px 3px;
|
||||
background: linear-gradient(90deg, #38bdf8, #818cf8);
|
||||
box-shadow: 0 0 12px rgb(99 102 241 / 0.7);
|
||||
}
|
||||
|
||||
.song-credits-eyebrow {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.22em;
|
||||
text-transform: uppercase;
|
||||
color: rgb(165 180 252 / 0.9);
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
|
||||
.song-credits-heading {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 800;
|
||||
color: #f8fafc;
|
||||
margin-bottom: 0.7rem;
|
||||
letter-spacing: 0.01em;
|
||||
text-shadow: 0 1px 8px rgb(0 0 0 / 0.5);
|
||||
}
|
||||
|
||||
.song-credits-line {
|
||||
font-size: 1.1rem;
|
||||
line-height: 1.55;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.song-credits-role {
|
||||
color: rgb(148 163 184 / 0.95);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.song-credits-name {
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
@keyframes song-credits-fade-in {
|
||||
from { opacity: 0; transform: translateY(-12px) scale(0.97); }
|
||||
to { opacity: 1; transform: translateY(0) scale(1); }
|
||||
}
|
||||
|
||||
+5
-26
@@ -343,10 +343,7 @@
|
||||
|
||||
<!-- ══ SETTINGS ═══════════════════════════════════════════════════════ -->
|
||||
<div id="settings" class="screen">
|
||||
<!-- fb-selectable: Settings is read-only content (paths, device names,
|
||||
version, diagnostics, About) the user copies — opt the whole panel
|
||||
back in under the v3 non-select default. See static/v3/v3.css. -->
|
||||
<div class="fb-settings fb-selectable">
|
||||
<div class="fb-settings">
|
||||
<button onclick="showScreen('home')" class="fb-settings-back">
|
||||
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg> Home
|
||||
</button>
|
||||
@@ -828,13 +825,7 @@
|
||||
|
||||
<!-- Top HUD — persistent (song info, time, Up Next) -->
|
||||
<div id="player-hud" class="absolute top-0 left-0 right-0 flex justify-between items-start px-5 py-4 pointer-events-none z-20">
|
||||
<!-- fb-selectable: now-playing song metadata (title / artist /
|
||||
arrangement / tuning) is copy-worthy content, not chrome.
|
||||
pointer-events-auto: the #player-hud parent is pointer-events-none
|
||||
(so the HUD doesn't eat clicks meant for the highway), which would
|
||||
also block the mouse from reaching this text to select it — opt
|
||||
just this block back into hit-testing. -->
|
||||
<div class="text-sm leading-tight fb-selectable pointer-events-auto">
|
||||
<div class="text-sm leading-tight">
|
||||
<div><span id="hud-artist" class="text-gray-300"></span> — <span id="hud-title" class="text-white font-semibold"></span></div>
|
||||
<div id="hud-arrangement" class="text-gray-500 text-xs mt-0.5"></div>
|
||||
<div id="hud-tuning" class="text-gray-500 text-xs mt-0.5"></div>
|
||||
@@ -855,12 +846,9 @@
|
||||
<div id="v3-live-performance-state" class="v3-live-performance-state" aria-hidden="true"></div>
|
||||
</div>
|
||||
<div id="v3-upnext" class="v3-upnext hidden">
|
||||
<div class="v3-upnext-row">
|
||||
<span class="text-gray-400">Up Next:</span>
|
||||
<span id="v3-upnext-name" class="v3-upnext-name"></span>
|
||||
<span id="v3-upnext-eta" class="text-gray-400 text-xs"></span>
|
||||
</div>
|
||||
<div class="v3-upnext-bar"><div id="v3-upnext-bar-fill" class="v3-upnext-bar-fill"></div></div>
|
||||
<span class="text-gray-400">Up Next:</span>
|
||||
<span id="v3-upnext-name" class="v3-upnext-name"></span>
|
||||
<span id="v3-upnext-eta" class="text-gray-400 text-xs"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -926,15 +914,6 @@
|
||||
<option value="0.5">Low</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="v3-pop-row">
|
||||
<span class="v3-pop-label" id="min-scale-label">Min res</span>
|
||||
<select id="min-scale-select" onchange="highway.setMinRenderScale && highway.setMinRenderScale(parseFloat(this.value))" class="v3-pop-select" aria-labelledby="min-scale-label" title="Minimum auto resolution — how far the highway may lower its resolution to hold the frame rate on heavy scenes. 'Full' disables auto-downscaling, but the Quality selector still caps the maximum (so it's only full resolution at Quality = HD).">
|
||||
<option value="0.25">25%</option>
|
||||
<option value="0.5">50%</option>
|
||||
<option value="0.75">75%</option>
|
||||
<option value="1">Full</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="v3-pop-row">
|
||||
<span class="v3-pop-label" id="scoreboard-label">Scoreboard</span>
|
||||
<select id="scoreboard-select" onchange="setScoreboard(this.value)" class="v3-pop-select" aria-labelledby="scoreboard-label" title="Highway scoreboard">
|
||||
|
||||
@@ -187,19 +187,6 @@
|
||||
const nm = $('v3-upnext-name'), eta = $('v3-upnext-eta');
|
||||
if (nm) nm.textContent = next.name || '—';
|
||||
if (eta) eta.textContent = 'in ' + dt.toFixed(1) + 's';
|
||||
// Progress bar: fraction of the current section elapsed toward `next`.
|
||||
// Previous boundary is the last section at/before now (else song start).
|
||||
const fill = $('v3-upnext-bar-fill');
|
||||
if (fill) {
|
||||
let prevT = 0;
|
||||
for (let i = 0; i < secs.length; i++) {
|
||||
if (typeof secs[i].time === 'number' && secs[i].time <= t) prevT = secs[i].time;
|
||||
else break;
|
||||
}
|
||||
const span = next.time - prevT;
|
||||
const prog = span > 0 ? Math.max(0, Math.min(1, (t - prevT) / span)) : 0;
|
||||
fill.style.width = (prog * 100).toFixed(1) + '%';
|
||||
}
|
||||
pill.classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
||||
+10
-48
@@ -330,16 +330,9 @@
|
||||
const editing = !!opts.editing;
|
||||
document.getElementById('v3-onboarding')?.remove();
|
||||
|
||||
// The amp-sim opt-in step (step 5) only exists in the desktop app — the
|
||||
// pure-web build has no native amp sims to monitor through, so the step
|
||||
// is skipped there (calibration is the last step at index 5 on web, 6 on
|
||||
// desktop). See feedBack-desktop#46.
|
||||
const isDesktop = !!window.feedBackDesktop;
|
||||
const lastStep = isDesktop ? 6 : 5;
|
||||
|
||||
const stepDots = editing ? '' :
|
||||
'<div class="flex justify-center gap-1.5 mt-3" id="v3-ob-dots">' +
|
||||
Array.from({ length: lastStep }, (_, i) => i + 1).map((n) => '<span data-dot="' + n + '" class="w-2 h-2 rounded-full bg-fb-border"></span>').join('') +
|
||||
[1, 2, 3, 4, 5].map((n) => '<span data-dot="' + n + '" class="w-2 h-2 rounded-full bg-fb-border"></span>').join('') +
|
||||
'</div>';
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
@@ -387,20 +380,8 @@
|
||||
'<label class="block text-xs uppercase tracking-wider text-fb-textDim mb-2">Pick your instrument path(s)</label>' +
|
||||
'<p class="text-sm text-fb-textDim mb-3">Each path levels up by completing challenges — together they make up your Mastery Rank. You can add more later.</p>' +
|
||||
'<div id="v3-ob-paths" class="grid grid-cols-3 gap-2"></div></div>' +
|
||||
// Step 5 — amp-sim opt-in (DESKTOP ONLY; default OFF / own-rig first).
|
||||
// Hidden div is always present in the DOM; setStep only navigates to
|
||||
// it on desktop. See feedBack-desktop#46.
|
||||
// Step 5 — calibration offer (first-run only).
|
||||
'<div id="v3-ob-step5" class="hidden">' +
|
||||
'<label class="block text-xs uppercase tracking-wider text-fb-textDim mb-2">How do you want to hear yourself?</label>' +
|
||||
'<p class="text-sm text-fb-textDim mb-3">fee[dB]ack can run your guitar through built-in <span class="text-fb-text">amp simulations</span> (NAM / IRs / plugins) so you hear a processed tone. If you already play through your <span class="text-fb-text">own amp or rig</span>, leave this off — you’ll get clean, silent monitoring and never an idle buzz.</p>' +
|
||||
'<label class="flex items-start gap-3 cursor-pointer rounded-lg border border-fb-border/50 bg-fb-bg/40 p-3">' +
|
||||
'<input type="checkbox" id="v3-ob-ampsims" class="mt-1 h-4 w-4 rounded border-gray-600 bg-gray-800 text-fb-primary focus:ring-fb-primary">' +
|
||||
'<span class="text-sm text-fb-text">Use in-app amp simulations' +
|
||||
'<span class="block text-xs text-fb-textDim mt-1">Loads your saved tone chain for monitoring. You can change this any time in the desktop Audio settings.</span></span>' +
|
||||
'</label>' +
|
||||
'<p class="text-xs text-fb-textDim mt-2">Leave it unticked if you monitor through your own gear. This is off by default.</p></div>' +
|
||||
// Step 6 — calibration offer (first-run only).
|
||||
'<div id="v3-ob-step6" class="hidden">' +
|
||||
'<label class="block text-xs uppercase tracking-wider text-fb-textDim mb-2">Calibration challenge</label>' +
|
||||
'<p class="text-sm text-fb-textDim">Prove your setup: play the <span class="text-fb-text">fee[dB]ack Diagnostic</span> with note detection and finish at <span class="text-fb-text font-semibold">100% accuracy</span> to reach <span class="text-fb-text font-semibold">Mastery Rank 1</span>.</p>' +
|
||||
'<p class="text-sm text-fb-textDim mt-2">Not ready? Skip it and you’ll start at Rank 1 anyway — you can still play it later from the Progress screen.</p></div>' +
|
||||
@@ -460,7 +441,7 @@
|
||||
function setStep(n) {
|
||||
step = n;
|
||||
errEl.classList.add('hidden');
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
overlay.querySelector('#v3-ob-step' + i).classList.toggle('hidden', i !== n);
|
||||
}
|
||||
overlay.querySelectorAll('#v3-ob-dots [data-dot]').forEach((d) => {
|
||||
@@ -473,13 +454,12 @@
|
||||
: n === 2 ? 'Point us at your songs'
|
||||
: n === 3 ? 'Feats of Power (optional)'
|
||||
: n === 4 ? 'Choose your instrument paths'
|
||||
: n === 5 ? 'How do you want to monitor?'
|
||||
: 'One last thing — calibrate your setup';
|
||||
}
|
||||
submit.textContent = n === 6 ? 'Play it now' : 'Next';
|
||||
submit.textContent = n === 5 ? 'Play it now' : 'Next';
|
||||
// Skip is offered on the song-directory step (configure later) and
|
||||
// the calibration challenge (the last step).
|
||||
skipBtn.classList.toggle('hidden', !(n === 2 || n === 6));
|
||||
// the calibration challenge.
|
||||
skipBtn.classList.toggle('hidden', !(n === 2 || n === 5));
|
||||
refreshSubmit();
|
||||
}
|
||||
|
||||
@@ -715,29 +695,11 @@
|
||||
// New step: input-device selection + calibration, between
|
||||
// path selection and the note-detect calibration challenge.
|
||||
await runInputSetup(selectedPaths);
|
||||
setStep(isDesktop ? 5 : 6);
|
||||
setStep(5);
|
||||
} catch (e) { showErr(e.message || 'Could not save profile.'); refreshSubmit(); }
|
||||
return;
|
||||
}
|
||||
if (step === 5) {
|
||||
// Step 5 (desktop only) — persist the amp-sim opt-in (default OFF
|
||||
// / own-rig). Best-effort: a failed write must not block onboarding;
|
||||
// it's settable later from the desktop Audio settings.
|
||||
submit.disabled = true;
|
||||
try {
|
||||
const ampEl = overlay.querySelector('#v3-ob-ampsims');
|
||||
const useAmpSims = !!(ampEl && ampEl.checked);
|
||||
try {
|
||||
await fetch('/api/settings', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ use_amp_sims: useAmpSims }),
|
||||
});
|
||||
} catch (e) { /* best-effort — settable later */ }
|
||||
setStep(6);
|
||||
} finally { refreshSubmit(); }
|
||||
return;
|
||||
}
|
||||
// Step 6 — "Play it now": leave calibration pending (it completes
|
||||
// Step 5 — "Play it now": leave calibration pending (it completes
|
||||
// through the normal scored-stats path) and launch the diagnostic.
|
||||
const target = diagnosticFilename;
|
||||
await finish({ launchingSong: !!target });
|
||||
@@ -751,8 +713,8 @@
|
||||
setStep(3);
|
||||
return;
|
||||
}
|
||||
// Calibration step (last) — skip: Mastery Rank 1 immediately,
|
||||
// calibration stays replayable from the Progress screen.
|
||||
// Step 5 — skip: Mastery Rank 1 immediately, calibration stays
|
||||
// replayable from the Progress screen.
|
||||
skipBtn.disabled = true;
|
||||
try {
|
||||
const res = await fetch('/api/progression/onboarding', {
|
||||
|
||||
+88
-753
File diff suppressed because it is too large
Load Diff
+2
-204
@@ -4,62 +4,6 @@
|
||||
* `fb` palette in tailwind.config.js.
|
||||
*/
|
||||
|
||||
/* ── Text-selection policy (v3) ──────────────────────────────────────────────
|
||||
Accidental drag/double-click selection of app chrome (sidebar, transport, the
|
||||
note highway/HUD, buttons, labels) makes the UI look broken and is never
|
||||
useful — so default the interface to non-selectable, then opt *content* back
|
||||
in. v3-only: this sheet loads only on /v3 (v2 is unchanged). The panel's
|
||||
guardrails are baked in:
|
||||
- NEVER a `* { user-select:none }` rule — it breaks input carets / IME
|
||||
composition on WebKit (bug 82692); we scope to `html` and re-enable below.
|
||||
- This is cosmetic only; it protects nothing (DevTools defeats it) and must
|
||||
never be used to "lock" copy-worthy text away (a11y: keep errors, IDs,
|
||||
paths, versions, metadata, lyrics selectable — incl. in modals/toasts). */
|
||||
html { -webkit-user-select: none; user-select: none; }
|
||||
|
||||
/* Form fields are ALWAYS selectable/editable — protects the caret + IME
|
||||
(including CJK / dead-key composition). The default must never swallow typing.
|
||||
`.fb-selectable *` forces descendants so a child element's own non-select
|
||||
can't strand copy-worthy text inside a content island. */
|
||||
input, textarea, select,
|
||||
[contenteditable]:not([contenteditable="false"]),
|
||||
[contenteditable]:not([contenteditable="false"]) * {
|
||||
-webkit-user-select: text; user-select: text;
|
||||
}
|
||||
|
||||
/* Plugin screens are content surfaces (editor, tabview, lyrics, theory, chord
|
||||
text, …). Re-enable their mounted subtree by INHERITANCE (no `*`) so the host
|
||||
policy can't silently make a plugin's copyable text un-selectable — including
|
||||
community / out-of-tree plugins that never adopt `.fb-selectable`. A plugin
|
||||
that wants its own chrome non-selectable still wins via its own element rule
|
||||
(which this inherited value doesn't override). */
|
||||
.screen[id^="plugin-"] { -webkit-user-select: text; user-select: text; }
|
||||
|
||||
/* Core read-only content opts back in by CONTAINER (lower-drift than tagging
|
||||
each value — a new setting added later inherits "selectable" for free):
|
||||
the Settings panel (values, paths, device names, version, diagnostics,
|
||||
About) and the now-playing song metadata (both tagged `.fb-selectable`).
|
||||
Plugins re-enable their own copyable regions with this same class
|
||||
(documented in CLAUDE.md).
|
||||
|
||||
The focused, transient surfaces below ALWAYS carry copy-worthy text (errors,
|
||||
IDs, file paths, device/version strings) per the a11y guardrail, so they're
|
||||
blanket-opted-in by selector rather than hand-tagged — they're single focused
|
||||
panels, not dense card lists, so re-enabling selection there can't recreate
|
||||
the across-cards marquee mess the policy prevents:
|
||||
- modals / dialogs: `.feedBack-modal`, `[role="dialog"]` (confirm, edit-meta,
|
||||
retune result/error, calibration, filter drawer);
|
||||
- toasts: `#fb-notify-stack`, `#v3-fb-toast`;
|
||||
- the library scan banner (`#scan-banner` — shows the current file path).
|
||||
(Dense card lists — the library grid, dashboard, profile — are intentionally
|
||||
left non-selectable; copy their text from the now-playing HUD / Settings.) */
|
||||
.fb-selectable, .fb-selectable *,
|
||||
.feedBack-modal, .feedBack-modal *,
|
||||
[role="dialog"], [role="dialog"] *,
|
||||
#fb-notify-stack, #fb-notify-stack *,
|
||||
#v3-fb-toast, #v3-fb-toast *,
|
||||
#scan-banner, #scan-banner * { -webkit-user-select: text; user-select: text; }
|
||||
|
||||
/* The v3 tuner card replaces the tuner plugin's floating launcher — hide it. */
|
||||
#tuner-toggle-btn { display: none !important; }
|
||||
|
||||
@@ -340,9 +284,8 @@ input, textarea, select,
|
||||
/* — Up Next pill (top-right, persistent) — */
|
||||
#player-hud .v3-upnext {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: .35rem;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
padding: .45rem .9rem;
|
||||
border-radius: .75rem;
|
||||
background: rgba(15, 23, 42, .7);
|
||||
@@ -352,26 +295,6 @@ input, textarea, select,
|
||||
pointer-events: auto;
|
||||
}
|
||||
#player-hud .v3-upnext.hidden { display: none; }
|
||||
/* Text row keeps the original inline layout untouched. */
|
||||
#player-hud .v3-upnext .v3-upnext-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
}
|
||||
/* Progress bar under the text — fills as the current section elapses. */
|
||||
#player-hud .v3-upnext .v3-upnext-bar {
|
||||
height: 4px;
|
||||
border-radius: 999px;
|
||||
background: rgba(148, 163, 184, .25);
|
||||
overflow: hidden;
|
||||
}
|
||||
#player-hud .v3-upnext .v3-upnext-bar-fill {
|
||||
height: 100%;
|
||||
width: 0%;
|
||||
border-radius: inherit;
|
||||
background: linear-gradient(90deg, #22d3ee, #a855f7, #f472b6);
|
||||
transition: width .12s linear;
|
||||
}
|
||||
|
||||
/* — Live performance HUD (top-right, read-only) — */
|
||||
.v3-live-performance-hud {
|
||||
@@ -1194,128 +1117,3 @@ html.fb-immersive #v3-main > .screen.active {
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* — A–Z jump rail (v3 Songs grid; static/v3/songs.js) — */
|
||||
/* Fixed to the right edge next to the scroller's scrollbar; vertically
|
||||
centered. Shown only for the grid view + alphabetical (artist/title) sorts. */
|
||||
.v3-azrail {
|
||||
position: fixed;
|
||||
right: 2px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
z-index: 25;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
max-height: 84vh;
|
||||
padding: 4px 1px;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
touch-action: none; /* let a drag scrub the rail without scrolling the page */
|
||||
}
|
||||
.v3-azrail-letter {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
background: none;
|
||||
border: 0;
|
||||
color: #94a3b8; /* fb-textDim */
|
||||
font-size: .62rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.05;
|
||||
padding: 1px 4px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.v3-azrail-letter:hover:not([disabled]),
|
||||
.v3-azrail-letter.is-active {
|
||||
color: #0ea5e9; /* fb-primary */
|
||||
}
|
||||
.v3-azrail-letter:focus-visible {
|
||||
outline: 2px solid #38bdf8; /* fb-primaryHi */
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.v3-azrail-letter[disabled] {
|
||||
color: rgba(148, 163, 184, .28);
|
||||
cursor: default;
|
||||
}
|
||||
/* Drag indicator bubble (Android fast-scroll pattern). */
|
||||
.v3-azbubble {
|
||||
position: fixed;
|
||||
right: 2.6rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
z-index: 26;
|
||||
width: 2.6rem;
|
||||
height: 2.6rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: .7rem;
|
||||
background: #0ea5e9; /* fb-primary */
|
||||
color: #f8fafc; /* fb-text */
|
||||
font-size: 1.15rem;
|
||||
font-weight: 800;
|
||||
box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
|
||||
pointer-events: none;
|
||||
}
|
||||
.v3-azrail.hidden,
|
||||
.v3-azbubble.hidden { display: none; }
|
||||
/* Coarse-pointer / short viewports: the 27-letter rail can crowd a phone edge.
|
||||
Tighten it; a collapse-to-anchors pass is a follow-up. */
|
||||
@media (max-height: 640px) {
|
||||
.v3-azrail-letter { font-size: .55rem; padding: 0 4px; }
|
||||
}
|
||||
|
||||
/* — Practice-aware library home: repertoire meter + "Keep practicing" shelf — */
|
||||
#v3-lib-home.hidden { display: none; }
|
||||
.v3-rep-meter { max-width: 30rem; }
|
||||
.v3-rep-track {
|
||||
height: 6px;
|
||||
border-radius: 999px;
|
||||
background: rgba(148, 163, 184, .22); /* fb-textDim @ low alpha */
|
||||
overflow: hidden;
|
||||
}
|
||||
.v3-rep-fill {
|
||||
height: 100%;
|
||||
border-radius: 999px;
|
||||
background: #0ea5e9; /* fb-primary */
|
||||
transition: width .4s ease;
|
||||
}
|
||||
/* Horizontal, scroll-snapping shelf of fixed-width cards. */
|
||||
.v3-kp-row {
|
||||
display: flex;
|
||||
gap: .75rem;
|
||||
overflow-x: auto;
|
||||
scroll-snap-type: x proximity;
|
||||
padding-bottom: 6px;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
.v3-kp-card {
|
||||
flex: 0 0 8.5rem;
|
||||
width: 8.5rem;
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
|
||||
/* — Windowed (virtualized) Songs grid (#636 item 3 stage 2) — */
|
||||
/* The grid is absolutely positioned inside #v3-songs-gridsizer, whose height is
|
||||
set to the FULL library (ceil(total/cols)*rowH) so the scrollbar reflects the
|
||||
whole library while only the visible window's cards are in the DOM. The inline
|
||||
`top` (set by renderWindow) offsets the window to the first visible row. */
|
||||
.v3-grid-window {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
/* The arrangement-chip row is rendered on EVERY card (even when empty) at a fixed
|
||||
single-line height — uniform card height is what makes the window's
|
||||
absolute-position math exact. Extra chips are clipped rather than wrapping. */
|
||||
.v3-card-chips {
|
||||
height: 1.5rem;
|
||||
overflow: hidden;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
/* Skeleton placeholder shown only if a window's fetch hasn't landed; mirrors a
|
||||
real card's vertical structure so it occupies an identical row height. */
|
||||
.v3-card-skel { pointer-events: none; }
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
// Pins the bounded-DOM invariant of the windowed v3 Songs grid (#636 item 3
|
||||
// stage 2). Before virtualization the grid appended every scrolled page, so for
|
||||
// a 2000-song library the card-node count grew unbounded (24 → 624 → 2001).
|
||||
// Now only the visible window (± overscan) is ever in the DOM while a sizer
|
||||
// element gives the scrollbar the full-library geometry.
|
||||
//
|
||||
// Route-mocked (same strategy as v3-tree-select.spec.ts) so the invariant is
|
||||
// deterministic in CI without a seeded 2000-row library: /api/library serves a
|
||||
// synthetic page from the page/after param with total 2001, and the keyset
|
||||
// cursor is mocked as the next absolute offset.
|
||||
|
||||
const TOTAL = 2001;
|
||||
const PAGE_SIZE = 24;
|
||||
const COLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
// Same bucketing as the seed/server: index % 26 → a first letter, so the A–Z
|
||||
// rail has real buckets and a jump has somewhere to land.
|
||||
function songAt(i: number) {
|
||||
const letter = COLS[i % 26];
|
||||
return {
|
||||
filename: `seed/${String(i).padStart(5, '0')}.sloppak`,
|
||||
title: `Song ${String(i).padStart(4, '0')}`,
|
||||
artist: `${letter}Band ${String(i).padStart(4, '0')}`,
|
||||
album: `${letter} Album`,
|
||||
format: 'sloppak',
|
||||
arrangements: [{ index: 0, name: 'Lead' }, { index: 1, name: 'Rhythm' }],
|
||||
};
|
||||
}
|
||||
|
||||
// sort_letters song-counts per bucket for index%26 over [0, TOTAL).
|
||||
function sortLetters() {
|
||||
const m: Record<string, number> = {};
|
||||
for (let i = 0; i < TOTAL; i++) { const L = COLS[i % 26]; m[L] = (m[L] || 0) + 1; }
|
||||
return m;
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.route('**/api/library?**', async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const after = url.searchParams.get('after');
|
||||
const size = Number(url.searchParams.get('size') || PAGE_SIZE);
|
||||
const offset = after != null ? Number(after) : Number(url.searchParams.get('page') || '0') * size;
|
||||
const songs = [];
|
||||
for (let i = offset; i < Math.min(TOTAL, offset + size); i++) songs.push(songAt(i));
|
||||
const nextOffset = offset + size;
|
||||
await route.fulfill({
|
||||
json: {
|
||||
songs, total: TOTAL, page: Math.floor(offset / size), size,
|
||||
next_cursor: nextOffset < TOTAL ? String(nextOffset) : null,
|
||||
},
|
||||
});
|
||||
});
|
||||
await page.route('**/api/library/stats**', (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const body: any = { total_songs: TOTAL, total: TOTAL, letters: {} };
|
||||
if (url.searchParams.get('sort_letters')) body.sort_letters = sortLetters();
|
||||
return route.fulfill({ json: body });
|
||||
});
|
||||
await page.route('**/api/library/artists**', (route) => route.fulfill({ json: { artists: [], total_artists: 0 } }));
|
||||
await page.route('**/api/library/providers', (route) => route.fulfill({ json: { providers: [{ id: 'local', label: 'My Library' }] } }));
|
||||
await page.route('**/api/library/tuning-names**', (route) => route.fulfill({ json: { tunings: [] } }));
|
||||
await page.route('**/api/stats/best', (route) => route.fulfill({ json: {} }));
|
||||
await page.route('**/api/stats/recent**', (route) => route.fulfill({ json: [] }));
|
||||
});
|
||||
|
||||
async function openSongs(page) {
|
||||
await page.goto('/');
|
||||
await page.waitForSelector('.screen.active', { timeout: 10000 });
|
||||
await page.evaluate(() => {
|
||||
// @ts-ignore — neutralize playback so a stray click can't navigate away.
|
||||
window.playSong = () => Promise.resolve();
|
||||
// @ts-ignore
|
||||
window.showScreen('v3-songs');
|
||||
});
|
||||
await page.waitForSelector('#v3-songs-grid [data-fn]', { state: 'attached', timeout: 10000 });
|
||||
}
|
||||
|
||||
test('the grid keeps a bounded number of card nodes while scrolling a 2001-song library', async ({ page }) => {
|
||||
await openSongs(page);
|
||||
|
||||
// The count reflects the FULL library even though only a window is rendered.
|
||||
await expect(page.locator('#v3-songs-count')).toHaveText('2001 songs');
|
||||
|
||||
// The sizer reserves the full scroll height (so the scrollbar is library-wide).
|
||||
const scrollHeight = await page.evaluate(() => document.getElementById('v3-main')!.scrollHeight);
|
||||
expect(scrollHeight).toBeGreaterThan(20000);
|
||||
|
||||
// Scroll the whole library; the in-DOM card count must stay bounded throughout.
|
||||
const CAP = 150;
|
||||
let maxNodes = await page.locator('#v3-songs-grid [data-fn]').count();
|
||||
for (let s = 0; s < 50; s++) {
|
||||
await page.evaluate(() => { const m = document.getElementById('v3-main')!; m.scrollTop += m.clientHeight * 0.85; });
|
||||
await page.waitForTimeout(60);
|
||||
const n = await page.locator('#v3-songs-grid [data-fn]').count();
|
||||
maxNodes = Math.max(maxNodes, n);
|
||||
expect(n).toBeLessThanOrEqual(CAP);
|
||||
}
|
||||
// Sanity: we actually rendered a window (not zero), and stayed well under the
|
||||
// unbounded 2001 the old append-everything grid would have produced.
|
||||
expect(maxNodes).toBeGreaterThan(0);
|
||||
expect(maxNodes).toBeLessThanOrEqual(CAP);
|
||||
|
||||
// The count is still correct after scrolling to the end.
|
||||
await expect(page.locator('#v3-songs-count')).toHaveText('2001 songs');
|
||||
});
|
||||
|
||||
test('the A–Z rail jumps directly to a letter without loading every page', async ({ page }) => {
|
||||
await openSongs(page);
|
||||
await page.waitForSelector('.v3-azrail-letter', { state: 'attached', timeout: 10000 });
|
||||
|
||||
// Jump to 'M'; the window scrolls to the row holding the first 'M' card.
|
||||
await page.evaluate(() => {
|
||||
const b = [...document.querySelectorAll('.v3-azrail-letter')]
|
||||
.find((x) => x.getAttribute('data-letter') === 'M' && !(x as HTMLButtonElement).disabled) as HTMLElement | undefined;
|
||||
if (!b) throw new Error('no M rail letter'); b.click();
|
||||
});
|
||||
|
||||
// After the jump+window render, an 'M' card is present near the top of the
|
||||
// viewport (the jump is O(1) via sort_letters, not a full page-through).
|
||||
await expect.poll(async () => page.evaluate(() => {
|
||||
const main = document.getElementById('v3-main')!;
|
||||
const top = main.getBoundingClientRect().top + (document.getElementById('v3-songs-toolbar')?.offsetHeight || 0);
|
||||
return [...document.querySelectorAll('#v3-songs-grid [data-fn]')].some((c) => {
|
||||
const r = c.getBoundingClientRect();
|
||||
return c.getAttribute('data-letter') === 'M' && r.top >= top - 4 && r.top < top + 320;
|
||||
});
|
||||
}), { timeout: 5000 }).toBe(true);
|
||||
});
|
||||
@@ -130,59 +130,6 @@ test('measure-start cache is invalidated on song change', () => {
|
||||
);
|
||||
});
|
||||
|
||||
// ── Fret-row fit guard ──────────────────────────────────────────────────────
|
||||
// Keeps the heat-coloured fret-number row from clipping off the bottom edge
|
||||
// when a tight, centred zoom (worst mid-neck) drops it below the lower-third
|
||||
// framing. camUpdate dollies the camera back via a capped, hysteretic boost.
|
||||
|
||||
test('fret-row fit guard constants are defined', () => {
|
||||
for (const name of [
|
||||
'FRET_ROW_FIT_NDC_MIN', 'FRET_ROW_FIT_DEADBAND', 'FRET_ROW_FIT_BOOST_MAX',
|
||||
]) {
|
||||
assert.match(src, new RegExp('const\\s+' + name + '\\s*='),
|
||||
`${name} must be declared as a fit-guard constant`);
|
||||
}
|
||||
});
|
||||
|
||||
test('the curDist lerp target applies the fit-guard dolly boost', () => {
|
||||
// The span-driven tgtDist still owns zooming in; the boost only pulls back.
|
||||
assert.match(
|
||||
src,
|
||||
/curDist\s*\+=\s*\(\s*tgtDist\s*\*\s*_fretRowFitBoost\s*-\s*curDist\s*\)\s*\*\s*lerp/,
|
||||
'curDist must lerp toward tgtDist * _fretRowFitBoost',
|
||||
);
|
||||
});
|
||||
|
||||
test('the guard projects the fret-row band and adjusts the boost with hysteresis', () => {
|
||||
// Row band Y mirrors the render position (sY(lowest) - S_GAP * 1.4).
|
||||
assert.match(
|
||||
src,
|
||||
/Math\.min\(\s*sY\(0\)\s*,\s*sY\(nStr\s*-\s*1\)\s*\)\s*-\s*S_GAP\s*\*\s*1\.4/,
|
||||
'the guard must probe the same row band the fret-number row is drawn at',
|
||||
);
|
||||
// Prompt pull-back when below the min, capped at BOOST_MAX.
|
||||
assert.match(
|
||||
src,
|
||||
/_rowNdcY\s*<\s*FRET_ROW_FIT_NDC_MIN[\s\S]*?Math\.min\(\s*FRET_ROW_FIT_BOOST_MAX/,
|
||||
'below the min NDC the boost rises, capped at FRET_ROW_FIT_BOOST_MAX',
|
||||
);
|
||||
// Lazy relax only once past the deadband, floored at 1.
|
||||
assert.match(
|
||||
src,
|
||||
/_rowNdcY\s*>\s*FRET_ROW_FIT_NDC_MIN\s*\+\s*FRET_ROW_FIT_DEADBAND[\s\S]*?Math\.max\(\s*1\s*,\s*_fretRowFitBoost/,
|
||||
'past the deadband the boost relaxes back toward 1',
|
||||
);
|
||||
});
|
||||
|
||||
test('the fit guard yields to the free-cam (Camera Director)', () => {
|
||||
// When the free-cam owns the view the auto dolly must reset to 1, not fight it.
|
||||
assert.match(
|
||||
src,
|
||||
/if\s*\(\s*_freeCam\s*&&\s*_freeCam\.enabled\s*\)\s*\{\s*if\s*\(\s*_fretRowFitBoost\s*!==\s*1\s*\)\s*_fretRowFitBoost\s*=\s*1/,
|
||||
'with the free-cam enabled the guard must drop any auto dolly back to 1',
|
||||
);
|
||||
});
|
||||
|
||||
// ── Debug hook stayed removed ───────────────────────────────────────────────
|
||||
|
||||
test('temporary camera debug hook is not present', () => {
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
// Pins the wide-pane horizontal-FOV-hold ("Hor+") framing in
|
||||
// plugins/highway_3d/screen.js.
|
||||
//
|
||||
// What it guards: ultra-wide panes (top/bottom 2-player split → full-width /
|
||||
// half-height → ~32:9) used to render the neck as a thin central sliver because
|
||||
// THREE's PerspectiveCamera fov is VERTICAL and was locked at 70°, ballooning
|
||||
// the horizontal cone past 130°. The fix lets camUpdate lower the effective
|
||||
// vertical fov as the pane widens (holding the horizontal cone ~constant) so the
|
||||
// neck fills the pane. It is gated behind window.__h3dAspectTune (default off →
|
||||
// byte-for-byte the prior behaviour) for live A/B comparison.
|
||||
//
|
||||
// A refactor that re-hardcodes the camera fov, drops the change-guarded cam.fov
|
||||
// write, stops caching the pane aspect, or removes the no-op-at-startAspect
|
||||
// guarantee would silently regress the feature (or worse, change normal-pane
|
||||
// framing). These are source-level pins — same strategy as the other
|
||||
// tests/js/ files (no DOM / WebGL in CI).
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const SCREEN_JS = path.join(__dirname, '..', '..', 'plugins', 'highway_3d', 'screen.js');
|
||||
const src = fs.readFileSync(SCREEN_JS, 'utf8');
|
||||
|
||||
// ── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
test('BASE_VFOV is a named constant (not a literal in the camera ctor)', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+BASE_VFOV\s*=\s*70\s*;/,
|
||||
'BASE_VFOV must be declared as a constant',
|
||||
);
|
||||
});
|
||||
|
||||
test('the camera is constructed with BASE_VFOV, not a bare 70', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/new\s+T\.PerspectiveCamera\(\s*BASE_VFOV\s*,/,
|
||||
'PerspectiveCamera must take BASE_VFOV as its vertical fov',
|
||||
);
|
||||
});
|
||||
|
||||
test('the Hor+ start-aspect and min-vfov defaults exist', () => {
|
||||
assert.match(src, /const\s+HORPLUS_START_ASPECT\s*=\s*16\s*\/\s*9\s*;/,
|
||||
'HORPLUS_START_ASPECT must default to 16/9 (no-op at/under the reference aspect)');
|
||||
assert.match(src, /const\s+HORPLUS_MIN_VFOV\s*=\s*\d+\s*;/,
|
||||
'HORPLUS_MIN_VFOV floor must be declared');
|
||||
});
|
||||
|
||||
// ── effectiveVfov: no-op guarantees ──────────────────────────────────────────
|
||||
|
||||
test('effectiveVfov returns the base fov when the bridge is off/absent', () => {
|
||||
// The disabled / malformed-input guard returns `base` before any Hor+ math,
|
||||
// so normal panes are unaffected when __h3dAspectTune is missing or off.
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+effectiveVfov\s*\(\s*aspect\s*,\s*tune\s*\)\s*\{[\s\S]*?if\s*\(\s*!tune\s*\|\|\s*!tune\.enabled[\s\S]*?return\s+base\s*;/,
|
||||
'effectiveVfov must short-circuit to the base fov when disabled',
|
||||
);
|
||||
});
|
||||
|
||||
test('effectiveVfov is a no-op at/under the start aspect', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/if\s*\(\s*aspect\s*<=\s*start\s*\)\s*return\s+base\s*;/,
|
||||
'effectiveVfov must return base when aspect <= start (no-op for normal/2x2 panes)',
|
||||
);
|
||||
});
|
||||
|
||||
// ── shipped defaults: off + coherent ─────────────────────────────────────────
|
||||
// The "default off → byte-for-byte prior behaviour" contract only holds if the
|
||||
// shipped _ASPECT_DEFAULTS actually ship disabled with a base that matches the
|
||||
// camera's constructed fov. A previous revision shipped enabled:true with
|
||||
// baseVfov:30 (and blend:0), which forced every pane's fov to 30/36 and
|
||||
// silently re-framed normal single-player panes. These pin against that.
|
||||
|
||||
test('_ASPECT_DEFAULTS ships disabled (no-op out of the box)', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+_ASPECT_DEFAULTS\s*=\s*\{[\s\S]*?\benabled\s*:\s*false\b/,
|
||||
'_ASPECT_DEFAULTS.enabled must default to false so the feature is opt-in',
|
||||
);
|
||||
});
|
||||
|
||||
test('the default base fov matches BASE_VFOV (enabling is still a no-op on normal panes)', () => {
|
||||
// baseVfov === BASE_VFOV means even with the feature ON, a <=startAspect pane
|
||||
// returns the unchanged 70° — the effect is confined to genuinely wide panes.
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+_ASPECT_DEFAULTS\s*=\s*\{[\s\S]*?\bbaseVfov\s*:\s*BASE_VFOV\b/,
|
||||
'_ASPECT_DEFAULTS.baseVfov must default to BASE_VFOV, not a divergent literal',
|
||||
);
|
||||
});
|
||||
|
||||
test('the default blend engages the hold and the floor sits below the base', () => {
|
||||
// blend:1 means turning the feature on actually holds the horizontal cone
|
||||
// (blend:0 would collapse effectiveVfov back to base = feature inert), and
|
||||
// minVfovDeg:HORPLUS_MIN_VFOV keeps the floor below baseVfov (a real floor,
|
||||
// not one that clamps the base upward).
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+_ASPECT_DEFAULTS\s*=\s*\{[\s\S]*?\bblend\s*:\s*1\b/,
|
||||
'_ASPECT_DEFAULTS.blend must default to 1 so the Hor+ hold actually applies when enabled',
|
||||
);
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+_ASPECT_DEFAULTS\s*=\s*\{[\s\S]*?\bminVfovDeg\s*:\s*HORPLUS_MIN_VFOV\b/,
|
||||
'_ASPECT_DEFAULTS.minVfovDeg must default to HORPLUS_MIN_VFOV (a floor below baseVfov)',
|
||||
);
|
||||
});
|
||||
|
||||
// ── camUpdate: change-guarded fov write + cached aspect ───────────────────────
|
||||
|
||||
test('applySize caches the pane aspect for camUpdate', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/_paneAspect\s*=\s*cam\.aspect\s*;/,
|
||||
'applySize must cache cam.aspect into _paneAspect',
|
||||
);
|
||||
});
|
||||
|
||||
test('camUpdate reads the live tune bridge and respects splitOnly', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+_aspTune\s*=\s*_aspectTune\(\)\s*;[\s\S]*?_aspTune\.splitOnly\s*&&\s*!_ssActive\(\)/,
|
||||
'camUpdate must read the bridge via _aspectTune() and gate splitOnly on _ssActive()',
|
||||
);
|
||||
});
|
||||
|
||||
test('the tune bridge seeds from localStorage (persisted sessions apply on load)', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+_aspectTune\s*\(\)[\s\S]*?localStorage\.getItem\(\s*_ASPECT_LS\s*\)/,
|
||||
'_aspectTune() must seed the bridge from localStorage',
|
||||
);
|
||||
});
|
||||
|
||||
test('a floating tuner panel is built and toggled with the A/B state', () => {
|
||||
assert.match(src, /function\s+_ensureAspectPanel\s*\(\)/,
|
||||
'_ensureAspectPanel() must exist to build the live panel');
|
||||
assert.match(src, /function\s+_setAspectPanelVisible\s*\(/,
|
||||
'_setAspectPanelVisible() must show/hide the panel with the feature');
|
||||
});
|
||||
|
||||
test('camUpdate only writes cam.fov when it actually changes', () => {
|
||||
// Guarding the write avoids a per-frame updateProjectionMatrix on a steady
|
||||
// pane and keeps the disabled path free.
|
||||
assert.match(
|
||||
src,
|
||||
/Math\.abs\(\s*_vfov\s*-\s*cam\.fov\s*\)\s*>\s*1e-4[\s\S]*?cam\.fov\s*=\s*_vfov\s*;[\s\S]*?cam\.updateProjectionMatrix\(\)/,
|
||||
'camUpdate must guard the cam.fov write behind a change check',
|
||||
);
|
||||
});
|
||||
|
||||
// ── A/B toggle + lifecycle reset ──────────────────────────────────────────────
|
||||
|
||||
test('an A/B toggle shortcut flips the tune enabled flag', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/registerShortcut\(\{[\s\S]*?const\s+t\s*=\s*_aspectTune\(\)\s*;[\s\S]*?t\.enabled\s*=\s*!\s*t\.enabled/,
|
||||
'a registerShortcut handler must toggle the bridge enabled flag',
|
||||
);
|
||||
});
|
||||
|
||||
test('destroy() resets the pane aspect and restores the base fov', () => {
|
||||
assert.match(src, /_paneAspect\s*=\s*0\s*;/,
|
||||
'destroy() must reset _paneAspect to 0');
|
||||
assert.match(
|
||||
src,
|
||||
/cam\.fov\s*!==\s*BASE_VFOV[\s\S]*?cam\.fov\s*=\s*BASE_VFOV\s*;\s*cam\.updateProjectionMatrix\(\)/,
|
||||
'destroy() must restore cam.fov to BASE_VFOV for instance reuse',
|
||||
);
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
// Guards the Section Practice popover's outside-click dismiss in static/app.js
|
||||
// (_installSectionPracticeDismiss). The v3 player-rail icon buttons call
|
||||
// e.stopPropagation() in their click handler (static/v3/player-chrome.js
|
||||
// wireRail), so a BUBBLE-phase document dismiss never fires when the user clicks
|
||||
// a different rail icon (Plugins, Audio, …) — leaving the Practice popover
|
||||
// stranded open under the newly-opened one (feedBack#638). The dismiss must bind
|
||||
// in the CAPTURE phase (runs before the target's stopPropagation can swallow it).
|
||||
// Esc must stay bubble-phase so it doesn't reorder ahead of the player's
|
||||
// Escape-to-exit handling. A revert to bubble-phase should fail here.
|
||||
//
|
||||
// Source-level only — same strategy as the other tests/js/ files.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const src = fs.readFileSync(path.join(__dirname, '..', '..', 'static', 'app.js'), 'utf8');
|
||||
const m = src.match(/function _installSectionPracticeDismiss\s*\(\)\s*\{[\s\S]*?\n\}/);
|
||||
assert.ok(m, '_installSectionPracticeDismiss() not found in static/app.js');
|
||||
const body = m[0];
|
||||
|
||||
test('the outside-click dismiss binds in the CAPTURE phase', () => {
|
||||
assert.match(
|
||||
body,
|
||||
/addEventListener\(\s*['"]click['"][\s\S]*?,\s*true\s*\)/,
|
||||
'the click dismiss must pass the capture flag (`, true`) so a rail icon\'s '
|
||||
+ 'stopPropagation() cannot swallow it',
|
||||
);
|
||||
});
|
||||
|
||||
test('only the click listener is capture (Escape keydown stays bubble-phase)', () => {
|
||||
// Exactly one capture binding in the installer — the click. The keydown
|
||||
// (Escape) listener must NOT be capture.
|
||||
const captureBinds = body.match(/,\s*true\s*\)/g) || [];
|
||||
assert.equal(captureBinds.length, 1, 'expected exactly one capture-phase binding (the click)');
|
||||
});
|
||||
|
||||
test('the dismiss ignores clicks inside the control (no self-close)', () => {
|
||||
assert.match(body, /section-practice-control/, 'must scope to #section-practice-control');
|
||||
assert.match(body, /ctrl\s*&&\s*ctrl\.contains\(e\.target\)\)\s*return/,
|
||||
'a click inside the control (incl. the pill) must not dismiss the popover');
|
||||
});
|
||||
@@ -1,133 +0,0 @@
|
||||
// Verify the feedpak credits overlay helpers in app.js:
|
||||
// - _creditLineLabel() role → friendly "<verb> by" label
|
||||
// - showSongCreditsOverlay() builds an XSS-safe card; no-op on empty list
|
||||
// - hideSongCreditsOverlay() removes the overlay element
|
||||
//
|
||||
// Same isolation strategy as autoplay_exit.test.js — extract the functions
|
||||
// from app.js by brace-matching and run them in a vm sandbox with a fake DOM.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
|
||||
const { extractFunction } = require('./test_utils');
|
||||
|
||||
const APP_JS = path.join(__dirname, '..', '..', 'static', 'app.js');
|
||||
const SRC = fs.readFileSync(APP_JS, 'utf8');
|
||||
|
||||
// Minimal fake DOM element: records className, children, and textContent.
|
||||
// Setting textContent clears children (matching real DOM) so we can assert
|
||||
// names were set via textContent (not innerHTML) — the XSS-safety contract.
|
||||
function makeEl() {
|
||||
return {
|
||||
className: '',
|
||||
children: [],
|
||||
_text: '',
|
||||
set textContent(v) { this._text = String(v); this.children = []; },
|
||||
get textContent() { return this._text; },
|
||||
appendChild(c) { this.children.push(c); return c; },
|
||||
replaceChildren() { this.children = []; },
|
||||
remove() { this.removed = true; },
|
||||
};
|
||||
}
|
||||
|
||||
function allText(node) {
|
||||
let s = node._text || '';
|
||||
for (const c of node.children) s += allText(c);
|
||||
return s;
|
||||
}
|
||||
|
||||
function buildSandbox(currentSong) {
|
||||
const body = makeEl();
|
||||
const sandbox = {
|
||||
document: { body, createElement: () => makeEl() },
|
||||
window: { feedBack: { currentSong, off() {} } },
|
||||
setTimeout: () => 1,
|
||||
clearTimeout: () => {},
|
||||
};
|
||||
vm.createContext(sandbox);
|
||||
const preamble = `
|
||||
let _creditsOverlay = null;
|
||||
let _creditsTimer = null;
|
||||
let _creditsHideOnPlay = null;
|
||||
let _creditsMaxTimer = null;
|
||||
const _CREDITS_MAX_MS = 12000;
|
||||
const _CREDIT_ROLE_VERBS = ${JSON.stringify({
|
||||
charter: 'Charted by', transcriber: 'Transcribed by',
|
||||
arranger: 'Arranged by', editor: 'Edited by', mixer: 'Mixed by',
|
||||
engineer: 'Engineered by', proofreader: 'Proofread by',
|
||||
})};
|
||||
`;
|
||||
vm.runInContext(
|
||||
preamble
|
||||
+ extractFunction(SRC, 'function _creditLineLabel(') + '\n'
|
||||
+ extractFunction(SRC, 'function showSongCreditsOverlay(') + '\n'
|
||||
+ extractFunction(SRC, 'function hideSongCreditsOverlay(') + '\n'
|
||||
+ 'globalThis._creditLineLabel = _creditLineLabel;'
|
||||
+ 'globalThis.showSongCreditsOverlay = showSongCreditsOverlay;'
|
||||
+ 'globalThis.hideSongCreditsOverlay = hideSongCreditsOverlay;'
|
||||
+ 'globalThis._getOverlay = () => _creditsOverlay;',
|
||||
sandbox,
|
||||
);
|
||||
return sandbox;
|
||||
}
|
||||
|
||||
test('_creditLineLabel maps known roles, title-cases unknown, blanks empty', () => {
|
||||
const s = buildSandbox({});
|
||||
assert.equal(s._creditLineLabel('charter'), 'Charted by');
|
||||
assert.equal(s._creditLineLabel('Editor'), 'Edited by'); // case-insensitive
|
||||
assert.equal(s._creditLineLabel('mixer'), 'Mixed by');
|
||||
assert.equal(s._creditLineLabel('luthier'), 'Luthier by'); // unknown → title-cased
|
||||
assert.equal(s._creditLineLabel(null), ''); // no role → bare name
|
||||
assert.equal(s._creditLineLabel(''), '');
|
||||
});
|
||||
|
||||
test('showSongCreditsOverlay builds a card with heading + credit lines', () => {
|
||||
const s = buildSandbox({ title: 'My Song' });
|
||||
s.showSongCreditsOverlay([
|
||||
{ name: 'Azure', role: 'charter' },
|
||||
{ name: 'Bob Lee', role: 'editor' },
|
||||
{ name: 'Solo', role: null },
|
||||
]);
|
||||
const overlay = s._getOverlay();
|
||||
assert.ok(overlay, 'overlay created');
|
||||
assert.equal(overlay.className, 'song-credits-overlay');
|
||||
assert.equal(s.document.body.children.length, 1);
|
||||
const text = allText(overlay);
|
||||
assert.match(text, /My Song/); // heading is the song title
|
||||
assert.match(text, /Charted by/);
|
||||
assert.match(text, /Azure/);
|
||||
assert.match(text, /Edited by/);
|
||||
assert.match(text, /Bob Lee/);
|
||||
assert.match(text, /Solo/); // role-less entry still shows the name
|
||||
});
|
||||
|
||||
test('showSongCreditsOverlay sets names via textContent (XSS-safe)', () => {
|
||||
const s = buildSandbox({ title: 'T' });
|
||||
s.showSongCreditsOverlay([{ name: '<img src=x onerror=alert(1)>', role: 'charter' }]);
|
||||
const overlay = s._getOverlay();
|
||||
// The raw string survives verbatim as text — proving it was never parsed
|
||||
// as HTML (no innerHTML interpolation anywhere on the path).
|
||||
assert.match(allText(overlay), /<img src=x onerror=alert\(1\)>/);
|
||||
});
|
||||
|
||||
test('showSongCreditsOverlay is a no-op for empty / non-array input', () => {
|
||||
const s = buildSandbox({ title: 'T' });
|
||||
s.showSongCreditsOverlay([]);
|
||||
assert.equal(s._getOverlay(), null);
|
||||
s.showSongCreditsOverlay(undefined);
|
||||
assert.equal(s._getOverlay(), null);
|
||||
assert.equal(s.document.body.children.length, 0);
|
||||
});
|
||||
|
||||
test('hideSongCreditsOverlay removes the overlay', () => {
|
||||
const s = buildSandbox({ title: 'T' });
|
||||
s.showSongCreditsOverlay([{ name: 'Azure', role: 'charter' }]);
|
||||
const overlay = s._getOverlay();
|
||||
assert.ok(overlay);
|
||||
s.hideSongCreditsOverlay();
|
||||
assert.equal(overlay.removed, true);
|
||||
assert.equal(s._getOverlay(), null);
|
||||
});
|
||||
@@ -1,94 +0,0 @@
|
||||
// Pins the v3 Songs A–Z jump rail wiring in static/v3/songs.js.
|
||||
//
|
||||
// The rail lets a user jump the library grid to artists/titles starting with a
|
||||
// letter (Plex/Radarr/iOS-contacts pattern). With the windowed grid (#636 item 3
|
||||
// stage 2) the jump seeks DIRECTLY: the sort_letters song-counts give the first
|
||||
// card's absolute index (cumulative of prior buckets), which converts to a
|
||||
// scrollTop — no page-through. The rail only offers letters the server reports
|
||||
// present for the active sort+filter (so a tap always lands on a real card). It
|
||||
// is shown only for the grid view + alphabetical (artist/title) sorts.
|
||||
//
|
||||
// Source-level only — same strategy as tests/js/highway_3d_camera_framing.test.js.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const SONGS_JS = path.join(__dirname, '..', '..', 'static', 'v3', 'songs.js');
|
||||
const src = fs.readFileSync(SONGS_JS, 'utf8');
|
||||
|
||||
test('the rail is context-gated to grid view + alphabetical sorts', () => {
|
||||
// railSortColumn returns the active alpha column or null (recent/year/tuning).
|
||||
assert.match(src, /function\s+railSortColumn\s*\(\)/);
|
||||
assert.match(src, /state\.sort === 'artist'[\s\S]*?return 'artist'/);
|
||||
assert.match(src, /state\.sort === 'title'[\s\S]*?return 'title'/);
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+railVisible\s*\(\)\s*\{\s*return\s+state\.view === 'grid'\s*&&\s*!!railSortColumn\(\)/,
|
||||
'the rail must be visible only for the grid view + an alphabetical sort',
|
||||
);
|
||||
});
|
||||
|
||||
test('cards carry a data-letter bucket and non-A–Z buckets under #', () => {
|
||||
assert.match(src, /data-letter="'\s*\+\s*esc\(songBucket\(song\)\)/,
|
||||
'each card must tag its sort-letter bucket via songBucket(song)');
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+songBucket[\s\S]*?\(ch >= 'A' && ch <= 'Z'\)\s*\?\s*ch\s*:\s*'#'/,
|
||||
'songBucket must bucket non-A–Z first chars under "#"',
|
||||
);
|
||||
});
|
||||
|
||||
test('refreshRail reads present letters from the stats endpoint (sort-aware)', () => {
|
||||
assert.match(src, /\/api\/library\/stats\?'\s*\+\s*queryParams/,
|
||||
'refreshRail must query /api/library/stats with the active filter params');
|
||||
// Opts into the active-sort breakdown so non-rail callers skip the scan.
|
||||
assert.match(src, /queryParams\(\{\s*sort_letters:\s*1\s*\}\)/,
|
||||
'refreshRail must request the sort_letters breakdown');
|
||||
assert.match(src, /letters\s*=\s*stats\s*&&\s*stats\.sort_letters/,
|
||||
'refreshRail must prefer the active-sort breakdown (sort_letters)');
|
||||
// The legacy artist `letters` is only a valid fallback for an artist sort;
|
||||
// a title sort with no sort_letters hides the rail rather than mislabel it.
|
||||
assert.match(src, /col === 'artist'[\s\S]*?stats\.letters/,
|
||||
'refreshRail must only fall back to letters for an artist sort');
|
||||
// Absent letters are disabled (non-interactive), not just dimmed.
|
||||
assert.match(src, /present\s*\?\s*''\s*:\s*' disabled'/);
|
||||
});
|
||||
|
||||
test('reload() refreshes the rail', () => {
|
||||
assert.match(src, /function reload\s*\([\s\S]*?refreshRail\(\)/,
|
||||
'reload() must call refreshRail() so the rail tracks filter/sort/view changes');
|
||||
});
|
||||
|
||||
test('the rail + drag bubble are rendered in the Songs markup', () => {
|
||||
assert.match(src, /id="v3-songs-azrail"[\s\S]*?aria-label="Jump to letter"/);
|
||||
assert.match(src, /id="v3-songs-azbubble"/);
|
||||
});
|
||||
|
||||
test('jumpToLetter seeks directly via sort_letters cumulative (no page-through)', () => {
|
||||
// The cumulative-count seek: sum the song-counts of buckets ordered before
|
||||
// the target to get its first row's absolute index.
|
||||
assert.match(src, /function\s+_letterStartIndex\s*\(letter\)/,
|
||||
'jumpToLetter must derive the target index from sort_letters counts');
|
||||
assert.match(
|
||||
src,
|
||||
/async function\s+jumpToLetter[\s\S]*?_letterStartIndex\(letter\)[\s\S]*?scrollTo/,
|
||||
'jumpToLetter must compute the target index then scrollTo (no _loadNextAwait page-through)',
|
||||
);
|
||||
// It pre-fetches the destination window so cards are ready when the scroll lands.
|
||||
assert.match(src, /async function\s+jumpToLetter[\s\S]*?ensureWindow\(/,
|
||||
'jumpToLetter must pre-fetch the destination window before scrolling');
|
||||
// The old forward-paging helper is gone (the seek is O(1)).
|
||||
assert.doesNotMatch(src, /_loadNextAwait/,
|
||||
'the page-through helper must be removed under the windowed grid');
|
||||
// A token still guards overlapping jumps (drag scrubbing) — newest wins.
|
||||
assert.match(src, /_jumpToken\s*!==\s*myToken/);
|
||||
});
|
||||
|
||||
test('the rail supports pointer drag-scrub + keyboard arrows', () => {
|
||||
assert.match(src, /addEventListener\('pointerdown'/);
|
||||
assert.match(src, /addEventListener\('pointermove'/);
|
||||
assert.match(src, /ArrowUp'[\s\S]*?ArrowDown'|ArrowDown'[\s\S]*?ArrowUp'/,
|
||||
'arrow keys must move between present letters');
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
// Pins the v3 "Save as collection" wiring in static/v3/songs.js (#636 item 2).
|
||||
// A smart collection is a saved live library filter, surfaced as a source in
|
||||
// the provider picker; the drawer can save the current filter set as one.
|
||||
// Source-level only — same strategy as tests/js/v3_az_rail.test.js.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const SONGS_JS = path.join(__dirname, '..', '..', 'static', 'v3', 'songs.js');
|
||||
const src = fs.readFileSync(SONGS_JS, 'utf8');
|
||||
|
||||
test('currentFilterRules builds the raw query-param rule object', () => {
|
||||
assert.match(src, /function\s+currentFilterRules/);
|
||||
// Multi-value filters are CSV strings (what the backend stores / re-parses).
|
||||
assert.match(src, /r\.tunings\s*=\s*f\.tunings\.join\(','\)/);
|
||||
assert.match(src, /r\.arrangements_has\s*=\s*f\.arr_has\.join\(','\)/);
|
||||
});
|
||||
|
||||
test('saving POSTs to /api/collections with name + rules', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/fetch\('\/api\/collections',[\s\S]*?JSON\.stringify\(\{\s*name,\s*rules\s*\}\)/,
|
||||
'saveCurrentAsCollection must POST {name, rules} to /api/collections',
|
||||
);
|
||||
// After save, switch the source to the new collection and rebuild the UI.
|
||||
assert.match(src, /state\.provider\s*=\s*'collection:'\s*\+\s*col\.id/);
|
||||
});
|
||||
|
||||
test('the drawer shows a Save-as-collection action only when filters are set', () => {
|
||||
assert.match(src, /Object\.keys\(currentFilterRules\(\)\)\.length[\s\S]*?data-drawer-save/);
|
||||
assert.match(src, /data-drawer-save[\s\S]*?saveCurrentAsCollection/);
|
||||
});
|
||||
@@ -1,74 +0,0 @@
|
||||
// Pins the practice-aware library home in static/v3/songs.js:
|
||||
// - a "Repertoire" progress meter (mastered / total library songs), and
|
||||
// - a "Keep practicing" shelf (recently played, not yet mastered).
|
||||
// Both reuse existing data (/api/stats/best already in state.accuracy, and
|
||||
// /api/stats/recent) and are shown only on the unfiltered grid front door.
|
||||
//
|
||||
// Source-level only — same strategy as tests/js/v3_az_rail.test.js.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const SONGS_JS = path.join(__dirname, '..', '..', 'static', 'v3', 'songs.js');
|
||||
const src = fs.readFileSync(SONGS_JS, 'utf8');
|
||||
|
||||
test('repertoire uses the same mastery threshold as the green accuracy badge', () => {
|
||||
assert.match(src, /const\s+MASTERY_ACCURACY\s*=\s*0\.9/);
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+_repertoireCounts[\s\S]*?v\s*>=\s*MASTERY_ACCURACY\s*\)\s*mastered\+\+;\s*else\s+learning\+\+/,
|
||||
'repertoire counts must bucket scored songs into mastered/learning at MASTERY_ACCURACY',
|
||||
);
|
||||
});
|
||||
|
||||
test('the home is the unfiltered grid front door, local provider only', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/function\s+libHomeVisible[\s\S]*?state\.view === 'grid'[\s\S]*?state\.provider === 'local'[\s\S]*?!state\.selectMode[\s\S]*?!state\.q[\s\S]*?activeFilterCount\(\)\s*===\s*0/,
|
||||
'libHomeVisible must require grid view, the local provider, no select mode, no search, no active filters',
|
||||
);
|
||||
});
|
||||
|
||||
test('the shelf is recently-played, not-yet-mastered songs (per-song, deduped)', () => {
|
||||
assert.match(src, /\/api\/stats\/recent\?limit=/);
|
||||
// Mastery is gated on the per-SONG best (state.accuracy, what the badge
|
||||
// shows), not the per-arrangement recents row, and each filename appears
|
||||
// once — so no green-badged "keep practicing" card and no duplicates.
|
||||
assert.match(
|
||||
src,
|
||||
/const\s+best\s*=\s*acc\[r\.filename\][\s\S]*?best\s*>=\s*MASTERY_ACCURACY/,
|
||||
'the shelf must gate on the per-song best (state.accuracy) at MASTERY_ACCURACY',
|
||||
);
|
||||
assert.match(src, /seen\.has\(r\.filename\)/, 'the shelf must dedupe recents by filename');
|
||||
});
|
||||
|
||||
test('the meter + shelf fetch together and a stale render is discarded', () => {
|
||||
assert.match(src, /Promise\.all\(\[[\s\S]*?library\/stats[\s\S]*?stats\/recent/,
|
||||
'the two reads must be issued together (Promise.all), not sequentially');
|
||||
assert.match(src, /_homeToken[\s\S]*?_homeToken !== myToken/,
|
||||
'a stale render must be superseded by a newer one via a token');
|
||||
});
|
||||
|
||||
test('the repertoire denominator is the unfiltered library total', () => {
|
||||
assert.match(src, /\/api\/library\/stats\?provider='/);
|
||||
assert.match(src, /total_songs\s*\?\?\s*stats\.total/);
|
||||
assert.match(src, /Math\.round\(\(mastered\s*\/\s*total\)\s*\*\s*100\)/);
|
||||
});
|
||||
|
||||
test('the home + #v3-lib-home host are wired into render and reload', () => {
|
||||
assert.match(src, /id="v3-lib-home"/, 'render() must include the #v3-lib-home host');
|
||||
assert.match(src, /function reload\s*\([\s\S]*?updateLibraryHome\(\)/,
|
||||
'reload() must refresh/toggle the home');
|
||||
assert.match(src, /function applyScoreRefresh[\s\S]*?renderLibraryHome\(\)/,
|
||||
'a new score must refresh the meter + shelf');
|
||||
});
|
||||
|
||||
test('shelf cards play the song on click', () => {
|
||||
assert.match(
|
||||
src,
|
||||
/querySelectorAll\('\.v3-kp-card'\)[\s\S]*?window\.playSong\(enc\(fn\)/,
|
||||
'a shelf card click must call window.playSong with the recents filename',
|
||||
);
|
||||
});
|
||||
@@ -36,15 +36,13 @@ function makeStore() {
|
||||
};
|
||||
}
|
||||
|
||||
// Mirror of static/v3/songs.js _saveLibraryScrollSnapshot. Under the windowed
|
||||
// grid (#636 item 3 stage 2) geometry is stable, so the snapshot is just
|
||||
// {hash, scrollTop, view} — no page/loadedCount depth bookkeeping (restore sets
|
||||
// scrollTop and re-renders the window that maps to it).
|
||||
function saveSnapshot(storage, state, scrollTop) {
|
||||
function saveSnapshot(storage, state, scrollTop, page, loadedCount) {
|
||||
const snap = {
|
||||
hash: buildLibraryStateHash(state),
|
||||
scrollTop,
|
||||
view: state.view,
|
||||
page,
|
||||
loadedCount,
|
||||
};
|
||||
storage.setItem(SCROLL_STATE_KEY, JSON.stringify(snap));
|
||||
}
|
||||
@@ -90,21 +88,19 @@ test('buildLibraryStateHash is stable for equivalent filter arrays', () => {
|
||||
assert.strictEqual(buildLibraryStateHash(s1), buildLibraryStateHash(s2));
|
||||
});
|
||||
|
||||
test('snapshot stores scrollTop + view + hash (geometry-stable restore)', () => {
|
||||
test('snapshot stores scrollTop and page', () => {
|
||||
const storage = makeStore();
|
||||
saveSnapshot(storage, baseState, 1840);
|
||||
saveSnapshot(storage, baseState, 1840, 3, 96);
|
||||
const snap = readSnapshot(storage);
|
||||
assert.strictEqual(snap.scrollTop, 1840);
|
||||
assert.strictEqual(snap.view, 'grid');
|
||||
assert.strictEqual(snap.page, 3);
|
||||
assert.strictEqual(snap.loadedCount, 96);
|
||||
assert.strictEqual(snap.hash, buildLibraryStateHash(baseState));
|
||||
// Page-depth bookkeeping is gone — the windowed grid restores from scrollTop.
|
||||
assert.strictEqual(snap.page, undefined);
|
||||
assert.strictEqual(snap.loadedCount, undefined);
|
||||
});
|
||||
|
||||
test('stale snapshot is detected when filters change', () => {
|
||||
const storage = makeStore();
|
||||
saveSnapshot(storage, baseState, 500);
|
||||
saveSnapshot(storage, baseState, 500, 1, 48);
|
||||
const snap = readSnapshot(storage);
|
||||
const changed = buildLibraryStateHash({ ...baseState, q: 'beatles' });
|
||||
assert.notStrictEqual(snap.hash, changed);
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// Guards the v3 text-selection policy (static/v3/v3.css + static/v3/index.html):
|
||||
// the UI defaults to non-selectable so accidental chrome selection can't look
|
||||
// broken, while form fields, plugin screens, and core content opt back in. A
|
||||
// future global reset clobbering the rule — or the content containers losing
|
||||
// their .fb-selectable opt-in — should fail here.
|
||||
//
|
||||
// Source-level only — same strategy as the other tests/js/ files.
|
||||
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const root = path.join(__dirname, '..', '..');
|
||||
// Strip block comments so the policy's own explanatory prose (which quotes the
|
||||
// `* { user-select:none }` anti-pattern as a warning) can't trip the assertions.
|
||||
const css = fs.readFileSync(path.join(root, 'static', 'v3', 'v3.css'), 'utf8')
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '');
|
||||
const html = fs.readFileSync(path.join(root, 'static', 'v3', 'index.html'), 'utf8');
|
||||
|
||||
test('v3 defaults to non-selectable on html (not a universal `*` rule)', () => {
|
||||
assert.match(css, /html\s*\{[^}]*user-select:\s*none/,
|
||||
'html must default user-select: none');
|
||||
// The `* { user-select: none }` anti-pattern breaks input carets / IME — must not exist.
|
||||
assert.doesNotMatch(css, /\*\s*\{[^}]*user-select:\s*none/,
|
||||
'must NOT use a universal `*` user-select:none rule');
|
||||
});
|
||||
|
||||
test('form fields are always re-enabled (caret / IME safe)', () => {
|
||||
assert.match(
|
||||
css,
|
||||
/input,\s*textarea,\s*select[\s\S]*?contenteditable[\s\S]*?user-select:\s*text/,
|
||||
'input/textarea/select/[contenteditable] must be re-enabled to user-select: text',
|
||||
);
|
||||
});
|
||||
|
||||
test('plugin screen subtree stays selectable by inheritance (no `*`, respects plugin opt-outs)', () => {
|
||||
assert.match(
|
||||
css,
|
||||
/\.screen\[id\^="plugin-"\]\s*\{[^}]*user-select:\s*text/,
|
||||
'plugin screens must be re-enabled so plugin content is not silently un-copyable',
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
css,
|
||||
/\.screen\[id\^="plugin-"\]\s*\*/,
|
||||
'the plugin carve must NOT use `*` (would override a plugin\'s own non-select chrome)',
|
||||
);
|
||||
});
|
||||
|
||||
// The rule that re-enables selection on copyable content. Find the single
|
||||
// declaration block whose body sets `user-select: text`, then assert each
|
||||
// required selector is one of its selectors — order/format independent.
|
||||
const selectableRule = (css.match(/([^{}]*)\{[^}]*user-select:\s*text[^}]*\}/g) || [])
|
||||
.join('\n');
|
||||
|
||||
test('core content opts back in via .fb-selectable (element + descendants)', () => {
|
||||
assert.match(selectableRule, /\.fb-selectable\b/, '.fb-selectable must set user-select: text');
|
||||
assert.match(selectableRule, /\.fb-selectable\s*\*/, '...and its descendants (.fb-selectable *)');
|
||||
});
|
||||
|
||||
test('focused copyable surfaces (modals/toasts/scan banner) opt back in', () => {
|
||||
// The PR\'s a11y guardrail keeps copyable text selectable "incl. in
|
||||
// modals/toasts" — these carry errors / IDs / paths the user copies.
|
||||
assert.match(selectableRule, /\.feedBack-modal\b/, 'modals (.feedBack-modal) must be selectable');
|
||||
assert.match(selectableRule, /\[role="dialog"\]/, 'dialogs ([role="dialog"]) must be selectable');
|
||||
assert.match(selectableRule, /#fb-notify-stack\b/, 'toasts (#fb-notify-stack) must be selectable');
|
||||
assert.match(selectableRule, /#scan-banner\b/, 'the scan banner (#scan-banner) must be selectable');
|
||||
});
|
||||
|
||||
// Match a class="" attribute that contains ALL given tokens in any order.
|
||||
const hasClasses = (...tokens) => new RegExp(
|
||||
'class="' + tokens.map((t) => '(?=[^"]*\\b' + t + '\\b)').join('') + '[^"]*"');
|
||||
|
||||
test('the Settings panel and now-playing metadata carry .fb-selectable', () => {
|
||||
assert.match(html, hasClasses('fb-settings', 'fb-selectable'),
|
||||
'the Settings panel must opt back in (paths / version / diagnostics / About)');
|
||||
assert.match(html, hasClasses('fb-selectable', 'pointer-events-auto'),
|
||||
'the now-playing metadata must opt back in AND re-enable pointer-events '
|
||||
+ '(its #player-hud parent is pointer-events-none, which would block mouse selection)');
|
||||
});
|
||||
@@ -1,164 +0,0 @@
|
||||
"""Tests for smart/dynamic collections (got-feedback/feedBack#636 item 2).
|
||||
|
||||
A collection is a saved set of library filter rules, surfaced as a registered
|
||||
library provider so it inherits the v3 Songs UI. Storage reuses the playlists
|
||||
table (a `rules` JSON blob → smart collection); membership is the LIVE filter
|
||||
result, not stored songs.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def server_mod(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path))
|
||||
sys.modules.pop("server", None)
|
||||
mod = importlib.import_module("server")
|
||||
yield mod
|
||||
conn = getattr(getattr(mod, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(server_mod):
|
||||
c = TestClient(server_mod.app)
|
||||
try:
|
||||
yield c
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def _put(server_mod, *, filename, title, artist, tuning_name="E Standard", tuning_sort_key=0):
|
||||
server_mod.meta_db.put(filename, 1.0, 1, {
|
||||
"title": title, "artist": artist, "album": "LP", "year": "", "duration": 1.0,
|
||||
"tuning": tuning_name, "arrangements": [], "has_lyrics": False, "format": "archive",
|
||||
"stem_count": 0, "stem_ids": [], "tuning_name": tuning_name,
|
||||
"tuning_sort_key": tuning_sort_key, "tuning_offsets": "",
|
||||
})
|
||||
|
||||
|
||||
def _seed_mixed(server_mod):
|
||||
_put(server_mod, filename="d1.archive", title="Drop One", artist="Anna", tuning_name="Drop D", tuning_sort_key=-2)
|
||||
_put(server_mod, filename="d2.archive", title="Drop Two", artist="Bea", tuning_name="Drop D", tuning_sort_key=-2)
|
||||
_put(server_mod, filename="e1.archive", title="Std One", artist="Cy", tuning_name="E Standard")
|
||||
|
||||
|
||||
# ── CRUD ────────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_create_list_delete_collection(client):
|
||||
assert client.get("/api/collections").json() == {"collections": []}
|
||||
|
||||
r = client.post("/api/collections", json={"name": "Drop D stuff", "rules": {"tunings": ["Drop D"]}})
|
||||
assert r.status_code == 200
|
||||
col = r.json()["collection"]
|
||||
assert col["name"] == "Drop D stuff"
|
||||
assert col["rules"] == {"tunings": "Drop D"} # raw query-param format
|
||||
cid = col["id"]
|
||||
|
||||
listed = client.get("/api/collections").json()["collections"]
|
||||
assert [c["name"] for c in listed] == ["Drop D stuff"]
|
||||
|
||||
assert client.request("DELETE", f"/api/collections/{cid}").json() == {"ok": True}
|
||||
assert client.get("/api/collections").json() == {"collections": []}
|
||||
|
||||
|
||||
def test_create_requires_name_and_sanitizes_rules(client):
|
||||
assert client.post("/api/collections", json={"rules": {}}).status_code == 400
|
||||
# Unknown rule keys are dropped (never 500); known ones normalized to the
|
||||
# raw query-param format (list→CSV, favorites→1).
|
||||
col = client.post("/api/collections", json={
|
||||
"name": "Mix", "rules": {"tunings": ["Drop D", "Eb Standard"], "sort": "title", "bogus": "x", "favorites": True},
|
||||
}).json()["collection"]
|
||||
assert col["rules"] == {"tunings": "Drop D,Eb Standard", "sort": "title", "favorites": 1}
|
||||
|
||||
|
||||
def test_update_collection(client):
|
||||
cid = client.post("/api/collections", json={"name": "A", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
r = client.put(f"/api/collections/{cid}", json={"name": "B", "rules": {"format": "sloppak"}})
|
||||
assert r.status_code == 200
|
||||
assert r.json()["collection"]["name"] == "B"
|
||||
assert r.json()["collection"]["rules"] == {"format": "sloppak"}
|
||||
assert client.put("/api/collections/99999", json={"name": "x"}).status_code == 404
|
||||
|
||||
|
||||
# ── Provider behaviour ──────────────────────────────────────────────────────
|
||||
|
||||
def test_collection_registers_as_a_provider(client, server_mod):
|
||||
_seed_mixed(server_mod)
|
||||
cid = client.post("/api/collections", json={"name": "DropD", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
providers = client.get("/api/library/providers").json()["providers"]
|
||||
ids = [p["id"] for p in providers]
|
||||
assert f"collection:{cid}" in ids
|
||||
|
||||
|
||||
def test_collection_provider_returns_only_matching_songs(client, server_mod):
|
||||
_seed_mixed(server_mod)
|
||||
cid = client.post("/api/collections", json={"name": "DropD", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
pid = f"collection:{cid}"
|
||||
|
||||
page = client.get("/api/library", params={"provider": pid}).json()
|
||||
titles = sorted(s["title"] for s in page["songs"])
|
||||
assert titles == ["Drop One", "Drop Two"] # E Standard song excluded
|
||||
|
||||
stats = client.get("/api/library/stats", params={"provider": pid}).json()
|
||||
assert stats["total_songs"] == 2
|
||||
|
||||
|
||||
def test_collection_provider_is_local_kind(client, server_mod):
|
||||
# kind="local" keeps the client's play/art paths on the local branch (a
|
||||
# collection's matched songs are local rows), not the remote-sync branch.
|
||||
cid = client.post("/api/collections", json={"name": "C", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
prov = next(p for p in client.get("/api/library/providers").json()["providers"]
|
||||
if p["id"] == f"collection:{cid}")
|
||||
assert prov["kind"] == "local"
|
||||
|
||||
|
||||
def test_collection_tolerates_corrupt_persisted_rules(client, server_mod):
|
||||
# A hand-edited / imported bad rules row (int where a string is expected, a
|
||||
# list for `sort`) must not crash the query — the provider re-sanitizes on
|
||||
# load. Write the bad JSON straight past the API sanitizer.
|
||||
_seed_mixed(server_mod)
|
||||
cid = client.post("/api/collections", json={"name": "Bad", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
# `artist: []` (list for a string field) and `sort: []` (unhashable) are
|
||||
# the values that would crash `.strip()` / `sort_map.get` if they reached a
|
||||
# query — they must be dropped, leaving the valid `tunings` rule intact.
|
||||
server_mod.meta_db.conn.execute(
|
||||
"UPDATE playlists SET rules = ? WHERE id = ?",
|
||||
('{"artist": [], "sort": [], "tunings": ["Drop D"]}', cid),
|
||||
)
|
||||
server_mod.meta_db.conn.commit()
|
||||
server_mod._sync_collection_provider(server_mod.meta_db.get_collection(cid))
|
||||
|
||||
r = client.get("/api/library", params={"provider": f"collection:{cid}"})
|
||||
assert r.status_code == 200 # no 500/503 from bad rules
|
||||
assert sorted(s["title"] for s in r.json()["songs"]) == ["Drop One", "Drop Two"]
|
||||
|
||||
|
||||
def test_collection_provider_survives_restart(client, server_mod, tmp_path, monkeypatch):
|
||||
_seed_mixed(server_mod)
|
||||
cid = client.post("/api/collections", json={"name": "DropD", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
server_mod.meta_db.conn.close()
|
||||
# Re-import the server (same CONFIG_DIR) → boot scan must re-register it.
|
||||
sys.modules.pop("server", None)
|
||||
mod2 = importlib.import_module("server")
|
||||
try:
|
||||
ids = [p["id"] for p in mod2.library_providers.list()]
|
||||
assert f"collection:{cid}" in ids
|
||||
finally:
|
||||
mod2.meta_db.conn.close()
|
||||
|
||||
|
||||
# ── Isolation from manual playlists ─────────────────────────────────────────
|
||||
|
||||
def test_collections_excluded_from_playlists_and_are_read_only(client):
|
||||
cid = client.post("/api/collections", json={"name": "Coll", "rules": {"tunings": ["Drop D"]}}).json()["collection"]["id"]
|
||||
# Not listed among manual playlists...
|
||||
assert all(p["id"] != cid for p in client.get("/api/playlists").json())
|
||||
# ...and manual-playlist mutations 404 on a collection id (get_playlist gate).
|
||||
assert client.post(f"/api/playlists/{cid}/songs", json={"filename": "d1.archive"}).status_code == 404
|
||||
assert client.get(f"/api/playlists/{cid}").status_code == 404
|
||||
@@ -1,159 +0,0 @@
|
||||
"""Tests for feedpak contributor credits on the highway.
|
||||
|
||||
Covers the `_sanitize_authors` helper (unit) and the `song_info` WebSocket
|
||||
frame carrying the manifest `authors` list end-to-end (integration). The
|
||||
frontend uses a non-empty `authors` list to gate a credits overlay shown when
|
||||
a song loads, so loose/archive/synthetic plays must surface `[]`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import json
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
# ── _sanitize_authors unit tests ────────────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def server_mod(monkeypatch, tmp_path):
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path / "config"))
|
||||
monkeypatch.setenv("DLC_DIR", str(tmp_path / "dlc"))
|
||||
(tmp_path / "dlc").mkdir()
|
||||
sys.modules.pop("server", None)
|
||||
mod = importlib.import_module("server")
|
||||
yield mod
|
||||
conn = getattr(getattr(mod, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_sanitize_authors_valid(server_mod):
|
||||
out = server_mod._sanitize_authors(
|
||||
{
|
||||
"authors": [
|
||||
{"name": "Azure", "role": "charter", "email": "a@b.c", "url": "x"},
|
||||
{"name": "Bob Lee", "role": "editor"},
|
||||
{"name": "Solo"},
|
||||
]
|
||||
}
|
||||
)
|
||||
# name + role only; email/url dropped; missing role → None.
|
||||
assert out == [
|
||||
{"name": "Azure", "role": "charter"},
|
||||
{"name": "Bob Lee", "role": "editor"},
|
||||
{"name": "Solo", "role": None},
|
||||
]
|
||||
|
||||
|
||||
def test_sanitize_authors_skips_malformed(server_mod):
|
||||
out = server_mod._sanitize_authors(
|
||||
{
|
||||
"authors": [
|
||||
{"name": ""}, # blank name → skipped
|
||||
{"name": " "}, # whitespace name → skipped
|
||||
{"role": "mixer"}, # no name → skipped
|
||||
"not-a-dict", # non-dict → skipped
|
||||
{"name": " Kept ", "role": " arranger "}, # trimmed
|
||||
]
|
||||
}
|
||||
)
|
||||
assert out == [{"name": "Kept", "role": "arranger"}]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("manifest", [None, {}, {"authors": None}, {"authors": "x"}, "nope"])
|
||||
def test_sanitize_authors_absent_or_nonlist(server_mod, manifest):
|
||||
assert server_mod._sanitize_authors(manifest) == []
|
||||
|
||||
|
||||
# ── song_info WS integration ────────────────────────────────────────────────
|
||||
|
||||
|
||||
def _write_sloppak(dlc_root, *, authors):
|
||||
pak = dlc_root / "authortest.sloppak"
|
||||
pak.mkdir()
|
||||
(pak / "arrangements").mkdir()
|
||||
(pak / "arrangements" / "lead.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"notes": [],
|
||||
"chords": [],
|
||||
"anchors": [],
|
||||
"handshapes": [],
|
||||
"templates": [],
|
||||
"beats": [{"time": 0.0, "measure": 1}],
|
||||
"sections": [{"name": "intro", "number": 1, "time": 0.0}],
|
||||
}
|
||||
)
|
||||
)
|
||||
manifest = {
|
||||
"title": "Author Test",
|
||||
"artist": "Tester",
|
||||
"album": "",
|
||||
"year": 2026,
|
||||
"duration": 10.0,
|
||||
"arrangements": [{"id": "lead", "name": "Lead", "file": "arrangements/lead.json"}],
|
||||
"stems": [],
|
||||
}
|
||||
if authors is not None:
|
||||
manifest["authors"] = authors
|
||||
(pak / "manifest.yaml").write_text(yaml.safe_dump(manifest, sort_keys=False))
|
||||
return pak
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def make_client(tmp_path, monkeypatch):
|
||||
def _make():
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path / "config"))
|
||||
monkeypatch.setenv("DLC_DIR", str(tmp_path / "dlc"))
|
||||
monkeypatch.setenv("FEEDBACK_SYNC_STARTUP", "1")
|
||||
sys.modules.pop("server", None)
|
||||
server = importlib.import_module("server")
|
||||
monkeypatch.setattr(server, "load_plugins", lambda *a, **kw: None)
|
||||
monkeypatch.setattr(server, "startup_scan", lambda: None)
|
||||
monkeypatch.setattr(server, "SLOPPAK_CACHE_DIR", tmp_path / "cache")
|
||||
return server
|
||||
|
||||
(tmp_path / "dlc").mkdir()
|
||||
yield _make
|
||||
server = sys.modules.get("server")
|
||||
conn = getattr(getattr(server, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _song_info(client, path):
|
||||
with client.websocket_connect(path) as ws:
|
||||
for _ in range(200):
|
||||
msg = ws.receive_json()
|
||||
if msg.get("error"):
|
||||
raise AssertionError(f"WS error frame: {msg}")
|
||||
if msg.get("type") == "song_info":
|
||||
return msg
|
||||
if msg.get("type") == "ready":
|
||||
break
|
||||
raise AssertionError("no song_info frame received")
|
||||
|
||||
|
||||
def test_song_info_carries_authors(make_client):
|
||||
server = make_client()
|
||||
_write_sloppak(
|
||||
server._get_dlc_dir(),
|
||||
authors=[{"name": "Azure", "role": "charter", "email": "a@b.c"}],
|
||||
)
|
||||
with TestClient(server.app) as client:
|
||||
info = _song_info(client, "/ws/highway/authortest.sloppak?arrangement=0")
|
||||
assert info["authors"] == [{"name": "Azure", "role": "charter"}]
|
||||
|
||||
|
||||
def test_song_info_authors_empty_when_absent(make_client):
|
||||
server = make_client()
|
||||
_write_sloppak(server._get_dlc_dir(), authors=None)
|
||||
with TestClient(server.app) as client:
|
||||
info = _song_info(client, "/ws/highway/authortest.sloppak?arrangement=0")
|
||||
assert info["authors"] == []
|
||||
@@ -398,39 +398,6 @@ def test_query_stats_groups_non_ascii_artist_letters_under_hash(client, server_m
|
||||
assert stats["letters"] == {"#": 1}
|
||||
|
||||
|
||||
def test_query_stats_sort_letters_artist_counts_songs(client, server_mod):
|
||||
"""The v3 jump rail's `sort_letters` counts SONGS per first-letter bucket
|
||||
of the active sort column (vs `letters`, which counts distinct artists).
|
||||
Two songs by the same A-artist → letters {A:1}, sort_letters {A:2}."""
|
||||
_put(server_mod, filename="a1.archive", title="Song One", artist="Abba")
|
||||
_put(server_mod, filename="a2.archive", title="Song Two", artist="Abba")
|
||||
_put(server_mod, filename="b1.archive", title="Another", artist="Beck")
|
||||
_put(server_mod, filename="num.archive", title="Track", artist="2Pac")
|
||||
|
||||
# sort_letters=1 opts into the active-sort breakdown (the jump rail path).
|
||||
stats = client.get("/api/library/stats", params={"sort": "artist", "sort_letters": 1}).json()
|
||||
assert stats["letters"] == {"A": 1, "B": 1, "#": 1} # distinct artists
|
||||
assert stats["sort_letters"] == {"A": 2, "B": 1, "#": 1} # songs
|
||||
|
||||
# Without the opt-in, the extra breakdown is not computed or returned.
|
||||
plain = client.get("/api/library/stats", params={"sort": "artist"}).json()
|
||||
assert "sort_letters" not in plain
|
||||
assert plain["letters"] == {"A": 1, "B": 1, "#": 1}
|
||||
|
||||
|
||||
def test_query_stats_sort_letters_follow_title_sort(client, server_mod):
|
||||
"""With a title sort, the rail buckets key on the TITLE's first letter,
|
||||
not the artist's, so a tap lands on a real card in the grid's order."""
|
||||
_put(server_mod, filename="z1.archive", title="Apple", artist="Zztop")
|
||||
_put(server_mod, filename="z2.archive", title="Banana", artist="Zztop")
|
||||
|
||||
stats = client.get("/api/library/stats", params={"sort": "title", "sort_letters": 1}).json()
|
||||
assert stats["sort_letters"] == {"A": 1, "B": 1}
|
||||
# The legacy artist breakdown is unchanged regardless of sort — both songs
|
||||
# share one artist, so it stays a single distinct-artist Z bucket.
|
||||
assert stats["letters"] == {"Z": 1}
|
||||
|
||||
|
||||
def test_query_stats_ignores_null_letter_counts(server_mod):
|
||||
"""Legacy/corrupt rows can surface as NULL-ish letter aggregate
|
||||
rows on some SQLite builds. The stats endpoint should ignore those
|
||||
@@ -462,13 +429,9 @@ def test_query_stats_ignores_null_letter_counts(server_mod):
|
||||
server_mod.meta_db.conn.close()
|
||||
server_mod.meta_db.conn = FakeConn()
|
||||
|
||||
stats = server_mod.meta_db.query_stats(want_sort_letters=True)
|
||||
stats = server_mod.meta_db.query_stats()
|
||||
|
||||
# `sort_letters` (the v3 jump-rail breakdown) shares the GROUP BY letter
|
||||
# path in this fake, so it surfaces the same single live bucket when the
|
||||
# caller opts in.
|
||||
assert stats == {"total_songs": 1, "total_artists": 1,
|
||||
"letters": {"T": 1}, "sort_letters": {"T": 1}}
|
||||
assert stats == {"total_songs": 1, "total_artists": 1, "letters": {"T": 1}}
|
||||
|
||||
|
||||
def test_compound_sort_with_legacy_dir_desc_doesnt_error(client, seeded):
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
"""Keyset (cursor) pagination for the library grid (feedBack#636 item 3, stage 1).
|
||||
|
||||
Pins the data layer the virtualized grid builds on:
|
||||
- every sort gets a unique `filename` tiebreak → a TOTAL order (fixes the
|
||||
latent OFFSET skip/dupe across equal-key rows);
|
||||
- `/api/library?after=<cursor>` walks the SAME total order with a WHERE-seek,
|
||||
returning exactly the OFFSET page would, with no gaps or dupes;
|
||||
- bad cursors / non-keyset sorts fall back to OFFSET safely.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def server_mod(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path))
|
||||
sys.modules.pop("server", None)
|
||||
mod = importlib.import_module("server")
|
||||
yield mod
|
||||
conn = getattr(getattr(mod, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(server_mod):
|
||||
c = TestClient(server_mod.app)
|
||||
try:
|
||||
yield c
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def _seed(server_mod, n=25, *, shared_artist=False):
|
||||
for i in range(n):
|
||||
artist = "SameArtist" if shared_artist else f"Artist{i:02d}"
|
||||
server_mod.meta_db.put(f"song{i:02d}.archive", float(i), 1, {
|
||||
"title": f"Title{i:02d}", "artist": artist, "album": "LP", "year": "",
|
||||
"duration": 1.0, "tuning": "E Standard", "arrangements": [], "has_lyrics": False,
|
||||
"format": "archive", "stem_count": 0, "stem_ids": [], "tuning_name": "E Standard",
|
||||
"tuning_sort_key": 0, "tuning_offsets": "",
|
||||
})
|
||||
|
||||
|
||||
def _walk_keyset(client, sort, size, total):
|
||||
"""Page the whole library via the cursor and return the filename order."""
|
||||
seen, cursor, guard = [], "", 0
|
||||
while len(seen) < total and guard < total + 5:
|
||||
guard += 1
|
||||
params = {"sort": sort, "size": size}
|
||||
if cursor:
|
||||
params["after"] = cursor
|
||||
body = client.get("/api/library", params=params).json()
|
||||
seen.extend(s["filename"] for s in body["songs"])
|
||||
cursor = body.get("next_cursor")
|
||||
if not body["songs"] or not cursor:
|
||||
break
|
||||
return seen
|
||||
|
||||
|
||||
def _walk_offset(client, sort, size, total):
|
||||
seen, page = [], 0
|
||||
while len(seen) < total:
|
||||
body = client.get("/api/library", params={"sort": sort, "size": size, "page": page}).json()
|
||||
if not body["songs"]:
|
||||
break
|
||||
seen.extend(s["filename"] for s in body["songs"])
|
||||
page += 1
|
||||
return seen
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sort", ["artist", "artist-desc", "title", "title-desc", "recent"])
|
||||
def test_keyset_matches_offset_exactly(client, server_mod, sort):
|
||||
_seed(server_mod, 25)
|
||||
offset_order = _walk_offset(client, sort, 7, 25)
|
||||
keyset_order = _walk_keyset(client, sort, 7, 25)
|
||||
assert keyset_order == offset_order # same order...
|
||||
assert len(keyset_order) == 25
|
||||
assert len(set(keyset_order)) == 25 # ...no gaps, no dupes
|
||||
|
||||
|
||||
def test_stable_tiebreak_on_equal_keys(client, server_mod):
|
||||
# 25 songs, all the SAME artist → the artist sort is decided entirely by the
|
||||
# filename tiebreak. Both pagers must still cover all 25 with no dupe.
|
||||
_seed(server_mod, 25, shared_artist=True)
|
||||
keyset_order = _walk_keyset(client, "artist", 6, 25)
|
||||
assert len(keyset_order) == 25 and len(set(keyset_order)) == 25
|
||||
assert keyset_order == sorted(keyset_order) # tiebreak is filename ASC
|
||||
|
||||
|
||||
def test_first_page_has_cursor_and_no_after_is_offset(client, server_mod):
|
||||
_seed(server_mod, 5)
|
||||
body = client.get("/api/library", params={"sort": "artist", "size": 2}).json()
|
||||
assert body["next_cursor"] # cursor offered
|
||||
assert [s["filename"] for s in body["songs"]] == ["song00.archive", "song01.archive"]
|
||||
|
||||
|
||||
def test_bad_cursor_falls_back_to_first_page(client, server_mod):
|
||||
_seed(server_mod, 5)
|
||||
body = client.get("/api/library", params={"sort": "artist", "size": 3, "after": "not-a-cursor"}).json()
|
||||
assert [s["filename"] for s in body["songs"]] == ["song00.archive", "song01.archive", "song02.archive"]
|
||||
|
||||
|
||||
def test_legacy_dir_desc_keysets_correctly(client, server_mod):
|
||||
# The legacy `sort=artist&dir=desc` shape must keyset against a DESC order
|
||||
# (canonicalized to artist-desc), not seek `>` against it → no gaps/dupes.
|
||||
_seed(server_mod, 20)
|
||||
offset_order, page = [], 0
|
||||
while True:
|
||||
body = client.get("/api/library", params={"sort": "artist", "dir": "desc", "size": 6, "page": page}).json()
|
||||
if not body["songs"]:
|
||||
break
|
||||
offset_order.extend(s["filename"] for s in body["songs"])
|
||||
page += 1
|
||||
keyset, cursor, guard = [], "", 0
|
||||
while len(keyset) < 20 and guard < 25:
|
||||
guard += 1
|
||||
params = {"sort": "artist", "dir": "desc", "size": 6}
|
||||
if cursor:
|
||||
params["after"] = cursor
|
||||
body = client.get("/api/library", params=params).json()
|
||||
keyset.extend(s["filename"] for s in body["songs"])
|
||||
cursor = body.get("next_cursor")
|
||||
if not body["songs"] or not cursor:
|
||||
break
|
||||
assert keyset == offset_order
|
||||
assert len(set(keyset)) == 20
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sort", ["artist", "artist-desc", "recent"])
|
||||
def test_keyset_handles_null_sort_keys(client, server_mod, sort):
|
||||
# NULL artist/mtime (corrupt/legacy rows past put()'s '' defaults) sort
|
||||
# first in ASC / last in DESC; keyset must cover them exactly like OFFSET.
|
||||
_seed(server_mod, 10)
|
||||
server_mod.meta_db.conn.executemany(
|
||||
"INSERT INTO songs (filename, mtime, size, title, artist) VALUES (?, NULL, 1, ?, NULL)",
|
||||
[("zznull1.archive", "ZZ1"), ("zznull2.archive", "ZZ2")],
|
||||
)
|
||||
server_mod.meta_db.conn.commit()
|
||||
offset_order = _walk_offset(client, sort, 4, 12)
|
||||
keyset_order = _walk_keyset(client, sort, 4, 12)
|
||||
assert keyset_order == offset_order
|
||||
assert len(keyset_order) == 12 and len(set(keyset_order)) == 12
|
||||
|
||||
|
||||
def test_non_keyset_sort_offers_no_cursor(client, server_mod):
|
||||
_seed(server_mod, 5)
|
||||
body = client.get("/api/library", params={"sort": "tuning", "size": 2}).json()
|
||||
assert body["next_cursor"] is None # compound sort → OFFSET only
|
||||
assert len(body["songs"]) == 2
|
||||
@@ -213,9 +213,7 @@ def test_registered_provider_handles_library_endpoints(server_mod, client):
|
||||
assert stats["letters"] == {"R": 1}
|
||||
assert "page" not in provider.stats_kwargs
|
||||
assert "size" not in provider.stats_kwargs
|
||||
# `sort` is forwarded to query_stats now (the v3 jump rail keys its
|
||||
# present-letter breakdown on the active sort column); defaults to "artist".
|
||||
assert provider.stats_kwargs.get("sort") == "artist"
|
||||
assert "sort" not in provider.stats_kwargs
|
||||
|
||||
tunings = client.get("/api/library/tuning-names", params={"provider": "remote:frodo"}).json()
|
||||
assert tunings["tunings"][0]["name"] == "E Standard"
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
"""Tests for the library-DB + custom-art half of the settings bundle
|
||||
(got-feedback/feedBack#636 item 1).
|
||||
|
||||
The base bundle (config + plugin files) is covered in test_settings_export.py;
|
||||
this file pins the additive `core_server_files` section:
|
||||
|
||||
- the live library DB is exported as a CONSISTENT single-file snapshot
|
||||
(SQLite online-backup), base64-encoded;
|
||||
- custom playlist covers / avatar are walked into the bundle;
|
||||
- on import the DB is STAGED to `web_library.db.restore` (never written
|
||||
over the live, open DB) and swapped in at next startup, clearing stale
|
||||
WAL sidecars; custom art is written immediately;
|
||||
- the whole thing round-trips: export → wipe → import → restart → data back.
|
||||
"""
|
||||
|
||||
import base64
|
||||
import importlib
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def server_mod(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path))
|
||||
sys.modules.pop("server", None)
|
||||
mod = importlib.import_module("server")
|
||||
yield mod
|
||||
conn = getattr(getattr(mod, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(server_mod):
|
||||
c = TestClient(server_mod.app)
|
||||
try:
|
||||
yield c
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def _valid_db_bytes(tmp_path, name="mk.db", marker="x"):
|
||||
"""Bytes of a small, valid (quick_check-clean) SQLite database."""
|
||||
p = tmp_path / name
|
||||
c = sqlite3.connect(str(p))
|
||||
try:
|
||||
c.execute("CREATE TABLE t (x TEXT)")
|
||||
c.execute("INSERT INTO t VALUES (?)", (marker,))
|
||||
c.commit()
|
||||
finally:
|
||||
c.close()
|
||||
return p.read_bytes()
|
||||
|
||||
|
||||
def _seed_song(server_mod, filename="marker.archive", title="Marker", artist="Tester"):
|
||||
server_mod.meta_db.put(filename, 1.0, 1, {
|
||||
"title": title, "artist": artist, "album": "LP", "year": "",
|
||||
"duration": 200.0, "tuning": "E Standard", "arrangements": [],
|
||||
"has_lyrics": False, "format": "archive", "stem_count": 0,
|
||||
"stem_ids": [], "tuning_name": "E Standard", "tuning_sort_key": 0,
|
||||
"tuning_offsets": "",
|
||||
})
|
||||
|
||||
|
||||
# ── Export ──────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_export_includes_consistent_library_db_snapshot(client, server_mod, tmp_path):
|
||||
_seed_song(server_mod, filename="snap.archive", title="SnapSong")
|
||||
|
||||
bundle = client.get("/api/settings/export").json()
|
||||
core = bundle["core_server_files"]
|
||||
assert "web_library.db" in core
|
||||
entry = core["web_library.db"]
|
||||
assert entry["encoding"] == "base64"
|
||||
|
||||
# The snapshot must be a complete, openable DB reflecting current data —
|
||||
# written to its own file (no WAL sidecar needed) and queryable.
|
||||
snap = tmp_path / "snapshot.db"
|
||||
snap.write_bytes(base64.b64decode(entry["data"]))
|
||||
conn = sqlite3.connect(str(snap))
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"SELECT title FROM songs WHERE filename = ?", ("snap.archive",)
|
||||
).fetchall()
|
||||
finally:
|
||||
conn.close()
|
||||
assert rows == [("SnapSong",)]
|
||||
|
||||
|
||||
def test_export_includes_custom_art_dirs(client, tmp_path):
|
||||
(tmp_path / "playlist_covers").mkdir()
|
||||
(tmp_path / "playlist_covers" / "3.png").write_bytes(b"\x89PNG-cover")
|
||||
(tmp_path / "avatars").mkdir()
|
||||
(tmp_path / "avatars" / "me.png").write_bytes(b"\x89PNG-avatar")
|
||||
|
||||
core = client.get("/api/settings/export").json()["core_server_files"]
|
||||
assert core["playlist_covers/3.png"]["encoding"] == "base64"
|
||||
assert base64.b64decode(core["playlist_covers/3.png"]["data"]) == b"\x89PNG-cover"
|
||||
assert base64.b64decode(core["avatars/me.png"]["data"]) == b"\x89PNG-avatar"
|
||||
|
||||
|
||||
# ── Import: DB is staged, never written over the live file ──────────────────
|
||||
|
||||
def test_import_stages_db_restore_without_touching_live_db(client, server_mod, tmp_path):
|
||||
live = tmp_path / "web_library.db"
|
||||
live_bytes_before = live.read_bytes()
|
||||
|
||||
payload = _valid_db_bytes(tmp_path, name="incoming.db", marker="restored")
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"web_library.db": {"encoding": "base64",
|
||||
"data": base64.b64encode(payload).decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["ok"] is True
|
||||
assert body["restart_required"] is True
|
||||
assert any("restart" in w.lower() for w in body["warnings"])
|
||||
assert "web_library.db" in body["applied"]["core_files"]
|
||||
|
||||
# Live DB untouched; the restore is staged beside it for next startup.
|
||||
assert live.read_bytes() == live_bytes_before
|
||||
assert (tmp_path / "web_library.db.restore").read_bytes() == payload
|
||||
|
||||
|
||||
def test_import_rejects_corrupt_db_with_valid_magic_header(client, server_mod, tmp_path):
|
||||
# The dangerous case: SQLite magic header but a corrupt body. It must be
|
||||
# refused at import — otherwise startup would delete the live DB and then
|
||||
# fail to open the bad restore.
|
||||
corrupt = b"SQLite format 3\x00" + b"\xff" * 200
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"web_library.db": {"encoding": "base64",
|
||||
"data": base64.b64encode(corrupt).decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 400
|
||||
assert not (tmp_path / "web_library.db.restore").exists()
|
||||
|
||||
|
||||
def test_import_rejects_non_sqlite_db_payload(client, server_mod, tmp_path):
|
||||
# A truncated / wrong file staged as the restore would brick startup —
|
||||
# reject anything lacking the SQLite magic header, before touching disk.
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"web_library.db": {"encoding": "base64",
|
||||
"data": base64.b64encode(b"not a database").decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 400
|
||||
assert not (tmp_path / "web_library.db.restore").exists()
|
||||
|
||||
|
||||
def test_import_writes_custom_art_immediately(client, server_mod, tmp_path):
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"playlist_covers/7.png": {"encoding": "base64",
|
||||
"data": base64.b64encode(b"cover7").decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 200
|
||||
assert r.json()["restart_required"] is False
|
||||
assert (tmp_path / "playlist_covers" / "7.png").read_bytes() == b"cover7"
|
||||
|
||||
|
||||
def test_import_core_path_traversal_rejected(client, server_mod, tmp_path):
|
||||
secret = tmp_path.parent / "escape.txt"
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"../escape.txt": {"encoding": "base64",
|
||||
"data": base64.b64encode(b"pwned").decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 400
|
||||
assert not secret.exists()
|
||||
|
||||
|
||||
def test_import_core_undeclared_path_skipped_not_fatal(client, server_mod, tmp_path):
|
||||
# A relpath outside the core allowlist is a warn-and-skip, not a refusal —
|
||||
# the rest of the bundle still applies.
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"audio_cache/x.ogg": {"encoding": "base64",
|
||||
"data": base64.b64encode(b"nope").decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 200
|
||||
assert not (tmp_path / "audio_cache" / "x.ogg").exists()
|
||||
assert any("undeclared" in w.lower() for w in r.json()["warnings"])
|
||||
|
||||
|
||||
# ── Startup swap ────────────────────────────────────────────────────────────
|
||||
|
||||
def test_apply_pending_db_restore_swaps_and_clears_sidecars(server_mod, tmp_path):
|
||||
main = tmp_path / "web_library.db"
|
||||
new_db = _valid_db_bytes(tmp_path, name="new.db", marker="new")
|
||||
# Simulate a live DB with stale WAL sidecars + a (valid) staged restore.
|
||||
main.write_bytes(b"OLD-DB")
|
||||
(tmp_path / "web_library.db-wal").write_bytes(b"OLD-WAL")
|
||||
(tmp_path / "web_library.db-shm").write_bytes(b"OLD-SHM")
|
||||
(tmp_path / "web_library.db.restore").write_bytes(new_db)
|
||||
|
||||
server_mod._apply_pending_db_restore(tmp_path)
|
||||
|
||||
assert main.read_bytes() == new_db # swapped in
|
||||
assert not (tmp_path / "web_library.db.restore").exists()
|
||||
assert not (tmp_path / "web_library.db-wal").exists() # stale sidecars gone
|
||||
assert not (tmp_path / "web_library.db-shm").exists()
|
||||
|
||||
|
||||
def test_apply_pending_db_restore_discards_corrupt_keeps_live(server_mod, tmp_path):
|
||||
# A corrupt staged restore must be thrown away WITHOUT destroying the
|
||||
# live DB — never brick startup or lose data for a bad bundle.
|
||||
main = tmp_path / "web_library.db"
|
||||
main.write_bytes(b"LIVE-GOOD-DB")
|
||||
(tmp_path / "web_library.db.restore").write_bytes(b"SQLite format 3\x00" + b"\xff" * 64)
|
||||
|
||||
server_mod._apply_pending_db_restore(tmp_path)
|
||||
|
||||
assert main.read_bytes() == b"LIVE-GOOD-DB" # live DB preserved
|
||||
assert not (tmp_path / "web_library.db.restore").exists() # bad restore dropped
|
||||
|
||||
|
||||
def test_apply_pending_db_restore_noop_without_staging(server_mod, tmp_path):
|
||||
(tmp_path / "web_library.db").write_bytes(b"LIVE")
|
||||
server_mod._apply_pending_db_restore(tmp_path) # nothing staged
|
||||
assert (tmp_path / "web_library.db").read_bytes() == b"LIVE"
|
||||
|
||||
|
||||
# ── Full round-trip ─────────────────────────────────────────────────────────
|
||||
|
||||
def test_full_db_backup_restore_round_trip(client, server_mod, tmp_path):
|
||||
_seed_song(server_mod, filename="keepme.archive", title="KeepMe")
|
||||
bundle = client.get("/api/settings/export").json()
|
||||
|
||||
# Lose the data (a song removed from the live DB after the backup).
|
||||
server_mod.meta_db.conn.execute("DELETE FROM songs WHERE filename = ?", ("keepme.archive",))
|
||||
server_mod.meta_db.conn.commit()
|
||||
assert server_mod.meta_db.conn.execute(
|
||||
"SELECT COUNT(*) FROM songs WHERE filename = ?", ("keepme.archive",)
|
||||
).fetchone()[0] == 0
|
||||
|
||||
# Re-import the bundle → DB staged, not yet live.
|
||||
r = client.post("/api/settings/import", json=bundle)
|
||||
assert r.status_code == 200 and r.json()["restart_required"] is True
|
||||
|
||||
# Simulate a restart: close the live conn, apply the staged restore,
|
||||
# reopen — the song is back.
|
||||
server_mod.meta_db.conn.close()
|
||||
server_mod._apply_pending_db_restore(tmp_path)
|
||||
conn = sqlite3.connect(str(tmp_path / "web_library.db"))
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"SELECT title FROM songs WHERE filename = ?", ("keepme.archive",)
|
||||
).fetchall()
|
||||
finally:
|
||||
conn.close()
|
||||
assert rows == [("KeepMe",)]
|
||||
assert not (tmp_path / "web_library.db.restore").exists()
|
||||
|
||||
|
||||
# ── Failure modes ───────────────────────────────────────────────────────────
|
||||
|
||||
def test_export_fails_hard_when_db_snapshot_unavailable(client, server_mod, monkeypatch):
|
||||
# A backup that silently omits the library DB is a data-loss trap — the
|
||||
# export must error rather than hand back an incomplete-looking bundle.
|
||||
monkeypatch.setattr(server_mod, "_snapshot_library_db", lambda: None)
|
||||
r = client.get("/api/settings/export")
|
||||
assert r.status_code == 500
|
||||
assert "library database" in r.json()["error"].lower()
|
||||
|
||||
|
||||
def test_failed_import_disarms_staged_db_restore(client, server_mod, tmp_path, monkeypatch):
|
||||
# If a later write in phase 2 fails, the request 500s — but a staged DB
|
||||
# restore must NOT survive to swap in on the next restart.
|
||||
payload = _valid_db_bytes(tmp_path, name="incoming.db")
|
||||
real_write = server_mod._atomic_write_file
|
||||
|
||||
def boom(target, data):
|
||||
if target.name == "config.json": # last write of the commit
|
||||
raise OSError("disk full")
|
||||
return real_write(target, data)
|
||||
|
||||
monkeypatch.setattr(server_mod, "_atomic_write_file", boom)
|
||||
r = client.post("/api/settings/import", json={
|
||||
"schema": server_mod.SETTINGS_BUNDLE_SCHEMA,
|
||||
"server_config": {},
|
||||
"core_server_files": {
|
||||
"web_library.db": {"encoding": "base64",
|
||||
"data": base64.b64encode(payload).decode()},
|
||||
},
|
||||
})
|
||||
assert r.status_code == 500
|
||||
assert not (tmp_path / "web_library.db.restore").exists()
|
||||
@@ -1,111 +0,0 @@
|
||||
"""Tests for the wishlist / "wanted" list (got-feedback/feedBack#636 item 4).
|
||||
|
||||
A wishlist entry is a song the user does NOT own yet (the *arr Wanted/Monitored
|
||||
analogue), so it lives in its own `wanted` table keyed by descriptive identity
|
||||
rather than a local filename. Producers (the find_more ownership-diff, or a
|
||||
manual add) POST entries; the API is idempotent on identity so a re-run of an
|
||||
ownership-diff can't duplicate.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def server_mod(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("CONFIG_DIR", str(tmp_path))
|
||||
sys.modules.pop("server", None)
|
||||
mod = importlib.import_module("server")
|
||||
yield mod
|
||||
conn = getattr(getattr(mod, "meta_db", None), "conn", None)
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(server_mod):
|
||||
c = TestClient(server_mod.app)
|
||||
try:
|
||||
yield c
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
def test_add_list_remove_round_trip(client):
|
||||
assert client.get("/api/wanted").json() == {"wanted": []}
|
||||
|
||||
r = client.post("/api/wanted", json={"artist": "Tool", "title": "Lateralus",
|
||||
"source": "find_more", "source_ref": "cf:123"})
|
||||
assert r.status_code == 200
|
||||
row = r.json()["wanted"]
|
||||
assert (row["artist"], row["title"], row["source"]) == ("Tool", "Lateralus", "find_more")
|
||||
wid = row["id"]
|
||||
|
||||
listed = client.get("/api/wanted").json()["wanted"]
|
||||
assert [w["title"] for w in listed] == ["Lateralus"]
|
||||
|
||||
assert client.request("DELETE", f"/api/wanted/{wid}").json() == {"ok": True}
|
||||
assert client.get("/api/wanted").json() == {"wanted": []}
|
||||
# Deleting an already-gone id is a no-op, not an error.
|
||||
assert client.request("DELETE", f"/api/wanted/{wid}").json() == {"ok": False}
|
||||
|
||||
|
||||
def test_add_is_idempotent_on_identity(client, server_mod):
|
||||
payload = {"artist": "Rush", "title": "YYZ", "source": "find_more", "source_ref": "x1"}
|
||||
first = client.post("/api/wanted", json=payload).json()["wanted"]
|
||||
# Same identity (case-insensitive on artist/title) → no duplicate, same row.
|
||||
again = client.post("/api/wanted", json={**payload, "artist": "rush", "title": "yyz"}).json()["wanted"]
|
||||
assert first["id"] == again["id"]
|
||||
assert server_mod.meta_db.count_wanted() == 1
|
||||
|
||||
# A different source_ref is a distinct entry.
|
||||
client.post("/api/wanted", json={**payload, "source_ref": "x2"})
|
||||
assert server_mod.meta_db.count_wanted() == 2
|
||||
|
||||
|
||||
def test_newest_first_ordering(client, server_mod):
|
||||
for t in ("First", "Second", "Third"):
|
||||
server_mod.meta_db.add_wanted(artist="A", title=t, source="manual")
|
||||
titles = [w["title"] for w in client.get("/api/wanted").json()["wanted"]]
|
||||
assert titles == ["Third", "Second", "First"]
|
||||
|
||||
|
||||
def test_add_requires_artist_or_title(client):
|
||||
r = client.post("/api/wanted", json={"source": "manual"})
|
||||
assert r.status_code == 400
|
||||
r2 = client.post("/api/wanted", json={"artist": "", "title": " "})
|
||||
assert r2.status_code == 400
|
||||
|
||||
|
||||
def test_add_defaults_source_to_manual(client):
|
||||
row = client.post("/api/wanted", json={"title": "Untitled"}).json()["wanted"]
|
||||
assert row["source"] == "manual"
|
||||
assert row["artist"] == ""
|
||||
|
||||
|
||||
def test_non_dict_body_rejected(client):
|
||||
# FastAPI's `data: dict` validation rejects a JSON array (422) before the
|
||||
# handler's own defensive isinstance guard; either way it's not a 2xx.
|
||||
assert client.post("/api/wanted", json=[]).status_code in (400, 422)
|
||||
|
||||
|
||||
def test_table_creation_is_idempotent(server_mod):
|
||||
# Re-running the CREATE TABLE / CREATE INDEX must not error or wipe rows —
|
||||
# pin the additive + idempotent migration guarantee (constitution IV).
|
||||
server_mod.meta_db.add_wanted(artist="Keep", title="Me")
|
||||
server_mod.meta_db.conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS wanted (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
artist TEXT NOT NULL DEFAULT '', title TEXT NOT NULL DEFAULT '',
|
||||
source TEXT NOT NULL DEFAULT '', source_ref TEXT NOT NULL DEFAULT '',
|
||||
note TEXT NOT NULL DEFAULT '', created_at TEXT
|
||||
)
|
||||
""")
|
||||
server_mod.meta_db.conn.execute(
|
||||
"CREATE UNIQUE INDEX IF NOT EXISTS idx_wanted_identity "
|
||||
"ON wanted(artist COLLATE NOCASE, title COLLATE NOCASE, source, source_ref)"
|
||||
)
|
||||
assert server_mod.meta_db.count_wanted() == 1
|
||||
Reference in New Issue
Block a user