// LimiterSection.tsx import VerticalSlider from '../../../../components/VerticalSlider/VerticalSlider'; import { OutputChannel } from '../../types'; import { DSP408 as DSP } from '../../../../types'; import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup'; import { LimiterGraph } from './LimiterGraph'; import MeterBar from '../../../../components/MeterBar/MeterBar'; import { useState } from 'react'; import './LimiterSection.css'; const LIMITER_SLIDER_PARAMS = [ { key: 'threshold', label: 'Threshold', short: 'Thr', min: -90, max: 20, step: 0.5, unit: ' dB' }, { key: 'attack', label: 'Attack', short: 'Atk', min: 1, max: 999, step: 1, unit: ' ms' }, { key: 'release', label: 'Release', short: 'Rel', min: 10, max: 3000, step: 1, unit: ' ms' }, ] as const; type LimiterParamKey = 'threshold' | 'attack' | 'release'; type LimiterValues = { threshold: number; attack: number; release: number; }; type SetLimiterFn = ( outputChannel: OutputChannel, threshold: number, attack: number, release: number ) => Promise; // Phone only: one view at a time (CSS hides the tabs on desktop) type LimiterView = 'controls' | 'response'; const LIMITER_VIEWS: { id: LimiterView; label: string }[] = [ { id: 'controls', label: 'Controls' }, { id: 'response', label: 'Limiter response' }, ]; function LimiterPanel({ channel, dsp, setLimiter, onLiveValue, }: { channel: OutputChannel; dsp: DSP; setLimiter: SetLimiterFn; onLiveValue: (channel: OutputChannel, key: LimiterParamKey, value: number) => void; }) { const outputState = dsp.state.current_config.output_states[channel]; // ASSUMPTION: limiter settings live at output_states[channel].limiter const lim = outputState.limiter as LimiterValues; const commit = (overrides: Partial) => { const next = { ...lim, ...overrides }; return setLimiter(channel, next.threshold, next.attack, next.release); }; return (
{outputState.name}
{LIMITER_SLIDER_PARAMS.map((param) => (
param.step} unit={param.unit} value={lim[param.key]} onInput={(value) => onLiveValue(channel, param.key, value)} onChange={(value) => commit({ [param.key]: value } as Partial)} style={{ width: '100%', flex: '1 1 auto' }} />
{param.label} {param.short}
))}
); } function LimiterSection({ dsp, set_limiter }: { dsp: DSP; set_limiter: SetLimiterFn }) { const outputs = [ OutputChannel.Out1, OutputChannel.Out2, OutputChannel.Out3, OutputChannel.Out4, OutputChannel.Out5, OutputChannel.Out6, OutputChannel.Out7, OutputChannel.Out8, ]; const [activeChannel, setActiveChannel] = useState(outputs[0]); const [liveLim, setLiveLim] = useState>>({}); const [view, setView] = useState('controls'); const handleLiveValue = (channel: OutputChannel, key: LimiterParamKey, value: number) => { setActiveChannel(channel); setLiveLim((prev) => { const base = prev[channel] ?? (dsp.state.current_config.output_states[channel].limiter as LimiterValues); return { ...prev, [channel]: { ...base, [key]: value } }; }); }; const handleSetLimiter: SetLimiterFn = async (channel, threshold, attack, release) => { setActiveChannel(channel); const success = await set_limiter(channel, threshold, attack, release); if (success) { setLiveLim((prev) => { if (!(channel in prev)) return prev; const next = { ...prev }; delete next[channel]; return next; }); } return success; }; const activeOutputState = dsp.state.current_config.output_states[activeChannel]; const activeLim = liveLim[activeChannel] ?? (activeOutputState.limiter as LimiterValues); return (
{/* Phone only (hidden on desktop by CSS): one view at a time */}
{LIMITER_VIEWS.map((v) => ( ))}
{/* Portrait phone only (CSS): the graph needs the width of landscape */}
Rotate your phone to landscape to see the limiter graph.
{activeOutputState.name} - Limiter
{outputs.map((output) => { const outputState = dsp.state.current_config.output_states[output]; return ( ); })}
{outputs.map((output) => ( ))}
); } export default LimiterSection;