From 648f6155603109d98819b3a5385280d6cc61fbcd Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:12:54 -0600 Subject: [PATCH] simplify interp and fix math --- web/src/components/timeline/MotionSegment.tsx | 16 ++-------------- web/src/hooks/use-motion-segment-utils.ts | 12 ++---------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/web/src/components/timeline/MotionSegment.tsx b/web/src/components/timeline/MotionSegment.tsx index 1cea97586..3bed07f86 100644 --- a/web/src/components/timeline/MotionSegment.tsx +++ b/web/src/components/timeline/MotionSegment.tsx @@ -219,9 +219,6 @@ export function MotionSegment({ style={{ width: interpolateMotionAudioData( getMotionSegmentValue(segmentTime), - 0, - 100, - 1, maxSegmentWidth, ), }} @@ -235,9 +232,6 @@ export function MotionSegment({ style={{ width: interpolateMotionAudioData( getAudioSegmentValue(segmentTime), - -100, - 0, - 1, maxSegmentWidth, ), }} @@ -253,10 +247,7 @@ export function MotionSegment({ onClick={segmentClick} style={{ width: interpolateMotionAudioData( - getMotionSegmentValue(segmentTime - segmentDuration / 2), - 0, - 100, - 1, + getMotionSegmentValue(segmentTime + segmentDuration / 2), maxSegmentWidth, ), }} @@ -269,10 +260,7 @@ export function MotionSegment({ onClick={segmentClick} style={{ width: interpolateMotionAudioData( - getAudioSegmentValue(segmentTime - segmentDuration / 2), - -100, - 0, - 1, + getAudioSegmentValue(segmentTime + segmentDuration / 2), maxSegmentWidth, ), }} diff --git a/web/src/hooks/use-motion-segment-utils.ts b/web/src/hooks/use-motion-segment-utils.ts index f65ce7beb..9cfa4e0d4 100644 --- a/web/src/hooks/use-motion-segment-utils.ts +++ b/web/src/hooks/use-motion-segment-utils.ts @@ -26,16 +26,8 @@ export const useMotionSegmentUtils = ( ); const interpolateMotionAudioData = useCallback( - ( - value: number, - oldMin: number, - oldMax: number, - newMin: number, - newMax: number, - ): number => { - return ( - ((value - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin - ); + (value: number, newMax: number): number => { + return Math.ceil((Math.abs(value) / 100.0) * newMax) || 1; }, [], );