fix: dont render graphs on every poll
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { memo, useCallback, useMemo } from 'react';
|
||||
import LinearGraph from '../../../../components/LinearGraph/LinearGraph';
|
||||
|
||||
const formatTick = (v: number) => Math.round(v).toString();
|
||||
|
||||
// Hard-knee brickwall limiter transfer curve, in dB.
|
||||
function limiterOutputDb(input: number, threshold: number): number {
|
||||
return input <= threshold ? input : threshold;
|
||||
}
|
||||
|
||||
export const LimiterGraph = memo(function LimiterGraph({ threshold }: { threshold: number }) {
|
||||
const curvePoints = useMemo(() => {
|
||||
const steps = 120;
|
||||
const points: [number, number][] = [];
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const x = -60 + (60 * i) / steps;
|
||||
points.push([x, limiterOutputDb(x, threshold)]);
|
||||
}
|
||||
return points;
|
||||
}, [threshold]);
|
||||
|
||||
const draw = useCallback(
|
||||
({ ctx, toPx }: any) => {
|
||||
// Unity reference line
|
||||
ctx.strokeStyle = '#6b7280';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([4, 4]);
|
||||
const [ux0, uy0] = toPx(-60, -60);
|
||||
const [ux1, uy1] = toPx(0, 0);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(ux0, uy0);
|
||||
ctx.lineTo(ux1, uy1);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
// Threshold marker
|
||||
ctx.strokeStyle = '#fbbf24';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([2, 3]);
|
||||
const [tx0, ty0] = toPx(threshold, -60);
|
||||
const [tx1, ty1] = toPx(threshold, 0);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tx0, ty0);
|
||||
ctx.lineTo(tx1, ty1);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
// Limiter curve
|
||||
ctx.strokeStyle = '#f87171';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineJoin = 'round';
|
||||
ctx.beginPath();
|
||||
curvePoints.forEach(([x, y], i) => {
|
||||
const [px, py] = toPx(x, y);
|
||||
if (i === 0) ctx.moveTo(px, py);
|
||||
else ctx.lineTo(px, py);
|
||||
});
|
||||
ctx.stroke();
|
||||
},
|
||||
[threshold, curvePoints]
|
||||
);
|
||||
|
||||
return (
|
||||
<LinearGraph
|
||||
xMin={-60}
|
||||
xMax={0}
|
||||
yMin={-60}
|
||||
yMax={0}
|
||||
xLabel="in dB"
|
||||
yLabel="out dB"
|
||||
formatX={formatTick}
|
||||
formatY={formatTick}
|
||||
draw={draw}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -3,9 +3,9 @@ import VerticalSlider from '../../../../components/VerticalSlider/VerticalSlider
|
||||
import { OutputChannel } from '../../types';
|
||||
import { DSP408 as DSP } from '../../../../types';
|
||||
import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup';
|
||||
import { LinearGraph } from '../../../../components/LinearGraph/LinearGraph';
|
||||
import { LimiterGraph } from './LimiterGraph';
|
||||
import MeterBar from '../../../../components/MeterBar/MeterBar';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import './LimiterSection.css';
|
||||
|
||||
const LIMITER_SLIDER_PARAMS = [
|
||||
@@ -74,11 +74,6 @@ function LimiterPanel({
|
||||
);
|
||||
}
|
||||
|
||||
// Hard-knee brickwall limiter transfer curve, in dB.
|
||||
function limiterOutputDb(input: number, threshold: number): number {
|
||||
return input <= threshold ? input : threshold;
|
||||
}
|
||||
|
||||
function LimiterSection({ dsp, set_limiter }: { dsp: DSP; set_limiter: SetLimiterFn }) {
|
||||
const outputs = [
|
||||
OutputChannel.Out1,
|
||||
@@ -122,70 +117,12 @@ function LimiterSection({ dsp, set_limiter }: { dsp: DSP; set_limiter: SetLimite
|
||||
const activeOutputState = dsp.state.current_config.output_states[activeChannel];
|
||||
const activeLim = liveLim[activeChannel] ?? (activeOutputState.limiter as LimiterValues);
|
||||
|
||||
const curvePoints = useMemo(() => {
|
||||
const { threshold } = activeLim;
|
||||
const steps = 120;
|
||||
const points: [number, number][] = [];
|
||||
for (let i = 0; i <= steps; i++) {
|
||||
const x = -60 + (60 * i) / steps;
|
||||
points.push([x, limiterOutputDb(x, threshold)]);
|
||||
}
|
||||
return points;
|
||||
}, [activeLim.threshold]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="limiter-linear-graph-section">
|
||||
<div className="limiter-graph-panel">
|
||||
<div className="limiter-graph__title">{activeOutputState.name} - Limiter</div>
|
||||
|
||||
<LinearGraph
|
||||
xMin={-60}
|
||||
xMax={0}
|
||||
yMin={-60}
|
||||
yMax={0}
|
||||
xLabel="in dB"
|
||||
yLabel="out dB"
|
||||
formatX={(v) => Math.round(v).toString()}
|
||||
formatY={(v) => Math.round(v).toString()}
|
||||
draw={({ ctx, toPx }) => {
|
||||
// Unity reference line
|
||||
ctx.strokeStyle = '#6b7280';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([4, 4]);
|
||||
const [ux0, uy0] = toPx(-60, -60);
|
||||
const [ux1, uy1] = toPx(0, 0);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(ux0, uy0);
|
||||
ctx.lineTo(ux1, uy1);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
// Threshold marker
|
||||
ctx.strokeStyle = '#fbbf24';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.setLineDash([2, 3]);
|
||||
const [tx0, ty0] = toPx(activeLim.threshold, -60);
|
||||
const [tx1, ty1] = toPx(activeLim.threshold, 0);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tx0, ty0);
|
||||
ctx.lineTo(tx1, ty1);
|
||||
ctx.stroke();
|
||||
ctx.setLineDash([]);
|
||||
|
||||
// Limiter curve
|
||||
ctx.strokeStyle = '#f87171';
|
||||
ctx.lineWidth = 2;
|
||||
ctx.lineJoin = 'round';
|
||||
ctx.beginPath();
|
||||
curvePoints.forEach(([x, y], i) => {
|
||||
const [px, py] = toPx(x, y);
|
||||
if (i === 0) ctx.moveTo(px, py);
|
||||
else ctx.lineTo(px, py);
|
||||
});
|
||||
ctx.stroke();
|
||||
}}
|
||||
/>
|
||||
<LimiterGraph threshold={activeLim.threshold} />
|
||||
</div>
|
||||
|
||||
<div className="limiter-meter-panel">
|
||||
|
||||
Reference in New Issue
Block a user