From d74fd3fc0f46fce599d45c1b8aa3bb3ec209078b Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 15 Apr 2026 06:18:15 +0200 Subject: [PATCH] Add set-project-sequencer-command.ts --- src/commands/set-project-sequencer-command.ts | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/commands/set-project-sequencer-command.ts diff --git a/src/commands/set-project-sequencer-command.ts b/src/commands/set-project-sequencer-command.ts new file mode 100644 index 00000000..521a914f --- /dev/null +++ b/src/commands/set-project-sequencer-command.ts @@ -0,0 +1,64 @@ +import { createOpaqueId } from "../core/ids"; +import { + cloneProjectScheduler, + type ProjectScheduler +} from "../scheduler/project-scheduler"; +import { + cloneProjectSequenceLibrary, + type ProjectSequenceLibrary +} from "../sequencer/project-sequences"; + +import type { EditorCommand } from "./command"; + +interface SetProjectSequencerCommandOptions { + label: string; + scheduler: ProjectScheduler; + sequences: ProjectSequenceLibrary; +} + +export function createSetProjectSequencerCommand( + options: SetProjectSequencerCommandOptions +): EditorCommand { + const nextScheduler = cloneProjectScheduler(options.scheduler); + const nextSequences = cloneProjectSequenceLibrary(options.sequences); + let previousScheduler: ProjectScheduler | null = null; + let previousSequences: ProjectSequenceLibrary | null = null; + + return { + id: createOpaqueId("command"), + label: options.label, + execute(context) { + const currentProjectDocument = context.getProjectDocument(); + + if (previousScheduler === null) { + previousScheduler = cloneProjectScheduler( + currentProjectDocument.scheduler + ); + } + + if (previousSequences === null) { + previousSequences = cloneProjectSequenceLibrary( + currentProjectDocument.sequences + ); + } + + context.setProjectDocument({ + ...currentProjectDocument, + scheduler: cloneProjectScheduler(nextScheduler), + sequences: cloneProjectSequenceLibrary(nextSequences) + }); + }, + undo(context) { + if (previousScheduler === null || previousSequences === null) { + return; + } + + const currentProjectDocument = context.getProjectDocument(); + context.setProjectDocument({ + ...currentProjectDocument, + scheduler: cloneProjectScheduler(previousScheduler), + sequences: cloneProjectSequenceLibrary(previousSequences) + }); + } + }; +}