@opendaw/studio-core 0.0.104 → 0.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/project/ProjectApi.js +1 -1
- package/dist/project/ProjectApi.test.d.ts +2 -0
- package/dist/project/ProjectApi.test.d.ts.map +1 -0
- package/dist/project/ProjectApi.test.js +109 -0
- package/dist/project/polyfill.d.ts +1 -0
- package/dist/project/polyfill.d.ts.map +1 -0
- package/dist/project/polyfill.js +14 -0
- package/package.json +2 -2
|
@@ -254,7 +254,7 @@ export class ProjectApi {
|
|
|
254
254
|
}
|
|
255
255
|
else {
|
|
256
256
|
const adapter = this.#project.boxAdapters.adapterFor(region, UnionAdapterTypes.isRegion);
|
|
257
|
-
adapter.copyTo({ target: targetTrackBox.regions, position: insertPosition });
|
|
257
|
+
adapter.copyTo({ target: targetTrackBox.regions, position: insertPosition, consolidate: true });
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
#createTrack({ field, target, trackType, insertIndex }) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProjectApi.test.d.ts","sourceRoot":"","sources":["../../src/project/ProjectApi.test.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import "./polyfill";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { asInstanceOf, Terminable, UUID } from "@opendaw/lib-std";
|
|
4
|
+
import { AudioUnitBox, CaptureAudioBox, TrackBox, ValueEventCollectionBox, ValueRegionBox } from "@opendaw/studio-boxes";
|
|
5
|
+
import { AudioUnitType } from "@opendaw/studio-enums";
|
|
6
|
+
import { ProjectSkeleton, TrackType } from "@opendaw/studio-adapters";
|
|
7
|
+
import { Project } from "./Project";
|
|
8
|
+
const createEnv = () => ({
|
|
9
|
+
audioContext: {},
|
|
10
|
+
audioWorklets: {},
|
|
11
|
+
sampleManager: {
|
|
12
|
+
getOrCreate: () => ({}),
|
|
13
|
+
record: () => { },
|
|
14
|
+
remove: () => { },
|
|
15
|
+
invalidate: () => { },
|
|
16
|
+
register: () => Terminable.Empty
|
|
17
|
+
},
|
|
18
|
+
soundfontManager: {
|
|
19
|
+
getOrCreate: () => ({}),
|
|
20
|
+
remove: () => { },
|
|
21
|
+
invalidate: () => { }
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
describe("ProjectApi.copyRegionTo", () => {
|
|
25
|
+
let project;
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
const skeleton = ProjectSkeleton.empty({ createDefaultUser: true, createOutputCompressor: false });
|
|
28
|
+
project = Project.fromSkeleton(createEnv(), skeleton, false);
|
|
29
|
+
});
|
|
30
|
+
afterEach(() => project.terminate());
|
|
31
|
+
const createTrackWithRegion = (project) => {
|
|
32
|
+
const { boxGraph } = project;
|
|
33
|
+
const captureBox = CaptureAudioBox.create(boxGraph, UUID.generate());
|
|
34
|
+
const audioUnitBox = AudioUnitBox.create(boxGraph, UUID.generate(), box => {
|
|
35
|
+
box.type.setValue(AudioUnitType.Instrument);
|
|
36
|
+
box.collection.refer(project.rootBox.audioUnits);
|
|
37
|
+
box.output.refer(project.masterBusBox.input);
|
|
38
|
+
box.capture.refer(captureBox);
|
|
39
|
+
box.index.setValue(1);
|
|
40
|
+
});
|
|
41
|
+
const trackBox = TrackBox.create(boxGraph, UUID.generate(), box => {
|
|
42
|
+
box.type.setValue(TrackType.Value);
|
|
43
|
+
box.tracks.refer(audioUnitBox.tracks);
|
|
44
|
+
box.target.refer(audioUnitBox);
|
|
45
|
+
box.index.setValue(0);
|
|
46
|
+
});
|
|
47
|
+
const collectionBox = ValueEventCollectionBox.create(boxGraph, UUID.generate());
|
|
48
|
+
const regionBox = ValueRegionBox.create(boxGraph, UUID.generate(), box => {
|
|
49
|
+
box.position.setValue(100);
|
|
50
|
+
box.duration.setValue(200);
|
|
51
|
+
box.loopDuration.setValue(200);
|
|
52
|
+
box.hue.setValue(0);
|
|
53
|
+
box.events.refer(collectionBox.owners);
|
|
54
|
+
box.regions.refer(trackBox.regions);
|
|
55
|
+
});
|
|
56
|
+
return { audioUnitBox, trackBox, regionBox, collectionBox };
|
|
57
|
+
};
|
|
58
|
+
it("same graph: moves region to target track and updates position", () => {
|
|
59
|
+
const { boxGraph } = project;
|
|
60
|
+
boxGraph.beginTransaction();
|
|
61
|
+
const { trackBox: trackA, regionBox } = createTrackWithRegion(project);
|
|
62
|
+
const trackB = TrackBox.create(boxGraph, UUID.generate(), box => {
|
|
63
|
+
box.type.setValue(TrackType.Value);
|
|
64
|
+
box.tracks.refer(asInstanceOf(trackA.tracks.targetVertex.unwrap().box, AudioUnitBox).tracks);
|
|
65
|
+
box.target.refer(trackA.tracks.targetVertex.unwrap().box);
|
|
66
|
+
box.index.setValue(1);
|
|
67
|
+
});
|
|
68
|
+
boxGraph.endTransaction();
|
|
69
|
+
boxGraph.beginTransaction();
|
|
70
|
+
project.api.copyRegionTo(regionBox, trackB, 500);
|
|
71
|
+
boxGraph.endTransaction();
|
|
72
|
+
boxGraph.verifyPointers();
|
|
73
|
+
expect(regionBox.position.getValue()).toBe(500);
|
|
74
|
+
const targetUuid = regionBox.regions.targetVertex.unwrap().box.address.uuid;
|
|
75
|
+
expect(UUID.equals(targetUuid, trackB.address.uuid)).toBe(true);
|
|
76
|
+
expect(trackB.regions.pointerHub.incoming().length).toBe(1);
|
|
77
|
+
expect(trackA.regions.pointerHub.incoming().length).toBe(0);
|
|
78
|
+
});
|
|
79
|
+
it("different graph: copies region to target track at given position", () => {
|
|
80
|
+
const sourceSkeleton = ProjectSkeleton.empty({ createDefaultUser: true, createOutputCompressor: false });
|
|
81
|
+
const sourceProject = Project.fromSkeleton(createEnv(), sourceSkeleton, false);
|
|
82
|
+
const sourceGraph = sourceProject.boxGraph;
|
|
83
|
+
sourceGraph.beginTransaction();
|
|
84
|
+
const { regionBox: sourceRegion } = createTrackWithRegion(sourceProject);
|
|
85
|
+
sourceGraph.endTransaction();
|
|
86
|
+
const { boxGraph } = project;
|
|
87
|
+
boxGraph.beginTransaction();
|
|
88
|
+
const { trackBox: targetTrack } = createTrackWithRegion(project);
|
|
89
|
+
boxGraph.endTransaction();
|
|
90
|
+
const regionsBefore = targetTrack.regions.pointerHub.incoming().length;
|
|
91
|
+
boxGraph.beginTransaction();
|
|
92
|
+
project.api.copyRegionTo(sourceRegion, targetTrack, 500);
|
|
93
|
+
boxGraph.endTransaction();
|
|
94
|
+
const regionsAfter = targetTrack.regions.pointerHub.incoming();
|
|
95
|
+
expect(regionsAfter.length).toBe(regionsBefore + 1);
|
|
96
|
+
const copiedRegion = regionsAfter.find(vertex => {
|
|
97
|
+
const box = vertex.box;
|
|
98
|
+
return box.position.getValue() === 500;
|
|
99
|
+
});
|
|
100
|
+
expect(copiedRegion).toBeDefined();
|
|
101
|
+
const copiedBox = copiedRegion.box;
|
|
102
|
+
expect(copiedBox.duration.getValue()).toBe(200);
|
|
103
|
+
expect(copiedBox.loopDuration.getValue()).toBe(200);
|
|
104
|
+
expect(UUID.equals(copiedBox.address.uuid, sourceRegion.address.uuid)).toBe(false);
|
|
105
|
+
boxGraph.verifyPointers();
|
|
106
|
+
sourceGraph.verifyPointers();
|
|
107
|
+
sourceProject.terminate();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../src/project/polyfill.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
if (typeof globalThis.localStorage === "undefined") {
|
|
3
|
+
const store = new Map();
|
|
4
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
5
|
+
value: {
|
|
6
|
+
getItem: (key) => store.get(key) ?? null,
|
|
7
|
+
setItem: (key, value) => store.set(key, value),
|
|
8
|
+
removeItem: (key) => store.delete(key),
|
|
9
|
+
clear: () => store.clear(),
|
|
10
|
+
get length() { return store.size; },
|
|
11
|
+
key: (index) => [...store.keys()][index] ?? null
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendaw/studio-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.105",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"@opendaw/studio-forge-boxes": "^0.0.74",
|
|
63
63
|
"@opendaw/typescript-config": "^0.0.28"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "b39d786e60cee02599e0f3d7106e635a870c47c6"
|
|
66
66
|
}
|