Skip to content

Commit 04032f1

Browse files
authored
Merge pull request #58 from diffusionstudio/konstantin/feat/transcript-subclips
Enhance Transcript functionality and Composition track removal
2 parents 489e31a + d905478 commit 04032f1

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
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.5.1",
4+
"version": "1.6.0",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/composition/composition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
268268
public removeTracks(Track: new (composition: Composition) => Track<Clip>): Track<Clip>[] {
269269
const removed = this.tracks.filter((track) => track instanceof Track);
270270
this.tracks = this.tracks.filter((track) => !(track instanceof Track));
271+
removed.forEach(track => this.removeTrack(track));
271272

272273
return removed;
273274
}

src/models/transcript.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,32 @@ is`
306306

307307
resetFetch();
308308
});
309+
310+
it('should be able to create a deep copy of the transcript', () => {
311+
const transcript = new Transcript([
312+
new WordGroup([
313+
new Word('Lorem', 0e3, 1e3),
314+
new Word('Ipsum', 2e3, 3e3),
315+
]),
316+
new WordGroup([
317+
new Word('is', 4e3, 5e3),
318+
new Word('simply', 6e3, 7e3),
319+
]),
320+
]);
321+
322+
const copy = transcript.copy();
323+
324+
expect(copy.id).not.toBe(transcript.id);
325+
expect(copy.groups.length).toBe(transcript.groups.length);
326+
expect(copy.groups[0].words.length).toBe(transcript.groups[0].words.length);
327+
expect(copy.groups[0].words[0].id).not.toBe(transcript.groups[0].words[0].id);
328+
329+
for (let i = 0; i < transcript.words.length; i++) {
330+
expect(copy.words[i].text).toBe(transcript.words[i].text);
331+
}
332+
333+
transcript.groups[0].words[0].text = 'Hello';
334+
335+
expect(copy.groups[0].words[0].text).not.toBe('Hello');
336+
});
309337
});

src/models/transcript.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ export class Transcript implements Serializer {
149149
return new Transcript([new WordGroup(words)]);
150150
}
151151

152+
/**
153+
* Create a deep copy of the transcript
154+
* @returns A new Transcript instance
155+
*/
156+
public copy(): Transcript {
157+
return Transcript.fromJSON(this.toJSON());
158+
}
159+
152160
public static fromJSON(data: Captions): Transcript {
153161
const transcipt = new Transcript();
154162

src/models/transcript.word.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import { Timestamp } from './timestamp';
99

1010
export class Word {
11+
/**
12+
* A unique identifier for the word
13+
*/
14+
public id = crypto.randomUUID();
1115
/**
1216
* Defines the text to be displayed
1317
*/

0 commit comments

Comments
 (0)