fix: dont render graphs on every poll
This commit is contained in:
@@ -3,9 +3,9 @@ import VerticalSlider from '../../../../components/VerticalSlider/VerticalSlider
|
||||
import { InputChannel } from '../../types';
|
||||
import { DSP408 as DSP } from '../../../../types';
|
||||
import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup';
|
||||
import { LinearGraph } from '../../../../components/LinearGraph/LinearGraph';
|
||||
import { GateGraph } from './GateGraph';
|
||||
import MeterBar from '../../../../components/MeterBar/MeterBar';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import './GateSection.css';
|
||||
|
||||
const GATE_PARAMS = [
|
||||
@@ -112,65 +112,16 @@ function GateSection({ dsp, set_gate }: { dsp: DSP; set_gate: SetGateFn }) {
|
||||
const activeInputState = dsp.state.current_config.input_states[activeChannel];
|
||||
const activeGate = liveGate[activeChannel] ?? activeInputState.gate;
|
||||
|
||||
const envelope = useMemo(() => {
|
||||
const { threshold, attack, hold, release } = activeGate;
|
||||
const roll = Math.max(20, (attack + hold + release) * 0.08);
|
||||
const t0 = 0;
|
||||
const t1 = t0 + roll;
|
||||
const t2 = t1 + attack;
|
||||
const t3 = t2 + hold;
|
||||
const t4 = t3 + release;
|
||||
const t5 = t4 + roll;
|
||||
return { threshold, t0, t1, t2, t3, t4, t5 };
|
||||
}, [activeGate.threshold, activeGate.attack, activeGate.hold, activeGate.release]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="gate-linear-graph-section">
|
||||
<div className="gate-graph-panel">
|
||||
<div className="gate-graph-title">Frequency Response</div>
|
||||
<LinearGraph
|
||||
xMin={envelope.t0}
|
||||
xMax={envelope.t5}
|
||||
yMin={-95}
|
||||
yMax={5}
|
||||
xLabel="ms"
|
||||
yLabel="dB"
|
||||
formatX={(v) => Math.round(v).toString()}
|
||||
formatY={(v) => Math.round(v).toString()}
|
||||
draw={({ toPx, ctx }) => {
|
||||
const { threshold, t0, t1, t2, t3, t4, t5 } = envelope;
|
||||
|
||||
ctx.strokeStyle = '#fbbf24';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([4, 4]);
|
||||
const [tx0, ty] = toPx(t0, threshold);
|
||||
const [tx1] = toPx(t5, threshold);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tx0, ty);
|
||||
ctx.lineTo(tx1, ty);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
ctx.strokeStyle = '#4ade80';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineJoin = 'round';
|
||||
const points: [number, number][] = [
|
||||
[t0, -90],
|
||||
[t1, -90],
|
||||
[t2, 0],
|
||||
[t3, 0],
|
||||
[t4, -90],
|
||||
[t5, -90],
|
||||
];
|
||||
ctx.beginPath();
|
||||
points.forEach(([t, g], i) => {
|
||||
const [px, py] = toPx(t, g);
|
||||
if (i === 0) ctx.moveTo(px, py);
|
||||
else ctx.lineTo(px, py);
|
||||
});
|
||||
ctx.stroke();
|
||||
}}
|
||||
<div className="gate-graph-title">Gate Response</div>
|
||||
<GateGraph
|
||||
threshold={activeGate.threshold}
|
||||
attack={activeGate.attack}
|
||||
hold={activeGate.hold}
|
||||
release={activeGate.release}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user