Skip to content

Commit 9c9f9de

Browse files
committed
renamed caption create method
1 parent 01a4aad commit 9c9f9de

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.0.0-beta.15",
4+
"version": "1.0.0-rc.1",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/clips/media/media.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,11 @@ describe('The Media Clip', () => {
296296
const composition = new Composition();
297297
await composition.add(clip);
298298

299-
await clip.generateCaptions();
299+
const track = await clip.generateCaptions();
300300

301301
expect(composition.tracks.length).toBe(2);
302302

303-
const track = composition.tracks[0];
304-
303+
expect(composition.tracks[0]).toBeInstanceOf(CaptionTrack);
305304
expect(track).toBeInstanceOf(CaptionTrack);
306305
expect(track.clips.length).toBe(36);
307306
expect(track.clips[0]).toBeInstanceOf(TextClip);

src/clips/media/media.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { replaceKeyframes } from '../clip/clip.utils';
1414
import { ValidationError } from '../../errors';
1515
import { Clip } from '../clip';
1616

17-
import type { CaptionPresetStrategy, Track } from '../../tracks';
17+
import type { CaptionPresetStrategy, CaptionTrack, Track } from '../../tracks';
1818
import type { float, frame } from '../../types';
1919
import type { MediaClipProps } from './media.interfaces';
2020

@@ -145,7 +145,7 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends As
145145
}
146146

147147
public async connect(track: Track<MediaClip>): Promise<void> {
148-
if (['LOADING', 'IDLE'].includes(this.state)) {
148+
if (['LOADING', 'IDLE'].includes(this.state) && this.element) {
149149
await new Promise(this.resolve('load'));
150150
};
151151

@@ -277,23 +277,23 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends As
277277

278278
/**
279279
* Generates a new caption track for the current clip using the specified captioning strategy.
280-
* @param preset An optional CaptionPresetStrategy to define how captions should be generated.
280+
* @param strategy An optional CaptionPresetStrategy to define how captions should be generated.
281281
* @returns {Promise<void>} A promise that resolves when the caption track has been successfully created.
282282
*/
283-
public async generateCaptions(preset?: CaptionPresetStrategy): Promise<this> {
283+
public async generateCaptions(strategy?: CaptionPresetStrategy | (new () => CaptionPresetStrategy)): Promise<CaptionTrack> {
284284
if (!this.track?.composition) {
285285
throw new ValidationError({
286286
i18n: 'compositionNotDefined',
287287
message: 'Captions can only be generated after the clip has been added to the composition',
288288
});
289289
}
290290

291-
await this.track.composition
291+
const track = await this.track.composition
292292
.createTrack('caption')
293293
.from(this)
294-
.create(preset);
294+
.generate(strategy);
295295

296-
return this;
296+
return track;
297297
}
298298

299299
public set(props?: Props): this {

src/tracks/caption/caption.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ describe('The Caption Track Object', () => {
5959

6060
it('should generate captions', async () => {
6161
expect(track.clips.length).toBe(0);
62-
await track.create();
62+
await track.generate();
6363
expect(track.clips.length).not.toBe(0);
6464
});
6565

6666
it('should update the offset when the media keyframes change', async () => {
67-
await track.create();
67+
await track.generate();
6868
expect(track.clips.at(0)?.start.seconds).toBe(0);
6969

7070
media.offsetBy(<frame>10);

src/tracks/caption/caption.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export class CaptionTrack extends Track<TextClip> {
4040

4141
/**
4242
* If a transcript has been added to the resource
43-
* you can create captions with this function
43+
* you can generate captions with this function
4444
* @param strategy The caption strategy to use
45-
* @default new ClassicCaptionPreset()
45+
* @default ClassicCaptionPreset
4646
*/
47-
public async create(strategy?: CaptionPresetStrategy | (new () => CaptionPresetStrategy)): Promise<this> {
47+
public async generate(strategy?: CaptionPresetStrategy | (new () => CaptionPresetStrategy)): Promise<this> {
4848
let preset = this.preset;
4949

5050
if (typeof strategy == 'object') {

src/tracks/caption/preset.1.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('(1) The Caption Presets', () => {
6262
})
6363
);
6464

65-
await track1.create();
65+
await track1.generate();
6666

6767
expect(track1.clips.at(0)?.start.seconds).toBe(0);
6868
expect(track1.clips.at(0)?.stop.seconds).toBe(1);
@@ -90,7 +90,7 @@ describe('(1) The Caption Presets', () => {
9090
]);
9191
const track2 = composition.createTrack('caption').from(media2);
9292

93-
await track2.create();
93+
await track2.generate();
9494

9595
expect(track2.clips.at(0)?.start.millis).toBe(21_001);
9696
expect(track2.clips.at(0)?.stop.millis).toBe(22_001);

0 commit comments

Comments
 (0)