@opendaw/studio-core 0.0.47 → 0.0.49

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.
Files changed (43) hide show
  1. package/dist/AudioOfflineRenderer.d.ts +2 -2
  2. package/dist/AudioOfflineRenderer.d.ts.map +1 -1
  3. package/dist/AudioOfflineRenderer.js +5 -68
  4. package/dist/Engine.d.ts +3 -3
  5. package/dist/Engine.d.ts.map +1 -1
  6. package/dist/EngineFacade.d.ts +2 -2
  7. package/dist/EngineFacade.d.ts.map +1 -1
  8. package/dist/EngineFacade.js +3 -3
  9. package/dist/EngineWorklet.d.ts +1 -1
  10. package/dist/EngineWorklet.d.ts.map +1 -1
  11. package/dist/EngineWorklet.js +9 -5
  12. package/dist/ffmpeg/FFmpegConverter.d.ts +6 -0
  13. package/dist/ffmpeg/FFmpegConverter.d.ts.map +1 -0
  14. package/dist/ffmpeg/FFmpegConverter.js +1 -0
  15. package/dist/ffmpeg/FFmpegWorker.d.ts +18 -0
  16. package/dist/ffmpeg/FFmpegWorker.d.ts.map +1 -0
  17. package/dist/ffmpeg/FFmpegWorker.js +115 -0
  18. package/dist/ffmpeg/flac.d.ts +12 -0
  19. package/dist/ffmpeg/flac.d.ts.map +1 -0
  20. package/dist/ffmpeg/flac.js +32 -0
  21. package/dist/ffmpeg/index.d.ts +3 -0
  22. package/dist/ffmpeg/index.d.ts.map +1 -0
  23. package/dist/ffmpeg/index.js +2 -0
  24. package/dist/ffmpeg/mp3.d.ts +13 -0
  25. package/dist/ffmpeg/mp3.d.ts.map +1 -0
  26. package/dist/ffmpeg/mp3.js +37 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -0
  30. package/dist/processors.js +14 -14
  31. package/dist/processors.js.map +4 -4
  32. package/dist/project/ProjectApi.d.ts +1 -9
  33. package/dist/project/ProjectApi.d.ts.map +1 -1
  34. package/dist/project/ProjectApi.js +3 -67
  35. package/dist/project/ProjectUtils.d.ts +12 -0
  36. package/dist/project/ProjectUtils.d.ts.map +1 -0
  37. package/dist/project/ProjectUtils.js +144 -0
  38. package/dist/project/index.d.ts +1 -0
  39. package/dist/project/index.d.ts.map +1 -1
  40. package/dist/project/index.js +1 -0
  41. package/dist/workers-main.js +2 -2
  42. package/dist/workers-main.js.map +2 -2
  43. package/package.json +21 -15
@@ -3,7 +3,7 @@ import { ppqn } from "@opendaw/lib-dsp";
3
3
  import { Field, PointerField } from "@opendaw/lib-box";
4
4
  import { AudioUnitType, Pointers } from "@opendaw/studio-enums";
5
5
  import { AudioBusBox, AudioUnitBox, NoteEventBox, NoteEventCollectionBox, NoteRegionBox, TrackBox, ValueRegionBox } from "@opendaw/studio-boxes";
6
- import { AnyClipBox, AnyRegionBox, AudioUnitBoxAdapter, EffectPointerType, IconSymbol, IndexedAdapterCollectionListener } from "@opendaw/studio-adapters";
6
+ import { AnyClipBox, AudioUnitBoxAdapter, EffectPointerType, IconSymbol, IndexedAdapterCollectionListener } from "@opendaw/studio-adapters";
7
7
  import { Project } from "./Project";
8
8
  import { InstrumentFactory } from "../InstrumentFactory";
9
9
  import { InstrumentProduct } from "../InstrumentProduct";
