Skip to content

Commit 3e33ffe

Browse files
authored
Merge pull request #39 from diffusionstudio/konstantin/fix/stack-add-at-zero
fixed add clip at zero bug
2 parents f6b9cf4 + a353e2a commit 3e33ffe

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/tracks/track/track.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ describe('The Track Object', () => {
9494

9595
expect(track.clips[1].start.frames).toBe(5);
9696
expect(track.clips[1].stop.frames).toBe(10);
97+
98+
await track.add(new Clip({ stop: 17, start: 3, name: 'abc' }), 0);
99+
100+
expect(track.clips[0].start.frames).toBe(0);
101+
expect(track.clips[0].stop.frames).toBe(14);
102+
expect(track.clips[0].name).toBe('abc');
103+
104+
expect(track.clips[1].start.frames).toBe(14);
105+
expect(track.clips[1].stop.frames).toBe(19);
97106
});
98107

99108
it('should snap the clip when it overlaps with the end of another clip', async () => {

src/tracks/track/track.strategies.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ export class DefaultInsertStrategy implements InsertStrategy<'DEFAULT'> {
6262
export class StackInsertStrategy implements InsertStrategy<'STACK'> {
6363
public mode = insertModes[1];
6464

65-
public add(clip: Clip, track: Track<Clip>, index: number = 0): void {
66-
// fallback is -1 because one frame will be added
67-
const stop = track.clips.at(index - 1)?.stop.millis ?? -1;
68-
const offset = stop - clip.start.millis + 1;
65+
public add(clip: Clip, track: Track<Clip>, index: number | undefined = undefined): void {
66+
let stop = -1;
6967

70-
clip.offsetBy(new Timestamp(offset));
68+
if (index != undefined && index > 0 || index == undefined) {
69+
stop = track.clips.at((index ?? 0) - 1)?.stop.millis ?? -1;
70+
}
71+
72+
clip.offsetBy(new Timestamp(stop - clip.start.millis + 1));
7173

72-
if (index == 0) {
74+
if (index == undefined) {
7375
track.clips.push(clip);
7476
} else {
7577
track.clips.splice(index, 0, clip);

0 commit comments

Comments
 (0)