Skip to content

Commit 517ccbc

Browse files
committed
feat(LFO): impact of update delay
1 parent cb6bfea commit 517ccbc

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

  • example/src/components/visualizaion
  • packages/components/visualization/LFO

example/src/components/visualizaion/EchoLFO.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const EchoLFO = () => {
9494
<Knob
9595
value={delay}
9696
min={0}
97-
max={100}
97+
max={1000}
9898
step={1}
9999
sensitivity={8}
100100
onChange={setDelay}

packages/components/visualization/LFO/LFO.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
2929
} = props
3030

3131
const amplitude = validValue(_anplitude, 0, 1)
32-
const delay = validValue(_delay, 0, 100)
32+
const delay = validValue(_delay, 0, 1000)
3333

3434
const LFORef = useRef<LFORef | null>(null)
3535
const xScale = useRef<d3.ScaleLinear<number, number> | null>(null)
3636
const yScale = useRef<d3.ScaleLinear<number, number> | null>(null)
37+
const delayInSeconds = delay / 1000
3738

3839
useImperativeHandle(ref, () => LFORef.current as LFORef)
3940

@@ -88,17 +89,17 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
8889
if (delay > 0) {
8990
svg
9091
.append('circle')
91-
.attr('cx', delay)
92-
.attr('cy', height / 2)
92+
.attr('cx', delayInSeconds)
93+
.attr('cy', yScale.current!(0.5))
9394
.attr('r', lineWidth / 2)
9495
.attr('fill', lineColor)
9596

9697
svg
9798
.append('line')
9899
.attr('x1', 0)
99-
.attr('y1', height / 2)
100-
.attr('x2', delay + 1)
101-
.attr('y2', height / 2)
100+
.attr('y1', yScale.current!(0.5))
101+
.attr('x2', xScale.current!(delayInSeconds) + 1)
102+
.attr('y2', yScale.current!(0.5))
102103
.attr('stroke', lineColor)
103104
.attr('stroke-width', lineWidth)
104105
}
@@ -130,7 +131,7 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
130131
.attr('stroke', lineColor)
131132
.attr('stroke-width', lineWidth)
132133
.attr('d', line)
133-
.attr('transform', `translate(${delay}, 0)`)
134+
.attr('transform', `translate(${delayInSeconds * width}, 0)`)
134135
}
135136

136137
const generateSineWaveData = (

0 commit comments

Comments
 (0)