import { useState } from 'react'; import { DSP } from '../../types/types'; import Sidebar from '../../components/Sidebar/Sidebar'; import { InfoIcon, KnobGainIcon } from '../../assets/icons/AudioIcons'; import ConnectionPanel from '../../components/dsp408/ConnectionSection/ConnectionSection'; import GainSection from '../../components/dsp408/GainSection/GainSection'; import { NotificationType } from '../../types/types'; import './DspPage.css'; import GateSection from '../../components/dsp408/GateSection/GateSection'; import { invoke } from '@tauri-apps/api/core'; import LoadingOverlay from '../../components/LoadingOverlay/LoadingOverlay'; function DSPPage({ dsp, onConnect, onDisconnect, notify, }: { dsp: DSP; onConnect: () => void; onDisconnect: () => void; notify: (message: string, type?: NotificationType, dspName?: string) => void; }) { const [activeSidebar, setActiveSidebar] = useState('overview'); const [sidebarExpanded, setSidebarExpanded] = useState(false); const [selectedPreset, setSelectedPreset] = useState(dsp.state?.presets.current_index ?? 0); const [presetLoading, setPresetLoading] = useState(false); const sidebarItems = [ { id: 'overview', label: 'Overview', icon: , }, { id: 'gain', label: 'Gain', icon: , }, { id: 'gate', label: 'Gate', icon: , }, { id: 'compressor', label: 'Compressor', icon: , }, { id: 'limiter', label: 'Limiter', icon: , }, { id: 'delay', label: 'Delay', icon: , }, { id: 'matrix', label: 'Matrix', icon: , }, { id: 'geq', label: 'Graphic Equalizer', icon: , }, { id: 'ina', label: 'In A', icon: , }, { id: 'inb', label: 'In B', icon: , }, { id: 'inc', label: 'In C', icon: , }, { id: 'ind', label: 'In D (TESTTEST)', icon: , }, { id: 'out1', label: 'Out 1', icon: , }, { id: 'out2', label: 'Out 2', icon: , }, { id: 'out3', label: 'Out 3', icon: , }, { id: 'out4', label: 'Out 4', icon: , }, { id: 'out5', label: 'Out 5', icon: , }, { id: 'out6', label: 'Out 6', icon: , }, { id: 'out7', label: 'Out 7', icon: , }, { id: 'out8', label: 'Out 8', icon: , }, { id: 'miscellaneous', label: 'Miscellaneous', icon: , }, ]; const presets = dsp.state?.presets.names ? [ { id: 'f00', name: 'Factory Preset', }, ...dsp.state.presets.names.map((name, index) => ({ id: `u${String(index + 1).padStart(2, '0')}`, name, })), ] : [ { id: 'f00', name: 'Factory Preset', }, ...Array.from({ length: 20 }, (_, index) => ({ id: `u${String(index + 1).padStart(2, '0')}`, name: 'Default Preset', })), ]; const recallPreset = async (presetIndex: number) => { try { const success = await invoke('recall_preset', { id: dsp.id, presetIndex, }); if (success) { notify(`Preset ${presetIndex} recalled`, 'success', dsp.name); } else { notify('Failed to recall preset', 'error', dsp.name); } return success; } catch (err) { notify(`Preset recall failed: ${String(err)}`, 'error', dsp.name); return false; } }; const setCurrentPresetName = async (name: string) => { try { const success = await invoke('set_current_preset_name', { id: dsp.id, name, }); if (success) { notify(`Preset renamed`, 'success', dsp.name); } else { notify('Failed to rename preset', 'error', dsp.name); } return success; } catch (err) { notify(`Preset rename failed: ${String(err)}`, 'error', dsp.name); return false; } }; const onAppChange = async (id: string) => { const presetIndex = presets.findIndex((preset) => preset.id === id); if (presetIndex === -1) return; setPresetLoading(true); const success = await recallPreset(presetIndex); if (success) { setSelectedPreset(presetIndex); } setPresetLoading(false); }; const renderTab = () => { switch (activeSidebar) { case 'overview': return ; case 'gain': return ; case 'gate': return ; default: return null; } }; return (
setSidebarExpanded((v) => !v)} />
{renderTab()}
); } export default DSPPage;