Added syllable-level timing adjustment to the karaoke editor.

This commit is contained in:
translator committed 2026-03-11 09:44:36 +09:00
1 parent 74f632297e
commit fa99da7100
12 files changed
+4311 -68

No files matched your search

+179
View File
@@ -0,0 +1,179 @@
# Lyrics Editor Overview
The Lyrics Editor is an Aegisub-style panel built into the Lyrics Preview component. It gives you a visual waveform, a timing table, and inline editing tools — all synchronized with the audio player.
---
## Opening the Editor
In the Lyrics Preview toolbar, click the **waveform icon** (Activity/zigzag icon) to toggle the editor panel. It sits between the toolbar and the lyrics display area.
Clicking the icon again, or clicking the **Style** (palette) or **Edit** (pencil) buttons, closes the panel.
---
## Layout
```
┌─────────────────────────────────────────┐
│ Toolbar [Scroll|Fade|…] [⊙][🎨][✏][⊞] │
├─────────────────────────────────────────┤
│ WAVEFORM − 1× + │
│ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ │
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ ← scrollbar (zoom only)
├─────────────────────────────────────────┤
│ LINES 42 │
│ # Start End Text … │
│ 1 0:00.00 0:03.21 Hello world │
│ 2 0:03.21 0:05.80 This is a test │
│ … │
└─────────────────────────────────────────┘
```
---
## Waveform Panel
### Playback and seeking
- **Click anywhere** on the waveform to seek the audio to that position.
- The **white playhead** moves in real time during playback.
- The portion to the left of the playhead is drawn in bright blue; the unplayed portion is dark blue.
### Line markers
- Small vertical ticks at the top of the waveform mark the **start time of each lyric line**.
- The **active line marker** (the line currently playing) is taller and brighter blue.
### Zoom
| Action | Effect |
|--------|--------|
| `Ctrl` + scroll wheel | Zoom in / out, centred on the cursor position |
| `+` button (top-right) | Zoom in one step (doubles the zoom level) |
| `−` button (top-right) | Zoom out one step |
| `✕` button (top-right) | Reset zoom to 1× (full song view) |
Zoom levels: 1×, 2×, 4×, 8×, 16×, 32×.
### Panning (when zoomed in)
| Action | Effect |
|--------|--------|
| Scroll wheel (no modifier) | Pan left / right |
| Shift + scroll wheel | Pan left / right (on trackpads that send vertical scroll) |
| Drag the scrollbar below the canvas | Pan to any position |
> **Tip:** The scrollbar only appears when zoom > 1×.
---
## Timing Table
The table below the waveform lists every lyric line with the following columns:
| Column | Description |
|--------|-------------|
| **#** | Line number (read-only) |
| **Start** | Line start time in `m:ss.xx` format — **editable** |
| **End** | Derived end time (next line's start, or total duration for the last line) — read-only |
| **Text** | Lyric text — **editable** |
| **Speaker** | Speaker ID from diarized transcription — read-only, shown only when diarization data is present |
### Navigation
- **Click any row** to seek the audio to that line's start time.
- **Arrow keys** (`←` / `→`) jump to the previous / next line while the editor is open (active when no input field is focused).
- The **active row** (currently playing line) is highlighted in blue and automatically scrolls into view.
---
## Inline Editing
### Editing a start time
1. **Double-click** the **Start** cell of any row.
2. An input field appears pre-filled with the current timestamp (`m:ss.xx`).
3. Type the new time. Accepted formats: `m:ss`, `m:ss.x`, `m:ss.xx` (e.g. `1:23.45`).
4. Press **Enter** or click away to commit. The line is re-sorted if the new time changes its order.
5. Press **Escape** to cancel without saving.
> If you type an invalid timestamp the edit is silently discarded and the original value is kept.
### Editing text
1. **Double-click** the **Text** cell of any row.
2. An input field appears with the current text.
3. Edit freely and press **Enter** or click away to commit.
4. Press **Escape** to cancel.
> **Note:** If a line has word-level (ELRC) timing, editing its text will replace the sub-word timestamps with plain text. This is indicated in the cell tooltip. The audio timing for the line itself is preserved; only the per-word karaoke fill is lost.
### Tab navigation
While an input field is open:
- **Tab** commits the current edit and moves to the next editable cell (Start → Text → next row's Start → …).
- **Shift + Tab** moves in reverse.
### How edits propagate
Every committed edit immediately:
1. Updates the live lyrics preview (the karaoke/scroll/fade view updates in real time).
2. Saves back to the project's LRC text via the same path as the raw text editor (`onLrcChange`).
---
## Word / Syllable Timing
Lines that were transcribed with word-level (ELRC) timestamps can have their individual word timings adjusted.
### Expanding a line
In the **#** column, lines with word data show a small **▶** indicator next to the row number. Click the **#** cell to expand that line into word sub-rows. Click again to collapse.
### Word sub-rows
Each word sub-row shows:
| Column | Description |
|--------|-------------|
| `└` | Indent marker — identifies this as a word row |
| **Start** | Word start time — **editable** (double-click) |
| **End** | Next word's start time, or line end — read-only |
| **Text** | Word text — read-only |
- **Click a word sub-row** to seek the audio to that word's start time.
- **Double-click Start** to open an inline `m:ss.xx` input (same flow as line start editing).
- **Tab / Shift+Tab** moves between word start cells within the same line.
- Word times are clamped: cannot go before the parent line's start or after the next word's start.
### Waveform word markers
When a line is expanded, **amber vertical ticks** appear on the waveform at each word's start position — distinct from the blue line-start markers.
### Drag-to-retime
While a line is expanded, hover the waveform over an amber word marker — the cursor changes to **⇔**. Drag left or right to move that word's start time:
- The marker follows the cursor in real time (live preview).
- Release to commit. The change is saved immediately and updates the karaoke fill/preview.
- Dragging is clamped to the same bounds as inline editing.
- If you click without dragging, it seeks as normal.
> **Note:** Word timing is only available when the source transcription includes ELRC word-level timestamps. If a line's text is edited inline, its word timing is replaced with plain text.
---
## Multi-stem mode
When the project uses separated stems instead of a single audio file, the waveform is decoded from the **first stem track**. All other editor features (timing table, editing, navigation, word timing) work identically regardless of the number of stems.
> **Note:** In multi-stem mode the waveform is not rendered, so drag-to-retime is unavailable. Word start times can still be edited via the inline double-click input in the table.
---
## Keyboard Reference
| Key | Action |
|-----|--------|
| `←` | Jump to the previous line |
| `→` | Jump to the next line |
| `Enter` (in cell) | Commit edit |
| `Escape` (in cell) | Cancel edit |
| `Tab` (in cell) | Commit and move to next editable cell |
| `Shift+Tab` (in cell) | Commit and move to previous editable cell |
| `Ctrl+scroll` | Zoom waveform in / out |
| `scroll` | Pan waveform left / right (when zoomed) |
| Click **#** cell | Expand / collapse word sub-rows (lines with word timing only) |
| Drag amber marker | Retime a word on the waveform (when a line is expanded) |
+177
View File
@@ -0,0 +1,177 @@
# Aegisub-Style Lyrics Editor: Implementation Plan
## What Already Exists (no re-invention needed)
- `LrcLine` / `LrcWord` types with `time: number` fields in `LyricsLivePreview.tsx`
- `seekTime(t)` already handles both single-track and multi-stem seek
- `currentTimeRef` is updated every frame by the existing RAF loop
- `audioRef` / `stemAudioRefs` already manage the `<audio>` elements
- `findActiveLine()` / `findActiveWord()` binary scans already implemented
- `parseLrcContent()` produces sorted `LrcLine[]` from ELRC/LRC text
---
## Core Recommendation: Raw Web Audio API + Canvas (no WaveSurfer.js)
WaveSurfer.js would conflict with the existing multi-stem audio setup — you cannot create two `MediaElementSource` nodes from the same `HTMLAudioElement` (throws `InvalidStateError`). Instead:
1. Fetch the audio URL once
2. Decode with a **dedicated** `AudioContext` (separate from the existing stem gain graph)
3. Downsample PCM data to ~1200 peak values
4. Pre-render to an offscreen canvas
5. RAF-driven playhead redraws on top each frame
This is the same pattern the existing component uses for karaoke word fill.
---
## New File: `frontend/src/components/KaraokeEditor.tsx`
One new component with two sub-sections.
### Props Interface
```ts
interface KaraokeEditorProps {
lines: LrcLine[]
currentTimeRef: React.MutableRefObject<number>
duration: number
audioUrl: string | undefined
onSeek: (t: number) => void // calls seekTime() in LyricsLivePreview
onLrcChange?: (newLrc: string) => void
}
```
### WaveformCanvas
- `fetch(audioUrl)` → `arrayBuffer` → dedicated `AudioContext.decodeAudioData()` → close context after decoding
- Downsample: chunk into ~1200 buckets, take `max(abs)` per bucket → `Float32Array`
- Pre-render bars to offscreen canvas (two colors: dim = future, bright = played)
- RAF loop reads `currentTimeRef.current` → draws 2px playhead at `(t / duration) * width`
- `onClick(e)` → `onSeek((x / width) * duration)`
### TimingTable (Aegisub-style grid)
| # | Start | End (derived) | Text | Speaker |
|---|-------|---------------|------|---------|
- Start time and text cells are inline-editable (`<input>` on click, `mm:ss.xx` format)
- End time = next line's start time, shown read-only
- Clicking a row calls `onSeek(line.time)`
- Active row highlighted via RAF loop reading `currentTimeRef` — no React re-renders per frame
- `scrollIntoView({ block: 'nearest', behavior: 'smooth' })` on active row index change
- On edit → reconstruct LRC string → call `onLrcChange(newLrc)`
---
## Minimal Changes to `LyricsLivePreview.tsx`
1. Add an "Aegisub" toggle button in the existing toolbar (next to existing Palette/Pencil buttons)
2. Render `<KaraokeEditor>` below the transport bar when toggled
3. Pass `currentTimeRef`, `duration`, `audioUrl`, `lines`, `seekTime`, `onLrcChange` as props
No changes to the RAF loop, audio element wiring, or any render functions.
---
## Data Flow
```
audioUrl ──────────────────────────────► WaveformCanvas (decode + draw)
currentTimeRef (RAF, no re-renders) ───► playhead position + active row highlight
onSeek(t) ◄──────────────────────────── click on waveform OR click table row
→ calls seekTime() in LyricsLivePreview
onLrcChange(newLrc) ◄────────────────── inline cell edits → reconstructed LRC string
```
---
## State Management
- **No new global state.** `KaraokeEditor` is a leaf component.
- **`currentTime` without re-renders:** `KaraokeEditor` reads `currentTimeRef.current` in its own internal RAF loop — never subscribes to React `currentTime` state. Matches existing DOM-mutation pattern.
- **Waveform data:** `useRef<Float32Array | null>` — never in React state (doesn't drive renders, only canvas draws).
- **Editing state:** `useState<LrcLine[]>` local override inside `KaraokeEditor` for in-progress edits, identical to how `editedLrc` works in `LyricsLivePreview`.
- **No context, Zustand, or new stores needed.**
---
## Critical Files
| File | Role |
|------|------|
| `frontend/src/components/LyricsLivePreview.tsx` | Modify: add toolbar button, render `<KaraokeEditor>`, expose `seekTime` + `currentTimeRef` |
| `frontend/src/components/KaraokeEditor.tsx` | **Create**: waveform canvas + timing table |
| `frontend/src/utils/audioRegistry.ts` | Reference only: follow existing stable-ref patterns; do NOT call `registerPlayback` from editor |
| `frontend/src/types.ts` | Reference: check naming before adding any new exported types |
| `frontend/src/pages/ProjectDetail.tsx` | Reference: caller context for `audioUrl`, `lrcText`, `onLrcChange` prop wiring |
---
## Implementation Order
### Phase 1 — Waveform canvas (read-only)
1. Create `KaraokeEditor.tsx` with `WaveformCanvas` only
2. Fetch + decode audio URL with dedicated `AudioContext`
3. Downsample → offscreen canvas pre-render
4. RAF loop: playhead line
5. Click-to-seek via `onSeek`
6. Wire into `LyricsLivePreview.tsx`: toolbar toggle button, conditional render below transport
### Phase 2 — Timing table (read-only)
7. Add `TimingTable` inside `KaraokeEditor`
8. Render all lines with start/end times, text, speaker columns
9. Active row highlight + `scrollIntoView` via shared RAF loop
10. Row click → `onSeek(line.time)`
### Phase 3 — Inline editing
11. Editable start-time cells (`mm:ss.xx` input)
12. Editable text cells
13. On change: reconstruct LRC string from modified lines array
14. Call `onLrcChange(newLrc)` to propagate upward
### Phase 4 — Polish
- Waveform horizontal zoom + scroll
- Line-start markers on waveform; arrow-key navigation (←/→ jump lines)
### Phase 5 — Syllable / word timing editor
All changes in `KaraokeEditor.tsx` only.
**New constants:**
```ts
const WORD_MARKER_COLOR = 'rgba(251,191,36,0.75)' // amber-400/75
const WORD_MARKER_DRAG_COLOR = '#fbbf24' // amber-400 bright
const WORD_MARKER_HIT_PX = 8 // ±px hit zone for drag
```
**Step 5-A — Expandable word sub-rows in `TimingTable`**
- Lines with `words.length > 0` show a `▶`/`▼` toggle in the `#` column
- Clicking expands into word sub-rows (indented, amber left border) directly below the parent line
- Sub-row columns: indent `└` | Start (editable, `m:ss.xx`) | End (read-only = next word's time) | Text (read-only) | Speaker (blank)
- Double-click Start on a word sub-row opens the same inline `<input>` as line start editing
- Word times clamped: `[line.time … nextWord.time − 0.01s]`
- Editing text on a parent line drops `words[]` and auto-collapses the expanded row
- New props on `TimingTable`: `expandedRow`, `onExpandRow`, `onWordTimeChange`
- `expandedRow: number | null` state lives in `KaraokeEditor`
- `handleWordTimeChange(lineIdx, wordIdx, newTime)` in `KaraokeEditor` mutates words, calls `reconstructLrc → onLrcChange`
**Step 5-B — Word markers on waveform (read-only)**
- `drawFrame` gains two optional trailing params: `wordLines?: LrcLineKE[]`, `dragPreview?: { wordIdx: number; time: number } | null`
- When `selectedLineIdx` is set, draws 2 px × 14 px amber ticks for each word in that line
- `WaveformCanvas` gains `selectedLineIdx: number | null` prop
**Step 5-C — Drag-to-retime on waveform**
- Replace `onClick` with unified pointer-event handlers (`onPointerDown`/`onPointerMove`/`onPointerUp`) + `canvas.setPointerCapture`
- `onPointerDown` within `WORD_MARKER_HIT_PX` of a word marker → start drag (`dragStateRef`)
- `onPointerMove` → update `dragPreviewRef`, `dirtyRef = true` (no React state change)
- `onPointerUp` → if moved: commit via `onWordTimeDrag('commit', …)`; else: treat as seek click
- Cursor: `ew-resize` when hovering a word marker hit zone, `crosshair` otherwise
- `dragPreviewRef` and `setDirty` callback passed from `KaraokeEditor` to `WaveformCanvas`
**Data flow:**
```
expandedRow ──────────────────────► TimingTable (sub-rows) + WaveformCanvas (word markers)
onWordTimeChange/onWordTimeDrag ──► KaraokeEditor mutates lines → reconstructLrc → onLrcChange
dragPreviewRef (RAF, no re-render) ► drawFrame dragPreview param → amber drag-position tick
```
+138 -6
View File
@@ -667,15 +667,147 @@ Also reverted an earlier incorrect change that added `'sylrc'` to formats when `
**Root cause (secondary):** `gc.collect()` was called only once in both `separator_service.py`'s `finally` block and `_clear_cuda_cache()`. PyTorch model objects form reference cycles (`_parameters → _modules → parent → …`) that Python's generational GC may not fully collect in a single pass — objects promoted to older generations require additional passes. This could leave model tensors resident in VRAM when the next job started.
**Fix — `backend/job_manager.py`:**
Added `gpu_vram_lock = threading.Lock()` — a shared VRAM coordination lock that both executor paths must hold for the duration of model loading + inference.
- Line 112: added `gpu_vram_lock = threading.Lock()` — a shared VRAM coordination lock that both executor paths must hold for the duration of model loading + inference.
**Fix — `backend/services/separator_service.py`:**
- `jm.gpu_vram_lock.acquire()` added before the separation `try:` block; `jm.gpu_vram_lock.release()` added at the end of the `finally:` block (after cleanup).
- Triple `gc.collect()` in the `finally` block instead of single.
- Lines 323–326: added `jm.gpu_vram_lock.acquire()` (with comment) immediately before the `# Run separation` / `try:` block.
- Lines 644–646: changed single `gc.collect()` to triple `gc.collect()` in the `finally` block.
- Lines 651–655: added `jm.gpu_vram_lock.release()` (wrapped in try/except RuntimeError) at the end of the `finally` block, after `empty_cache()`.
**Fix — `backend/services/lyric_transcriber_service.py`:**
- `jm.gpu_vram_lock.acquire()` added before the transcription `try:` block in `run_lyric_transcription`.
- Added a `finally:` block (previously absent) that calls `_clear_cuda_cache()` and releases the lock on both success and failure paths.
- `_clear_cuda_cache()` updated to call `gc.collect()` three times instead of once.
- Lines 859–875: `_clear_cuda_cache()` updated to call `gc.collect()` three times instead of once, with an explanatory docstring.
- Lines 1331–1334: added `jm.gpu_vram_lock.acquire()` (with comment) immediately before the transcription `try:` block in `run_lyric_transcription`.
- Lines 1859–1864: removed `_clear_cuda_cache()` from the `except` block (moved to `finally`).
- Lines 1866–1874: added new `finally:` block (previously absent) that calls `_clear_cuda_cache()` and `jm.gpu_vram_lock.release()` on both success and failure paths.
**Effect:** Separation and transcription jobs now queue against the same lock. Whichever starts first holds VRAM exclusively until its `finally` cleanup completes, then releases the lock so the other can proceed. No model can be double-loaded simultaneously regardless of how jobs are submitted.
---
## 2026-03-10
### Fix — `enable_denoise` keyword removed from audio-separator `Separator` API
**Problem:** `Separator.__init__() got an unexpected keyword argument 'enable_denoise'` raised whenever the ensemble separator ran the `bs_roformer_sw` model component. The audio-separator library dropped `enable_denoise` from its `Separator.__init__` signature in a recent update.
**Fix — `backend/services/bs_roformer_sw_separator.py`:**
- Lines 48–55: removed `enable_denoise=False`, `normalization_threshold=0.9`, and `cpu_separation=self.cpu_separation` from the `Separator()` constructor call in `_get_separator()`. All three parameters were dropped from the audio-separator `Separator.__init__` API (≥0.28.0). Constructor now matches the pattern used by all other working separators in this codebase.
---
### 2026-03-10 — Feature — Waveform editor (Phase 1): `KaraokeEditor` component
**New file — `frontend/src/components/KaraokeEditor.tsx`:**
- `WaveformCanvas`: fetches `audioUrl`, decodes with a dedicated `AudioContext` (separate from the existing multi-stem gain graph; closed immediately after decoding), downsamples PCM to 1200 peak values, pre-renders bars, and runs its own RAF loop to draw a playhead at `(currentTimeRef.current / duration) × width`. Two-color bars: played = `#60a5fa`, unplayed = `#1e3a5f`. Click-to-seek via `onSeek` prop.
- `KaraokeEditor`: wraps the canvas with a header row showing line count and a note when waveform is unavailable (multi-stem mode with no `audioUrl`).
**Modified — `frontend/src/components/LyricsLivePreview.tsx`:**
- Line 2: added `Activity` to lucide-react imports.
- Line 5: added `import KaraokeEditor from './KaraokeEditor'`.
- Line 801: added `const [showAegisub, setShowAegisub] = useState(false)`.
- Lines 2152–2161: added "Waveform editor" toolbar button (`Activity` icon) that toggles `showAegisub` and closes the other panels.
- Lines 2243–2251: added `{showAegisub && <KaraokeEditor .../>}` panel rendered after the existing LrcEditor panel; receives `lines`, `currentTimeRef`, `displayDuration`, `audioUrl ?? stems?.[0]?.url`, and `seekTime`.
### 2026-03-10 — Feature — Waveform editor (Phase 2): `TimingTable` component
**Modified — `frontend/src/components/KaraokeEditor.tsx`:**
- Added `TimingTable` sub-component: scrollable table (height 200 px) with columns `#`, `Start`, `End`, `Text`, and optional `Speaker` (shown only when any line has a speaker field).
- End time derived as next line's start time, or `duration` for the last line.
- Active row highlight driven by its own RAF loop reading `currentTimeRef.current` — no React re-renders per frame. Direct DOM color mutations on `<tr>` and its `<td>` children. `scrollIntoView({ block: 'nearest', behavior: 'smooth' })` called when active index changes.
- Row click calls `onSeek(line.time)` to seek audio.
- `linesRef` pattern keeps the RAF closure reading the latest lines without re-subscribing.
- Fixed: `React.MouseEvent` → `ReactMouseEvent` (imported as type alias); typed `el` ref callback as `HTMLTableRowElement | null`.
### 2026-03-10 — Feature — Waveform editor (Phase 3): inline timing/text editing
**Modified — `frontend/src/components/KaraokeEditor.tsx`:**
- Added `onLrcChange?: (newLrc: string) => void` to `KaraokeEditorProps` and `TimingTable` props.
- Added `reconstructLrc(lines)`: rebuilds a full LRC/ELRC string from a `LrcLineKE[]` array, preserving word-level timestamps and speaker tags.
- Added `parseTs(raw)`: parses user-typed `m:ss.xx` / `m:ss` / `m:ss.x` timestamps back to seconds; returns `null` on invalid input (edit is silently discarded).
- Added `editing` / `draft` state to `TimingTable` for the active inline edit cell.
- **Start time cell**: double-click opens an inline `<input>` pre-filled with `formatTs(line.time)`. On commit (Enter / blur): parses the new time, rebuilds sorted `LrcLineKE[]`, calls `reconstructLrc` → `onLrcChange`. Word timestamps on the line are preserved.
- **Text cell**: double-click opens an inline `<input>` pre-filled with `line.text`. On commit: sets `words: []` for that line (drops sub-word timing), calls `reconstructLrc` → `onLrcChange`. Tooltip warns when the line has ELRC word timing.
- **Tab navigation**: Tab/Shift-Tab commits the current cell and moves to the adjacent editable cell (start → text → next-row start).
- Escape discards the edit without calling `onLrcChange`.
- All inline event handler `e` parameters explicitly typed (`ReactMouseEvent<HTMLTableCellElement>`, `ReactMouseEvent<HTMLInputElement>`, `ReactChangeEvent<HTMLInputElement>`) to satisfy the project's strict `noImplicitAny` setting.
**Modified — `frontend/src/components/LyricsLivePreview.tsx`:**
- `<KaraokeEditor>` now receives `onLrcChange` that calls both `setEditedLrc(newLrc)` and the parent's `onLrcChange?.(newLrc)`, matching the same pattern used by `LrcEditor`.
### 2026-03-10 — Feature — Waveform editor (Phase 4): zoom, line markers, arrow-key navigation
**Modified — `frontend/src/components/KaraokeEditor.tsx`:**
**Waveform zoom + scroll:**
- `WaveformCanvas` gains `lines` prop for marker rendering.
- Replaced `drawWaveform`/`drawEmpty` with a unified `drawFrame(ctx, peaks, lines, w, h, fraction, zoom, scrollFrac, duration, activeLineIdx)` that handles all zoom/scroll/marker logic in one pass.
- `zoom` and `scroll` stored as both React state (drives controls re-render) and refs (read by RAF loop with zero re-render overhead). `dirtyRef` force-triggers a redraw whenever zoom or scroll changes.
- **Ctrl+scroll** (or Cmd+scroll) zooms in/out up to 32×, centred on the mouse cursor position (anchor-preserving zoom math).
- **Plain scroll** pans the waveform horizontally when zoomed in. Shift+scroll or horizontal `deltaX` also pans.
- **`+` / `−` buttons** (top-right canvas overlay) snap zoom to the next/previous power of 2. `✕` resets to 1×.
- **Horizontal scrollbar** (`<input type="range">`) appears below the canvas only when zoomed in; its `max` tracks `1 − 1/zoom` so it can never scroll past the end.
- `handleClick` updated to account for zoom and scroll when mapping canvas x to seek time.
**Line-start markers:**
- Each lyric line gets a 1 px vertical tick at the top of the canvas at its start timestamp.
- Active line marker: 10 px tall, `rgba(96,165,250,0.9)` (blue-400). Inactive: 5 px tall, `rgba(100,116,139,0.55)` (slate-500). Computed fresh each RAF frame from `findActiveLine`.
**Arrow-key navigation (in `KaraokeEditor`):**
- `useEffect` attaches a `keydown` listener on `document` while the editor is mounted.
- `ArrowLeft` → seek to the previous line's start time; `ArrowRight` → seek to the next line's start time.
- Skipped when the active element is an `INPUT`, `TEXTAREA`, or `SELECT` (so inline cell editing is unaffected).
- Reads `linesRef.current` so it never needs to re-subscribe when lines change.
### 2026-03-10 — Feature — Syllable/word timing editor (Phase 5, Steps A–C)
**Modified — `frontend/src/components/KaraokeEditor.tsx`** (only file changed):
**Step A — Expandable word sub-rows in TimingTable:**
- Added `TimingTableProps` interface extending the existing props with `expandedRow`, `onExpandRow`, `onWordTimeChange`.
- Lines with `words.length > 0` show a `▶`/`▼` toggle in the `#` column. Clicking the cell expands/collapses without triggering a seek.
- Word sub-rows render below the parent line using `<Fragment key={i}>`, with amber left border (`rgba(251,191,36,0.3)`). Columns: indent `└` | Start (editable) | End (read-only) | Text (read-only).
- Word start time editing uses the same double-click → `<input>` → Enter/blur/Escape/Tab flow as line editing, with amber `wordInputStyle`.
- Word times clamped on commit: `[line.time … nextWord.time − 0.01s]`. Tab moves between word cells.
- `expandedRow` state and `handleWordTimeChange` live in `KaraokeEditor`; commits via `reconstructLrc → onLrcChange`.
**Step B — Word markers on waveform:**
- Added `WORD_MARKER_COLOR` (amber-400/70), `WORD_MARKER_DRAG_COLOR`, `WORD_MARKER_HIT_PX = 8`.
- `drawFrame` gained optional `wordLine` and `dragPreview` params. New drawing pass: 2 px × 14 px amber ticks per word; drag preview word shows `WORD_MARKER_DRAG_COLOR`.
- `WaveformCanvasProps` interface added with `selectedLineIdx` and `onWordTimeDrag`. Added `selectedLineIdxRef`, `dragStateRef`, `dragPreviewRef` refs. RAF loop passes `wordLine` and `dragPreviewRef.current` to `drawFrame`.
**Step C — Drag-to-retime:**
- Removed `handleClick`/`useCallback`; replaced with a pointer-event `useEffect` (`pointerdown`/`pointermove`/`pointerup`). `canvas.setPointerCapture` keeps events during drag outside the canvas.
- `onPointerDown`: near a word marker → start drag. Otherwise → background click.
- `onPointerMove`: if dragging → update `dragPreviewRef` + `dirtyRef = true` (no React re-renders). If not → set cursor `ew-resize` near a marker, `crosshair` otherwise.
- `onPointerUp`: if moved → clamp + commit via `onWordTimeDrag`; else → seek click.
- `handleWordTimeDrag(wordIdx, newTime)` in `KaraokeEditor` delegates to `handleWordTimeChange(expandedRow, wordIdx, newTime)`.
**Documentation updated — `Lyrics Editor Overview.md`:**
- Added "Word / Syllable Timing" section, updated keyboard reference.
### 2026-03-10 — Fix — KaraokeEditor scrollbar color bleedover
**Modified — `frontend/src/components/KaraokeEditor.tsx`:**
- Removed `accentColor: '#60a5fa'` from the horizontal scrollbar `<input type="range">` inline style.
- `index.css` already applies `appearance-none` and `bg-brand-500` (CSS variable) to all `input[type="range"]` elements globally, so the hardcoded hex was both redundant and a violation of the theming system. The thumb now correctly follows the active accent color.
### 2026-03-11 — StemEngine WebUI redesign plan (MetroUI)
**Created — `StemEngine WebUI.md`:**
High-level plan to redesign the StemEngine React frontend using MetroUI (`@olton/metroui`),
replacing Tailwind CSS. Covers installation, design language decisions, layout shell changes
(AppBar + SideNav), page-by-page redesign (Separator, ProjectDetail, Settings, Sidebar,
GlobalAudioBar), Metro Live Tile project browser, 6-phase migration order, ThemeContext
`data-theme`/`data-accent` attribute changes, components that must NOT be touched
(KaraokeEditor, LyricsLivePreview internals), and risk notes (MetroUI JS + React event
system, `data-role` auto-init in dynamic React renders, Vite side-effects config).
### 2026-03-11 — KaraokeEditor Phase 5 bug fixes + word row highlight
**Modified — `frontend/src/components/KaraokeEditor.tsx`:**
**Bug fix — pointer events `useEffect` deps:** The `[duration, onSeek, onWordTimeDrag]` dependency array caused the pointer event listeners on the waveform canvas to be torn down and re-added on every render (since `onWordTimeDrag`/`onSeek` are new function references each render of `KaraokeEditor`). Fixed by adding stable `onSeekRef`, `onWordTimeDragRef`, `durationRef` inline-updated refs in `WaveformCanvas` and reading from these inside the pointer event closures. Deps changed to `[]` — listeners registered once for the canvas lifetime.
**Bug fix — waveform not redrawing on expand:** When `expandedRow` changed (line expanded or collapsed), `dirtyRef.current` was never set, so the word markers didn't appear/disappear until the next playhead movement frame. Fixed by adding `useEffect(() => { dirtyRef.current = true }, [selectedLineIdx])` in `WaveformCanvas`.
**Feature — word sub-row highlight on click:** Clicking a word sub-row in the timing table now applies an amber (`rgba(251,191,36,0.12)`) background highlight to that row (direct DOM mutation, no re-render). Clicking a different word row moves the highlight; the highlight clears automatically when the active line changes during playback (RAF loop). Implemented via `wordRowRefsMap` (keyed `${lineIdx}-${wordIdx}`), `activeWordRowRef`, and `highlightWordRow()` helper in `TimingTable`.
+396
View File
@@ -0,0 +1,396 @@
# StemEngine Web UI Redesign — MetroUI Plan
Redesign the StemEngine React frontend using the
[MetroUI](https://github.com/olton/metroui) (`@olton/metroui`) component framework,
replacing the current Tailwind CSS utility-class approach with MetroUI's Metro Style
design language (flat, tile-based, high-contrast, strongly typographic).
---
## Current Stack
| Layer | Current |
|-------|---------|
| Build | Vite 5 + TypeScript |
| Framework | React 18 |
| Styling | Tailwind CSS 3 + custom CSS variables (`--brand-*`) |
| Icons | lucide-react |
| Query | TanStack React Query 5 |
| Audio | Tone.js, @tonejs/midi, abcjs |
The Tailwind dependency is removed; everything else stays.
---
## Why MetroUI
- **Zero external dependencies** — one CSS + one JS bundle, no tree-shaking puzzle.
- **Metro Style** matches the tool's technical, editor-like aesthetic better than a
generic utility framework.
- **Built-in dark theme** — `data-theme="dark"` on `<html>`, no custom variable juggling.
- **Rich component set** already covers every current UI pattern: panels, tiles, appbar,
sidenav, progress bars, sliders, dialogs, toasts, accordions, tabs, badges, activity
indicators.
- **Live Tiles** — ideal for the project browser grid: each project tile can show
job-status colour and animated activity indicator natively.
- **CSS-class driven** — React keeps all interactivity; MetroUI JS is only needed for
a handful of overlay components (dialog, toast, window). No framework conflict.
---
## Installation
```bash
npm install @olton/metroui
```
In `main.tsx` (replaces Tailwind imports in `index.css`):
```ts
import '@olton/metroui/dist/css/metro.css'
import '@olton/metroui/dist/css/icons.css'
// MetroUI JS (for dialog/toast/tooltip JS API)
import '@olton/metroui/dist/js/metro.js'
```
Remove from `package.json`:
- `tailwindcss`, `autoprefixer`, `postcss`
- `tailwind.config.js`, `postcss.config.js`
The `index.css` file is reduced to:
- Custom scrollbar overrides
- `KaraokeEditor` canvas variables (these are purely internal and not Tailwind)
- Any one-off layout rules not covered by MetroUI
---
## Design Language Decisions
| Decision | Choice |
|----------|--------|
| Theme | Dark (`data-theme="dark"`) by default; user can toggle to Light |
| Accent | Six Metro accent colours matching current set: Blue, Violet, Rose, Emerald, Amber, Cyan — applied via `data-accent` on `<html>` and MetroUI's built-in accent palette |
| Typography | Keep current font selection feature (Archivo, Inter, Poppins, etc.); MetroUI's font stack is overridden with the user's chosen font |
| Border radius | Metro default (minimal rounding, ~2–4 px) |
| Spacing | MetroUI grid (12-column) + flexbox utilities |
| Icons | Replace lucide-react with MetroUI icon font (`<span class="mif-...">`) or keep lucide SVGs as-is (both work) |
---
## Layout Shell (App.tsx)
### Current
Flex column: fixed header → flex row (collapsible sidebar + main content) → fixed footer.
Tab navigation (`Separator` / `ProjectDetail` / `Settings`) via `activeTabId` state.
### MetroUI Redesign
```
┌─────────────────────────────────────────────────────┐
│ AppBar [≡ StemEngine] [GPU status] [⚙ Settings] │ ← metro appbar
├───────────┬─────────────────────────────────────────┤
│ │ │
│ SideNav │ Main content panel │
│ │ (routed view) │
│ Project │ │
│ list │ │
│ (tiles) │ │
│ │ │
├───────────┴─────────────────────────────────────────┤
│ GlobalAudioBar (fixed bottom strip) │
└─────────────────────────────────────────────────────┘
```
**Key class mappings:**
| Old | MetroUI |
|-----|---------|
| `fixed top-0` header div | `<div data-role="appbar">` |
| Sidebar div | `<div data-role="sidenav-m3">` or custom vertical nav panel |
| Main content flex area | `<div class="container-fluid">` with MetroUI grid |
| Footer credits | `<div class="app-footer">` |
Navigation moves from tab buttons to **AppBar action buttons + sidenav** so the
main content area is maximised.
---
## Page: Separator
### Current
Long vertical form: file upload zone → model accordion → format options → output
settings → submit button.
### MetroUI Redesign
Use a **two-column panel** layout:
```
┌──────────────────────┬────────────────────────────┐
│ Drop Zone │ Configuration Panel │
│ │ │
│ [Metro drop-zone │ ┌─ Model ──────────────┐ │
│ with dashed border │ │ accordion (closed) │ │
│ and icon] │ └──────────────────────┘ │
│ │ ┌─ Output Format ──────┐ │
│ Imported files list │ │ radio tiles │ │
│ (metro listview) │ └──────────────────────┘ │
│ │ ┌─ Stems ──────────────┐ │
│ │ │ slider group │ │
│ │ └──────────────────────┘ │
│ │ [Separate ▶] │
└──────────────────────┴────────────────────────────┘
```
**MetroUI components:**
| UI element | MetroUI |
|------------|---------|
| File drop zone | `data-role="drop-zone"` |
| Accordion sections | `data-role="accordion"` |
| Model radio tiles | Metro tile grid with `data-role="radio"` |
| Format select | `data-role="select"` |
| Level sliders | `data-role="slider"` with custom track labels |
| Job status | `data-role="progress"` + `data-role="activity"` spinner |
| Submit | `<button class="button large primary">` |
| Toast notification | Metro toast API on job queue |
---
## Page: ProjectDetail
### Current
Vertical stack: stem file list → job action buttons → KaraokeEditor → DynamicMixPlayer
→ LyricsLivePreview — all in one scrollable column.
### MetroUI Redesign
**Resizable window panels** — each major feature area is a collapsible Metro
`data-role="panel"` with a title bar, independently collapsible. Power users can
collapse all but the one they're working in.
```
┌── Project: "Song Title" ─────────────────────────── [↑ actions] ┐
│ │
│ ┌─ Stems ──────────────────────────────────── [▼] ────────────┐│
│ │ [stem tiles with colour-coded job badges] ││
│ └─────────────────────────────────────────────────────────────┘│
│ │
│ ┌─ Karaoke Editor ─────────────────────────── [▼] ────────────┐│
│ │ WaveformCanvas + TimingTable (unchanged internally) ││
│ └─────────────────────────────────────────────────────────────┘│
│ │
│ ┌─ Dynamic Mix ────────────────────────────── [▼] ────────────┐│
│ │ DynamicMixPlayer sliders + master gain ││
│ └─────────────────────────────────────────────────────────────┘│
│ │
│ ┌─ Lyrics Preview ─────────────────────────── [▼] ────────────┐│
│ │ LyricsLivePreview (unchanged internally) ││
│ └─────────────────────────────────────────────────────────────┘│
└──────────────────────────────────────────────────────────────────┘
```
**MetroUI components:**
| UI element | MetroUI |
|------------|---------|
| Panel sections | `data-role="panel"` with `data-collapsible="true"` |
| Stem tiles | Metro tile grid — colour indicates stem type |
| Job status badges | `<span class="badge ...">` |
| Action buttons (transcribe, align, etc.) | `<button class="button">` + `data-role="dropdown"` for multi-action |
| Job progress | `data-role="progress"` bar inside stem tile |
| File download links | `<a class="button flat">` with icon |
---
## Page: Settings
### Current
Horizontal tab strip (Appearance / Models / Subsonic / Maintenance / Power / AutoPipeline)
with tab panel content below.
### MetroUI Redesign
Keep tabs but use MetroUI `data-role="tabs"` with a **left-side vertical pill list**
on desktop and collapsing to a `data-role="select"` dropdown on narrow viewports.
**Appearance tab:**
- Theme radio tiles (Dark / Light / System) — Metro style tiles with check mark
- Font select → `data-role="select"` with preview label
- Accent colour — a horizontal row of Metro colour tiles
**Models tab:**
- `data-role="listview"` with group rows and expand/collapse
- Progress bars inside each model row for download status
- Action buttons (Download / Pause / Cancel / Remove) inline
**Subsonic tab:**
- Metro form layout with `data-role="input"` fields
- `data-role="treeview"` for the library browser
**Maintenance tab:**
- `data-role="accordion"` grouping related cleanup actions
- Each action: button + status badge + result count
**Power tab:**
- Metro form grid with labelled inputs and toggle switches
(`data-role="switch"`)
**AutoPipeline tab:**
- Step-builder as a sortable `data-role="listview"` with
`data-role="accordion"` detail panels per step
---
## Sidebar: Project Browser
### Current
Fixed-width div with search input, filter checkboxes, and a flat list of project cards.
### MetroUI Redesign
```
┌─────────────────────────────┐
│ 🔍 [Search input] │
│ Filter: [All ▼] │
├─────────────────────────────┤
│ ┌── Live Tile ─────────────┐│
│ │ Artist — Title ││ ← Metro medium tile
│ │ ████░░░░ Separating… ││ ← job progress strip at bottom
│ └──────────────────────────┘│
│ ┌── Tile ──────────────────┐│
│ │ Artist — Title ✓ ││
│ └──────────────────────────┘│
│ ... │
├─────────────────────────────┤
│ ▶ Imported Files │ ← metro accordion section
│ ▶ Subsonic Browser │
└─────────────────────────────┘
```
**MetroUI components:**
| UI element | MetroUI |
|------------|---------|
| Project tiles | Metro tile grid (`tile`, `tile-medium`) |
| Search | `data-role="input"` with search icon |
| Filter | `data-role="select"` |
| Imported files | `data-role="accordion"` > `data-role="listview"` |
| Subsonic tree | `data-role="accordion"` > `data-role="treeview"` |
Live Tile behaviour: tile background colour reflects job state —
- `bg-blue` — separating
- `bg-amber` — transcribing / aligning
- `bg-green` — complete
- `bg-red` — error
- Animated `data-role="activity"` spinner appears while any job is running.
---
## GlobalAudioBar
Fixed bottom strip, unchanged in function. Reskin with MetroUI:
- `<div class="app-bar bottom fixed">` container
- Metro-style playback buttons (`<button class="button cycle">`)
- `data-role="slider"` for seek bar and volume
- `<span class="badge">` for current stem label
---
## KaraokeEditor & LyricsLivePreview
**These components are NOT reskinned.** They are complex custom canvas/DOM components
with their own internal style systems (direct colour constants, inline styles).
They will be wrapped in a MetroUI `data-role="panel"` shell but their internals remain
unchanged. This is explicitly called out because they must not be broken by the migration.
---
## ThemeContext
Currently manages `light | dark | system` and applies a `dark` class to `<html>`.
Replaces the class toggle with MetroUI's `data-theme` attribute:
```ts
// was: document.documentElement.classList.toggle('dark', isDark)
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light')
```
Accent colours: set `data-accent` attribute on `<html>` exactly as now, but map to
MetroUI's built-in accent palette names (`blue`, `violet`, `crimson`, `green`,
`amber`, `cyan`).
---
## Migration Phases
### Phase 1 — Install & Shell (App.tsx)
1. `npm install @olton/metroui`; remove Tailwind packages.
2. Swap `index.css` imports; update `main.tsx`.
3. Rebuild `App.tsx` AppBar + SideNav shell in MetroUI classes.
4. Verify dark/light theme toggle and accent switching still work.
5. No page content changed yet — inner pages still render their existing JSX.
### Phase 2 — Sidebar
1. Project tile grid with job-status colour coding.
2. Imported files + Subsonic accordion sections.
3. Search input + filter select.
### Phase 3 — Separator page
1. Drop zone.
2. Model accordion + format radio tiles.
3. Slider group for stem levels.
4. Job progress + toast notifications.
### Phase 4 — ProjectDetail page
1. Panel sections (Stems, Karaoke Editor, Dynamic Mix, Lyrics Preview).
2. Stem tiles with badges + progress.
3. Action button dropdowns.
*(KaraokeEditor and LyricsLivePreview interiors untouched.)*
### Phase 5 — Settings page
1. Vertical tab nav.
2. Appearance: theme tiles, font select, accent tiles.
3. Models: listview with progress rows.
4. Subsonic: form + treeview.
5. Maintenance / Power / AutoPipeline panels.
### Phase 6 — GlobalAudioBar + polish
1. Reskin audio bar.
2. Remove any remaining Tailwind class remnants.
3. Audit icon usage — decide lucide SVG vs MetroUI icon font.
4. Cross-browser / dark-mode QA pass.
---
## What Does NOT Change
| Item | Reason |
|------|--------|
| `KaraokeEditor.tsx` internals | Custom canvas engine; MetroUI-independent |
| `LyricsLivePreview.tsx` internals | Custom RAF renderer |
| `api/client.ts` | Pure data layer |
| `utils/` | Pure logic |
| `ThemeContext.tsx` logic | Only the DOM attribute changes |
| TanStack React Query | Unaffected by styling |
| Tone.js / abcjs / midi | Audio/music — unaffected |
| Vite config | No changes needed |
| TypeScript types | Unaffected |
---
## Risk Notes
- **MetroUI JS and React event system**: MetroUI's JS-initialised components (dialog,
dropdown, tooltip) bypass React's synthetic event system. Use MetroUI CSS classes
only for those components and implement open/close logic in React state, or use the
MetroUI JS API via `useEffect` with refs — never let both systems control the same
element.
- **`data-role` auto-init**: MetroUI scans the DOM on load for `data-role` attributes
and initialises JS widgets. Components rendered after initial load (dynamically by
React) need `Metro.makePlugin(el, 'role-name')` called in a `useEffect` — or switch
to CSS-only for those elements.
- **Vite tree-shaking**: Metro bundles are monolithic (CSS + JS). Ensure `metro.css`
and `metro.js` are imported as side-effects (`"sideEffects": true` in package config
or explicit import) so Vite doesn't exclude them.
- **SSR / hydration**: Not applicable (Vite SPA mode, no SSR).
+235
View File
@@ -0,0 +1,235 @@
# Syllable / Word Timing Editor — Implementation Plan
Extends the existing `KaraokeEditor` (Phase 1–4) with the ability to view and adjust the
start time of every individual word (syllable) within a line that already has ELRC word-level
timestamps.
---
## What Already Exists
- `LrcWordKE { time, text, isWordEnd }` — word-level data already decoded and passed in
- `LrcLineKE { time, text, words[], speaker? }` — container
- `reconstructLrc()` already serialises word timestamps back to ELRC format
- `drawFrame()` already accepts `lines[]` for line-start markers on the waveform
- `WaveformCanvas` already handles zoom/scroll/seek; its coordinate helpers can be reused
- `TimingTable` already has expandable-style row rendering infrastructure
---
## User-Facing Behaviour
1. A line that has word-level timing shows a small **▶** toggle in the `#` column.
2. Clicking **▶** expands the line into word sub-rows beneath it (click again to collapse).
3. Each word sub-row shows: indent marker | **Start** (editable) | **End** (read-only) | **Text** (read-only) | Speaker (blank).
4. While a line is expanded, its word markers appear on the **waveform** as short amber ticks — distinct from the blue line-start markers.
5. **Dragging** a word marker on the waveform retimes that word in real time (live preview) and commits on mouse-up.
6. **Double-clicking** the Start cell of a word sub-row opens an inline `m:ss.xx` input, identical to the existing line-start editing flow.
7. Word times are clamped: `lineTick.time ≤ wordTime ≤ nextWordTime − 0.01s`.
---
## Data Flow
```
expandedRow: number | null (state in KaraokeEditor)
│
▼
TimingTable — renders word sub-rows for the expanded line
│ double-click Start cell
▼
onWordTimeChange(lineIdx, wordIdx, newTime)
│
▼
KaraokeEditor — mutates a local copy of lines, calls reconstructLrc → onLrcChange
WaveformCanvas — receives selectedLineIdx + lines
│ mousedown near word marker
▼
onWordTimeDrag(wordIdx, newTime, phase: 'move'|'commit')
│
▼
KaraokeEditor — on 'move': update dragPreviewRef only (no React state, just dirtyRef=true)
— on 'commit': same as onWordTimeChange above
```
---
## Changes per File
### `KaraokeEditor.tsx` (all changes here — no other file touched)
#### New constants
```ts
const WORD_MARKER_COLOR = 'rgba(251,191,36,0.75)' // amber-400/75
const WORD_MARKER_ACTIVE_COLOR = 'rgba(251,191,36,1.0)' // amber-400 solid
const WORD_MARKER_DRAG_COLOR = '#fbbf24' // amber-400 bright
const WORD_MARKER_HIT_PX = 8 // ±px hit zone for drag
```
#### `drawFrame` signature extension
Add two new parameters at the end (defaultable so call sites without word data still work):
```ts
function drawFrame(
ctx, peaks, lines, w, h, fraction, zoom, scrollFrac, duration, activeLineIdx,
wordLines?: LrcLineKE[], // lines whose word ticks to draw (just the expanded line)
dragPreview?: { wordIdx: number; time: number } | null,
)
```
New drawing pass after the existing line-marker loop:
- For each word in `wordLines[0]` (only expanded line's words are passed):
- Compute canvas x from word time (same formula as line markers)
- Draw a **2 px wide, 14 px tall** tick at the top of the canvas
- Color: `WORD_MARKER_DRAG_COLOR` if this is the active drag preview word, `WORD_MARKER_COLOR` otherwise
#### `WaveformCanvas` new props
```ts
interface WaveformCanvasProps extends Pick<KaraokeEditorProps, ...> {
selectedLineIdx: number | null
onWordTimeDrag: (wordIdx: number, newTime: number, phase: 'move' | 'commit') => void
}
```
#### Drag logic in `WaveformCanvas`
Replace `onClick` + existing `onMouseDown` (none currently) with a unified pointer-event handler:
```
dragStateRef = { active: false, wordIdx: -1, hasMoved: false }
onMouseDown(e):
compute xFrac → timeAtCursor
find nearest word marker within WORD_MARKER_HIT_PX px on canvas
if found:
dragStateRef = { active: true, wordIdx, hasMoved: false }
e.preventDefault() // suppress text selection
else:
dragStateRef = { active: false, ... } // will become a seek click
onMouseMove(e):
if !dragStateRef.active return
dragStateRef.hasMoved = true
compute newTime from xFrac (clamped to word bounds)
onWordTimeDrag(dragStateRef.wordIdx, newTime, 'move')
onMouseUp(e):
if dragStateRef.active && dragStateRef.hasMoved:
compute final newTime
onWordTimeDrag(dragStateRef.wordIdx, newTime, 'commit')
else if !dragStateRef.active || !dragStateRef.hasMoved:
onSeek(timeAtCursor) // treat as regular seek click
dragStateRef.active = false
```
Pointer capture (`canvas.setPointerCapture(e.pointerId)`) ensures `mousemove`/`mouseup` are
received even when the cursor leaves the canvas during a drag.
Cursor: set to `'ew-resize'` when the cursor is within the hit zone of any word marker.
Implement via `onMouseMove` checking the non-dragging case to update `canvas.style.cursor`.
#### `TimingTable` new props
```ts
expandedRow: number | null
onExpandRow: (row: number | null) => void
onWordTimeChange: (lineIdx: number, wordIdx: number, newTime: number) => void
```
#### Word sub-rows in `TimingTable`
After rendering the line `<tr>`, if `expandedRow === i` and `line.words.length > 0`, render
a sub-row `<tr>` for each word immediately after:
```
col 0 (#): indent indicator "└" — no expand toggle
col 1 (Start): editable, same double-click input flow as existing line start editing
clamped to [line.time, nextWord.time − 0.01]
col 2 (End): read-only = next word's time (or line's end time for the last word)
col 3 (Text): read-only (word text)
col 4 (Spkr): empty
```
Sub-rows use a slightly indented left border (`borderLeft: '2px solid rgba(251,191,36,0.3)'`)
to visually group them under the parent line.
#### Expand toggle in `#` column
When `line.words.length > 0`, render a small `▶` / `▼` button instead of the plain line number.
Click stops propagation (no seek), toggles `expandedRow`.
#### `onWordTimeChange` handler in `KaraokeEditor`
```ts
function handleWordTimeChange(lineIdx: number, wordIdx: number, newTime: number) {
const newLines = lines.map((l, i) => {
if (i !== lineIdx) return l
const newWords = l.words.map((w, j) => j === wordIdx ? { ...w, time: newTime } : w)
return { ...l, words: newWords }
})
onLrcChange?.(reconstructLrc(newLines))
}
```
#### `dragPreviewRef` in `KaraokeEditor`
```ts
const dragPreviewRef = useRef<{ wordIdx: number; time: number } | null>(null)
```
On `onWordTimeDrag('move', ...)`: update `dragPreviewRef.current`, set `dirtyRef.current = true`
on `WaveformCanvas` (passed down via a `setDirty` callback ref).
On `onWordTimeDrag('commit', ...)`: clear `dragPreviewRef.current`, call `handleWordTimeChange`.
---
## State Management
| State | Location | Why |
|-------|----------|-----|
| `expandedRow: number \| null` | `KaraokeEditor` useState | drives both TimingTable sub-rows and WaveformCanvas word markers |
| `dragPreviewRef` | `KaraokeEditor` useRef | RAF-driven, no re-render |
| word `editing`/`draft` | `TimingTable` useState (extend existing) | already exists for line editing |
No new global state. No context. No Zustand.
---
## Constraints / Edge Cases
| Case | Handling |
|------|----------|
| Line has no words (`words = []`) | No expand toggle, no word markers, no change |
| User edits text of an expanded line | Existing flow: drops `words[]`, reconstruct plain LRC. Collapse the expanded row automatically (set `expandedRow = null` if `lineIdx === expandedRow`) |
| Word dragged before line start | Clamp to `line.time` |
| Word dragged past next word | Clamp to `nextWord.time − 0.01` (last word clamps to `nextLine.time − 0.01`) |
| Two words at the same time | Can't happen after clamping |
| Multi-stem mode (no waveform) | `WaveformCanvas` not rendered → drag not available; word sub-rows still editable via double-click |
| Zoomed waveform | Hit-zone check and drag coordinate mapping already account for `zoomRef` and `scrollRef` |
---
## Implementation Order
### Step 1 — Word sub-rows in TimingTable (no waveform changes)
- Add `expandedRow` / `onExpandRow` / `onWordTimeChange` props
- Render `▶`/`▼` toggle in `#` column when `line.words.length > 0`
- Render word sub-rows with read-only text and editable start-time cells
- Wire `onWordTimeChange` in `KaraokeEditor`
### Step 2 — Word markers on waveform (read-only)
- Extend `drawFrame` with `wordLines` + `dragPreview` parameters
- Pass `selectedLineIdx` down to `WaveformCanvas`
- Draw amber word ticks on the canvas
### Step 3 — Drag-to-retime
- Replace `onClick` with unified pointer-event approach in `WaveformCanvas`
- Implement drag-state logic, clamping, `onWordTimeDrag` callback
- `dragPreviewRef` + `setDirty` in `KaraokeEditor`
- Cursor feedback (`ew-resize` over hit zones)
---
## What This Does NOT Touch
- `LyricsLivePreview.tsx` — no changes
- `parseLrcContent()` — no changes (word timestamps already decoded)
- `reconstructLrc()` — already handles ELRC output correctly
- Any other component
@@ -50,9 +50,6 @@ class BSRoformerSWSeparator:
output_dir=None,
output_format=self.output_format,
output_bitrate=self.mp3_bitrate if self.output_format == "mp3" else None,
normalization_threshold=0.9,
enable_denoise=False,
cpu_separation=self.cpu_separation,
)
# Load the SW model - this may need specific model name
+2 -2
View File
@@ -19,8 +19,8 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="StemEngine" />
<link rel="apple-touch-icon" href="/icon.svg" />
<script type="module" crossorigin src="/assets/index-DbaYmYBz.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-02k6pNvN.css">
<script type="module" crossorigin src="/assets/index-CbPgJQFv.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-eZreWOFb.css">
</head>
<body>
<div id="root"></div>
File diff suppressed because it is too large. Load diff
+841
View File
@@ -0,0 +1,841 @@
/**
* KaraokeEditor — Aegisub-style lyrics timing editor.
*
* Phase 1: Waveform canvas with click-to-seek and real-time playhead.
* Phase 2: Timing table with active-row highlight + scroll.
* Phase 3: Inline start-time and text editing with LRC reconstruction.
* Phase 4: Waveform zoom + horizontal scroll, line markers, arrow-key navigation.
*/
import { useState, useEffect, useRef, Fragment } from 'react'
import type { MutableRefObject, MouseEvent as ReactMouseEvent, KeyboardEvent as ReactKeyboardEvent, ChangeEvent as ReactChangeEvent } from 'react'
// ─── Types ────────────────────────────────────────────────────────────────────
export interface LrcWordKE {
time: number
text: string
isWordEnd: boolean
}
export interface LrcLineKE {
time: number
text: string
words: LrcWordKE[]
speaker?: string
}
export interface KaraokeEditorProps {
lines: LrcLineKE[]
currentTimeRef: MutableRefObject<number>
duration: number
/** Single-track audio URL. May be undefined in multi-stem mode. */
audioUrl: string | undefined
onSeek: (t: number) => void
/** Called whenever the user commits an inline edit — passes the full reconstructed LRC string. */
onLrcChange?: (newLrc: string) => void
}
// ─── Constants ────────────────────────────────────────────────────────────────
const BUCKET_COUNT = 1200
const CANVAS_HEIGHT = 80 // CSS px
const TABLE_HEIGHT = 200 // CSS px
const MAX_ZOOM = 32
const PLAYED_COLOR = '#60a5fa' // blue-400
const UNPLAYED_COLOR = '#1e3a5f' // dark blue-tinted bar
const UNPLAYED_BG = '#0f172a' // slate-900 background
const PLAYHEAD_COLOR = '#f1f5f9' // slate-100
const MARKER_COLOR = 'rgba(100,116,139,0.55)' // slate-500/55
const MARKER_ACTIVE_COLOR = 'rgba(96,165,250,0.9)' // blue-400/90
const WORD_MARKER_COLOR = 'rgba(251,191,36,0.7)' // amber-400
const WORD_MARKER_DRAG_COLOR = '#fbbf24' // amber-400 bright
const WORD_MARKER_HIT_PX = 8 // ±px hit zone for drag
const ROW_ACTIVE_BG = 'rgba(96, 165, 250, 0.15)'
const ROW_ACTIVE_FG = '#e2e8f0' // slate-200
const ROW_DIM_FG = '#475569' // slate-600
const ROW_NUM_FG = '#334155' // slate-700
// ─── Helpers ──────────────────────────────────────────────────────────────────
function downsample(channelData: Float32Array, buckets: number): Float32Array {
const peaks = new Float32Array(buckets)
const chunkSize = Math.ceil(channelData.length / buckets)
for (let i = 0; i < buckets; i++) {
let peak = 0
const start = i * chunkSize
const end = Math.min(start + chunkSize, channelData.length)
for (let j = start; j < end; j++) {
const abs = Math.abs(channelData[j])
if (abs > peak) peak = abs
}
peaks[i] = peak
}
return peaks
}
/**
* Draw one frame of the waveform canvas.
* Accounts for zoom and scrollFrac; draws line-start markers and the playhead.
*/
function drawFrame(
ctx: CanvasRenderingContext2D,
peaks: Float32Array | null,
lines: LrcLineKE[],
w: number,
h: number,
fraction: number, // 0–1 playback progress
zoom: number,
scrollFrac: number, // 0..(1−1/zoom)
duration: number,
activeLineIdx: number,
wordLine?: LrcLineKE | null,
dragPreview?: { wordIdx: number; time: number } | null,
) {
ctx.clearRect(0, 0, w, h)
const totalBuckets = BUCKET_COUNT
const visibleBuckets = totalBuckets / zoom
const startBucket = Math.min(scrollFrac * totalBuckets, totalBuckets - visibleBuckets)
// Playhead x in canvas pixels
const playBucket = fraction * totalBuckets
const cutoffX = ((playBucket - startBucket) / visibleBuckets) * w
// ── Bars ──
if (peaks) {
const barW = w / visibleBuckets
const mid = h / 2
for (let i = 0; i < Math.ceil(visibleBuckets); i++) {
const bucket = Math.floor(startBucket) + i
if (bucket >= totalBuckets) break
const x = i * barW
const barH = Math.max(1, peaks[bucket] * h * 0.9)
ctx.fillStyle = x < cutoffX ? PLAYED_COLOR : UNPLAYED_COLOR
ctx.fillRect(x, mid - barH / 2, Math.max(1, barW - 0.5), barH)
}
} else {
ctx.fillStyle = UNPLAYED_COLOR
ctx.fillRect(0, h / 2 - 1, w, 2)
}
// ── Line-start markers (ticks at the top of the canvas) ──
const dur = Math.max(duration, 0.001)
for (let li = 0; li < lines.length; li++) {
const lineBucket = (lines[li].time / dur) * totalBuckets
if (lineBucket < startBucket - 1 || lineBucket > startBucket + visibleBuckets + 1) continue
const x = Math.round(((lineBucket - startBucket) / visibleBuckets) * w)
const isAct = li === activeLineIdx
ctx.fillStyle = isAct ? MARKER_ACTIVE_COLOR : MARKER_COLOR
ctx.fillRect(x, 0, 1, isAct ? 10 : 5)
}
// ── Word-start markers (amber ticks for the expanded line) ──
if (wordLine) {
for (let wi = 0; wi < wordLine.words.length; wi++) {
const t = (dragPreview?.wordIdx === wi ? dragPreview.time : wordLine.words[wi].time)
const bucket = (t / dur) * totalBuckets
if (bucket < startBucket - 1 || bucket > startBucket + visibleBuckets + 1) continue
const x = Math.round(((bucket - startBucket) / visibleBuckets) * w)
ctx.fillStyle = dragPreview?.wordIdx === wi ? WORD_MARKER_DRAG_COLOR : WORD_MARKER_COLOR
ctx.fillRect(x, 0, 2, 14)
}
}
// ── Playhead ──
if (cutoffX >= 0 && cutoffX <= w) {
ctx.fillStyle = PLAYHEAD_COLOR
ctx.fillRect(Math.round(cutoffX) - 1, 0, 2, h)
}
}
/** Format seconds as `m:ss.xx` for display and LRC output. */
function formatTs(s: number): string {
const m = Math.floor(s / 60)
const sec = (s % 60).toFixed(2)
return `${m}:${sec.padStart(5, '0')}`
}
/**
* Parse a user-typed timestamp back to seconds.
* Accepts `m:ss`, `m:ss.x`, `m:ss.xx`. Returns null on failure.
*/
function parseTs(raw: string): number | null {
const m = raw.trim().match(/^(\d+):(\d{2}(?:\.\d{1,2})?)$/)
if (!m) return null
const t = parseInt(m[1], 10) * 60 + parseFloat(m[2])
return isFinite(t) && t >= 0 ? t : null
}
/** Reconstruct a full LRC/ELRC string from a lines array. */
function reconstructLrc(lines: LrcLineKE[]): string {
return lines.map(line => {
const lineTs = `[${formatTs(line.time)}]`
const spTag = line.speaker ? `|sp:${line.speaker}|` : ''
if (line.words.length > 0) {
const wordPart = line.words
.map((w, i) => `<${formatTs(w.time)}>${w.text}${w.isWordEnd && i < line.words.length - 1 ? ' ' : ''}`)
.join('')
return `${lineTs}${spTag}${wordPart}`
}
return `${lineTs}${spTag}${line.text}`
}).join('\n')
}
/** Same scan as `findActiveLine` in LyricsLivePreview. */
function findActiveLine(lines: LrcLineKE[], t: number): number {
let idx = -1
for (let i = 0; i < lines.length; i++) {
if (t >= lines[i].time) idx = i
else break
}
return idx
}
// ─── WaveformCanvas ───────────────────────────────────────────────────────────
interface WaveformCanvasProps extends Pick<KaraokeEditorProps, 'currentTimeRef' | 'duration' | 'audioUrl' | 'onSeek' | 'lines'> {
selectedLineIdx: number | null
onWordTimeDrag: (wordIdx: number, newTime: number) => void
}
function WaveformCanvas({
currentTimeRef, duration, audioUrl, onSeek, lines,
selectedLineIdx, onWordTimeDrag,
}: WaveformCanvasProps) {
const canvasRef = useRef<HTMLCanvasElement>(null)
const peaksRef = useRef<Float32Array | null>(null)
const rafRef = useRef<number | null>(null)
const lastFracRef = useRef(-1)
const dirtyRef = useRef(true) // force-redraw flag
const linesRef = useRef(lines)
linesRef.current = lines
const selectedLineIdxRef = useRef<number | null>(null)
selectedLineIdxRef.current = selectedLineIdx
const dragStateRef = useRef<{ active: boolean; wordIdx: number; hasMoved: boolean } | null>(null)
const dragPreviewRef = useRef<{ wordIdx: number; time: number } | null>(null)
// Stable callback refs — lets pointer-events effect use [] deps without stale closures
const onSeekRef = useRef(onSeek); onSeekRef.current = onSeek
const onWordTimeDragRef = useRef(onWordTimeDrag); onWordTimeDragRef.current = onWordTimeDrag
const durationRef = useRef(duration); durationRef.current = duration
// Zoom & scroll — kept in both state (for React re-render of controls) and refs (for RAF)
const [zoom, setZoom] = useState(1)
const [scroll, setScroll] = useState(0)
const zoomRef = useRef(1)
const scrollRef = useRef(0)
// ── Audio decode ─────────────────────────────────────────────────────────
useEffect(() => {
peaksRef.current = null
dirtyRef.current = true
if (!audioUrl) return
let cancelled = false
const actx = new AudioContext()
fetch(audioUrl)
.then(r => { if (cancelled) throw new Error('cancelled'); return r.arrayBuffer() })
.then(buf => actx.decodeAudioData(buf))
.then(audioBuf => {
if (cancelled) return
peaksRef.current = downsample(audioBuf.getChannelData(0), BUCKET_COUNT)
dirtyRef.current = true
})
.catch(() => {})
.finally(() => actx.close())
return () => { cancelled = true; actx.close() }
}, [audioUrl])
// ── Size canvas to CSS box ────────────────────────────────────────────────
useEffect(() => {
const canvas = canvasRef.current
if (!canvas) return
const init = () => {
canvas.width = canvas.offsetWidth || 800
canvas.height = canvas.offsetHeight || CANVAS_HEIGHT
dirtyRef.current = true
}
init()
const ro = new ResizeObserver(init)
ro.observe(canvas)
return () => ro.disconnect()
}, [])
// ── RAF draw loop ────────────────────────────────────────────────────────
useEffect(() => {
const canvas = canvasRef.current
if (!canvas) return
const ctx = canvas.getContext('2d')
if (!ctx) return
function loop() {
const fraction = duration > 0 ? Math.min(1, currentTimeRef.current / duration) : 0
const w = canvas!.width, h = canvas!.height
const moved = Math.abs(fraction - lastFracRef.current) * w >= 0.5
if (moved || dirtyRef.current) {
dirtyRef.current = false
lastFracRef.current = fraction
const activeIdx = findActiveLine(linesRef.current, currentTimeRef.current)
const wordLine = selectedLineIdxRef.current !== null ? (linesRef.current[selectedLineIdxRef.current] ?? null) : null
drawFrame(ctx!, peaksRef.current, linesRef.current, w, h, fraction, zoomRef.current, scrollRef.current, duration, activeIdx, wordLine, dragPreviewRef.current)
}
rafRef.current = requestAnimationFrame(loop)
}
rafRef.current = requestAnimationFrame(loop)
return () => { if (rafRef.current != null) cancelAnimationFrame(rafRef.current) }
}, [currentTimeRef, duration])
// ── Wheel: Ctrl = zoom centred on cursor; plain = horizontal scroll ───────
useEffect(() => {
const canvas = canvasRef.current
if (!canvas) return
function onWheel(e: WheelEvent) {
e.preventDefault()
if (e.ctrlKey || e.metaKey) {
// Zoom centred on the cursor
const rect = canvas!.getBoundingClientRect()
const mouseXFrac = (e.clientX - rect.left) / rect.width
const curZoom = zoomRef.current
const curScroll = scrollRef.current
const factor = e.deltaY > 0 ? 1 / 1.5 : 1.5
const newZoom = Math.max(1, Math.min(MAX_ZOOM, curZoom * factor))
const anchorBucket = curScroll * BUCKET_COUNT + mouseXFrac * (BUCKET_COUNT / curZoom)
const newVisibleBuckets = BUCKET_COUNT / newZoom
const newScroll = Math.max(0, Math.min(1 - 1 / newZoom, (anchorBucket - mouseXFrac * newVisibleBuckets) / BUCKET_COUNT))
zoomRef.current = newZoom
scrollRef.current = newScroll
setZoom(newZoom)
setScroll(newScroll)
} else {
if (zoomRef.current <= 1) return
const delta = e.shiftKey || e.deltaX !== 0 ? (e.deltaX || e.deltaY) : e.deltaY
const step = delta / ((canvasRef.current?.clientWidth ?? 800) * zoomRef.current)
const newScroll = Math.max(0, Math.min(1 - 1 / zoomRef.current, scrollRef.current + step))
scrollRef.current = newScroll
setScroll(newScroll)
}
dirtyRef.current = true
}
canvas.addEventListener('wheel', onWheel, { passive: false })
return () => canvas.removeEventListener('wheel', onWheel)
}, []) // stable — reads only refs
// ── selectedLineIdx change → force waveform redraw to show/hide word markers
useEffect(() => { dirtyRef.current = true }, [selectedLineIdx])
// ── Pointer events: click-to-seek + drag-to-retime word markers ─────────
// deps=[] — reads duration/callbacks through stable refs so listeners are
// registered once and never torn down/re-added on every render.
useEffect(() => {
const canvas = canvasRef.current
if (!canvas) return
function getTimeAt(clientX: number): number {
const dur = durationRef.current
const rect = canvas!.getBoundingClientRect()
const xFrac = (clientX - rect.left) / rect.width
const bucket = scrollRef.current * BUCKET_COUNT + xFrac * (BUCKET_COUNT / zoomRef.current)
return Math.max(0, Math.min(dur, (bucket / BUCKET_COUNT) * dur))
}
function nearestWordIdx(clientX: number): number {
const lineIdx = selectedLineIdxRef.current
if (lineIdx === null) return -1
const words = linesRef.current[lineIdx]?.words
if (!words?.length) return -1
const rect = canvas!.getBoundingClientRect()
const dur = Math.max(durationRef.current, 0.001)
const visibleBuckets = BUCKET_COUNT / zoomRef.current
for (let wi = 0; wi < words.length; wi++) {
const bucket = (words[wi].time / dur) * BUCKET_COUNT
const x = ((bucket - scrollRef.current * BUCKET_COUNT) / visibleBuckets) * rect.width
if (Math.abs((clientX - rect.left) - x) <= WORD_MARKER_HIT_PX) return wi
}
return -1
}
function onPointerDown(e: PointerEvent) {
if (durationRef.current <= 0) return
const wi = nearestWordIdx(e.clientX)
if (wi >= 0) {
dragStateRef.current = { active: true, wordIdx: wi, hasMoved: false }
canvas!.setPointerCapture(e.pointerId)
e.preventDefault()
} else {
dragStateRef.current = { active: false, wordIdx: -1, hasMoved: false }
}
}
function onPointerMove(e: PointerEvent) {
const ds = dragStateRef.current
if (ds?.active) {
ds.hasMoved = true
const lineIdx = selectedLineIdxRef.current!
const line = linesRef.current[lineIdx]
const cap = line.words[ds.wordIdx + 1]?.time ?? (linesRef.current[lineIdx + 1]?.time ?? durationRef.current)
dragPreviewRef.current = { wordIdx: ds.wordIdx, time: Math.max(line.time, Math.min(cap - 0.01, getTimeAt(e.clientX))) }
dirtyRef.current = true
} else {
const near = nearestWordIdx(e.clientX)
canvas!.style.cursor = near >= 0 ? 'ew-resize' : (durationRef.current > 0 ? 'crosshair' : 'default')
}
}
function onPointerUp(e: PointerEvent) {
const ds = dragStateRef.current
dragStateRef.current = null
if (!ds) return
if (ds.active && ds.hasMoved) {
const lineIdx = selectedLineIdxRef.current!
const line = linesRef.current[lineIdx]
const cap = line.words[ds.wordIdx + 1]?.time ?? (linesRef.current[lineIdx + 1]?.time ?? durationRef.current)
const clamped = Math.max(line.time, Math.min(cap - 0.01, getTimeAt(e.clientX)))
dragPreviewRef.current = null
dirtyRef.current = true
onWordTimeDragRef.current(ds.wordIdx, clamped)
} else {
if (durationRef.current > 0) onSeekRef.current(getTimeAt(e.clientX))
}
}
canvas.addEventListener('pointerdown', onPointerDown)
canvas.addEventListener('pointermove', onPointerMove)
canvas.addEventListener('pointerup', onPointerUp)
return () => {
canvas.removeEventListener('pointerdown', onPointerDown)
canvas.removeEventListener('pointermove', onPointerMove)
canvas.removeEventListener('pointerup', onPointerUp)
}
}, []) // stable — all dynamic values read through refs
// ── Zoom helpers ─────────────────────────────────────────────────────────
function applyZoom(newZoom: number) {
const clamped = Math.max(1, Math.min(MAX_ZOOM, newZoom))
const newScroll = clamped === 1 ? 0 : Math.max(0, Math.min(1 - 1 / clamped, scrollRef.current))
zoomRef.current = clamped
scrollRef.current = newScroll
setZoom(clamped)
setScroll(newScroll)
dirtyRef.current = true
}
const btnStyle: Record<string, string | number> = {
background: 'rgba(255,255,255,0.08)', color: '#94a3b8',
border: 'none', borderRadius: 3, cursor: 'pointer',
fontSize: 12, lineHeight: 1, padding: '1px 5px', fontFamily: 'system-ui, sans-serif',
}
return (
<div style={{ position: 'relative' }}>
<canvas
ref={canvasRef}
title={zoom > 1 ? 'Click to seek · drag amber marker to retime · Ctrl+scroll to zoom · scroll to pan' : 'Click to seek · drag amber marker to retime · Ctrl+scroll to zoom'}
style={{ display: 'block', width: '100%', height: CANVAS_HEIGHT, cursor: duration > 0 ? 'crosshair' : 'default', backgroundColor: UNPLAYED_BG }}
/>
{/* Zoom controls — top-right overlay */}
<div style={{ position: 'absolute', top: 4, right: 4, display: 'flex', alignItems: 'center', gap: 3 }}>
<button style={btnStyle} onClick={() => applyZoom(zoomRef.current / 2)} title="Zoom out">−</button>
<span style={{ fontSize: 10, color: '#64748b', fontFamily: 'system-ui, sans-serif', minWidth: 26, textAlign: 'center' }}>
{zoom >= 2 ? `${Math.round(zoom)}×` : '1×'}
</span>
<button style={btnStyle} onClick={() => applyZoom(zoomRef.current * 2)} title="Zoom in">+</button>
{zoom > 1 && (
<button style={{ ...btnStyle, fontSize: 9 }} onClick={() => applyZoom(1)} title="Reset zoom">✕</button>
)}
</div>
{/* Horizontal scrollbar — only visible when zoomed in */}
{zoom > 1 && (
<input
type="range"
min={0}
max={1 - 1 / zoom}
step={0.0001}
value={scroll}
onChange={(e: ReactChangeEvent<HTMLInputElement>) => {
const v = parseFloat(e.target.value)
scrollRef.current = v
setScroll(v)
dirtyRef.current = true
}}
style={{ display: 'block', width: '100%', height: 6, margin: 0, cursor: 'pointer' }}
/>
)}
</div>
)
}
// ─── TimingTable ──────────────────────────────────────────────────────────────
type EditingCell = { row: number; col: 'start' | 'text' } | null
interface TimingTableProps extends Pick<KaraokeEditorProps, 'lines' | 'currentTimeRef' | 'duration' | 'onSeek' | 'onLrcChange'> {
expandedRow: number | null
onExpandRow: (row: number | null) => void
onWordTimeChange: (lineIdx: number, wordIdx: number, newTime: number) => void
}
function TimingTable({
lines, currentTimeRef, duration, onSeek, onLrcChange,
expandedRow, onExpandRow, onWordTimeChange,
}: TimingTableProps) {
// ── Inline editing ────────────────────────────────────────────────────────
const [editing, setEditing] = useState<EditingCell>(null)
const [draft, setDraft] = useState('')
function startEdit(row: number, col: 'start' | 'text', initialValue: string, e: ReactMouseEvent) {
e.stopPropagation()
setEditing({ row, col })
setDraft(initialValue)
}
function commitEdit() {
if (!editing || !onLrcChange) { setEditing(null); return }
const { row, col } = editing
if (col === 'start') {
const t = parseTs(draft)
if (t === null) { setEditing(null); return }
const newLines = lines.map((l, i) => i === row ? { ...l, time: t } : l).sort((a, b) => a.time - b.time)
onLrcChange(reconstructLrc(newLines))
} else {
const newLines = lines.map((l, i) => i === row ? { ...l, text: draft.trim(), words: [] } : l)
onLrcChange(reconstructLrc(newLines))
}
setEditing(null)
}
function cancelEdit() { setEditing(null) }
// ── Word-level inline editing ─────────────────────────────────────────────
const [wordEditing, setWordEditing] = useState<{ lineIdx: number; wordIdx: number } | null>(null)
const [wordDraft, setWordDraft] = useState('')
function startWordEdit(lineIdx: number, wordIdx: number, e: ReactMouseEvent) {
e.stopPropagation()
setWordEditing({ lineIdx, wordIdx })
setWordDraft(formatTs(lines[lineIdx].words[wordIdx].time))
}
function commitWordEdit() {
if (!wordEditing) { setWordEditing(null); return }
const { lineIdx, wordIdx } = wordEditing
const t = parseTs(wordDraft)
if (t === null) { setWordEditing(null); return }
const line = lines[lineIdx]
const cap = line.words[wordIdx + 1]?.time ?? (lines[lineIdx + 1]?.time ?? duration)
onWordTimeChange(lineIdx, wordIdx, Math.max(line.time, Math.min(cap - 0.01, t)))
setWordEditing(null)
}
function cancelWordEdit() { setWordEditing(null) }
function handleWordKeyDown(e: ReactKeyboardEvent<HTMLInputElement>) {
if (e.key === 'Enter') { e.preventDefault(); commitWordEdit() }
if (e.key === 'Escape') { e.preventDefault(); cancelWordEdit() }
if (e.key === 'Tab' && wordEditing) {
e.preventDefault()
const { lineIdx, wordIdx } = wordEditing
const line = lines[lineIdx]
const t = parseTs(wordDraft)
if (t !== null) {
const cap = line.words[wordIdx + 1]?.time ?? (lines[lineIdx + 1]?.time ?? duration)
onWordTimeChange(lineIdx, wordIdx, Math.max(line.time, Math.min(cap - 0.01, t)))
}
const nextIdx = e.shiftKey ? wordIdx - 1 : wordIdx + 1
if (nextIdx >= 0 && nextIdx < line.words.length) {
setWordEditing({ lineIdx, wordIdx: nextIdx })
setWordDraft(formatTs(line.words[nextIdx].time))
} else {
setWordEditing(null)
}
}
}
function handleKeyDown(e: ReactKeyboardEvent<HTMLInputElement>) {
if (e.key === 'Enter') { e.preventDefault(); commitEdit() }
if (e.key === 'Escape') { e.preventDefault(); cancelEdit() }
if (e.key === 'Tab' && editing) {
e.preventDefault()
commitEdit()
const next = e.shiftKey
? (editing.col === 'text' ? { row: editing.row, col: 'start' as const }
: editing.row > 0 ? { row: editing.row - 1, col: 'text' as const } : null)
: (editing.col === 'start' ? { row: editing.row, col: 'text' as const }
: editing.row < lines.length - 1 ? { row: editing.row + 1, col: 'start' as const } : null)
if (next) {
const nextLine = lines[next.row]
setEditing(next)
setDraft(next.col === 'start' ? formatTs(nextLine.time) : nextLine.text)
}
}
}
// ── Active-row highlight (RAF, no React re-renders) ───────────────────────
const rowRefs = useRef<(HTMLTableRowElement | null)[]>([])
const wordRowRefsMap = useRef<Record<string, HTMLTableRowElement | null>>({})
const activeRef = useRef(-1)
const activeWordRowRef = useRef<HTMLTableRowElement | null>(null)
const rafRef = useRef<number | null>(null)
const linesRef = useRef(lines)
linesRef.current = lines
function highlightWordRow(el: HTMLTableRowElement | null) {
if (activeWordRowRef.current && activeWordRowRef.current !== el) {
activeWordRowRef.current.style.backgroundColor = 'transparent'
}
activeWordRowRef.current = el
if (el) el.style.backgroundColor = 'rgba(251,191,36,0.12)'
}
useEffect(() => {
rowRefs.current = new Array(lines.length).fill(null)
activeRef.current = -1
}, [lines.length])
useEffect(() => {
function applyRow(idx: number, active: boolean) {
const row = rowRefs.current[idx]
if (!row) return
row.style.backgroundColor = active ? ROW_ACTIVE_BG : 'transparent'
const cells = row.children
for (let c = 0; c < cells.length; c++) {
const td = cells[c] as HTMLElement
td.style.color = active ? (c === 0 ? ROW_DIM_FG : ROW_ACTIVE_FG) : (c === 0 ? ROW_NUM_FG : ROW_DIM_FG)
}
}
function loop() {
const newIdx = findActiveLine(linesRef.current, currentTimeRef.current)
const oldIdx = activeRef.current
if (newIdx !== oldIdx) {
if (oldIdx >= 0) applyRow(oldIdx, false)
if (newIdx >= 0) {
applyRow(newIdx, true)
rowRefs.current[newIdx]?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
}
activeRef.current = newIdx
// Clear word-row highlight when the active line changes
highlightWordRow(null)
}
rafRef.current = requestAnimationFrame(loop)
}
rafRef.current = requestAnimationFrame(loop)
return () => { if (rafRef.current != null) cancelAnimationFrame(rafRef.current) }
}, [currentTimeRef])
// ── Render ────────────────────────────────────────────────────────────────
const hasSpeakers = lines.some(l => l.speaker)
const canEdit = !!onLrcChange
const inputStyle: Record<string, string | number> = {
width: '100%', boxSizing: 'border-box',
background: 'rgba(96,165,250,0.12)', color: '#e2e8f0',
border: '1px solid rgba(96,165,250,0.5)', borderRadius: 3,
padding: '0 4px', fontSize: 11,
fontFamily: '"Roboto Mono","Fira Code",monospace',
outline: 'none', height: 20,
}
const wordInputStyle: Record<string, string | number> = {
width: '100%', boxSizing: 'border-box',
background: 'rgba(251,191,36,0.08)', color: '#e2e8f0',
border: '1px solid rgba(251,191,36,0.4)', borderRadius: 3,
padding: '0 4px', fontSize: 11,
fontFamily: '"Roboto Mono","Fira Code",monospace',
outline: 'none', height: 20,
}
return (
<div style={{ height: TABLE_HEIGHT, overflowY: 'auto', overflowX: 'hidden' }}>
<table style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed' }}>
<colgroup>
<col style={{ width: 36 }} />
<col style={{ width: 78 }} />
<col style={{ width: 72 }} />
<col />
{hasSpeakers && <col style={{ width: 80 }} />}
</colgroup>
<thead>
<tr style={{ position: 'sticky', top: 0, zIndex: 1, backgroundColor: '#0c1523', borderBottom: '1px solid rgba(255,255,255,0.08)' }}>
{(['#', 'Start', 'End', 'Text', ...(hasSpeakers ? ['Speaker'] : [])] as string[]).map(h => (
<th key={h} style={{ padding: '3px 6px', textAlign: 'left', fontSize: 9, fontWeight: 600, color: '#334155', letterSpacing: '0.06em', textTransform: 'uppercase', fontFamily: 'system-ui, sans-serif', overflow: 'hidden' }}>{h}</th>
))}
</tr>
</thead>
<tbody>
{lines.map((line, i) => {
const endTime = lines[i + 1]?.time ?? duration
const editingStart = editing?.row === i && editing.col === 'start'
const editingText = editing?.row === i && editing.col === 'text'
return (
<Fragment key={i}>
<tr
ref={(el: HTMLTableRowElement | null) => { rowRefs.current[i] = el }}
onClick={() => onSeek(line.time)}
style={{ cursor: 'pointer', borderBottom: '1px solid rgba(255,255,255,0.03)', backgroundColor: 'transparent' }}
>
<td
style={{ padding: '3px 4px', textAlign: 'right', fontSize: 11, color: ROW_NUM_FG, fontFamily: 'system-ui, sans-serif', userSelect: 'none', cursor: line.words.length > 0 ? 'pointer' : 'default' }}
onClick={line.words.length > 0 ? (e: ReactMouseEvent<HTMLTableCellElement>) => { e.stopPropagation(); onExpandRow(expandedRow === i ? null : i) } : undefined}
title={line.words.length > 0 ? (expandedRow === i ? 'Collapse word timing' : 'Expand word timing') : undefined}
>
{line.words.length > 0 && <span style={{ fontSize: 8, color: '#64748b' }}>{expandedRow === i ? '▼ ' : '▶ '}</span>}
{i + 1}
</td>
<td
style={{ padding: editingStart ? '1px 4px' : '3px 6px', fontSize: 11, color: ROW_DIM_FG, fontFamily: '"Roboto Mono","Fira Code",monospace', fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }}
title={canEdit ? 'Double-click to edit' : undefined}
onDoubleClick={canEdit ? (e: ReactMouseEvent<HTMLTableCellElement>) => startEdit(i, 'start', formatTs(line.time), e) : undefined}
>
{editingStart ? (
<input autoFocus style={inputStyle} value={draft}
onChange={(e: ReactChangeEvent<HTMLInputElement>) => setDraft(e.target.value)}
onBlur={commitEdit} onKeyDown={handleKeyDown}
onClick={(e: ReactMouseEvent<HTMLInputElement>) => e.stopPropagation()} />
) : formatTs(line.time)}
</td>
<td style={{ padding: '3px 6px', fontSize: 11, color: ROW_NUM_FG, fontFamily: '"Roboto Mono","Fira Code",monospace', fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }}>
{formatTs(endTime)}
</td>
<td
style={{ padding: editingText ? '1px 4px' : '3px 8px', fontSize: 12, color: ROW_DIM_FG, fontFamily: 'system-ui, sans-serif', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: editingText ? undefined : 'nowrap' }}
title={canEdit ? 'Double-click to edit' + (line.words.length > 0 ? ' (word timing will be replaced with plain text)' : '') : undefined}
onDoubleClick={canEdit ? (e: ReactMouseEvent<HTMLTableCellElement>) => startEdit(i, 'text', line.text, e) : undefined}
>
{editingText ? (
<input autoFocus style={{ ...inputStyle, fontFamily: 'system-ui, sans-serif' }} value={draft}
onChange={(e: ReactChangeEvent<HTMLInputElement>) => setDraft(e.target.value)}
onBlur={commitEdit} onKeyDown={handleKeyDown}
onClick={(e: ReactMouseEvent<HTMLInputElement>) => e.stopPropagation()} />
) : line.text}
</td>
{hasSpeakers && (
<td style={{ padding: '3px 6px', fontSize: 10, color: ROW_NUM_FG, fontFamily: 'system-ui, sans-serif', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{line.speaker ?? ''}
</td>
)}
</tr>
{expandedRow === i && line.words.length > 0 && line.words.map((word, j) => {
const wEnd = line.words[j + 1]?.time ?? endTime
const isWordEdit = wordEditing?.lineIdx === i && wordEditing?.wordIdx === j
const wKey = `${i}-${j}`
return (
<tr
key={`w-${j}`}
ref={(el: HTMLTableRowElement | null) => { wordRowRefsMap.current[wKey] = el }}
onClick={(e: ReactMouseEvent<HTMLTableRowElement>) => { e.stopPropagation(); onSeek(word.time); highlightWordRow(wordRowRefsMap.current[wKey] ?? null) }}
style={{ cursor: 'pointer', borderBottom: '1px solid rgba(255,255,255,0.02)', backgroundColor: 'transparent' }}
>
<td style={{ padding: '2px 4px', textAlign: 'right', fontSize: 10, color: '#1e293b', fontFamily: 'system-ui, sans-serif', userSelect: 'none', borderLeft: '2px solid rgba(251,191,36,0.3)' }}>
└
</td>
<td
style={{ padding: isWordEdit ? '1px 4px' : '2px 6px', fontSize: 11, color: '#475569', fontFamily: '"Roboto Mono","Fira Code",monospace', fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }}
title={canEdit ? 'Double-click to edit word start time' : undefined}
onDoubleClick={canEdit ? (e: ReactMouseEvent<HTMLTableCellElement>) => startWordEdit(i, j, e) : undefined}
>
{isWordEdit ? (
<input autoFocus style={wordInputStyle} value={wordDraft}
onChange={(e: ReactChangeEvent<HTMLInputElement>) => setWordDraft(e.target.value)}
onBlur={commitWordEdit} onKeyDown={handleWordKeyDown}
onClick={(e: ReactMouseEvent<HTMLInputElement>) => e.stopPropagation()} />
) : formatTs(word.time)}
</td>
<td style={{ padding: '2px 6px', fontSize: 11, color: '#334155', fontFamily: '"Roboto Mono","Fira Code",monospace', fontVariantNumeric: 'tabular-nums', whiteSpace: 'nowrap' }}>
{formatTs(wEnd)}
</td>
<td style={{ padding: '2px 8px', fontSize: 11, color: '#475569', fontFamily: 'system-ui, sans-serif', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{word.text}
</td>
{hasSpeakers && <td />}
</tr>
)
})}
</Fragment>
)
})}
</tbody>
</table>
</div>
)
}
// ─── KaraokeEditor ────────────────────────────────────────────────────────────
export default function KaraokeEditor({
lines, currentTimeRef, duration, audioUrl, onSeek, onLrcChange,
}: KaraokeEditorProps) {
// Keep a stable ref for the keyboard shortcut handler
const linesRef = useRef(lines)
linesRef.current = lines
// ── Expanded word-timing row ──────────────────────────────────────────────
const [expandedRow, setExpandedRow] = useState<number | null>(null)
function handleWordTimeChange(lineIdx: number, wordIdx: number, newTime: number) {
const newLines = lines.map((l, i) => {
if (i !== lineIdx) return l
const newWords = l.words.map((w, j) => j === wordIdx ? { ...w, time: newTime } : w)
return { ...l, words: newWords }
})
onLrcChange?.(reconstructLrc(newLines))
}
function handleWordTimeDrag(wordIdx: number, newTime: number) {
if (expandedRow === null) return
handleWordTimeChange(expandedRow, wordIdx, newTime)
}
// ── Arrow-key navigation: ← prev line · → next line ──────────────────────
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return
const tag = (document.activeElement as HTMLElement | null)?.tagName
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return
e.preventDefault()
const ls = linesRef.current
const idx = findActiveLine(ls, currentTimeRef.current)
if (e.key === 'ArrowLeft') {
const prev = Math.max(0, idx > 0 ? idx - 1 : 0)
if (ls[prev]) onSeek(ls[prev].time)
} else {
const next = idx + 1
if (ls[next]) onSeek(ls[next].time)
}
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [currentTimeRef, onSeek])
return (
<div style={{ borderTop: '1px solid rgba(255,255,255,0.08)', backgroundColor: UNPLAYED_BG, userSelect: 'none' }}>
{/* Waveform header */}
<div style={{ display: 'flex', alignItems: 'center', padding: '4px 10px', borderBottom: '1px solid rgba(255,255,255,0.06)', backgroundColor: 'rgba(255,255,255,0.03)' }}>
<span style={{ fontSize: 10, color: '#64748b', fontFamily: 'system-ui, sans-serif', letterSpacing: '0.05em', textTransform: 'uppercase' }}>Waveform</span>
{!audioUrl
? <span style={{ fontSize: 10, color: '#475569', marginLeft: 8, fontFamily: 'system-ui, sans-serif' }}>— not available in multi-stem mode</span>
: <span style={{ fontSize: 10, color: '#334155', marginLeft: 8, fontFamily: 'system-ui, sans-serif' }}>Ctrl+scroll to zoom · scroll to pan · ←→ keys jump lines</span>
}
</div>
<WaveformCanvas currentTimeRef={currentTimeRef} duration={duration} audioUrl={audioUrl} onSeek={onSeek} lines={lines}
selectedLineIdx={expandedRow} onWordTimeDrag={handleWordTimeDrag} />
{/* Lines header */}
<div style={{ display: 'flex', alignItems: 'center', padding: '4px 10px', borderTop: '1px solid rgba(255,255,255,0.06)', borderBottom: '1px solid rgba(255,255,255,0.06)', backgroundColor: 'rgba(255,255,255,0.03)' }}>
<span style={{ fontSize: 10, color: '#64748b', fontFamily: 'system-ui, sans-serif', letterSpacing: '0.05em', textTransform: 'uppercase' }}>Lines</span>
{onLrcChange && <span style={{ fontSize: 10, color: '#334155', marginLeft: 8, fontFamily: 'system-ui, sans-serif' }}>— double-click Start or Text to edit</span>}
<span style={{ fontSize: 10, color: '#334155', marginLeft: 'auto', fontFamily: 'system-ui, sans-serif' }}>{lines.length}</span>
</div>
<TimingTable lines={lines} currentTimeRef={currentTimeRef} duration={duration} onSeek={onSeek} onLrcChange={onLrcChange}
expandedRow={expandedRow} onExpandRow={setExpandedRow} onWordTimeChange={handleWordTimeChange} />
</div>
)
}
+26 -2
View File
@@ -1,7 +1,8 @@
import { useState, useEffect, useLayoutEffect, useRef, useCallback, useMemo } from 'react'
import { Play, Pause, SkipBack, Volume2, VolumeX, Palette, Pencil, X, AlignLeft, AlignCenter, AlignRight, Type, Crosshair, Maximize2, Minimize2 } from 'lucide-react'
import { Play, Pause, SkipBack, Volume2, VolumeX, Palette, Pencil, X, AlignLeft, AlignCenter, AlignRight, Type, Crosshair, Maximize2, Minimize2, Activity } from 'lucide-react'
import type { LyricsStyleOptions } from '../types'
import { registerPlayback, unregisterPlayback, publishMeta, clearMeta } from '../utils/audioRegistry'
import KaraokeEditor from './KaraokeEditor'
// ─── Types ───────────────────────────────────────────────────────────────────
@@ -797,6 +798,7 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
// UI panels
const [showStylePicker, setShowStylePicker] = useState(false)
const [showEditor, setShowEditor] = useState(false)
const [showAegisub, setShowAegisub] = useState(false)
// Editable style state — seeded from styleOptions prop, then overridden by any saved preference
const [style, setStyle] = useState<StyleState>(() => {
@@ -2143,12 +2145,19 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
<Palette className="w-3.5 h-3.5" />
</button>
<button
onClick={() => { setShowEditor(p => !p); setShowStylePicker(false) }}
onClick={() => { setShowEditor(p => !p); setShowStylePicker(false); setShowAegisub(false) }}
title="Edit timing / lyrics"
className={`p-1.5 rounded-md transition-colors ${showEditor ? 'bg-brand-500 text-white' : isFullscreen ? 'text-slate-400 hover:bg-white/10' : 'text-slate-500 dark:text-gray-400 hover:bg-slate-200 dark:hover:bg-gray-700'}`}
>
<Pencil className="w-3.5 h-3.5" />
</button>
<button
onClick={() => { setShowAegisub(!showAegisub); setShowStylePicker(false); setShowEditor(false) }}
title="Waveform editor"
className={`p-1.5 rounded-md transition-colors ${showAegisub ? 'bg-brand-500 text-white' : isFullscreen ? 'text-slate-400 hover:bg-white/10' : 'text-slate-500 dark:text-gray-400 hover:bg-slate-200 dark:hover:bg-gray-700'}`}
>
<Activity className="w-3.5 h-3.5" />
</button>
<button
onClick={toggleFullscreen}
title={isFullscreen ? 'Exit fullscreen' : 'Fullscreen'}
@@ -2237,6 +2246,21 @@ export default function LyricsLivePreview({ lrcText, audioUrl, stems, title, sty
/>
)}
{/* Waveform editor panel */}
{showAegisub && (
<KaraokeEditor
lines={lines}
currentTimeRef={currentTimeRef}
duration={displayDuration}
audioUrl={audioUrl ?? stems?.[0]?.url}
onSeek={seekTime}
onLrcChange={(newLrc) => {
setEditedLrc(newLrc)
onLrcChange?.(newLrc)
}}
/>
)}
{/* Content area: fullscreen with art → side-by-side on wide screens, stacked on mobile */}
{isFullscreen && coverArtUrl && artLoaded ? (
<div style={{ flex: '1 1 0', display: 'flex', flexDirection: isNarrow ? 'column' : 'row', overflow: 'hidden' }}>
-29
View File
@@ -1,41 +1,12 @@
services:
# Minimal privileged init container: sets the GPU power limit then exits.
# Runs before stemengine so the main container never needs SYS_ADMIN.
stemengine-gpu-init:
container_name: stemengine-gpu-init
image: nvidia/cuda:12.1.0-base-ubuntu22.04
runtime: nvidia
restart: "no"
cap_add:
- SYS_ADMIN
entrypoint:
- sh
- -c
- |
PL="${STEMENGINE_GPU_POWER_LIMIT:-50}"
if [ "$$PL" != "0" ]; then
echo "[gpu-init] Setting power limit to $${PL} W..."
nvidia-smi --power-limit="$$PL" && echo "[gpu-init] Done." || echo "[gpu-init] Failed."
fi
environment:
- STEMENGINE_GPU_POWER_LIMIT=${STEMENGINE_GPU_POWER_LIMIT:-100}
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
stemengine:
container_name: stemengine
image: ghcr.io/seclusionenthusiast/stemengine:latest
runtime: nvidia
entrypoint: []
restart: unless-stopped
depends_on:
stemengine-gpu-init:
condition: service_completed_successfully
networks:
- t2_proxy
security_opt:
-26
View File
@@ -1,32 +1,6 @@
services:
# Minimal privileged init container: sets the GPU power limit then exits.
# Runs before stemengine so the main container never needs SYS_ADMIN.
stemengine-gpu-init:
container_name: stemengine-gpu-init
image: nvidia/cuda:12.1.0-base-ubuntu22.04
runtime: nvidia
restart: "no"
cap_add:
- SYS_ADMIN
entrypoint:
- sh
- -c
- |
PL="${STEMENGINE_GPU_POWER_LIMIT:-100}"
if [ "$$PL" != "0" ]; then
echo "[gpu-init] Setting power limit to $${PL} W..."
nvidia-smi --power-limit="$$PL" && echo "[gpu-init] Done." || echo "[gpu-init] Failed."
fi
environment:
- STEMENGINE_GPU_POWER_LIMIT=${STEMENGINE_GPU_POWER_LIMIT:-100}
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
stemengine:
container_name: stemengine
image: ghcr.io/seclusionenthusiast/stemengine:latest