fix: dont render graphs on every poll
This commit is contained in:
@@ -17,8 +17,7 @@ import {
|
||||
import { Channel, PEQBand, PEQFilter, PEQ, Crossover } from '../../types';
|
||||
import { DSP408 as DSP } from '../../../../types';
|
||||
import { CrossoverFilter } from '../../types';
|
||||
import { LinearGraph, LinearGraphHandle } from '../../../../components/LinearGraph/LinearGraph';
|
||||
import { useRef, useState, useEffect } from 'react';
|
||||
import { useRef, useState, useEffect, useMemo } from 'react';
|
||||
import './ChannelSection.css';
|
||||
import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup';
|
||||
import Button from '../../../../components/Button/Button';
|
||||
@@ -26,15 +25,8 @@ import {
|
||||
FREQUENCY_MAX,
|
||||
FREQUENCY_MIN,
|
||||
FREQUENCY_QUANTIZATION,
|
||||
GRAPH_X_MAX,
|
||||
GRAPH_X_MIN,
|
||||
GRAPH_Y_MAX,
|
||||
GRAPH_Y_MIN,
|
||||
} from '../../constants';
|
||||
import { drawCurves } from '../../utils/graph/draw';
|
||||
import { getPeqCurvePoints, getPeqPhasePoints } from '../../utils/graph/peq';
|
||||
import { logSpace, sumCurvePoints, sumPhaseCurvePoints } from '../../utils/graph/curve';
|
||||
import { getCrossoverCurvePoints, getCrossoverPhasePoints } from '../../utils/graph/crossover';
|
||||
import { MagnitudeGraph, PhaseGraph } from './ChannelGraph';
|
||||
|
||||
function nearestQValue(q: number, values: readonly number[] = PEAK_Q_VALUES): number {
|
||||
return values.reduce((nearest, current) =>
|
||||
@@ -482,8 +474,6 @@ function ChannelSection({
|
||||
const [liveLpFreq, setLiveLpFreq] = useState<number>(FREQUENCY_MAX);
|
||||
const [livePeq, setLivePeq] = useState<Partial<Record<PEQBand, PEQ>>>({});
|
||||
|
||||
const magnitudeGraphRef = useRef<LinearGraphHandle>(null);
|
||||
|
||||
// DSP values
|
||||
const isInput = 'Input' in channel;
|
||||
|
||||
@@ -589,17 +579,20 @@ function ChannelSection({
|
||||
return success;
|
||||
};
|
||||
|
||||
// Diplay value (merge live and real)
|
||||
const displayPeq: Record<PEQBand, PEQ> = {
|
||||
...ActivePeq.bands,
|
||||
...livePeq,
|
||||
const displayPeq = useMemo(
|
||||
() => ({ ...ActivePeq.bands, ...livePeq }) as Record<PEQBand, PEQ>,
|
||||
[ActivePeq.bands, livePeq]
|
||||
);
|
||||
|
||||
const graphProps = {
|
||||
bands: displayPeq,
|
||||
bypass: ActivePeq.bypass,
|
||||
hpFreq: liveHpFreq,
|
||||
hpSlope: ActiveHighPassFilter.slope,
|
||||
lpFreq: liveLpFreq,
|
||||
lpSlope: ActiveLowPassFilter.slope,
|
||||
};
|
||||
|
||||
const highPassSpec = { frequency: liveHpFreq, filter_type: ActiveHighPassFilter.slope };
|
||||
const lowPassSpec = { frequency: liveLpFreq, filter_type: ActiveLowPassFilter.slope };
|
||||
|
||||
const freqs = logSpace(GRAPH_X_MIN, GRAPH_X_MAX, 1000);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="channel-graph-section">
|
||||
@@ -611,84 +604,11 @@ function ChannelSection({
|
||||
|
||||
{(graphView === 'both' || graphView === 'magnitude') && (
|
||||
<div className="channel-graph-panel__magnitude-wrap">
|
||||
<LinearGraph
|
||||
ref={magnitudeGraphRef}
|
||||
xMin={GRAPH_X_MIN}
|
||||
xMax={GRAPH_X_MAX}
|
||||
xScale="log"
|
||||
yMin={GRAPH_Y_MIN}
|
||||
yMax={GRAPH_Y_MAX}
|
||||
yStep={3}
|
||||
xLabel="Frequency - Hz"
|
||||
yLabel="Magnituded - dB"
|
||||
showGrid={true}
|
||||
formatX={(v) => Math.round(v).toString()}
|
||||
formatY={(v) => Math.round(v).toString()}
|
||||
draw={({ ctx, toPx }) => {
|
||||
drawCurves({
|
||||
ctx,
|
||||
toPx,
|
||||
xMin: GRAPH_X_MIN,
|
||||
xMax: GRAPH_X_MAX,
|
||||
yMin: GRAPH_Y_MIN,
|
||||
yMax: GRAPH_Y_MAX,
|
||||
curves: [
|
||||
{
|
||||
points: sumCurvePoints([
|
||||
getPeqCurvePoints({ freqs, bands: displayPeq }),
|
||||
getCrossoverCurvePoints({
|
||||
freqs,
|
||||
highPass: highPassSpec,
|
||||
lowPass: lowPassSpec,
|
||||
}),
|
||||
]),
|
||||
style: { strokeColor: '#e5e7eb', dimmed: ActivePeq.bypass },
|
||||
},
|
||||
],
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<MagnitudeGraph {...graphProps} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(graphView === 'both' || graphView === 'phase') && (
|
||||
<LinearGraph
|
||||
xMin={GRAPH_X_MIN}
|
||||
xMax={GRAPH_X_MAX}
|
||||
xScale="log"
|
||||
yMin={-180}
|
||||
yMax={180}
|
||||
yStep={45}
|
||||
xLabel="Frequency - Hz"
|
||||
yLabel="Phase - Deg"
|
||||
showGrid={true}
|
||||
formatX={(v) => Math.round(v).toString()}
|
||||
formatY={(v) => Math.round(v).toString()}
|
||||
draw={({ ctx, toPx }) => {
|
||||
drawCurves({
|
||||
ctx,
|
||||
toPx,
|
||||
xMin: GRAPH_X_MIN,
|
||||
xMax: GRAPH_X_MAX,
|
||||
yMin: GRAPH_Y_MIN,
|
||||
yMax: GRAPH_Y_MAX,
|
||||
curves: [
|
||||
{
|
||||
points: sumPhaseCurvePoints([
|
||||
getPeqPhasePoints({ freqs, bands: displayPeq }),
|
||||
getCrossoverPhasePoints({
|
||||
freqs,
|
||||
highPass: highPassSpec,
|
||||
lowPass: lowPassSpec,
|
||||
}),
|
||||
]),
|
||||
style: { strokeColor: '#e5e7eb', dimmed: ActivePeq.bypass },
|
||||
},
|
||||
],
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{(graphView === 'both' || graphView === 'phase') && <PhaseGraph {...graphProps} />}
|
||||
|
||||
{ActivePeq.bypass && (
|
||||
<div className="channel-bypass-overlay">
|
||||
|
||||
Reference in New Issue
Block a user