feat: add geq graph + bypass warning

This commit is contained in:
2026-08-12 11:51:26 +02:00
parent 34fad6f905
commit ddec10ca8f
6 changed files with 341 additions and 81 deletions
@@ -5,6 +5,8 @@ import Button from '../../../../components/Button/Button';
import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup';
import { LinearGraph } from '../../../../components/LinearGraph/LinearGraph';
import './GainSection.css';
import { DiscreteFrequency } from '../../types';
import { DISCRETE_FREQUENCIES } from '../../constants';
function GainPanel({
dsp,
@@ -48,6 +50,7 @@ function GainPanel({
step={(v) => (v >= -20 ? 0.1 : 0.5)}
unit=" dB"
value={gain}
formatValue={(v, d) => (v > 0 ? `+${v.toFixed(d)}` : v.toFixed(d))}
onChange={(value) => setGain(channel, value)}
/>
@@ -116,6 +119,8 @@ function GainSection({
{ channel: { Output: OutputChannel.Out8 }, title: 'Out 8' },
];
const currentChannel = dsp.state.current_config.input_states[InputChannel.InA];
return (
<>
<div className="gain-linear-graph-section">
@@ -131,13 +136,46 @@ function GainSection({
xLabel="Hz"
yLabel="dB"
draw={({ ctx, toPx }) => {
const geq = currentChannel.geq;
if (geq.bypass) {
return;
}
const points = Object.entries(geq.gains)
.map(([frequency, gain]) => ({
frequency: DISCRETE_FREQUENCIES[frequency as DiscreteFrequency],
gain,
}))
.sort((a, b) => a.frequency - b.frequency)
.map(({ frequency, gain }) => {
const [x, y] = toPx(frequency, gain);
return { x, y };
});
if (points.length < 2) {
return;
}
ctx.strokeStyle = '#4ade80';
ctx.lineWidth = 2;
const [x0, y0] = toPx(20, 0);
const [x1, y1] = toPx(20000, 0);
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(x0, y0);
ctx.lineTo(x1, y1);
ctx.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
const previous = points[i - 1];
const current = points[i];
const midX = (previous.x + current.x) / 2;
ctx.quadraticCurveTo(previous.x, previous.y, midX, (previous.y + current.y) / 2);
ctx.quadraticCurveTo(current.x, current.y, current.x, current.y);
}
ctx.stroke();
}}
/>
@@ -141,3 +141,29 @@
flex: 1;
min-height: 0;
}
.geq-graph-canvas-wrap {
position: relative;
}
.geq-bypass-overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
z-index: 2;
padding-bottom: 40cqh;
}
.geq-bypass-overlay span {
font-size: 8cqh;
font-weight: 800;
letter-spacing: 0.15em;
color: #f87171;
text-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
transform: rotate(-8deg);
opacity: 0.85;
user-select: none;
}
@@ -4,54 +4,22 @@ import { DSP408 as DSP } from '../../../../types';
import Button from '../../../../components/Button/Button';
import ChannelGroup from '../../../../components/ChannelGroup/ChannelGroup';
import { LinearGraph } from '../../../../components/LinearGraph/LinearGraph';
import { useMemo, useState } from 'react';
import { GEQ_BAND_HZ, buildGeqCurveDraw } from '../../utils/geqCurve';
import {
INPUT_ORDER,
GRAPH_X_MIN,
GRAPH_X_MAX,
GRAPH_Y_MIN,
GRAPH_Y_MAX,
GRAPH_GEQ_CURVE_Q,
GEQ_GAIN_MIN,
GEQ_GAIN_MAX,
GEQ_GAIN_STEP,
GEQ_BANDS_LABEL,
} from '../../constants';
import { useState } from 'react';
import './GeqSection.css';
const GEQ_BANDS = [
{ frequency: DiscreteFrequency.F20, label: '20' },
{ frequency: DiscreteFrequency.F25, label: '25' },
{ frequency: DiscreteFrequency.F31_5, label: '31.5' },
{ frequency: DiscreteFrequency.F40, label: '40' },
{ frequency: DiscreteFrequency.F50, label: '50' },
{ frequency: DiscreteFrequency.F63, label: '63' },
{ frequency: DiscreteFrequency.F80, label: '80' },
{ frequency: DiscreteFrequency.F100, label: '100' },
{ frequency: DiscreteFrequency.F125, label: '125' },
{ frequency: DiscreteFrequency.F160, label: '160' },
{ frequency: DiscreteFrequency.F200, label: '200' },
{ frequency: DiscreteFrequency.F250, label: '250' },
{ frequency: DiscreteFrequency.F315, label: '315' },
{ frequency: DiscreteFrequency.F400, label: '400' },
{ frequency: DiscreteFrequency.F500, label: '500' },
{ frequency: DiscreteFrequency.F630, label: '630' },
{ frequency: DiscreteFrequency.F800, label: '800' },
{ frequency: DiscreteFrequency.F1000, label: '1k' },
{ frequency: DiscreteFrequency.F1250, label: '1.25k' },
{ frequency: DiscreteFrequency.F1600, label: '1.6k' },
{ frequency: DiscreteFrequency.F2000, label: '2k' },
{ frequency: DiscreteFrequency.F2500, label: '2.5k' },
{ frequency: DiscreteFrequency.F3150, label: '3.15k' },
{ frequency: DiscreteFrequency.F4000, label: '4k' },
{ frequency: DiscreteFrequency.F5000, label: '5k' },
{ frequency: DiscreteFrequency.F6300, label: '6.3k' },
{ frequency: DiscreteFrequency.F8000, label: '8k' },
{ frequency: DiscreteFrequency.F10000, label: '10k' },
{ frequency: DiscreteFrequency.F12500, label: '12.5k' },
{ frequency: DiscreteFrequency.F16000, label: '16k' },
{ frequency: DiscreteFrequency.F20000, label: '20k' },
] as const;
const GEQ_GAIN_MIN = -12;
const GEQ_GAIN_MAX = 12;
const GEQ_GAIN_STEP = 0.1;
const INPUT_ORDER: InputChannel[] = [
InputChannel.InA,
InputChannel.InB,
InputChannel.InC,
InputChannel.InD,
];
type LiveBands = Partial<Record<DiscreteFrequency, number>>;
type SetGeqBandFn = (
@@ -78,7 +46,7 @@ function GeqBandPanel({
return (
<div className="geq-band-panel">
{GEQ_BANDS.map(({ frequency, label }) => (
{GEQ_BANDS_LABEL.map(({ frequency, label }) => (
<div className="geq-band-cell" key={frequency}>
<VerticalSlider
min={GEQ_GAIN_MIN}
@@ -112,13 +80,7 @@ function GeqGraph({
}) {
const geq = dsp.state.current_config.input_states[channel].geq;
const labelByX = useMemo(() => {
const map = new Map<number, string>();
GEQ_BANDS.forEach((band, i) => map.set(i + 1, band.label));
return map;
}, []);
const values = GEQ_BANDS.map(
const values = GEQ_BANDS_LABEL.map(
({ frequency }) => liveBands?.[frequency] ?? geq.gains[frequency] ?? 0
);
@@ -126,31 +88,31 @@ function GeqGraph({
<div className="geq-graph-panel">
<div className="geq-graph-title">{title}</div>
<LinearGraph
xMin={0.5}
xMax={GEQ_BANDS.length + 0.5}
xStep={1}
yMin={GEQ_GAIN_MIN}
yMax={GEQ_GAIN_MAX}
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}
formatX={(v) => labelByX.get(Math.round(v)) ?? ''}
formatY={(v) => v.toFixed(0)}
draw={({ ctx, toPx, plot }) => {
const barWidth = (plot.width / GEQ_BANDS.length) * 0.6;
values.forEach((gain, i) => {
const x = i + 1;
const [xPx, zeroY] = toPx(x, 0);
const [, gainY] = toPx(x, gain);
ctx.fillStyle = gain >= 0 ? '#4ade80' : '#f87171';
const top = Math.min(zeroY, gainY);
const height = Math.abs(gainY - zeroY);
ctx.fillRect(xPx - barWidth / 2, top, barWidth, height);
});
}}
draw={buildGeqCurveDraw({
values,
bandHz: GEQ_BAND_HZ,
q: GRAPH_GEQ_CURVE_Q * 0.5,
xMin: GRAPH_X_MIN,
xMax: GRAPH_X_MAX,
yMin: GRAPH_Y_MIN,
yMax: GRAPH_Y_MAX,
dimmed: geq.bypass,
})}
/>
{geq.bypass && (
<div className="geq-bypass-overlay">
<span>BYPASSED</span>
</div>
)}
</div>
);
}
@@ -274,7 +236,7 @@ function GeqSection({
if (resetting) return;
setResetting(true);
for (const { frequency } of GEQ_BANDS) {
for (const { frequency } of GEQ_BANDS_LABEL) {
// Skip bands already at 0 to save a round trip.
const current = dsp.state.current_config.input_states[channel].geq.gains[frequency] ?? 0;
if (current === 0) continue;