Motion timeline updates (#10242)

* adjust segment math

* simplify interp and fix math

* fix math and update dependency

* push debug

* Revert "push debug"

This reverts commit 07c171b341.
This commit is contained in:
Josh Hawkins 2024-03-04 16:18:27 -06:00 committed by GitHub
parent 282c92c9c8
commit 38e76666e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 43 deletions

View File

@ -113,6 +113,7 @@ export function MotionReviewTimeline({
minimapStartTime, minimapStartTime,
minimapEndTime, minimapEndTime,
events, events,
motion_events,
]); ]);
const segments = useMemo( const segments = useMemo(
@ -128,6 +129,7 @@ export function MotionReviewTimeline({
minimapStartTime, minimapStartTime,
minimapEndTime, minimapEndTime,
events, events,
motion_events,
], ],
); );

View File

@ -217,15 +217,10 @@ export function MotionSegment({
className={`h-[2px] rounded-full bg-motion_review`} className={`h-[2px] rounded-full bg-motion_review`}
onClick={segmentClick} onClick={segmentClick}
style={{ style={{
width: width: interpolateMotionAudioData(
maxSegmentWidth - getMotionSegmentValue(segmentTime + segmentDuration / 2),
interpolateMotionAudioData( maxSegmentWidth,
getMotionSegmentValue(segmentTime - segmentDuration / 2), ),
0,
100,
1,
maxSegmentWidth,
),
}} }}
></div> ></div>
</div> </div>
@ -236,10 +231,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,
), ),
}} }}
@ -254,15 +246,10 @@ export function MotionSegment({
className={`h-[2px] rounded-full bg-motion_review`} className={`h-[2px] rounded-full bg-motion_review`}
onClick={segmentClick} onClick={segmentClick}
style={{ style={{
width: width: interpolateMotionAudioData(
maxSegmentWidth - getMotionSegmentValue(segmentTime),
interpolateMotionAudioData( maxSegmentWidth,
getMotionSegmentValue(segmentTime), ),
0,
100,
1,
maxSegmentWidth,
),
}} }}
></div> ></div>
</div> </div>
@ -274,9 +261,6 @@ export function MotionSegment({
style={{ style={{
width: interpolateMotionAudioData( width: interpolateMotionAudioData(
getAudioSegmentValue(segmentTime), getAudioSegmentValue(segmentTime),
-100,
0,
1,
maxSegmentWidth, maxSegmentWidth,
), ),
}} }}

View File

@ -1,41 +1,39 @@
import { useCallback } from "react"; import { useCallback, useMemo } from "react";
import { MockMotionData } from "@/pages/UIPlayground"; import { MockMotionData } from "@/pages/UIPlayground";
export const useMotionSegmentUtils = ( export const useMotionSegmentUtils = (
segmentDuration: number, segmentDuration: number,
motion_events: MockMotionData[], motion_events: MockMotionData[],
) => { ) => {
const halfSegmentDuration = useMemo(
() => segmentDuration / 2,
[segmentDuration],
);
const getSegmentStart = useCallback( const getSegmentStart = useCallback(
(time: number): number => { (time: number): number => {
return Math.floor(time / segmentDuration) * segmentDuration; return Math.floor(time / halfSegmentDuration) * halfSegmentDuration;
}, },
[segmentDuration], [halfSegmentDuration],
); );
const getSegmentEnd = useCallback( const getSegmentEnd = useCallback(
(time: number | undefined): number => { (time: number | undefined): number => {
if (time) { if (time) {
return ( return (
Math.floor(time / segmentDuration) * segmentDuration + segmentDuration Math.floor(time / halfSegmentDuration) * halfSegmentDuration +
halfSegmentDuration
); );
} else { } else {
return Date.now() / 1000 + segmentDuration; return Date.now() / 1000 + halfSegmentDuration;
} }
}, },
[segmentDuration], [halfSegmentDuration],
); );
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
);
}, },
[], [],
); );
@ -45,7 +43,7 @@ export const useMotionSegmentUtils = (
const matchingEvent = motion_events.find((event) => { const matchingEvent = motion_events.find((event) => {
return ( return (
time >= getSegmentStart(event.start_time) && time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time) time < getSegmentEnd(event.start_time)
); );
}); });
@ -59,7 +57,7 @@ export const useMotionSegmentUtils = (
const matchingEvent = motion_events.find((event) => { const matchingEvent = motion_events.find((event) => {
return ( return (
time >= getSegmentStart(event.start_time) && time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time) time < getSegmentEnd(event.start_time)
); );
}); });