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={{ style={{
width: interpolateMotionAudioData( width: interpolateMotionAudioData(
getMotionSegmentValue(segmentTime), getMotionSegmentValue(segmentTime),
0,
100,
1,
maxSegmentWidth, maxSegmentWidth,
), ),
}} }}
@ -235,9 +232,6 @@ export function MotionSegment({
style={{ style={{
width: interpolateMotionAudioData( width: interpolateMotionAudioData(
getAudioSegmentValue(segmentTime), getAudioSegmentValue(segmentTime),
-100,
0,
1,
maxSegmentWidth, maxSegmentWidth,
), ),
}} }}
@ -253,10 +247,7 @@ export function MotionSegment({
onClick={segmentClick} onClick={segmentClick}
style={{ style={{
width: interpolateMotionAudioData( width: interpolateMotionAudioData(
getMotionSegmentValue(segmentTime - segmentDuration / 2), getMotionSegmentValue(segmentTime + segmentDuration / 2),
0,
100,
1,
maxSegmentWidth, maxSegmentWidth,
), ),
}} }}
@ -269,10 +260,7 @@ export function MotionSegment({
onClick={segmentClick} onClick={segmentClick}
style={{ style={{
width: interpolateMotionAudioData( width: interpolateMotionAudioData(
getAudioSegmentValue(segmentTime - segmentDuration / 2), getAudioSegmentValue(segmentTime + segmentDuration / 2),
-100,
0,
1,
maxSegmentWidth, maxSegmentWidth,
), ),
}} }}

View File

@ -26,16 +26,8 @@ export const useMotionSegmentUtils = (
); );
const interpolateMotionAudioData = useCallback( const interpolateMotionAudioData = useCallback(
( (value: number, newMax: number): number => {
value: number, return Math.ceil((Math.abs(value) / 100.0) * newMax) || 1;
oldMin: number,
oldMax: number,
newMin: number,
newMax: number,
): number => {
return (
((value - oldMin) / (oldMax - oldMin)) * (newMax - newMin) + newMin
);
}, },
[], [],
); );