// GateSection.tsx import VerticalSlider from '../../../../components/VerticalSlider/VerticalSlider'; import { InputChannel } from '../../types'; import { DSP408 as DSP } from '../../../../types'; import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup'; import { GateGraph } from './GateGraph'; import MeterBar from '../../../../components/MeterBar/MeterBar'; import { useState } from 'react'; import './GateSection.css'; const GATE_PARAMS = [ { key: 'threshold', label: 'Threshold', min: -90, max: 0, step: 0.5, unit: ' dB' }, { key: 'attack', label: 'Attack', min: 1, max: 999, step: 1, unit: ' ms' }, { key: 'hold', label: 'Hold', min: 10, max: 999, step: 1, unit: ' ms' }, { key: 'release', label: 'Release', min: 10, max: 3000, step: 1, unit: ' ms' }, ] as const; type GateParamKey = (typeof GATE_PARAMS)[number]['key']; type GateValues = { threshold: number; attack: number; hold: number; release: number; }; type SetGateFn = ( inputChannel: InputChannel, threshold: number, attack: number, hold: number, release: number ) => Promise; function GatePanel({ channel, dsp, setGate, onLiveValue, }: { channel: InputChannel; dsp: DSP; setGate: SetGateFn; onLiveValue: (channel: InputChannel, key: GateParamKey, value: number) => void; }) { const inputState = dsp.state.current_config.input_states[channel]; const gate = inputState.gate; return (
{inputState.name}
{GATE_PARAMS.map((param) => (
param.step} unit={param.unit} value={gate[param.key]} onInput={(value) => onLiveValue(channel, param.key, value)} onChange={(value) => { return setGate( channel, param.key === 'threshold' ? value : gate.threshold, param.key === 'attack' ? value : gate.attack, param.key === 'hold' ? value : gate.hold, param.key === 'release' ? value : gate.release ); }} style={{ width: '100%', flex: '1 1 auto' }} />
{param.label}
))}
); } function GateSection({ dsp, set_gate }: { dsp: DSP; set_gate: SetGateFn }) { const inputs = [InputChannel.InA, InputChannel.InB, InputChannel.InC, InputChannel.InD]; const [activeChannel, setActiveChannel] = useState(inputs[0]); const [liveGate, setLiveGate] = useState>>({}); const handleLiveValue = (channel: InputChannel, key: GateParamKey, value: number) => { setActiveChannel(channel); setLiveGate((prev) => { const base = prev[channel] ?? dsp.state.current_config.input_states[channel].gate; return { ...prev, [channel]: { ...base, [key]: value } }; }); }; const handleSetGate: SetGateFn = async (channel, threshold, attack, hold, release) => { setActiveChannel(channel); const success = await set_gate(channel, threshold, attack, hold, release); if (success) { setLiveGate((prev) => { if (!(channel in prev)) return prev; const next = { ...prev }; delete next[channel]; return next; }); } return success; }; const activeInputState = dsp.state.current_config.input_states[activeChannel]; const activeGate = liveGate[activeChannel] ?? activeInputState.gate; return ( <>
Gate Response
{inputs.map((input) => { const inputState = dsp.state.current_config.input_states[input]; return ( ); })}
{inputs.map((input) => ( ))}
); } export default GateSection;