🎥 Make videos programmatically with React
Move timeline frame subscriptions into leaf components
Jonny Burger7606b1aa319d
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex a7792b6aa4..0b4acb6397 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -17,7 +17,7 @@ import type {SequencePropsSubscriptionKey,TSequence,} from 'remotion';-import {Internals, useCurrentFrame} from 'remotion';+import {Internals} from 'remotion';import {StudioServerConnectionCtx} from '../../helpers/client-id';import {BLUE,@@ -28,8 +28,6 @@ import {TIMELINE_VIDEO_GRADIENT,TRANSPARENT,WHITE,- WHITE_ALPHA_20,- WHITE_ALPHA_50,} from '../../helpers/colors';import {createDragAwareDoubleClickTracker} from '../../helpers/drag-aware-double-click';import {@@ -88,6 +86,7 @@ import {useTimelineRowSelection,} from './TimelineSelection';import {TimelineSequenceFrame} from './TimelineSequenceFrame';+import {TimelineSequenceMountIndicator} from './TimelineSequenceMountIndicator';import {canResizeTimelineSequenceDuration,getTimelineSequenceEndField,@@ -298,7 +297,7 @@ const TimelineSequenceNegativeStart = React.memo(TimelineSequenceNegativeStartInner,);-const TimelineSequenceCurrentFrame: React.FC<{+const TimelineSequenceBar: React.FC<{readonly s: TSequence;readonly annotationLocation: ResolvedStackLocation | null;readonly activeTrimEdge: 'left' | 'right' | null;@@ -387,25 +386,6 @@ const TimelineSequenceCurrentFrame: React.FC<{},[fromCanUpdate, onMoveDragPointerDown, onSelect, selected],);- const frame = useCurrentFrame();- const relativeFrame = frame - s.from;- const sequenceFrame =- relativeFrame * s.sequencePlaybackRate + sequenceFrameOffset;- const relativeFrameWithPremount = relativeFrame + (s.premountDisplay ?? 0);- const relativeFrameWithPostmount = relativeFrame - displayDurationInFrames;-- const roundedFrame = Math.round(sequenceFrame * 100) / 100;-- const isInRange =- relativeFrame >= 0 && relativeFrame < displayDurationInFrames;- const isPremounting =- relativeFrameWithPremount >= 0 &&- relativeFrameWithPremount < displayDurationInFrames &&- !isInRange;- const isPostmounting =- relativeFrameWithPostmount >= 0 &&- relativeFrameWithPostmount < (s.postmountDisplay ?? 0) &&- !isInRange;const negativeStartEnd = negativeStart? negativeStart.left + negativeStart.width: 0;@@ -438,38 +418,24 @@ const TimelineSequenceCurrentFrame: React.FC<{const content = (<>{premount ? (- <div- style={{- left: premount.left,- width: premount.width,- height: '100%',- background: `repeating-linear-gradient(- -45deg,- ${TRANSPARENT},- ${TRANSPARENT} 2px,- ${isPremounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 2px,- ${isPremounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 4px- )`,- position: 'absolute',- }}+ <TimelineSequenceMountIndicator+ from={s.from}+ displayDurationInFrames={displayDurationInFrames}+ mountDurationInFrames={s.premountDisplay ?? 0}+ mountType="premount"+ left={premount.left}+ width={premount.width}/>) : null}{postmount ? (- <div- style={{- left: postmount.left,- width: postmount.width,- height: '100%',- background: `repeating-linear-gradient(- -45deg,- ${TRANSPARENT},- ${TRANSPARENT} 2px,- ${isPostmounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 2px,- ${isPostmounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 4px- )`,- position: 'absolute',- }}+ <TimelineSequenceMountIndicator+ from={s.from}+ displayDurationInFrames={displayDurationInFrames}+ mountDurationInFrames={s.postmountDisplay ?? 0}+ mountType="postmount"+ left={postmount.left}+ width={postmount.width}/>) : null}@@ -478,23 +444,14 @@ const TimelineSequenceCurrentFrame: React.FC<{{s.type !== 'audio' &&s.type !== 'video' &&s.type !== 'image' &&- s.loopDisplay === undefined &&- (frozenFrame !== null || isInRange || isPremounting || isPostmounting) ? (- <div- style={{- paddingLeft: 5 + negativeStartEnd + (premount?.width ?? 0),- height: '100%',- display: 'flex',- alignItems: 'center',- }}- >- <TimelineSequenceFrame- premounted={isPremounting}- postmounted={isPostmounting ? s.duration - 1 : null}- roundedFrame={roundedFrame}- frozenFrame={frozenFrame}- />- </div>+ s.loopDisplay === undefined ? (+ <TimelineSequenceFrame+ s={s}+ sequenceFrameOffset={sequenceFrameOffset}+ displayDurationInFrames={displayDurationInFrames}+ paddingLeft={5 + negativeStartEnd + (premount?.width ?? 0)}+ frozenFrame={frozenFrame}+ />) : null}{activeTrimEdge === null ||@@ -1616,7 +1573,7 @@ const TimelineSequenceInner: React.FC<{: 0;const sequence = (- <TimelineSequenceCurrentFrame+ <TimelineSequenceBars={s}annotationLocation={originalLocation}activeTrimEdge={activeTrimEdge}@@ -1761,7 +1718,7 @@ const TimelineSequenceInner: React.FC<{visibleWidth={visibleLayout.width}/>)}- </TimelineSequenceCurrentFrame>+ </TimelineSequenceBar>);return (diff --git a/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx b/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsxindex 8f25e761f0..71fde573f6 100644--- a/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceFrame.tsx@@ -1,4 +1,6 @@import React from 'react';+import type {TSequence} from 'remotion';+import {useCurrentFrame} from 'remotion';import {CURRENT_COLOR, WHITE} from '../../helpers/colors';import {SnowflakeIcon} from '../../icons/snowflake';@@ -23,22 +25,60 @@ const snowflakeStyle: React.CSSProperties = {};export const TimelineSequenceFrame: React.FC<{- readonly roundedFrame: number;+ readonly s: TSequence;+ readonly sequenceFrameOffset: number;+ readonly displayDurationInFrames: number;+ readonly paddingLeft: number;readonly frozenFrame: number | null;- readonly premounted: boolean;- readonly postmounted: number | null;-}> = ({roundedFrame, frozenFrame, premounted, postmounted}) => {+}> = ({+ s,+ sequenceFrameOffset,+ displayDurationInFrames,+ paddingLeft,+ frozenFrame,+}) => {+ const frame = useCurrentFrame();+ const relativeFrame = frame - s.from;+ const sequenceFrame =+ relativeFrame * s.sequencePlaybackRate + sequenceFrameOffset;+ const roundedFrame = Math.round(sequenceFrame * 100) / 100;+ const isInRange =+ relativeFrame >= 0 && relativeFrame < displayDurationInFrames;+ const relativeFrameWithPremount = relativeFrame + (s.premountDisplay ?? 0);+ const isPremounting =+ relativeFrameWithPremount >= 0 &&+ relativeFrameWithPremount < displayDurationInFrames &&+ !isInRange;+ const relativeFrameWithPostmount = relativeFrame - displayDurationInFrames;+ const isPostmounting =+ relativeFrameWithPostmount >= 0 &&+ relativeFrameWithPostmount < (s.postmountDisplay ?? 0) &&+ !isInRange;++ if (frozenFrame === null && !isInRange && !isPremounting && !isPostmounting) {+ return null;+ }+return (- <div style={relativeFrameStyle}>- {frozenFrame === null ? null : (- <SnowflakeIcon style={snowflakeStyle} color={CURRENT_COLOR} />- )}- {frozenFrame ??- (premounted- ? '0 (Premounted)'- : postmounted !== null- ? `${postmounted} (Postmounted)`- : roundedFrame)}+ <div+ style={{+ paddingLeft,+ height: '100%',+ display: 'flex',+ alignItems: 'center',+ }}+ >+ <div style={relativeFrameStyle}>+ {frozenFrame === null ? null : (+ <SnowflakeIcon style={snowflakeStyle} color={CURRENT_COLOR} />+ )}+ {frozenFrame ??+ (isPremounting+ ? '0 (Premounted)'+ : isPostmounting+ ? `${s.duration - 1} (Postmounted)`+ : roundedFrame)}+ </div></div>);};diff --git a/packages/studio/src/components/Timeline/TimelineSequenceMountIndicator.tsx b/packages/studio/src/components/Timeline/TimelineSequenceMountIndicator.tsxnew file mode 100644index 0000000000..d4a3fab132--- /dev/null+++ b/packages/studio/src/components/Timeline/TimelineSequenceMountIndicator.tsx@@ -0,0 +1,57 @@+import React from 'react';+import {useCurrentFrame} from 'remotion';+import {+ TRANSPARENT,+ WHITE_ALPHA_20,+ WHITE_ALPHA_50,+} from '../../helpers/colors';++export const TimelineSequenceMountIndicator: React.FC<{+ readonly from: number;+ readonly displayDurationInFrames: number;+ readonly mountDurationInFrames: number;+ readonly mountType: 'premount' | 'postmount';+ readonly left: number;+ readonly width: number;+}> = ({+ from,+ displayDurationInFrames,+ mountDurationInFrames,+ mountType,+ left,+ width,+}) => {+ const frame = useCurrentFrame();+ const relativeFrame = frame - from;+ const isInRange =+ relativeFrame >= 0 && relativeFrame < displayDurationInFrames;+ const relativeMountFrame =+ mountType === 'premount'+ ? relativeFrame + mountDurationInFrames+ : relativeFrame - displayDurationInFrames;+ const isMounting =+ !isInRange &&+ relativeMountFrame >= 0 &&+ relativeMountFrame <+ (mountType === 'premount'+ ? displayDurationInFrames+ : mountDurationInFrames);++ return (+ <div+ style={{+ left,+ width,+ height: '100%',+ background: `repeating-linear-gradient(+ -45deg,+ ${TRANSPARENT},+ ${TRANSPARENT} 2px,+ ${isMounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 2px,+ ${isMounting ? WHITE_ALPHA_50 : WHITE_ALPHA_20} 4px+ )`,+ position: 'absolute',+ }}+ />+ );+};