From e9b0129ab9c497058cd71f1ea733c20d0c62170e Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Tue, 20 May 2025 13:12:43 +0800 Subject: [PATCH 1/3] allow deleting split clips --- apps/desktop/src/components/Toggle.tsx | 26 +-- .../src/routes/editor/ConfigSidebar.tsx | 158 +++++++++++++----- apps/desktop/src/routes/editor/Player.tsx | 14 +- .../src/routes/editor/Timeline/ClipTrack.tsx | 87 +++++++--- .../src/routes/editor/Timeline/Track.tsx | 18 +- .../src/routes/editor/Timeline/ZoomTrack.tsx | 41 ++++- .../src/routes/editor/Timeline/index.tsx | 53 ++++-- apps/desktop/src/routes/editor/context.ts | 5 +- apps/desktop/src/routes/editor/index.tsx | 2 +- apps/desktop/src/routes/editor/ui.tsx | 23 +-- apps/desktop/src/styles/timeline.css | 34 +--- 11 files changed, 295 insertions(+), 166 deletions(-) diff --git a/apps/desktop/src/components/Toggle.tsx b/apps/desktop/src/components/Toggle.tsx index ca6925177ce..f537ee279cf 100644 --- a/apps/desktop/src/components/Toggle.tsx +++ b/apps/desktop/src/components/Toggle.tsx @@ -9,34 +9,36 @@ const toggleControlStyles = cva( size: { sm: "w-9 h-[1.25rem] p-[0.125rem]", md: "w-11 h-[1.5rem] p-[0.125rem]", - lg: "w-14 h-[1.75rem] p-[0.1875rem]" - } + lg: "w-14 h-[1.75rem] p-[0.1875rem]", + }, }, defaultVariants: { - size: "md" - } + size: "md", + }, } ); const toggleThumbStyles = cva( - "ui-checked:bg-solid-white bg-gray-10 rounded-full transition-transform ui-checked:translate-x-[calc(100%)]", + "bg-white rounded-full transition-transform ui-checked:translate-x-[calc(100%)]", { variants: { size: { sm: "size-[1rem]", md: "size-[1.25rem]", - lg: "size-[1.5rem]" - } + lg: "size-[1.5rem]", + }, }, defaultVariants: { - size: "md" - } + size: "md", + }, } ); -export function Toggle(props: ComponentProps & { size?: 'sm' | 'md' | 'lg' }) { - const [local, others] = splitProps(props, ['size']); - +export function Toggle( + props: ComponentProps & { size?: "sm" | "md" | "lg" } +) { + const [local, others] = splitProps(props, ["size"]); + return ( diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx index 7bde1a99757..6c544ef7e93 100644 --- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx +++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx @@ -19,6 +19,7 @@ import { cx } from "cva"; import { For, Show, + Suspense, ValidComponent, batch, createEffect, @@ -42,6 +43,7 @@ import { generalSettingsStore } from "~/store"; import { type BackgroundSource, StereoMode, + TimelineSegment, ZoomSegment, commands, } from "~/utils/tauri"; @@ -215,7 +217,7 @@ export function ConfigSidebar() { return ( - { - const selection = - editorState.timeline.selection?.type === "zoom" && - editorState.timeline.selection; - if (!selection) return; - - const segment = project.timeline?.zoomSegments?.[selection.index]; - if (!segment) return; - - return { selection, segment }; - })()} - > - {(value) => ( - + + {(selection) => ( +
+ + { + const zoomSelection = selection(); + if (zoomSelection.type !== "zoom") return; + + const segment = + project.timeline?.zoomSegments?.[zoomSelection.index]; + if (!segment) return; + + return { selection: zoomSelection, segment }; + })()} + > + {(value) => ( + + )} + + { + const clipSegment = selection(); + if (clipSegment.type !== "clip") return; + + const segment = + project.timeline?.segments?.[clipSegment.index]; + if (!segment) return; + + return { selection: clipSegment, segment }; + })()} + > + {(value) => ( + + )} + + +
)}
@@ -1613,7 +1641,6 @@ function ZoomSegmentConfig(props: { project, setProject, editorInstance, - editorState, setEditorState, projectHistory, } = useEditorContext(); @@ -1626,10 +1653,7 @@ function ZoomSegmentConfig(props: { }; return ( -
+ <>
{ - if (v === "auto") { - setProject( - "timeline", - "zoomSegments", - props.segmentIndex, - "mode", - "auto" - ); - } else { - setProject( - "timeline", - "zoomSegments", - props.segmentIndex, - "mode", - { manual: states.manual } - ); - } + setProject( + "timeline", + "zoomSegments", + props.segmentIndex, + "mode", + v === "auto" ? "auto" : { manual: states.manual } + ); }} > @@ -1716,7 +1730,7 @@ function ZoomSegmentConfig(props: { Manual -
+
@@ -1893,7 +1907,65 @@ function ZoomSegmentConfig(props: { -
+ + ); +} + +function ClipSegmentConfig(props: { + segmentIndex: number; + segment: TimelineSegment; +}) { + const { setProject, setEditorState, project } = useEditorContext(); + + return ( + <> +
+
+ setEditorState("timeline", "selection", null)} + leftIcon={} + > + Done + +
+ { + batch(() => { + setProject( + "timeline", + "segments", + produce((s) => { + if (!s) return; + return s.splice(props.segmentIndex, 1); + }) + ); + setEditorState("timeline", "selection", null); + }); + }} + disabled={ + ( + project.timeline?.segments.filter( + (s) => s.recordingSegment === props.segment.recordingSegment + ) ?? [] + ).length < 2 + } + leftIcon={} + > + Delete + +
+ + } /> + + + } + /> + + ); } diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx index 40f265a803e..a660a95fda0 100644 --- a/apps/desktop/src/routes/editor/Player.tsx +++ b/apps/desktop/src/routes/editor/Player.tsx @@ -74,7 +74,7 @@ export function Player() { }); return ( -
+
} - />{" "} + leftIcon={ + + } + />
, "ref">) { +export function ClipTrack( + props: Pick, "ref"> & { + handleUpdatePlayhead: (e: MouseEvent) => void; + } +) { const { project, setProject, editorInstance, projectHistory, editorState, + setEditorState, totalDuration, } = useEditorContext(); @@ -85,6 +94,17 @@ export function ClipTrack(props: Pick, "ref">) { position: "right", })); + const isSelected = createMemo(() => { + const selection = editorState.timeline.selection; + if (!selection || selection.type !== "clip") return false; + + const segmentIndex = project.timeline?.segments?.findIndex( + (s) => s.start === segment.start && s.end === segment.end + ); + + return segmentIndex === selection.index; + }); + return ( <> @@ -191,35 +211,50 @@ export function ClipTrack(props: Pick, "ref">) { { - if (editorState.timeline.interactMode !== "split") return; e.stopPropagation(); - const rect = e.currentTarget.getBoundingClientRect(); - const fraction = (e.clientX - rect.left) / rect.width; - - const splitTime = - segment.start + fraction * (segment.end - segment.start); - - setProject( - "timeline", - "segments", - produce((segments) => { - segments.splice(i() + 1, 0, { - start: splitTime, - end: segment.end, - timescale: 1, - recordingSegment: segment.recordingSegment, + if (editorState.timeline.interactMode === "split") { + const rect = e.currentTarget.getBoundingClientRect(); + const fraction = (e.clientX - rect.left) / rect.width; + + const splitTime = + segment.start + fraction * (segment.end - segment.start); + + setProject( + "timeline", + "segments", + produce((segments) => { + segments.splice(i() + 1, 0, { + start: splitTime, + end: segment.end, + timescale: 1, + recordingSegment: segment.recordingSegment, + }); + segments[i()].end = splitTime; + }) + ); + } else { + createRoot((dispose) => { + createEventListener(e.currentTarget, "mouseup", (e) => { + dispose(); + + setEditorState("timeline", "selection", { + type: "clip", + index: i(), + }); + props.handleUpdatePlayhead(e); }); - segments[i()].end = splitTime; - }) - ); + }); + } }} > @@ -293,14 +328,14 @@ export function ClipTrack(props: Pick, "ref">) { }); }} /> - + {(() => { const ctx = useSegmentContext(); return ( 100}>
- + {hasMultipleRecordingSegments() ? `Clip ${segment.recordingSegment}` : "Clip"} diff --git a/apps/desktop/src/routes/editor/Timeline/Track.tsx b/apps/desktop/src/routes/editor/Timeline/Track.tsx index 72121c1d1ea..28d6dbb697b 100644 --- a/apps/desktop/src/routes/editor/Timeline/Track.tsx +++ b/apps/desktop/src/routes/editor/Timeline/Track.tsx @@ -18,7 +18,7 @@ export function TrackRoot(props: ComponentProps<"div">) {
{props.children}
@@ -56,19 +56,6 @@ export function SegmentRoot( ) => void; } ) { - const { editorState: state, project } = useEditorContext(); - - const isSelected = createMemo(() => { - const selection = state.timeline.selection; - if (!selection || selection.type !== "zoom") return false; - - const segmentIndex = project.timeline?.zoomSegments?.findIndex( - (s) => s.start === props.segment.start && s.end === props.segment.end - ); - - return segmentIndex === selection.index; - }); - const translateX = useSegmentTranslateX(() => props.segment); const width = useSegmentWidth(() => props.segment); @@ -78,8 +65,7 @@ export function SegmentRoot( {...props} class={cx( "absolute overflow-hidden border rounded-xl inset-y-0", - props.class, - isSelected() && "wobble-wrapper border border-gray-500" + props.class )} style={{ "--segment-x": `${translateX()}px`, diff --git a/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx index 0c5ba13c804..b00da7a6dc4 100644 --- a/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx +++ b/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx @@ -1,17 +1,25 @@ import { - createEventListener, - createEventListenerMap, + createEventListener, + createEventListenerMap, } from "@solid-primitives/event-listener"; -import { For, Show, batch, createRoot, createSignal } from "solid-js"; +import { + For, + Show, + batch, + createMemo, + createRoot, + createSignal, +} from "solid-js"; import { produce } from "solid-js/store"; import { useEditorContext } from "../context"; import { - useSegmentContext, - useTimelineContext, - useTrackContext, + useSegmentContext, + useTimelineContext, + useTrackContext, } from "./context"; import { SegmentContent, SegmentHandle, SegmentRoot, TrackRoot } from "./Track"; +import { cx } from "cva"; export type ZoomSegmentDragState = | { type: "idle" } @@ -200,9 +208,26 @@ export function ZoomTrack(props: { }; } + const isSelected = createMemo(() => { + const selection = editorState.timeline.selection; + if (!selection || selection.type !== "zoom") return false; + + const segmentIndex = project.timeline?.zoomSegments?.findIndex( + (s) => s.start === segment.start && s.end === segment.end + ); + + return segmentIndex === selection.index; + }); + return ( { @@ -355,7 +380,7 @@ export function ZoomTrack(props: { end: time() + 1, }} > - +

+

diff --git a/apps/desktop/src/routes/editor/Timeline/index.tsx b/apps/desktop/src/routes/editor/Timeline/index.tsx index 72c5fc5f4a0..4a5a84a8cc8 100644 --- a/apps/desktop/src/routes/editor/Timeline/index.tsx +++ b/apps/desktop/src/routes/editor/Timeline/index.tsx @@ -5,6 +5,8 @@ import { cx } from "cva"; import { For, Show, batch, createRoot, createSignal, onMount } from "solid-js"; import { produce } from "solid-js/store"; +import "../../../styles/timeline.css"; + import { useEditorContext } from "../context"; import { formatTime } from "../utils"; import { ClipTrack } from "./ClipTrack"; @@ -85,16 +87,42 @@ export function Timeline() { createEventListener(window, "keydown", (e) => { if (e.code === "Backspace" || e.code === "Delete") { - if (editorState.timeline.selection?.type !== "zoom") return; const selection = editorState.timeline.selection; + if (!selection) return; - batch(() => { - setProject( - produce((project) => { - project.timeline?.zoomSegments.splice(selection.index, 1); - }) + if (selection.type === "zoom") { + batch(() => { + setProject( + produce((project) => { + project.timeline?.zoomSegments.splice(selection.index, 1); + }) + ); + }); + } else if (selection.type === "clip") { + const selectedSegment = project.timeline?.segments.find( + (_, i) => i === selection.index ); - }); + if (!selectedSegment || selectedSegment.recordingSegment === undefined) + return; + + const timeline = project.timeline; + if (!timeline) return; + + if ( + timeline.segments.filter( + (s) => s.recordingSegment === selectedSegment.recordingSegment + ).length < 2 + ) + return; + + batch(() => { + setProject( + produce((project) => { + project.timeline?.segments.splice(selection.index, 1); + }) + ); + }); + } } }); @@ -212,7 +240,10 @@ export function Timeline() {
- + { zoomSegmentDragState = v; @@ -239,12 +270,12 @@ function TimelineMarkings() { }; return ( -
+
{(second) => ( 0}>
-
+
{formatTime(second)}
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.ts index b1b134db92f..94b50ff01a4 100644 --- a/apps/desktop/src/routes/editor/context.ts +++ b/apps/desktop/src/routes/editor/context.ts @@ -155,7 +155,10 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider( playing: false, timeline: { interactMode: "seek" as "seek" | "split", - selection: null as null | { type: "zoom"; index: number }, + selection: null as + | null + | { type: "zoom"; index: number } + | { type: "clip"; index: number }, transform: { // visible seconds zoom: zoomOutLimit(), diff --git a/apps/desktop/src/routes/editor/index.tsx b/apps/desktop/src/routes/editor/index.tsx index 87ccc0265f8..9ebffd007d5 100644 --- a/apps/desktop/src/routes/editor/index.tsx +++ b/apps/desktop/src/routes/editor/index.tsx @@ -22,7 +22,7 @@ export default function () { return (
) { return (
- + {props.icon} {props.name} {props.value &&
{props.value}
} @@ -58,9 +62,6 @@ export function Subfield( ); } - - - export function Slider( props: ComponentProps & { formatTooltip?: string | ((v: number) => string); @@ -145,7 +146,6 @@ export function Slider( ); } - export function Input(props: ComponentProps<"input">) { return ( ); }, @@ -251,9 +248,7 @@ export function DialogContent( return ( <> - - {props.title} - + {props.title} {props.children} - + Coming Soon diff --git a/apps/desktop/src/styles/timeline.css b/apps/desktop/src/styles/timeline.css index 71c060a5c74..9f85faa7cc9 100644 --- a/apps/desktop/src/styles/timeline.css +++ b/apps/desktop/src/styles/timeline.css @@ -1,42 +1,14 @@ @keyframes wobble { - 0%, 100% { + 0%, + 100% { transform: translateY(0) translateX(var(--segment-x)); } 50% { - transform: translateY(-4px) translateX(var(--segment-x)); + transform: translateY(-3px) translateX(var(--segment-x)); } } .wobble-wrapper { animation: wobble 1s ease-in-out infinite; will-change: transform; - -} - -.timeline-gradient-border::before { - content: ''; - position: absolute; - inset: 0; - padding: 1px; - border-radius: 12px; - background: linear-gradient(to bottom, #ffffff4a 50%, #ffffff00 100%); - -webkit-mask: - linear-gradient(#fff 0 0) content-box, - linear-gradient(#fff 0 0); - -webkit-mask-composite: xor; - mask-composite: exclude; } - -.zoom-gradient-border::before { - content: ''; - position: absolute; - inset: 0; - padding: 1px; - border-radius: 12px; - background: linear-gradient(to bottom, #ffffff1f 50%, #ffffff00 100%); - -webkit-mask: - linear-gradient(#fff 0 0) content-box, - linear-gradient(#fff 0 0); - -webkit-mask-composite: xor; - mask-composite: exclude; -} \ No newline at end of file From f7a80209325d7cc5a14f9cc70d3c8bba4c61c577 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Tue, 20 May 2025 13:46:14 +0800 Subject: [PATCH 2/3] remove active preset --- apps/desktop/src/routes/editor/PresetsDropdown.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/desktop/src/routes/editor/PresetsDropdown.tsx b/apps/desktop/src/routes/editor/PresetsDropdown.tsx index d0011abca5d..a779d2df087 100644 --- a/apps/desktop/src/routes/editor/PresetsDropdown.tsx +++ b/apps/desktop/src/routes/editor/PresetsDropdown.tsx @@ -15,7 +15,6 @@ import { export function PresetsDropdown() { const { setDialog, presets, setProject } = useEditorContext(); - const [activePreset, setActivePreset] = createSignal(presets.query.data?.default ?? null); return ( @@ -55,15 +54,9 @@ export function PresetsDropdown() { onClick={() => { setShowSettings(false); setProject(reconcile(preset.config)); - setActivePreset(i()); }} > {preset.name} - - - Current - - Default From 950df9e42972cac788611fa7e93c56f612cc6d79 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Tue, 20 May 2025 13:47:47 +0800 Subject: [PATCH 3/3] fix end trim marker --- apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx index fc611185c04..2f3ea8128bd 100644 --- a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx +++ b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx @@ -540,7 +540,7 @@ function useSectionMarker( return () => { const { segments, i, position } = props(); - if (i === 0) { + if (i === 0 && position === "left") { return segments[0].start === 0 ? null : {