Skip to content

Commit 5e2ac3d

Browse files
committed
feat: add clip related methods to Track
1 parent f300830 commit 5e2ac3d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/Track.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,42 @@ export class Track extends Properties<
494494
return await Promise.all(clipSlots.filter((cs) => cs.hasClip).map(async (cs) => await cs.clip()));
495495
}
496496

497+
/**
498+
* Get a specific clip based on Scene number
499+
*
500+
* @memberof Track
501+
* @return {(Promise<(Clip | null)>)}
502+
*/
503+
async getClip(scene: number): Promise<Clip | null> {
504+
const clipSlots = await this.children('clip_slots');
505+
506+
if (scene < 1 || scene > clipSlots.length) return Promise.reject(null);
507+
508+
const clipSlot = clipSlots[scene - 1];
509+
510+
return await clipSlot.clip();
511+
}
512+
513+
/**
514+
* Get a specific clip based on Scene number and creates one if there's none
515+
*
516+
* @memberof Track
517+
* @param {number} scene
518+
* @param {number} [length=4]
519+
* @return {(Promise<Clip>)}
520+
*/
521+
async getOrCreateClip(scene: number, length: number = 4): Promise<Clip> {
522+
const clipSlots = await this.children('clip_slots');
523+
524+
if (scene < 1 || scene > clipSlots.length) return Promise.reject(null);
525+
526+
const clipSlot = clipSlots[scene - 1];
527+
528+
if (!clipSlot.hasClip) return await clipSlot.createClip(length);
529+
530+
return (await clipSlot.clip()) as Clip;
531+
}
532+
497533
/**
498534
* Is the track a group track
499535
*

0 commit comments

Comments
 (0)