@@ -54,13 +54,5 @@ export declare class ProjectApi {
54
54
  createTrackRegion(trackBox: TrackBox, position: ppqn, duration: ppqn, { name, hue }?: ClipRegionOptions): Option<NoteRegionBox> | Option<ValueRegionBox>;
55
55
  createNoteEvent({ owner, position, duration, velocity, pitch, chance, cent }: NoteEventParams): NoteEventBox;
56
56
  deleteAudioUnit(audioUnitBox: AudioUnitBox): void;
57
- extractIntoNew(audioUnits: ReadonlyArray<AudioUnitBox>, option?: {
58
- includeAux?: boolean;
59
- includeBus?: boolean;
60
- }): Project;
61
- mergeInto(...sources: ReadonlyArray<{
62
- source: Project | AnyRegionBox;
63
- insertAt: ppqn;
64
- }>): Promise<void>;
65
57
  }
66
58
  //# sourceMappingURL=ProjectApi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,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G,gBAAgB,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,GAAE,GAA6B,GAAG,QAAQ;IAIlG,qBAAqB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,GAAE,GAA6B,GAAG,QAAQ;IAI3I,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAC,GAAE,iBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC;IAgCvG,gBAAgB,CAAC,EACI,QAAQ,EACR,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,YAAY,EACxB,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,IAAI,EAAE,GAAG,EAClB,EAAE,gBAAgB,GAAG,aAAa;IAoBpD,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAC,IAAI,EAAE,GAAG,EAAC,GAAE,iBAAsB;IAkCzG,eAAe,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAC,EAAE,eAAe,GAAG,YAAY;IAe1G,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;CA2DpD"}
@@ -1,10 +1,9 @@
1
- import { Arrays, asDefined, asInstanceOf, assert, ByteArrayInput, clamp, Option, Strings, UUID } from "@opendaw/lib-std";
1
+ import { asDefined, asInstanceOf, assert, clamp, Option, Strings, UUID } from "@opendaw/lib-std";
2
2
  import { PPQN } from "@opendaw/lib-dsp";
3
- import { IndexedBox, PointerField, StringField } from "@opendaw/lib-box";
3
+ import { IndexedBox, StringField } from "@opendaw/lib-box";
4
4
  import { AudioUnitType } from "@opendaw/studio-enums";
5
- import { AudioBusBox, AudioFileBox, AudioUnitBox, AuxSendBox, CaptureAudioBox, CaptureMidiBox, NoteClipBox, NoteEventBox, NoteEventCollectionBox, NoteRegionBox, SelectionBox, TrackBox, ValueClipBox, ValueEventCollectionBox, ValueRegionBox } from "@opendaw/studio-boxes";
5
+ import { AudioBusBox, AudioUnitBox, CaptureAudioBox, CaptureMidiBox, NoteClipBox, NoteEventBox, NoteEventCollectionBox, NoteRegionBox, TrackBox, ValueClipBox, ValueEventCollectionBox, ValueRegionBox } from "@opendaw/studio-boxes";
6
6
  import { IconSymbol, TrackType } from "@opendaw/studio-adapters";
7
- import { Project } from "./Project";
8
7
  import { ColorCodes } from "../ColorCodes";
9
8
  import { AudioUnitOrdering } from "../AudioUnitOrdering";
10
9
  // noinspection JSUnusedGlobalSymbols
@@ -179,69 +178,6 @@ export class ProjectApi {
179
178
  IndexedBox.removeOrder(rootBox.audioUnits, audioUnitBox.index.getValue());
180
179
  audioUnitBox.delete();
181
180
  }
