Files
stemengine_old/frontend/src/components/PerformanceSidebar.tsx
T
2026-04-14 10:36:33 +09:00

876 lines
44 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useCallback, useEffect, useRef } from 'react'
import type { LyricsVisualStyle } from './LyricsLivePreview'
interface Stem {
name: string
label: string
url: string
}
interface SidebarStyleState {
fontFamily: string
fontSize: number
fontBold: boolean
textAlign: 'left' | 'center' | 'right'
activeLineVerticalAlign: 'top' | 'center' | 'bottom'
lineSpacing: number
textColor: string
highlightColor: string
bgColor: string
videoDisplayMode: 'scroll' | 'line' | 'word' | 'syllable'
layoutOffsetXScroll: number
layoutOffsetYScroll: number
layoutOffsetXLine: number
layoutOffsetYLine: number
layoutOffsetXWord: number
layoutOffsetYWord: number
layoutOffsetXSyllable: number
layoutOffsetYSyllable: number
}
type DeepPartial<T> = {
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
}
interface VizSettings {
quality: 'low' | 'balanced' | 'high'
fps_cap: 30 | 60 | 120
muon: {
radius_multiplier: number
aperture: number
spacing: number
particle_count: number
rotation_speed: number
glow_intensity: number
particle_size: number
drum_reactivity: number
hue_range: number
beat_sensitivity: number
ellipse_ratio: number
idle_speed: number
noise_scale: number
noise_force: number
mono_color: boolean
divisions: number
lifespan: number
particle_mirror: boolean
dynamic_radius: number
delta_response_limit: number
visualization_preset: 'default' | 'orbital' | 'flower' | 'spiro' | 'hybrid'
}
fluid: {
spawn_density: number
splat_force: number
decay: number
background_persistence: number
beat_burst_count: number
treble_pulse: number
drag: number
blob_life: number
color_speed: number
}
tendrils: {
noise_weight: number
noise_scale: number
flow_weight: number
flow_decay: number
force_weight: number
speed_limit: number
damping: number
hue_range: number
mono_color: boolean
visualization_preset: string
}
spirit: {
speed: number
die_speed: number
radius: number
curl_size: number
attraction: number
bloom_intensity: number
bloom_threshold: number
afterimage_damp: number
visualization_preset: string
}
}
const VIZ_DEFAULTS: VizSettings = {
quality: 'balanced',
fps_cap: 60,
muon: {
radius_multiplier: 1.0,
aperture: 1.0,
spacing: 1.0,
particle_count: 220,
rotation_speed: 1.0,
glow_intensity: 1.0,
particle_size: 1.0,
drum_reactivity: 1.0,
hue_range: 1.0,
beat_sensitivity: 1.0,
ellipse_ratio: 0.62,
idle_speed: 1.0,
noise_scale: 1.0,
noise_force: 1.0,
mono_color: false,
divisions: 16,
lifespan: 180,
particle_mirror: false,
dynamic_radius: 1.0,
delta_response_limit: 0.005,
visualization_preset: 'hybrid',
},
fluid: {
spawn_density: 1.0,
splat_force: 1.0,
decay: 1.0,
background_persistence: 1.0,
beat_burst_count: 1.0,
treble_pulse: 1.0,
drag: 1.0,
blob_life: 1.0,
color_speed: 1.0,
},
tendrils: {
noise_weight: 1.0,
noise_scale: 1.0,
flow_weight: 1.0,
flow_decay: 1.0,
force_weight: 1.0,
speed_limit: 1.0,
damping: 1.0,
hue_range: 1.0,
mono_color: false,
visualization_preset: 'flow',
},
spirit: {
speed: 1.0,
die_speed: 1.0,
radius: 1.5,
curl_size: 0.4,
attraction: 0.08,
bloom_intensity: 1.5,
bloom_threshold: 0.05,
afterimage_damp: 0.88,
visualization_preset: 'spirit',
},
}
// Named muon presets — applied to vizSettings.muon only (leaves other keys untouched).
const MUON_PRESETS: Array<{ label: string; values: VizSettings['muon'] }> = [
{
label: 'Default',
values: { radius_multiplier: 1.0, aperture: 1.0, spacing: 1.0, particle_count: 220, rotation_speed: 1.0, glow_intensity: 1.0, particle_size: 1.0, drum_reactivity: 1.0, hue_range: 1.0, beat_sensitivity: 1.0, ellipse_ratio: 0.62, idle_speed: 1.0, noise_scale: 1.0, noise_force: 1.0, mono_color: false, divisions: 16, lifespan: 180, particle_mirror: false, dynamic_radius: 1.0, delta_response_limit: 0.005, visualization_preset: 'hybrid' },
},
{
label: 'Calm',
values: { radius_multiplier: 1.0, aperture: 0.8, spacing: 1.2, particle_count: 120, rotation_speed: 0.5, glow_intensity: 0.4, particle_size: 0.7, drum_reactivity: 0.5, hue_range: 0.4, beat_sensitivity: 0.5, ellipse_ratio: 0.55, idle_speed: 0.6, noise_scale: 0.7, noise_force: 0.6, mono_color: false, divisions: 12, lifespan: 220, particle_mirror: false, dynamic_radius: 0.7, delta_response_limit: 0.007, visualization_preset: 'orbital' },
},
{
label: 'Energetic',
values: { radius_multiplier: 1.1, aperture: 1.3, spacing: 0.9, particle_count: 350, rotation_speed: 2.0, glow_intensity: 2.0, particle_size: 1.4, drum_reactivity: 1.8, hue_range: 1.8, beat_sensitivity: 2.0, ellipse_ratio: 0.68, idle_speed: 1.5, noise_scale: 1.4, noise_force: 1.5, mono_color: false, divisions: 24, lifespan: 160, particle_mirror: true, dynamic_radius: 1.6, delta_response_limit: 0.003, visualization_preset: 'hybrid' },
},
{
label: 'Dreamy',
values: { radius_multiplier: 1.2, aperture: 0.7, spacing: 1.5, particle_count: 280, rotation_speed: 0.6, glow_intensity: 2.5, particle_size: 1.1, drum_reactivity: 0.6, hue_range: 2.5, beat_sensitivity: 0.4, ellipse_ratio: 0.45, idle_speed: 0.8, noise_scale: 1.7, noise_force: 1.2, mono_color: false, divisions: 20, lifespan: 260, particle_mirror: false, dynamic_radius: 0.8, delta_response_limit: 0.008, visualization_preset: 'flower' },
},
{
label: 'Minimal',
values: { radius_multiplier: 0.8, aperture: 1.0, spacing: 2.0, particle_count: 60, rotation_speed: 0.8, glow_intensity: 0.0, particle_size: 0.6, drum_reactivity: 1.2, hue_range: 0.0, beat_sensitivity: 1.0, ellipse_ratio: 1.0, idle_speed: 0.5, noise_scale: 0.4, noise_force: 0.3, mono_color: true, divisions: 8, lifespan: 120, particle_mirror: false, dynamic_radius: 0.7, delta_response_limit: 0.012, visualization_preset: 'default' },
},
{
label: 'Cosmic',
values: { radius_multiplier: 1.3, aperture: 1.2, spacing: 0.7, particle_count: 400, rotation_speed: 1.5, glow_intensity: 1.8, particle_size: 1.8, drum_reactivity: 1.4, hue_range: 2.0, beat_sensitivity: 1.5, ellipse_ratio: 0.38, idle_speed: 1.2, noise_scale: 1.8, noise_force: 1.6, mono_color: false, divisions: 28, lifespan: 190, particle_mirror: true, dynamic_radius: 1.4, delta_response_limit: 0.004, visualization_preset: 'spiro' },
},
]
// Named fluid presets — applied to vizSettings.fluid only.
const FLUID_PRESETS: Array<{ label: string; values: VizSettings['fluid'] }> = [
{
label: 'Default',
values: { spawn_density: 1.0, splat_force: 1.0, decay: 1.0, background_persistence: 1.0, beat_burst_count: 1.0, treble_pulse: 1.0, drag: 1.0, blob_life: 1.0, color_speed: 1.0 },
},
{
label: 'Ink',
values: { spawn_density: 0.5, splat_force: 0.5, decay: 0.3, background_persistence: 3.0, beat_burst_count: 1.5, treble_pulse: 0.3, drag: 2.5, blob_life: 2.5, color_speed: 0.2 },
},
{
label: 'Foam',
values: { spawn_density: 3.0, splat_force: 0.3, decay: 3.0, background_persistence: 0.2, beat_burst_count: 3.0, treble_pulse: 2.5, drag: 0.4, blob_life: 0.3, color_speed: 3.0 },
},
{
label: 'Lava',
values: { spawn_density: 0.3, splat_force: 2.0, decay: 0.2, background_persistence: 3.5, beat_burst_count: 0.5, treble_pulse: 0.2, drag: 3.0, blob_life: 3.0, color_speed: 0.2 },
},
{
label: 'Mist',
values: { spawn_density: 1.5, splat_force: 0.2, decay: 2.0, background_persistence: 0.5, beat_burst_count: 0.5, treble_pulse: 1.5, drag: 0.5, blob_life: 0.5, color_speed: 0.8 },
},
{
label: 'Storm',
values: { spawn_density: 2.5, splat_force: 3.0, decay: 1.0, background_persistence: 1.0, beat_burst_count: 3.0, treble_pulse: 2.5, drag: 0.4, blob_life: 1.0, color_speed: 2.5 },
},
]
const EPS = 0.015
function muonPresetMatch(current: VizSettings['muon'], preset: VizSettings['muon']): boolean {
const keys = Object.keys(preset) as Array<keyof VizSettings['muon']>
return keys.every((k) => {
const a = current[k]
const b = preset[k]
if (typeof a === 'boolean') return a === b
if (typeof a === 'string') return a === b
return Math.abs((a as number) - (b as number)) < EPS
})
}
function fluidPresetMatch(current: VizSettings['fluid'], preset: VizSettings['fluid']): boolean {
const keys = Object.keys(preset) as Array<keyof VizSettings['fluid']>
return keys.every((k) => Math.abs(current[k] - preset[k]) < EPS)
}
const FONT_OPTIONS = [
{ value: 'system-ui, sans-serif', label: 'System' },
{ value: '"Inter", sans-serif', label: 'Inter' },
{ value: '"Work Sans", sans-serif', label: 'Work Sans' },
{ value: '"Archivo", sans-serif', label: 'Archivo' },
{ value: '"Poppins", sans-serif', label: 'Poppins' },
{ value: '"Roboto", sans-serif', label: 'Roboto' },
{ value: '"Oswald", sans-serif', label: 'Oswald' },
{ value: '"EB Garamond", serif', label: 'EB Garamond' },
{ value: '"Libre Baskerville", serif', label: 'Libre Baskerville' },
{ value: '"Young Serif", serif', label: 'Young Serif' },
]
interface PerformanceSidebarProps {
isNarrow: boolean
visualStyle: LyricsVisualStyle
setVisualStyle: (s: LyricsVisualStyle) => void
hasVideo: boolean
stems: Stem[] | undefined
mutedStems: Record<string, boolean>
soloedStems: Record<string, boolean>
gains: Record<string, number>
toggleStemMute: (name: string) => void
toggleStemSolo: (name: string) => void
setStemGain: (name: string, value: number) => void
style: SidebarStyleState
patchStyle: (patch: Partial<SidebarStyleState>) => void
vizSettings: VizSettings
manifestVizSettings: VizSettings | null
patchVizSettings: (patch: DeepPartial<VizSettings>) => void
lyricsTrackKeys: string[]
selectedLyricsTrack: string
onSelectLyricsTrack: (key: string) => void
hasElrc: boolean
onClose: () => void
}
function formatMultiplier(value: number): string {
return `${value.toFixed(2)}×`
}
function getLayoutOffset(style: SidebarStyleState): { x: number; y: number } {
switch (style.videoDisplayMode) {
case 'line':
return { x: style.layoutOffsetXLine, y: style.layoutOffsetYLine }
case 'word':
return { x: style.layoutOffsetXWord, y: style.layoutOffsetYWord }
case 'syllable':
return { x: style.layoutOffsetXSyllable, y: style.layoutOffsetYSyllable }
case 'scroll':
default:
return { x: style.layoutOffsetXScroll, y: style.layoutOffsetYScroll }
}
}
export default function PerformanceSidebar({
isNarrow,
visualStyle,
setVisualStyle,
hasVideo,
stems,
mutedStems,
soloedStems,
gains,
toggleStemMute,
toggleStemSolo,
setStemGain,
style,
patchStyle,
vizSettings,
manifestVizSettings,
patchVizSettings,
lyricsTrackKeys,
selectedLyricsTrack,
onSelectLyricsTrack,
hasElrc,
onClose,
}: PerformanceSidebarProps) {
const autoHideTimerRef = useRef<number | null>(null)
const scheduleAutoHide = useCallback(() => {
if (autoHideTimerRef.current !== null) {
window.clearTimeout(autoHideTimerRef.current)
}
autoHideTimerRef.current = window.setTimeout(() => {
onClose()
}, 4000)
}, [onClose])
useEffect(() => {
scheduleAutoHide()
return () => {
if (autoHideTimerRef.current !== null) {
window.clearTimeout(autoHideTimerRef.current)
}
}
}, [scheduleAutoHide])
const activeOffset = getLayoutOffset(style)
const isVisualizerMode = visualStyle === 'muon' || visualStyle === 'fluid' || visualStyle === 'tendrils' || visualStyle === 'spirit'
const isStaticMode = visualStyle !== 'muon' && visualStyle !== 'fluid' && visualStyle !== 'tendrils' && visualStyle !== 'spirit' && visualStyle !== 'video'
const patchOffset = (axis: 'x' | 'y', value: number) => {
if (style.videoDisplayMode === 'line') {
patchStyle(axis === 'x' ? { layoutOffsetXLine: value } : { layoutOffsetYLine: value })
return
}
if (style.videoDisplayMode === 'word') {
patchStyle(axis === 'x' ? { layoutOffsetXWord: value } : { layoutOffsetYWord: value })
return
}
if (style.videoDisplayMode === 'syllable') {
patchStyle(axis === 'x' ? { layoutOffsetXSyllable: value } : { layoutOffsetYSyllable: value })
return
}
patchStyle(axis === 'x' ? { layoutOffsetXScroll: value } : { layoutOffsetYScroll: value })
}
// Preset detection
const activeMuonPreset = MUON_PRESETS.find((p) => muonPresetMatch(vizSettings.muon, p.values))
const activeFluidPreset = FLUID_PRESETS.find((p) => fluidPresetMatch(vizSettings.fluid, p.values))
const panelClass = isNarrow
? 'absolute inset-x-0 bottom-0 h-[62vh] rounded-t-2xl border-t border-white/15'
: 'absolute right-0 top-0 h-full border-l border-white/15'
const slider = (
label: string,
value: number,
displayValue: string,
min: number,
max: number,
step: number,
onChange: (v: number) => void,
) => (
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-slate-400">
<span>{label}</span>
<span>{displayValue}</span>
</div>
<input
type="range"
min={min}
max={max}
step={step}
value={value}
onChange={(e) => onChange(parseFloat(e.target.value))}
className="w-full h-1.5 accent-brand-500"
/>
</div>
)
return (
<div
className={`${panelClass} z-[9] bg-black/70 backdrop-blur-md text-slate-100 overflow-y-auto`}
style={isNarrow ? undefined : { width: 280 }}
onMouseMove={scheduleAutoHide}
onPointerMove={scheduleAutoHide}
>
<div className="sticky top-0 z-10 px-3 py-2 border-b border-white/10 bg-black/75 backdrop-blur-md flex items-center justify-between">
<span className="text-xs font-semibold uppercase tracking-[0.08em] text-slate-300">Controls</span>
<button
type="button"
onClick={onClose}
className="w-7 h-7 rounded bg-white/10 hover:bg-white/20 text-slate-200 text-sm"
title="Close"
>
✕
</button>
</div>
<div className="px-3 py-3 space-y-4">
{/* ── LYRICS TRACKS ── */}
{lyricsTrackKeys.length > 1 && (
<details className="rounded-md border border-white/10 bg-white/[0.02]" open>
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
LYRICS TRACKS
</summary>
<div className="px-2.5 pb-2.5 pt-1">
<div className={isNarrow ? 'flex flex-wrap gap-2' : 'grid grid-cols-2 gap-2'}>
{lyricsTrackKeys.map((key) => (
<button
key={key}
type="button"
onClick={() => onSelectLyricsTrack(key)}
className={`rounded-md px-2 py-2 text-xs border transition-colors ${isNarrow ? 'flex-1 min-w-[70px]' : ''} ${
selectedLyricsTrack === key
? 'border-violet-400 bg-violet-500/20 text-white'
: 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'
}`}
title={`Show ${key.charAt(0).toUpperCase() + key.slice(1)} lyrics`}
>
{key.charAt(0).toUpperCase() + key.slice(1)}
</button>
))}
</div>
</div>
</details>
)}
{/* ── LINE DISPLAY ── */}
<details className="rounded-md border border-white/10 bg-white/[0.02]" open>
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
DISPLAY
</summary>
<div className="px-2.5 pb-2.5 pt-1">
<div className={isNarrow ? 'flex flex-wrap gap-2' : 'grid grid-cols-2 gap-2'}>
{(['scroll', 'line', 'word', 'syllable'] as const).map((mode) => (
<button
key={mode}
type="button"
disabled={(mode === 'word' || mode === 'syllable') && !hasElrc}
onClick={() => patchStyle({ videoDisplayMode: mode })}
title={(mode === 'word' || mode === 'syllable') && !hasElrc ? 'No word-timing data available' : `Show ${mode} display`}
className={`rounded-md px-2 py-2 text-xs border transition-colors capitalize ${isNarrow ? 'flex-1 min-w-[70px]' : ''} ${
style.videoDisplayMode === mode
? 'border-violet-400 bg-violet-500/20 text-white'
: 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'
} disabled:opacity-40 disabled:cursor-not-allowed`}
>
{mode}
</button>
))}
</div>
</div>
</details>
{/* ── BACKGROUND ── */}
<details className="rounded-md border border-white/10 bg-white/[0.02]" open>
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
BACKGROUND
</summary>
<div className="px-2.5 pb-2.5 pt-1">
<div className={isNarrow ? 'flex flex-wrap gap-2' : 'grid grid-cols-2 gap-2'}>
{[
{ key: 'static', label: 'Static', value: 'karaoke' as LyricsVisualStyle, active: isStaticMode },
{ key: 'muon', label: 'Muon', value: 'muon' as LyricsVisualStyle, active: visualStyle === 'muon' },
{ key: 'fluid', label: 'Fluid', value: 'fluid' as LyricsVisualStyle, active: visualStyle === 'fluid' },
{ key: 'tendrils', label: 'Tendrils', value: 'tendrils' as LyricsVisualStyle, active: visualStyle === 'tendrils' },
{ key: 'spirit', label: 'Spirit', value: 'spirit' as LyricsVisualStyle, active: visualStyle === 'spirit' },
...(hasVideo ? [{ key: 'video', label: 'Video', value: 'video' as LyricsVisualStyle, active: visualStyle === 'video' }] : []),
].map((mode) => (
<button
key={mode.key}
type="button"
onClick={() => setVisualStyle(mode.value)}
className={`rounded-md px-2 py-2 text-xs border transition-colors ${isNarrow ? 'min-w-[70px] flex-1' : ''} ${mode.active ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{mode.label}
</button>
))}
</div>
</div>
</details>
{/* ── STEMS ── */}
<details className="rounded-md border border-white/10 bg-white/[0.02]" open>
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
STEMS
</summary>
<div className="px-2.5 pb-2.5 pt-1">
<div className="space-y-2">
{stems?.length ? stems.map((stem) => (
<div key={stem.name} className="space-y-1.5">
<div className="flex items-center gap-2">
<span className="text-xs font-medium text-slate-300 flex-1 truncate">{stem.label}</span>
<button
type="button"
onClick={() => toggleStemMute(stem.name)}
className={`w-6 h-6 text-[10px] rounded ${mutedStems[stem.name] ? 'bg-red-500 text-white' : 'bg-white/10 text-slate-300'}`}
>
M
</button>
<button
type="button"
onClick={() => toggleStemSolo(stem.name)}
className={`w-6 h-6 text-[10px] rounded ${soloedStems[stem.name] ? 'bg-yellow-300 text-black' : 'bg-white/10 text-slate-300'}`}
>
S
</button>
</div>
<div className="flex items-center gap-2">
<input
type="range"
min={0}
max={2}
step={0.05}
value={gains[stem.name] ?? 1}
onChange={(e) => setStemGain(stem.name, parseFloat(e.target.value))}
className="w-full h-1.5 accent-brand-500"
/>
<span className="text-[10px] tabular-nums text-slate-400 w-11 text-right">{Math.round((gains[stem.name] ?? 1) * 100)}%</span>
</div>
</div>
)) : (
<p className="text-[11px] text-slate-400">No stems — single track mode</p>
)}
</div>
</div>
</details>
{/* ── LYRICS ── */}
<details className="rounded-md border border-white/10 bg-white/[0.02]">
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
LYRICS STYLE
</summary>
<div className="space-y-2.5 px-2.5 pb-2.5 pt-1">
<div className="flex items-center gap-2">
<select
value={style.fontFamily}
onChange={(e) => patchStyle({ fontFamily: e.target.value })}
className="flex-1 text-xs bg-white/10 border border-white/15 rounded px-2 py-1"
>
{FONT_OPTIONS.map((font) => (
<option key={font.value} value={font.value} style={{ background: '#0f172a', color: '#e2e8f0', fontFamily: font.value }}>
{font.label}
</option>
))}
</select>
<button
type="button"
onClick={() => patchStyle({ fontBold: !style.fontBold })}
className={`px-2 py-1 rounded text-xs font-semibold ${style.fontBold ? 'bg-white/25 text-white' : 'bg-white/10 text-slate-300'}`}
>
B
</button>
</div>
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-slate-400"><span>Size</span><span>{style.fontSize}</span></div>
<input type="range" min={12} max={56} step={1} value={style.fontSize} onChange={(e) => patchStyle({ fontSize: parseInt(e.target.value, 10) })} className="w-full h-1.5 accent-brand-500" />
</div>
<div className="flex items-center gap-2">
{(['left', 'center', 'right'] as const).map((align) => (
<button key={align} type="button" onClick={() => patchStyle({ textAlign: align })}
className={`flex-1 rounded px-2 py-1 text-xs ${style.textAlign === align ? 'bg-white/20 text-white' : 'bg-white/10 text-slate-300'}`}
>
{align === 'left' ? 'L' : align === 'center' ? 'C' : 'R'}
</button>
))}
</div>
<div className="flex items-center gap-2">
{(['top', 'center', 'bottom'] as const).map((pos) => (
<button key={pos} type="button" onClick={() => patchStyle({ activeLineVerticalAlign: pos })}
className={`flex-1 rounded px-2 py-1 text-xs ${style.activeLineVerticalAlign === pos ? 'bg-white/20 text-white' : 'bg-white/10 text-slate-300'}`}
>
{pos === 'top' ? 'T' : pos === 'center' ? 'C' : 'B'}
</button>
))}
</div>
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-slate-400"><span>Line spacing</span><span>{style.lineSpacing.toFixed(2)}</span></div>
<input type="range" min={1} max={2.5} step={0.05} value={style.lineSpacing} onChange={(e) => patchStyle({ lineSpacing: parseFloat(e.target.value) })} className="w-full h-1.5 accent-brand-500" />
</div>
<div className="grid grid-cols-3 gap-2 text-[10px] text-slate-300">
<label className="space-y-1"><span className="block">Text</span><input type="color" value={style.textColor} onChange={(e) => patchStyle({ textColor: e.target.value })} className="w-full h-7 rounded border border-white/15 bg-transparent" /></label>
<label className="space-y-1"><span className="block">Highlight</span><input type="color" value={style.highlightColor} onChange={(e) => patchStyle({ highlightColor: e.target.value })} className="w-full h-7 rounded border border-white/15 bg-transparent" /></label>
<label className="space-y-1"><span className="block">BG</span><input type="color" value={style.bgColor} onChange={(e) => patchStyle({ bgColor: e.target.value })} className="w-full h-7 rounded border border-white/15 bg-transparent" /></label>
</div>
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-slate-400"><span>X offset</span><span>{activeOffset.x}</span></div>
<input type="range" min={-50} max={50} step={1} value={activeOffset.x} onChange={(e) => patchOffset('x', parseInt(e.target.value, 10))} className="w-full h-1.5 accent-brand-500" />
</div>
<div className="space-y-1">
<div className="flex items-center justify-between text-[10px] text-slate-400"><span>Y offset</span><span>{activeOffset.y}</span></div>
<input type="range" min={-50} max={50} step={1} value={activeOffset.y} onChange={(e) => patchOffset('y', parseInt(e.target.value, 10))} className="w-full h-1.5 accent-brand-500" />
</div>
</div>
</details>
{/* ── VISUALIZER ── */}
<details className="rounded-md border border-white/10 bg-white/[0.02]">
<summary className="cursor-pointer select-none px-2.5 py-2 text-xs font-semibold tracking-wide text-slate-200">
VISUALIZER
</summary>
<div className="space-y-2.5 px-2.5 pb-2.5 pt-1">
{/* Quality */}
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Quality</div>
<div className="grid grid-cols-3 gap-1.5">
{(['low', 'balanced', 'high'] as const).map((q) => (
<button key={q} type="button" onClick={() => patchVizSettings({ quality: q })}
className={`rounded px-2 py-1 text-[11px] border ${vizSettings.quality === q ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{q === 'balanced' ? 'Balanced' : q === 'low' ? 'Low' : 'High'}
</button>
))}
</div>
</div>
{/* FPS cap */}
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">FPS cap</div>
<div className="grid grid-cols-3 gap-1.5">
{([30, 60, 120] as const).map((fps) => (
<button key={fps} type="button" onClick={() => patchVizSettings({ fps_cap: fps })}
className={`rounded px-2 py-1 text-[11px] border ${vizSettings.fps_cap === fps ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{fps}
</button>
))}
</div>
</div>
{!isVisualizerMode && (
<p className="text-[11px] text-slate-400">
Switch background to Muon, Fluid, Tendrils, or Spirit to access mode-specific controls.
</p>
)}
{/* ── Muon controls ── */}
{visualStyle === 'muon' && (
<>
{/* Preset pills */}
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Preset</div>
<div className="flex flex-wrap gap-1.5">
{MUON_PRESETS.map((preset) => {
const isActive = activeMuonPreset?.label === preset.label
return (
<button
key={preset.label}
type="button"
onClick={() => patchVizSettings({ muon: preset.values })}
className={`rounded px-2 py-1 text-[11px] border transition-colors ${isActive ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{preset.label}
</button>
)
})}
{!activeMuonPreset && (
<span className="rounded px-2 py-1 text-[11px] border border-amber-400/60 bg-amber-500/10 text-amber-300">
Custom
</span>
)}
</div>
</div>
{/* Sliders */}
{slider('Radius', vizSettings.muon.radius_multiplier, formatMultiplier(vizSettings.muon.radius_multiplier), 0.25, 2, 0.05, (v) => patchVizSettings({ muon: { radius_multiplier: v } }))}
{slider('Aperture', vizSettings.muon.aperture, formatMultiplier(vizSettings.muon.aperture), 0.25, 2, 0.05, (v) => patchVizSettings({ muon: { aperture: v } }))}
{slider('Spacing', vizSettings.muon.spacing, formatMultiplier(vizSettings.muon.spacing), 0.25, 2, 0.05, (v) => patchVizSettings({ muon: { spacing: v } }))}
{slider('Particles', vizSettings.muon.particle_count, String(vizSettings.muon.particle_count), 40, 500, 10, (v) => patchVizSettings({ muon: { particle_count: Math.round(v) } }))}
{slider('Rotation', vizSettings.muon.rotation_speed, formatMultiplier(vizSettings.muon.rotation_speed), 0.2, 4, 0.1, (v) => patchVizSettings({ muon: { rotation_speed: v } }))}
{slider('Glow', vizSettings.muon.glow_intensity, formatMultiplier(vizSettings.muon.glow_intensity), 0, 3, 0.1, (v) => patchVizSettings({ muon: { glow_intensity: v } }))}
{slider('Size', vizSettings.muon.particle_size, formatMultiplier(vizSettings.muon.particle_size), 0.25, 3, 0.05, (v) => patchVizSettings({ muon: { particle_size: v } }))}
{slider('Reactivity', vizSettings.muon.drum_reactivity, formatMultiplier(vizSettings.muon.drum_reactivity), 0, 2, 0.1, (v) => patchVizSettings({ muon: { drum_reactivity: v } }))}
{slider('Hue range', vizSettings.muon.hue_range, formatMultiplier(vizSettings.muon.hue_range), 0, 3, 0.1, (v) => patchVizSettings({ muon: { hue_range: v } }))}
{slider('Beat sensitivity', vizSettings.muon.beat_sensitivity, formatMultiplier(vizSettings.muon.beat_sensitivity), 0.2, 3, 0.1, (v) => patchVizSettings({ muon: { beat_sensitivity: v } }))}
{slider('Orbit shape', vizSettings.muon.ellipse_ratio, vizSettings.muon.ellipse_ratio.toFixed(2), 0.3, 1, 0.02, (v) => patchVizSettings({ muon: { ellipse_ratio: v } }))}
{slider('Idle speed', vizSettings.muon.idle_speed, formatMultiplier(vizSettings.muon.idle_speed), 0, 2, 0.1, (v) => patchVizSettings({ muon: { idle_speed: v } }))}
{slider('Divisions', vizSettings.muon.divisions, String(vizSettings.muon.divisions), 8, 48, 1, (v) => patchVizSettings({ muon: { divisions: Math.round(v) } }))}
{slider('Lifespan', vizSettings.muon.lifespan, String(vizSettings.muon.lifespan), 45, 420, 5, (v) => patchVizSettings({ muon: { lifespan: Math.round(v) } }))}
{slider('Dynamic radius', vizSettings.muon.dynamic_radius, formatMultiplier(vizSettings.muon.dynamic_radius), 0.2, 3, 0.05, (v) => patchVizSettings({ muon: { dynamic_radius: v } }))}
{slider('Delta gate', vizSettings.muon.delta_response_limit, vizSettings.muon.delta_response_limit.toFixed(3), 0.001, 0.05, 0.001, (v) => patchVizSettings({ muon: { delta_response_limit: v } }))}
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Pattern preset</div>
<div className="flex flex-wrap gap-1.5">
{(['default', 'orbital', 'flower', 'spiro', 'hybrid'] as const).map((preset) => {
const active = vizSettings.muon.visualization_preset === preset
return (
<button
key={preset}
type="button"
onClick={() => patchVizSettings({ muon: { visualization_preset: preset } })}
className={`rounded px-2 py-1 text-[11px] border transition-colors ${active ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{preset}
</button>
)
})}
</div>
</div>
{/* Mono color toggle */}
<label className="flex items-center gap-2 cursor-pointer">
<div
role="checkbox"
aria-checked={vizSettings.muon.mono_color}
tabIndex={0}
onClick={() => patchVizSettings({ muon: { mono_color: !vizSettings.muon.mono_color } })}
onKeyDown={(e) => { if (e.key === ' ' || e.key === 'Enter') patchVizSettings({ muon: { mono_color: !vizSettings.muon.mono_color } }) }}
className={`w-8 h-4 rounded-full transition-colors ${vizSettings.muon.mono_color ? 'bg-violet-500' : 'bg-white/20'} relative`}
>
<div className={`absolute top-0.5 w-3 h-3 rounded-full bg-white transition-transform ${vizSettings.muon.mono_color ? 'translate-x-4' : 'translate-x-0.5'}`} />
</div>
<span className="text-[11px] text-slate-300">Mono color</span>
</label>
{/* Mirror toggle */}
<label className="flex items-center gap-2 cursor-pointer">
<div
role="checkbox"
aria-checked={vizSettings.muon.particle_mirror}
tabIndex={0}
onClick={() => patchVizSettings({ muon: { particle_mirror: !vizSettings.muon.particle_mirror } })}
onKeyDown={(e) => { if (e.key === ' ' || e.key === 'Enter') patchVizSettings({ muon: { particle_mirror: !vizSettings.muon.particle_mirror } }) }}
className={`w-8 h-4 rounded-full transition-colors ${vizSettings.muon.particle_mirror ? 'bg-violet-500' : 'bg-white/20'} relative`}
>
<div className={`absolute top-0.5 w-3 h-3 rounded-full bg-white transition-transform ${vizSettings.muon.particle_mirror ? 'translate-x-4' : 'translate-x-0.5'}`} />
</div>
<span className="text-[11px] text-slate-300">Mirror particles</span>
</label>
</>
)}
{/* ── Fluid controls ── */}
{visualStyle === 'fluid' && (
<>
{/* Preset pills */}
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Preset</div>
<div className="flex flex-wrap gap-1.5">
{FLUID_PRESETS.map((preset) => {
const isActive = activeFluidPreset?.label === preset.label
return (
<button
key={preset.label}
type="button"
onClick={() => patchVizSettings({ fluid: preset.values })}
className={`rounded px-2 py-1 text-[11px] border transition-colors ${isActive ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{preset.label}
</button>
)
})}
{!activeFluidPreset && (
<span className="rounded px-2 py-1 text-[11px] border border-amber-400/60 bg-amber-500/10 text-amber-300">
Custom
</span>
)}
</div>
</div>
{/* Sliders */}
{slider('Density', vizSettings.fluid.spawn_density, formatMultiplier(vizSettings.fluid.spawn_density), 0.25, 3, 0.05, (v) => patchVizSettings({ fluid: { spawn_density: v } }))}
{slider('Force', vizSettings.fluid.splat_force, formatMultiplier(vizSettings.fluid.splat_force), 0.25, 3, 0.05, (v) => patchVizSettings({ fluid: { splat_force: v } }))}
{slider('Trail decay', vizSettings.fluid.decay, formatMultiplier(vizSettings.fluid.decay), 0.25, 3, 0.05, (v) => patchVizSettings({ fluid: { decay: v } }))}
{slider('Trail length', vizSettings.fluid.background_persistence, formatMultiplier(vizSettings.fluid.background_persistence), 0.2, 3, 0.1, (v) => patchVizSettings({ fluid: { background_persistence: v } }))}
{slider('Beat bursts', vizSettings.fluid.beat_burst_count, formatMultiplier(vizSettings.fluid.beat_burst_count), 0.25, 3, 0.05, (v) => patchVizSettings({ fluid: { beat_burst_count: v } }))}
{slider('Treble pulse', vizSettings.fluid.treble_pulse, formatMultiplier(vizSettings.fluid.treble_pulse), 0, 3, 0.1, (v) => patchVizSettings({ fluid: { treble_pulse: v } }))}
{slider('Drag', vizSettings.fluid.drag, formatMultiplier(vizSettings.fluid.drag), 0.5, 2, 0.05, (v) => patchVizSettings({ fluid: { drag: v } }))}
{slider('Blob life', vizSettings.fluid.blob_life, formatMultiplier(vizSettings.fluid.blob_life), 0.25, 3, 0.05, (v) => patchVizSettings({ fluid: { blob_life: v } }))}
{slider('Color speed', vizSettings.fluid.color_speed, formatMultiplier(vizSettings.fluid.color_speed), 0, 3, 0.1, (v) => patchVizSettings({ fluid: { color_speed: v } }))}
</>
)}
{/* ── Tendrils controls ── */}
{visualStyle === 'tendrils' && (
<>
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Pattern preset</div>
<div className="flex flex-wrap gap-1.5">
{(['flow', 'scatter', 'pulse', 'ethereal', 'hybrid'] as const).map((preset) => {
const active = vizSettings.tendrils.visualization_preset === preset
return (
<button
key={preset}
type="button"
onClick={() => patchVizSettings({ tendrils: { visualization_preset: preset } })}
className={`rounded px-2 py-1 text-[11px] border transition-colors ${active ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{preset}
</button>
)
})}
</div>
</div>
{slider('Noise', vizSettings.tendrils.noise_weight, formatMultiplier(vizSettings.tendrils.noise_weight), 0, 3, 0.05, (v) => patchVizSettings({ tendrils: { noise_weight: v } }))}
{slider('Flow', vizSettings.tendrils.flow_weight, formatMultiplier(vizSettings.tendrils.flow_weight), 0, 3, 0.05, (v) => patchVizSettings({ tendrils: { flow_weight: v } }))}
{slider('Speed', vizSettings.tendrils.speed_limit, formatMultiplier(vizSettings.tendrils.speed_limit), 0, 3, 0.05, (v) => patchVizSettings({ tendrils: { speed_limit: v } }))}
{slider('Damping', vizSettings.tendrils.damping, formatMultiplier(vizSettings.tendrils.damping), 0, 3, 0.05, (v) => patchVizSettings({ tendrils: { damping: v } }))}
{slider('Hue range', vizSettings.tendrils.hue_range, formatMultiplier(vizSettings.tendrils.hue_range), 0, 3, 0.05, (v) => patchVizSettings({ tendrils: { hue_range: v } }))}
<label className="flex items-center gap-2 cursor-pointer">
<div
role="checkbox"
aria-checked={vizSettings.tendrils.mono_color}
tabIndex={0}
onClick={() => patchVizSettings({ tendrils: { mono_color: !vizSettings.tendrils.mono_color } })}
onKeyDown={(e) => { if (e.key === ' ' || e.key === 'Enter') patchVizSettings({ tendrils: { mono_color: !vizSettings.tendrils.mono_color } }) }}
className={`w-8 h-4 rounded-full transition-colors ${vizSettings.tendrils.mono_color ? 'bg-violet-500' : 'bg-white/20'} relative`}
>
<div className={`absolute top-0.5 w-3 h-3 rounded-full bg-white transition-transform ${vizSettings.tendrils.mono_color ? 'translate-x-4' : 'translate-x-0.5'}`} />
</div>
<span className="text-[11px] text-slate-300">Mono color</span>
</label>
</>
)}
{/* ── Spirit controls ── */}
{visualStyle === 'spirit' && (
<>
<div className="space-y-1.5">
<div className="text-[10px] text-slate-400">Pattern preset</div>
<div className="flex flex-wrap gap-1.5">
{(['spirit', 'storm', 'drift', 'pulse', 'aurora'] as const).map((preset) => {
const active = vizSettings.spirit.visualization_preset === preset
return (
<button
key={preset}
type="button"
onClick={() => patchVizSettings({ spirit: { visualization_preset: preset } })}
className={`rounded px-2 py-1 text-[11px] border transition-colors ${active ? 'border-violet-400 bg-violet-500/20 text-white' : 'border-white/15 bg-white/5 text-slate-300 hover:bg-white/10'}`}
>
{preset}
</button>
)
})}
</div>
</div>
{slider('Speed', vizSettings.spirit.speed, formatMultiplier(vizSettings.spirit.speed), 0.1, 6, 0.05, (v) => patchVizSettings({ spirit: { speed: v } }))}
{slider('Die speed', vizSettings.spirit.die_speed, vizSettings.spirit.die_speed.toFixed(3), 0.001, 0.12, 0.001, (v) => patchVizSettings({ spirit: { die_speed: v } }))}
{slider('Curl', vizSettings.spirit.curl_size, formatMultiplier(vizSettings.spirit.curl_size), 0.05, 3, 0.05, (v) => patchVizSettings({ spirit: { curl_size: v } }))}
{slider('Attraction', vizSettings.spirit.attraction, vizSettings.spirit.attraction.toFixed(2), -2, 2, 0.05, (v) => patchVizSettings({ spirit: { attraction: v } }))}
{slider('Bloom', vizSettings.spirit.bloom_intensity, formatMultiplier(vizSettings.spirit.bloom_intensity), 0, 4, 0.05, (v) => patchVizSettings({ spirit: { bloom_intensity: v } }))}
{slider('Afterimage', vizSettings.spirit.afterimage_damp, vizSettings.spirit.afterimage_damp.toFixed(2), 0.6, 0.96, 0.01, (v) => patchVizSettings({ spirit: { afterimage_damp: v } }))}
</>
)}
<button
type="button"
onClick={() => patchVizSettings(manifestVizSettings ?? VIZ_DEFAULTS)}
className="w-full rounded-md px-2 py-1.5 text-xs bg-white/10 hover:bg-white/20 text-slate-200"
>
{manifestVizSettings ? 'Reset to song defaults' : 'Reset to defaults'}
</button>
</div>
</details>
</div>
</div>
)
}