fix: matrix gain
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
} from '../../constants';
|
||||
import { SidebarId } from '../../constants';
|
||||
import SignalFlowMatrix from '../../../../components/SignalFlowMatrix/SignalFlowMatrix';
|
||||
import { useState } from 'react';
|
||||
import './Matrixsection.css';
|
||||
|
||||
const GAIN_VALUES: number[] = (() => {
|
||||
@@ -39,6 +40,12 @@ function getRoutedInputs(dsp: DSP, output: OutputChannel): InputChannel[] {
|
||||
return getMatrixRoutes(dsp, output).connected;
|
||||
}
|
||||
|
||||
function snapToGain(g: number): number {
|
||||
return GAIN_VALUES.reduce((best, v) =>
|
||||
Math.abs(v - g) < Math.abs(best - g) ? v : best
|
||||
);
|
||||
}
|
||||
|
||||
function MatrixSection({
|
||||
dsp,
|
||||
setMatrixRouting,
|
||||
@@ -68,6 +75,21 @@ function MatrixSection({
|
||||
void setMatrixGain(input, output, gain);
|
||||
};
|
||||
|
||||
const [liveGains, setLiveGains] = useState<Record<string, number>>({});
|
||||
|
||||
// value = number while wheeling, null once the commit is done
|
||||
const previewGain = (input: InputChannel, output: OutputChannel, value: number | null) => {
|
||||
const key = `${input}-${output}`;
|
||||
setLiveGains((prev) => {
|
||||
if (value === null) {
|
||||
if (!(key in prev)) return prev;
|
||||
const { [key]: _removed, ...rest } = prev;
|
||||
return rest;
|
||||
}
|
||||
return { ...prev, [key]: value };
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="matrix-flow">
|
||||
@@ -76,6 +98,7 @@ function MatrixSection({
|
||||
setMatrixRouting={setMatrixRouting}
|
||||
setMatrixGain={setMatrixGain}
|
||||
setActiveSidebar={setActiveSidebar}
|
||||
onGainPreview={previewGain}
|
||||
/>
|
||||
</div>
|
||||
<div className="matrix-section">
|
||||
@@ -90,7 +113,7 @@ function MatrixSection({
|
||||
<div className="matrix-panel__rows">
|
||||
{INPUT_ORDER.map((input) => {
|
||||
const connected = isRouted(dsp, output, input);
|
||||
const gain = getLinkGain(dsp, output, input);
|
||||
const gain = liveGains[`${input}-${output}`] ?? getLinkGain(dsp, output, input);
|
||||
|
||||
return (
|
||||
<div className="matrix-panel__row" key={String(input)}>
|
||||
@@ -111,7 +134,7 @@ function MatrixSection({
|
||||
|
||||
<ChoiceStepper
|
||||
className="matrix-gain-stepper"
|
||||
value={gain}
|
||||
value={snapToGain(gain)}
|
||||
values={GAIN_VALUES}
|
||||
formatLabel={(v: number) => `${v > 0 ? '+' : ''}${v.toFixed(1)} dB`}
|
||||
onChange={(g) => handleGainChange(output, input, g)}
|
||||
|
||||
Reference in New Issue
Block a user