Skip to content
Open
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
107 changes: 64 additions & 43 deletions src/api/premierepro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { premierepro } from "../globals";
import type { AudioTrack, Project, Sequence, VideoTrack } from "../types/ppro";
import { asTransaction, lockedTransaction } from "./utils/premierepro-utils";

export const notify = async (message: string) => {
Expand Down Expand Up @@ -31,26 +32,6 @@ export const renameItem = async () => {
"Rename Item",
);
};

// export const renameItemCurrent = async () => {
// const proj = await premierepro.Project.getActiveProject();
// const root = await proj.getRootItem();
// // Undo Group #1
// proj.lockedAccess(() =>
// proj.executeTransaction(async (compAction) => {
// compAction.addAction(root.createBinAction("Bin1", true));
// }, "Create Bin"),
// );
// // Have to find the new Bin
// const itemsNew = await root.getItems();
// const newBin = itemsNew.find((item) => item.name === "Bin1")!;
// // Undo Group #2
// proj.lockedAccess(() =>
// proj.executeTransaction(async (compAction) => {
// compAction.addAction(newBin.createSetNameAction("TEST"));
// }, "Rename Bin"),
// );
// };
export const renameItemCurrent = async () => {
const proj = await premierepro.Project.getActiveProject();
const root = await proj.getRootItem();
Expand All @@ -65,27 +46,67 @@ export const renameItemCurrent = async () => {
);
};

// export const renameItemIdeal = async () => {
// const proj = await premierepro.Project.getActiveProject();
// const root = await proj.getRootItem();
// const items = await root.getItems();
// // Undo Group #1
// proj.lockedAccess(() =>
// proj.executeTransaction(async (compAction) => {
// compAction.addAction(root.createBinAction("Bin1", true)).then(newBin => {
// // Manipulate result immediately
// compAction.addAction(newBin.createSetNameAction("TEST"));
// })
// }, 'Create + Rename Bin'),
// );
// };
export const forEachAudioTrack = async (
sequence: Sequence,
callback: (track: AudioTrack, index: number) => Promise<void>,
reverse?: boolean,
) => {
const num = await sequence.getAudioTrackCount();
if (reverse) {
for (let i = num - 1; i > -1; i--) {
const track = await sequence.getAudioTrack(i);
await callback(track, i);
}
} else {
for (let i = 0; i < num; i++) {
const track = await sequence.getAudioTrack(i);
await callback(track, i);
}
}
};

export const forEachVideoTrack = async (
sequence: Sequence,
callback: (track: VideoTrack, index: number) => Promise<void>,
reverse?: boolean,
) => {
const num = await sequence.getVideoTrackCount();
if (reverse) {
for (let i = num - 1; i > -1; i--) {
const track = await sequence.getVideoTrack(i);
await callback(track, i);
}
} else {
for (let i = 0; i < num; i++) {
const track = await sequence.getVideoTrack(i);
await callback(track, i);
}
}
};

// export const renameItemDREAMING = async () => {
// const proj = await premierepro.Project.getActiveProject();
// const root = await proj.getRootItem();
// const items = await root.getItems();
// proj.beginUndoGroup('Create + Rename Bin');
// const newItem = root.createBin("Bin1", true);
// const newItem = newItem.setName("TEST");
// proj.endUndoGroup('Create + Rename Bin');
// };
export const cloneSequence = async (
project: Project,
sequence: Sequence,
name: string,
) => {
const existingIds = (await project.getSequences()).map((s) => s.guid);
await asTransaction(
project,
[sequence.createCloneAction()],
"Clone Sequence",
);
const clonedSequence = (await project.getSequences()).find(
(s) => !existingIds.includes(s.guid),
);
if (clonedSequence) {
const clonedProjItem = await clonedSequence.getProjectItem();
await asTransaction(
project,
[clonedProjItem.createSetNameAction(name)],
"Rename Cloned Sequence",
);
} else {
console.warn("cannot find new sequence");
}
return clonedSequence;
};
Loading