import { useMemo, useState } from 'react'; import { useEditorStore } from '../store/editorStore'; import { Trash2, Volume2 } from 'lucide-react'; export default function VolumePanel() { const { words, selectedWordIndices, globalGainDb, gainRanges, setGlobalGainDb, addGainRange, updateGainRange, removeGainRange, } = useEditorStore(); const [selectionGainDb, setSelectionGainDb] = useState(3); const canApplySelection = selectedWordIndices.length > 0; const selectedRange = useMemo(() => { if (!canApplySelection) return null; const sorted = [...selectedWordIndices].sort((a, b) => a - b); const startWord = words[sorted[0]]; const endWord = words[sorted[sorted.length - 1]]; if (!startWord || !endWord) return null; return { start: startWord.start, end: endWord.end, }; }, [canApplySelection, selectedWordIndices, words]); const applySelectionGain = () => { if (!selectedRange) return; addGainRange(selectedRange.start, selectedRange.end, selectionGainDb); }; return (

Volume / Gain

Apply global gain or per-selection gain ranges.

setGlobalGainDb(Number(e.target.value))} className="w-full" />
-24 dB {globalGainDb.toFixed(1)} dB +24 dB
setSelectionGainDb(Number(e.target.value) || 0)} className="w-24 px-2 py-1.5 text-xs bg-editor-surface border border-editor-border rounded focus:border-editor-accent focus:outline-none" />

{canApplySelection ? `${selectedWordIndices.length} selected words${selectedRange ? ` (${selectedRange.start.toFixed(2)}s - ${selectedRange.end.toFixed(2)}s)` : ''}` : 'Select transcript words to apply a gain range.'}

{gainRanges.length > 0 && (
Gain Ranges
{gainRanges.map((range) => (
{range.start.toFixed(2)}s - {range.end.toFixed(2)}s
{range.id}
updateGainRange(range.id, Number(e.target.value) || 0)} className="w-20 px-2 py-1 text-xs bg-editor-bg border border-editor-border rounded" title="Gain dB" />
))}
)}
); }