simplify interp and fix math

This commit is contained in:
Josh Hawkins 2024-03-04 14:12:54 -06:00
parent a4c406c911
commit 648f615560
2 changed files with 4 additions and 24 deletions

View File

@ -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,
),
}}

View File

@ -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;
},
[],
);