182
- // This version ignores selected items, buses and aux-sends. All outputs will be redirected to the primary output.
183
- extractIntoNew(audioUnits, option = {}) {
184
- console.time("extractIntoNew");
185
- assert(Arrays.satisfy(audioUnits, (a, b) => a.graph === b.graph), "AudioUnits must share the same BoxGraph");
186
- // TODO Implement include options.
187
- assert(!option.includeAux && !option.includeBus, "Options are not yet implemented");
188
- const targetProject = Project.new(this.#project.env);
189
- const { boxGraph, masterBusBox, masterAudioUnit, rootBox } = targetProject;
190
- const dependencies = audioUnits
191
- .flatMap(box => Array.from(box.graph.dependenciesOf(box).boxes))
192
- .filter(box => box.name !== SelectionBox.ClassName && box.name !== AuxSendBox.ClassName);
193
- const uuidMap = UUID.newSet(({ source }) => source);
194
- const allAdded = uuidMap.addMany([
195
- ...audioUnits
196
- .filter(({ output: { targetAddress } }) => targetAddress.nonEmpty())
197
- .map(box => ({
198
- source: box.output.targetAddress.unwrap().uuid,
199
- target: masterBusBox.address.uuid
200
- })),
201
- ...audioUnits
202
- .map(box => ({
203
- source: box.collection.targetAddress.unwrap("AudioUnitBox was not connect to a RootBox").uuid,
204
- target: rootBox.audioUnits.address.uuid
205
- })),
206
- ...audioUnits
207
- .map(box => ({ source: box.address.uuid, target: UUID.generate() })),
208
- ...dependencies
209
- .map(({ address: { uuid }, name }) => ({ source: uuid, target: name === AudioFileBox.ClassName ? uuid : UUID.generate() }))
210
- ]);
211
- assert(allAdded, "Some mapping are redundant");
212
- boxGraph.beginTransaction();
213
- PointerField.decodeWith({
214
- map: (_pointer, newAddress) => newAddress.map(address => uuidMap.opt(address.uuid).match({
215
- none: () => address,
216
- some: ({ target }) => address.moveTo(target)
217
- }))
218
- }, () => {
219
- audioUnits
220
- .toSorted((a, b) => a.index.getValue() - b.index.getValue())
221
- .forEach((source, index) => {
222
- const input = new ByteArrayInput(source.toArrayBuffer());
223
- const key = source.name;
224
- const uuid = uuidMap.get(source.address.uuid).target;
225
- const copy = boxGraph.createBox(key, uuid, box => box.read(input));
226
- copy.index.setValue(index);
227
- });
228
- masterAudioUnit.index.setValue(audioUnits.length);
229
- dependencies
230
- .forEach((source) => {
231
- const input = new ByteArrayInput(source.toArrayBuffer());
232
- const key = source.name;
233
- const uuid = uuidMap.get(source.address.uuid).target;
234
- boxGraph.createBox(key, uuid, box => box.read(input));
235
- });
236
- });
237
- boxGraph.endTransaction();
238
- boxGraph.verifyPointers();
239
- console.timeEnd("extractIntoNew");
240
- return targetProject;
241
- }
242
- mergeInto(...sources) {
243
- return Promise.reject("Not implemented");
244
- }
245
181
  #createAudioUnit(type, capture, index) {
246
182
  const { boxGraph, rootBox, masterBusBox } = this.#project;
247
183
  const insertIndex = index ?? this.#sortAudioUnitOrdering(type);
@@ -0,0 +1,12 @@
1
+ import { ppqn } from "@opendaw/lib-dsp";
2
+ import { AnyRegionBox } from "@opendaw/studio-adapters";
3
+ import { Project } from "./Project";
4
+ import { AudioUnitBox } from "@opendaw/studio-boxes";
5
+ export declare namespace ProjectUtils {
6
+ const extractAudioUnits: (audioUnitBoxes: ReadonlyArray<AudioUnitBox>, targetProject: Project, options?: {
7
+ includeAux?: boolean;
8
+ includeBus?: boolean;
9
+ }) => void;
10
+ const extractRegions: (regionBoxes: ReadonlyArray<AnyRegionBox>, targetProject: Project, insertPosition?: ppqn) => void;
11
+ }
12
+ //# sourceMappingURL=ProjectUtils.d.ts.map
@@ -0,0 +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;AAYjC,OAAO,EAEH,YAAY,EAMf,MAAM,uBAAuB,CAAA;AAG9B,yBAAiB,YAAY,CAAC;IAKnB,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,IAuChG,CAAA;IAEM,MAAM,cAAc,GAAI,aAAa,aAAa,CAAC,YAAY,CAAC,EACxC,eAAe,OAAO,EACtB,iBAAgB,IAAU,KAAG,IAyE3D,CAAA;CAmCJ"}
@@ -0,0 +1,144 @@
1
+ import { UnionBoxTypes } from "@opendaw/studio-adapters";
2
+ import { Arrays, asInstanceOf, assert, ByteArrayInput, isInstanceOf, SetMultimap, UUID } from "@opendaw/lib-std";
3
+ import { AudioFileBox, AudioUnitBox, AuxSendBox, SelectionBox, SoundfontFileBox, TrackBox } from "@opendaw/studio-boxes";
4
+ import { PointerField } from "@opendaw/lib-box";
5
+ export var ProjectUtils;
6
+ (function (ProjectUtils) {
7
+ const isSameGraph = ({ graph: a }, { graph: b }) => a === b;
8
+ ProjectUtils.extractAudioUnits = (audioUnitBoxes, targetProject, options = {}) => {
9
+ assert(Arrays.satisfy(audioUnitBoxes, isSameGraph), "AudioUnits must share the same BoxGraph");
10
+ // TODO Implement include options.
11
+ assert(!options.includeAux && !options.includeBus, "Options are not yet implemented");
12
+ const { boxGraph, masterBusBox, masterAudioUnit, rootBox } = targetProject;
13
+ const dependencies = audioUnitBoxes
14
+ .flatMap(box => Array.from(box.graph.dependenciesOf(box, { alwaysFollowMandatory: true }).boxes))
15
+ .filter(box => box.name !== SelectionBox.ClassName && box.name !== AuxSendBox.ClassName);
16
+ const uuidMap = generateUUIDMap(audioUnitBoxes, dependencies, rootBox.audioUnits.address.uuid, masterBusBox.address.uuid);
17
+ boxGraph.beginTransaction();
18
+ PointerField.decodeWith({
19
+ map: (_pointer, newAddress) => newAddress.map(address => uuidMap.opt(address.uuid).match({
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
+ });
42
+ boxGraph.endTransaction();
43
+ boxGraph.verifyPointers();
44
+ console.timeEnd("extractIntoNew");
45
+ };
46
+ ProjectUtils.extractRegions = (regionBoxes, targetProject, insertPosition = 0.0) => {
47
+ assert(Arrays.satisfy(regionBoxes, isSameGraph), "Region smust be from the same BoxGraph");
48
+ const compareIndex = (a, b) => a.index.getValue() - b.index.getValue();
49
+ const regionBoxSet = new Set(regionBoxes);
50
+ const trackBoxSet = new Set();
51
+ const audioUnitBoxSet = new SetMultimap();
52
+ // Collect AudioUnits and Tracks
53
+ regionBoxes.forEach(regionBox => {
54
+ const trackBox = asInstanceOf(regionBox.regions.targetVertex.unwrap().box, TrackBox);
55
+ trackBoxSet.add(trackBox);
56
+ const audioUnitBox = asInstanceOf(trackBox.tracks.targetVertex.unwrap().box, AudioUnitBox);
57
+ audioUnitBoxSet.add(audioUnitBox, trackBox);
58
+ console.debug(regionBox, trackBox);
59
+ });
60
+ console.debug(`Found ${audioUnitBoxSet.keyCount()} audioUnits`);
61
+ console.debug(`Found ${trackBoxSet.size} tracks`);
62
+ const audioUnitBoxes = [...audioUnitBoxSet.keys()];
63
+ const { boxGraph, masterBusBox, masterAudioUnit, rootBox } = targetProject;
64
+ const excludeBox = box => (isInstanceOf(box, TrackBox) && !trackBoxSet.has(box))
65
+ || (UnionBoxTypes.isRegionBox(box) && !regionBoxSet.has(box));
66
+ const dependencies = audioUnitBoxes
67
+ .flatMap(box => Array.from(box.graph.dependenciesOf(box, { excludeBox, alwaysFollowMandatory: true }).boxes))
68
+ .filter(box => box.name !== SelectionBox.ClassName && box.name !== AuxSendBox.ClassName);
69
+ const uuidMap = generateUUIDMap(audioUnitBoxes, dependencies, rootBox.audioUnits.address.uuid, masterBusBox.address.uuid);
70
+ boxGraph.beginTransaction();
71
+ PointerField.decodeWith({
72
+ map: (_pointer, newAddress) => newAddress.map(address => uuidMap.opt(address.uuid).match({
73
+ none: () => address,
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
+ });
95
+ audioUnitBoxSet.forEach((_, trackBoxes) => [...trackBoxes]
96
+ .sort(compareIndex)
97
+ .forEach((source, index) => {
98
+ const box = boxGraph
99
+ .findBox(uuidMap.get(source.address.uuid).target)
100
+ .unwrap("Target Track has not been copied");
101
+ asInstanceOf(box, TrackBox).index.setValue(index);
102
+ }));
103
+ const minPosition = regionBoxes.reduce((min, region) => Math.min(min, region.position.getValue()), Number.MAX_VALUE);
104
+ const delta = insertPosition - minPosition;
105
+ regionBoxes.forEach((source) => {
106
+ const box = boxGraph
107
+ .findBox(uuidMap.get(source.address.uuid).target)
108
+ .unwrap("Target Track has not been copied");
109
+ const position = UnionBoxTypes.asRegionBox(box).position;
110
+ position.setValue(position.getValue() + delta);
111
+ });
112
+ boxGraph.endTransaction();
113
+ boxGraph.verifyPointers();
114
+ };
115
+ const generateUUIDMap = (audioUnitBoxes, dependencies, rootBoxUUID, masterBusBoxUUID) => {
116
+ const uuidMap = UUID.newSet(({ source }) => source);
117
+ uuidMap.addMany([
118
+ ...audioUnitBoxes
119
+ .filter(({ output: { targetAddress } }) => targetAddress.nonEmpty())
120
+ .map(box => ({
121
+ source: box.output.targetAddress.unwrap().uuid,
122
+ target: masterBusBoxUUID
123
+ })),
124
+ ...audioUnitBoxes
125
+ .map(box => ({
126
+ source: box.collection.targetAddress.unwrap("AudioUnitBox was not connected to a RootBox").uuid,
127
+ target: rootBoxUUID
128
+ })),
129
+ ...audioUnitBoxes
130
+ .map(box => ({
131
+ source: box.address.uuid,
132
+ target: UUID.generate()
133
+ })),
134
+ ...dependencies
135
+ .map(({ address: { uuid }, name }) => ({
136
+ source: uuid,
137
+ target: name === AudioFileBox.ClassName || name === SoundfontFileBox.ClassName
138
+ ? uuid
139
+ : UUID.generate()
140
+ }))
141
+ ]);
142
+ return uuidMap;
143
+ };
144
+ })(ProjectUtils || (ProjectUtils = {}));
@@ -7,5 +7,6 @@ export * from "./ProjectPaths";
7
7
  export * from "./ProjectProfile";
8
8
  export * from "./ProjectSignals";
9
9
  export * from "./ProjectStorage";
10
+ export * from "./ProjectUtils";
10
11
  export * from "./Recovery";
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/project/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
@@ -7,4 +7,5 @@ export * from "./ProjectPaths";
7
7
  export * from "./ProjectProfile";
8
8
  export * from "./ProjectSignals";
9
9
  export * from "./ProjectStorage";
10
+ export * from "./ProjectUtils";
10
11
  export * from "./Recovery";