@opendaw/studio-core 0.0.49 → 0.0.50
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectUtils.d.ts","sourceRoot":"","sources":["../../src/project/ProjectUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,EAAC,YAAY,EAAgB,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"ProjectUtils.d.ts","sourceRoot":"","sources":["../../src/project/ProjectUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,EAAC,YAAY,EAAgB,MAAM,0BAA0B,CAAA;AACpE,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AAcjC,OAAO,EAEH,YAAY,EAOf,MAAM,uBAAuB,CAAA;AAI9B,yBAAiB,YAAY,CAAC;IAMnB,MAAM,iBAAiB,GAAI,gBAAgB,aAAa,CAAC,YAAY,CAAC,EAC3C,eAAe,OAAO,EACtB,UAAS;QAAE,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAO,KAAG,IAehG,CAAA;IAEM,MAAM,cAAc,GAAI,aAAa,aAAa,CAAC,YAAY,CAAC,EACxC,eAAe,OAAO,EACtB,iBAAgB,IAAU,KAAG,IAkD3D,CAAA;CAmFJ"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { UnionBoxTypes } from "@opendaw/studio-adapters";
|
|
2
2
|
import { Arrays, asInstanceOf, assert, ByteArrayInput, isInstanceOf, SetMultimap, UUID } from "@opendaw/lib-std";
|
|
3
3
|
import { AudioFileBox, AudioUnitBox, AuxSendBox, SelectionBox, SoundfontFileBox, TrackBox } from "@opendaw/studio-boxes";
|
|
4
|
-
import { PointerField } from "@opendaw/lib-box";
|
|
4
|
+
import { IndexedBox, PointerField } from "@opendaw/lib-box";
|
|
5
|
+
import { AudioUnitOrdering } from "../AudioUnitOrdering";
|
|
5
6
|
export var ProjectUtils;
|
|
6
7
|
(function (ProjectUtils) {
|
|
7
8
|
const isSameGraph = ({ graph: a }, { graph: b }) => a === b;
|
|
9
|
+
const compareIndex = (a, b) => a.index.getValue() - b.index.getValue();
|
|
8
10
|
ProjectUtils.extractAudioUnits = (audioUnitBoxes, targetProject, options = {}) => {
|
|
9
11
|
assert(Arrays.satisfy(audioUnitBoxes, isSameGraph), "AudioUnits must share the same BoxGraph");
|
|
10
12
|
// TODO Implement include options.
|
|
@@ -13,39 +15,15 @@ export var ProjectUtils;
|
|
|
13
15
|
const dependencies = audioUnitBoxes
|
|
14
16
|
.flatMap(box => Array.from(box.graph.dependenciesOf(box, { alwaysFollowMandatory: true }).boxes))
|
|
15
17
|
.filter(box => box.name !== SelectionBox.ClassName && box.name !== AuxSendBox.ClassName);
|
|
16
|
-
const uuidMap =
|
|
18
|
+
const uuidMap = generateTransferMap(audioUnitBoxes, dependencies, rootBox.audioUnits.address.uuid, masterBusBox.address.uuid);
|
|
17
19
|
boxGraph.beginTransaction();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
none: () => address,
|
|
21
|
-
some: ({ target }) => address.moveTo(target)
|
|
22
|
-
}))
|
|
23
|
-
}, () => {
|
|
24
|
-
audioUnitBoxes
|
|
25
|
-
.toSorted((a, b) => a.index.getValue() - b.index.getValue())
|
|
26
|
-
.forEach((source, index) => {
|
|
27
|
-
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
28
|
-
const key = source.name;
|
|
29
|
-
const uuid = uuidMap.get(source.address.uuid).target;
|
|
30
|
-
const copy = boxGraph.createBox(key, uuid, box => box.read(input));
|
|
31
|
-
copy.index.setValue(index);
|
|
32
|
-
});
|
|
33
|
-
masterAudioUnit.index.setValue(audioUnitBoxes.length);
|
|
34
|
-
dependencies
|
|
35
|
-
.forEach((source) => {
|
|
36
|
-
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
37
|
-
const key = source.name;
|
|
38
|
-
const uuid = uuidMap.get(source.address.uuid).target;
|
|
39
|
-
boxGraph.createBox(key, uuid, box => box.read(input));
|
|
40
|
-
});
|
|
41
|
-
});
|
|
20
|
+
copy(uuidMap, boxGraph, audioUnitBoxes, dependencies);
|
|
21
|
+
reorderAudioUnits(uuidMap, audioUnitBoxes, rootBox);
|
|
42
22
|
boxGraph.endTransaction();
|
|
43
23
|
boxGraph.verifyPointers();
|
|
44
|
-
console.timeEnd("extractIntoNew");
|
|
45
24
|
};
|
|
46
25
|
ProjectUtils.extractRegions = (regionBoxes, targetProject, insertPosition = 0.0) => {
|
|
47
26
|
assert(Arrays.satisfy(regionBoxes, isSameGraph), "Region smust be from the same BoxGraph");
|
|
48
|
-
const compareIndex = (a, b) => a.index.getValue() - b.index.getValue();
|
|
49
27
|
const regionBoxSet = new Set(regionBoxes);
|
|
50
28
|
const trackBoxSet = new Set();
|
|
51
29
|
const audioUnitBoxSet = new SetMultimap();
|
|
@@ -55,7 +33,6 @@ export var ProjectUtils;
|
|
|
55
33
|
trackBoxSet.add(trackBox);
|
|
56
34
|
const audioUnitBox = asInstanceOf(trackBox.tracks.targetVertex.unwrap().box, AudioUnitBox);
|
|
57
35
|
audioUnitBoxSet.add(audioUnitBox, trackBox);
|
|
58
|
-
console.debug(regionBox, trackBox);
|
|
59
36
|
});
|
|
60
37
|
console.debug(`Found ${audioUnitBoxSet.keyCount()} audioUnits`);
|
|
61
38
|
console.debug(`Found ${trackBoxSet.size} tracks`);
|
|
@@ -66,32 +43,11 @@ export var ProjectUtils;
|
|
|
66
43
|
const dependencies = audioUnitBoxes
|
|
67
44
|
.flatMap(box => Array.from(box.graph.dependenciesOf(box, { excludeBox, alwaysFollowMandatory: true }).boxes))
|
|
68
45
|
.filter(box => box.name !== SelectionBox.ClassName && box.name !== AuxSendBox.ClassName);
|
|
69
|
-
const uuidMap =
|
|
46
|
+
const uuidMap = generateTransferMap(audioUnitBoxes, dependencies, rootBox.audioUnits.address.uuid, masterBusBox.address.uuid);
|
|
70
47
|
boxGraph.beginTransaction();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
some: ({ target }) => address.moveTo(target)
|
|
75
|
-
}))
|
|
76
|
-
}, () => {
|
|
77
|
-
audioUnitBoxes
|
|
78
|
-
.toSorted(compareIndex)
|
|
79
|
-
.forEach((source, index) => {
|
|
80
|
-
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
81
|
-
const key = source.name;
|
|
82
|
-
const uuid = uuidMap.get(source.address.uuid).target;
|
|
83
|
-
const copy = boxGraph.createBox(key, uuid, box => box.read(input));
|
|
84
|
-
copy.index.setValue(index);
|
|
85
|
-
});
|
|
86
|
-
masterAudioUnit.index.setValue(audioUnitBoxes.length);
|
|
87
|
-
dependencies
|
|
88
|
-
.forEach((source) => {
|
|
89
|
-
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
90
|
-
const key = source.name;
|
|
91
|
-
const uuid = uuidMap.get(source.address.uuid).target;
|
|
92
|
-
boxGraph.createBox(key, uuid, box => box.read(input));
|
|
93
|
-
});
|
|
94
|
-
});
|
|
48
|
+
copy(uuidMap, boxGraph, audioUnitBoxes, dependencies);
|
|
49
|
+
reorderAudioUnits(uuidMap, audioUnitBoxes, rootBox);
|
|
50
|
+
// reorder track indices
|
|
95
51
|
audioUnitBoxSet.forEach((_, trackBoxes) => [...trackBoxes]
|
|
96
52
|
.sort(compareIndex)
|
|
97
53
|
.forEach((source, index) => {
|
|
@@ -100,6 +56,7 @@ export var ProjectUtils;
|
|
|
100
56
|
.unwrap("Target Track has not been copied");
|
|
101
57
|
asInstanceOf(box, TrackBox).index.setValue(index);
|
|
102
58
|
}));
|
|
59
|
+
// move new regions to the target position
|
|
103
60
|
const minPosition = regionBoxes.reduce((min, region) => Math.min(min, region.position.getValue()), Number.MAX_VALUE);
|
|
104
61
|
const delta = insertPosition - minPosition;
|
|
105
62
|
regionBoxes.forEach((source) => {
|
|
@@ -112,7 +69,7 @@ export var ProjectUtils;
|
|
|
112
69
|
boxGraph.endTransaction();
|
|
113
70
|
boxGraph.verifyPointers();
|
|
114
71
|
};
|
|
115
|
-
const
|
|
72
|
+
const generateTransferMap = (audioUnitBoxes, dependencies, rootBoxUUID, masterBusBoxUUID) => {
|
|
116
73
|
const uuidMap = UUID.newSet(({ source }) => source);
|
|
117
74
|
uuidMap.addMany([
|
|
118
75
|
...audioUnitBoxes
|
|
@@ -141,4 +98,48 @@ export var ProjectUtils;
|
|
|
141
98
|
]);
|
|
142
99
|
return uuidMap;
|
|
143
100
|
};
|
|
101
|
+
const copy = (uuidMap, boxGraph, audioUnitBoxes, dependencies) => {
|
|
102
|
+
PointerField.decodeWith({
|
|
103
|
+
map: (_pointer, newAddress) => newAddress.map(address => uuidMap.opt(address.uuid).match({
|
|
104
|
+
none: () => address,
|
|
105
|
+
some: ({ target }) => address.moveTo(target)
|
|
106
|
+
}))
|
|
107
|
+
}, () => {
|
|
108
|
+
audioUnitBoxes
|
|
109
|
+
.forEach((source) => {
|
|
110
|
+
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
111
|
+
const key = source.name;
|
|
112
|
+
const uuid = uuidMap.get(source.address.uuid).target;
|
|
113
|
+
boxGraph.createBox(key, uuid, box => box.read(input));
|
|
114
|
+
});
|
|
115
|
+
dependencies
|
|
116
|
+
.forEach((source) => {
|
|
117
|
+
const input = new ByteArrayInput(source.toArrayBuffer());
|
|
118
|
+
const key = source.name;
|
|
119
|
+
const uuid = uuidMap.get(source.address.uuid).target;
|
|
120
|
+
boxGraph.createBox(key, uuid, box => box.read(input));
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const reorderAudioUnits = (uuidMap, audioUnitBoxes, rootBox) => {
|
|
125
|
+
audioUnitBoxes
|
|
126
|
+
.toSorted(compareIndex)
|
|
127
|
+
.forEach((box) => {
|
|
128
|
+
const boxes = IndexedBox.collectIndexedBoxes(rootBox.audioUnits, AudioUnitBox);
|
|
129
|
+
const order = AudioUnitOrdering[box.type.getValue()];
|
|
130
|
+
let index = 0 | 0;
|
|
131
|
+
for (; index < boxes.length; index++) {
|
|
132
|
+
if (AudioUnitOrdering[boxes[index].type.getValue()] > order) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const insertIndex = index;
|
|
137
|
+
while (index < boxes.length) {
|
|
138
|
+
boxes[index].index.setValue(++index);
|
|
139
|
+
}
|
|
140
|
+
asInstanceOf(rootBox.graph
|
|
141
|
+
.findBox(uuidMap.get(box.address.uuid).target)
|
|
142
|
+
.unwrap("Target Track has not been copied"), AudioUnitBox).index.setValue(insertIndex);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
144
145
|
})(ProjectUtils || (ProjectUtils = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendaw/studio-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"test": "vitest run --config vitest.config.ts"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@opendaw/lib-box": "^0.0.
|
|
30
|
-
"@opendaw/lib-dawproject": "^0.0.
|
|
31
|
-
"@opendaw/lib-dom": "^0.0.
|
|
32
|
-
"@opendaw/lib-dsp": "^0.0.
|
|
33
|
-
"@opendaw/lib-fusion": "^0.0.
|
|
34
|
-
"@opendaw/lib-runtime": "^0.0.
|
|
35
|
-
"@opendaw/lib-std": "^0.0.
|
|
36
|
-
"@opendaw/studio-adapters": "^0.0.
|
|
37
|
-
"@opendaw/studio-boxes": "^0.0.
|
|
38
|
-
"@opendaw/studio-enums": "^0.0.
|
|
29
|
+
"@opendaw/lib-box": "^0.0.41",
|
|
30
|
+
"@opendaw/lib-dawproject": "^0.0.27",
|
|
31
|
+
"@opendaw/lib-dom": "^0.0.41",
|
|
32
|
+
"@opendaw/lib-dsp": "^0.0.41",
|
|
33
|
+
"@opendaw/lib-fusion": "^0.0.41",
|
|
34
|
+
"@opendaw/lib-runtime": "^0.0.41",
|
|
35
|
+
"@opendaw/lib-std": "^0.0.41",
|
|
36
|
+
"@opendaw/studio-adapters": "^0.0.42",
|
|
37
|
+
"@opendaw/studio-boxes": "^0.0.41",
|
|
38
|
+
"@opendaw/studio-enums": "^0.0.32",
|
|
39
39
|
"dropbox": "^10.34.0",
|
|
40
40
|
"y-websocket": "^1.4.5",
|
|
41
41
|
"yjs": "^13.6.27",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@ffmpeg/ffmpeg": "^0.12.15",
|
|
50
50
|
"@ffmpeg/util": "^0.12.2",
|
|
51
51
|
"@opendaw/eslint-config": "^0.0.20",
|
|
52
|
-
"@opendaw/studio-core-processors": "^0.0.
|
|
53
|
-
"@opendaw/studio-core-workers": "^0.0.
|
|
54
|
-
"@opendaw/studio-forge-boxes": "^0.0.
|
|
52
|
+
"@opendaw/studio-core-processors": "^0.0.42",
|
|
53
|
+
"@opendaw/studio-core-workers": "^0.0.37",
|
|
54
|
+
"@opendaw/studio-forge-boxes": "^0.0.41",
|
|
55
55
|
"@opendaw/typescript-config": "^0.0.20"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "cc371b41cc7a5a0d3ef9c13f29df42c893374a53"
|
|
58
58
|
}
|