Files
dsp-thomann-interface/src/features/dsp408/components/GeqSection/GeqGraph.tsx
T
Lucas 4b5606dd15
CI / Frontend (push) Successful in 1m19s
CI / Rust (Tauri backend) (push) Failing after 1m13s
chore; add lint
2026-11-04 11:36:41 +01:00

75 lines
2.0 KiB
TypeScript

import { memo, useCallback, useMemo } from 'react';
import { logSpace } from '../../utils/graph/curve';
import { drawCurves } from '../../utils/graph/draw';
import { GRAPH_X_MIN, GRAPH_X_MAX, GRAPH_Y_MIN, GRAPH_Y_MAX, GEQ_CURVE_Q } from '../../constants';
import { DiscreteFrequency } from '../../types';
import { GEQ_BANDS_LABEL } from '../../constants';
import { getGeqCurvePoints } from '../../utils/graph/geq';
import { LiveBands } from './GeqSection';
import LinearGraph, {
type LinearGraphHelpers,
} from '../../../../components/LinearGraph/LinearGraph';
const GEQ_FREQS = logSpace(GRAPH_X_MIN, GRAPH_X_MAX, 1000);
export const GeqGraph = memo(function GeqGraph({
title,
gains,
bypass,
liveBands,
}: {
title: string;
gains: Record<DiscreteFrequency, number>;
bypass: boolean;
liveBands: LiveBands | undefined;
}) {
const curvePoints = useMemo(() => {
const values = GEQ_BANDS_LABEL.map(
({ frequency }) => liveBands?.[frequency] ?? gains[frequency] ?? 0
);
return getGeqCurvePoints({ freqs: GEQ_FREQS, values, q: GEQ_CURVE_Q });
}, [gains, liveBands]);
const draw = useCallback(
({ ctx, toPx }: LinearGraphHelpers) => {
drawCurves({
ctx,
toPx,
xMin: GRAPH_X_MIN,
xMax: GRAPH_X_MAX,
yMin: GRAPH_Y_MIN,
yMax: GRAPH_Y_MAX,
curves: [
{
points: curvePoints,
style: { strokeColor: '#e5e7eb', dimmed: bypass },
},
],
});
},
[curvePoints, bypass]
);
return (
<div className="geq-graph-panel">
<div className="geq-graph-title">{title}</div>
<LinearGraph
xMin={GRAPH_X_MIN}
xMax={GRAPH_X_MAX}
xScale="log"
yMin={GRAPH_Y_MIN}
yMax={GRAPH_Y_MAX}
yStep={3}
xLabel="Band Hz"
yLabel="dB"
showGrid={true}
draw={draw}
/>
{bypass && (
<div className="geq-bypass-overlay">
<span>BYPASSED</span>
</div>
)}
</div>
);
});