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; 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 (
{title}
{bypass && (
BYPASSED
)}
); });