feat: add geq graph + bypass warning
This commit is contained in:
@@ -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();
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user