summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks/actions/use-editor-actions.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-03-31 23:23:36 +0200
committerMaze Winther <mazewinther@gmail.com>2026-03-31 23:23:36 +0200
commitf1d5932c54178c4f8eac61d3d3e0e4a30101780f (patch)
tree73ebf833517b1f0a9925151a703f335bedf49216 /apps/web/src/hooks/actions/use-editor-actions.ts
parentd23be079cce6108482fc3e85401cccf949087174 (diff)
downloadopencut-f1d5932c54178c4f8eac61d3d3e0e4a30101780f.tar.gz
feat: separate audio from elements
Diffstat (limited to 'apps/web/src/hooks/actions/use-editor-actions.ts')
-rw-r--r--apps/web/src/hooks/actions/use-editor-actions.ts48
1 files changed, 47 insertions, 1 deletions
diff --git a/apps/web/src/hooks/actions/use-editor-actions.ts b/apps/web/src/hooks/actions/use-editor-actions.ts
index bfac931b..087ea687 100644
--- a/apps/web/src/hooks/actions/use-editor-actions.ts
+++ b/apps/web/src/hooks/actions/use-editor-actions.ts
@@ -6,9 +6,13 @@ import { useActionHandler } from "@/hooks/actions/use-action-handler";
import { useEditor } from "../use-editor";
import { useElementSelection } from "../timeline/element/use-element-selection";
import { useKeyframeSelection } from "../timeline/element/use-keyframe-selection";
-import { getElementsAtTime } from "@/lib/timeline";
+import {
+ getElementsAtTime,
+ hasMediaId,
+} from "@/lib/timeline";
import { cancelInteraction } from "@/lib/cancel-interaction";
import { invokeAction } from "@/lib/actions";
+import { canToggleSourceAudio } from "@/lib/timeline/audio-separation";
import {
activateScope,
clearActiveScope,
@@ -267,6 +271,48 @@ export function useEditorActions() {
);
useActionHandler(
+ "toggle-source-audio",
+ () => {
+ if (selectedElements.length !== 1) {
+ return;
+ }
+
+ const selectedElement = editor.timeline.getElementsWithTracks({
+ elements: selectedElements,
+ })[0];
+ if (!selectedElement) {
+ return;
+ }
+
+ const mediaAsset = (() => {
+ const { element } = selectedElement;
+ if (!hasMediaId(element)) {
+ return null;
+ }
+
+ return (
+ editor.media.getAssets().find((asset) => asset.id === element.mediaId) ??
+ null
+ );
+ })();
+ if (
+ !canToggleSourceAudio({
+ element: selectedElement.element,
+ mediaAsset,
+ })
+ ) {
+ return;
+ }
+
+ editor.timeline.toggleSourceAudioSeparation({
+ trackId: selectedElement.track.id,
+ elementId: selectedElement.element.id,
+ });
+ },
+ undefined,
+ );
+
+ useActionHandler(
"select-all",
() => {
const allElements = editor.timeline.getTracks().flatMap((track) =>