Skip to content

Motion timeline updates #10242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/src/components/timeline/MotionReviewTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function MotionReviewTimeline({
minimapStartTime,
minimapEndTime,
events,
motion_events,
]);

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

Expand Down
34 changes: 9 additions & 25 deletions web/src/components/timeline/MotionSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,10 @@ export function MotionSegment({
className={`h-[2px] rounded-full bg-motion_review`}
onClick={segmentClick}
style={{
width:
maxSegmentWidth -
interpolateMotionAudioData(
getMotionSegmentValue(segmentTime - segmentDuration / 2),
0,
100,
1,
maxSegmentWidth,
),
width: interpolateMotionAudioData(
getMotionSegmentValue(segmentTime + segmentDuration / 2),
maxSegmentWidth,
),
}}
></div>
</div>
Expand All @@ -236,10 +231,7 @@ export function MotionSegment({
onClick={segmentClick}
style={{
width: interpolateMotionAudioData(
getAudioSegmentValue(segmentTime - segmentDuration / 2),
-100,
0,
1,
getAudioSegmentValue(segmentTime + segmentDuration / 2),
maxSegmentWidth,
),
}}
Expand All @@ -254,15 +246,10 @@ export function MotionSegment({
className={`h-[2px] rounded-full bg-motion_review`}
onClick={segmentClick}
style={{
width:
maxSegmentWidth -
interpolateMotionAudioData(
getMotionSegmentValue(segmentTime),
0,
100,
1,
maxSegmentWidth,
),
width: interpolateMotionAudioData(
getMotionSegmentValue(segmentTime),
maxSegmentWidth,
),
}}
></div>
</div>
Expand All @@ -274,9 +261,6 @@ export function MotionSegment({
style={{
width: interpolateMotionAudioData(
getAudioSegmentValue(segmentTime),
-100,
0,
1,
maxSegmentWidth,
),
}}
Expand Down
34 changes: 16 additions & 18 deletions web/src/hooks/use-motion-segment-utils.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import { useCallback } from "react";
import { useCallback, useMemo } from "react";
import { MockMotionData } from "@/pages/UIPlayground";

export const useMotionSegmentUtils = (
segmentDuration: number,
motion_events: MockMotionData[],
) => {
const halfSegmentDuration = useMemo(
() => segmentDuration / 2,
[segmentDuration],
);

const getSegmentStart = useCallback(
(time: number): number => {
return Math.floor(time / segmentDuration) * segmentDuration;
return Math.floor(time / halfSegmentDuration) * halfSegmentDuration;
},
[segmentDuration],
[halfSegmentDuration],
);

const getSegmentEnd = useCallback(
(time: number | undefined): number => {
if (time) {
return (
Math.floor(time / segmentDuration) * segmentDuration + segmentDuration
Math.floor(time / halfSegmentDuration) * halfSegmentDuration +
halfSegmentDuration
);
} else {
return Date.now() / 1000 + segmentDuration;
return Date.now() / 1000 + halfSegmentDuration;
}
},
[segmentDuration],
[halfSegmentDuration],
);

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;
},
[],
);
Expand All @@ -45,7 +43,7 @@ export const useMotionSegmentUtils = (
const matchingEvent = motion_events.find((event) => {
return (
time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time)
time < getSegmentEnd(event.start_time)
);
});

Expand All @@ -59,7 +57,7 @@ export const useMotionSegmentUtils = (
const matchingEvent = motion_events.find((event) => {
return (
time >= getSegmentStart(event.start_time) &&
time < getSegmentEnd(event.end_time)
time < getSegmentEnd(event.start_time)
);
});

Expand Down