@opendaw/studio-core 0.0.9 → 0.0.10

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.
@@ -0,0 +1,35 @@
1
+ import { NanoDeviceBox, PlayfieldDeviceBox, TapeDeviceBox, TrackBox, VaporisateurDeviceBox } from "@opendaw/studio-boxes";
2
+ import { BoxGraph } from "@opendaw/lib-box";
3
+ import { DeviceHost, IconSymbol } from "@opendaw/studio-adapters";
4
+ import { Project } from "./Project";
5
+ export declare namespace Instruments {
6
+ interface Factory {
7
+ defaultName: string;
8
+ icon: IconSymbol;
9
+ description: string;
10
+ createDevice: (boxGraph: BoxGraph, deviceHost: DeviceHost, name: string, icon: IconSymbol) => DeviceBox;
11
+ createTrack: (boxGraph: BoxGraph, deviceHost: DeviceHost) => TrackBox;
12
+ }
13
+ type CreationOptions = {
14
+ name?: string;
15
+ icon?: IconSymbol;
16
+ };
17
+ type DeviceBox = TapeDeviceBox | VaporisateurDeviceBox | NanoDeviceBox | PlayfieldDeviceBox;
18
+ type FactoryResult = {
19
+ device: DeviceBox;
20
+ track: TrackBox;
21
+ };
22
+ const Tape: Factory;
23
+ const Nano: Factory;
24
+ const Playfield: Factory;
25
+ const Vaporisateur: Factory;
26
+ const create: (project: Project, factory: Factory, { name, icon }?: CreationOptions) => FactoryResult;
27
+ const Named: {
28
+ Vaporisateur: Factory;
29
+ Playfield: Factory;
30
+ Nano: Factory;
31
+ Tape: Factory;
32
+ };
33
+ type Keys = keyof typeof Named;
34
+ }
35
+ //# sourceMappingURL=Instruments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Instruments.d.ts","sourceRoot":"","sources":["../src/Instruments.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,QAAQ,EACR,qBAAqB,EACxB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AAEzC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+ import { Strings, UUID } from "@opendaw/lib-std";
3
+ import { Waveform } from "@opendaw/lib-dsp";
4
+ import { AudioUnitType } from "@opendaw/studio-enums";
5
+ import { AudioUnitBoxAdapter, IconSymbol, TrackType } from "@opendaw/studio-adapters";
6
+ import { Modifier } from "./Modifier";
7
+ export var Instruments;
8
+ (function (Instruments) {
9
+ const useFile = (boxGraph, fileUUID, name) => boxGraph.findBox(fileUUID)
10
+ .unwrapOrElse(() => AudioFileBox.create(boxGraph, fileUUID, box => {
11
+ box.fileName.setValue(name);
12
+ }));
13
+ Instruments.Tape = {
14
+ defaultName: "Tape",
15
+ icon: IconSymbol.Tape,
16
+ description: "Plays audio regions & clips",
17
+ createDevice: (boxGraph, deviceHost, name, icon) => TapeDeviceBox.create(boxGraph, UUID.generate(), box => {
18
+ box.label.setValue(name);
19
+ box.icon.setValue(IconSymbol.toName(icon));
20
+ box.flutter.setValue(0.2);
21
+ box.wow.setValue(0.05);
22
+ box.noise.setValue(0.02);
23
+ box.saturation.setValue(0.5);
24
+ box.host.refer(deviceHost.inputField);
25
+ }),
26
+ createTrack: (boxGraph, deviceHost) => TrackBox.create(boxGraph, UUID.generate(), box => {
27
+ box.index.setValue(0);
28
+ box.type.setValue(TrackType.Audio);
29
+ box.tracks.refer(deviceHost.tracksField);
30
+ box.target.refer(deviceHost.audioUnitBoxAdapter().box);
31
+ })
32
+ };
33
+ Instruments.Nano = {
34
+ defaultName: "Nano",
35
+ icon: IconSymbol.NanoWave,
36
+ description: "Simple Sampler",
37
+ createDevice: (boxGraph, deviceHost, name, icon) => {
38
+ const fileUUID = UUID.parse("c1678daa-4a47-4cba-b88f-4f4e384663c3");
39
+ const audioFileBox = boxGraph.findBox(fileUUID)
40
+ .unwrapOrElse(() => AudioFileBox.create(boxGraph, fileUUID, box => {
41
+ box.fileName.setValue("Rhode");
42
+ }));
43
+ return NanoDeviceBox.create(boxGraph, UUID.generate(), box => {
44
+ box.label.setValue(name);
45
+ box.icon.setValue(IconSymbol.toName(icon));
46
+ box.file.refer(audioFileBox);
47
+ box.host.refer(deviceHost.inputField);
48
+ });
49
+ },
50
+ createTrack: (boxGraph, deviceHost) => TrackBox.create(boxGraph, UUID.generate(), box => {
51
+ box.index.setValue(0);
52
+ box.type.setValue(TrackType.Notes);
53
+ box.tracks.refer(deviceHost.tracksField);
54
+ box.target.refer(deviceHost.audioUnitBoxAdapter().box);
55
+ })
56
+ };
57
+ Instruments.Playfield = {
58
+ defaultName: "Playfield",
59
+ icon: IconSymbol.Playfield,
60
+ description: "Drumcomputer",
61
+ createDevice: (boxGraph, deviceHost, name, icon) => {
62
+ const deviceBox = PlayfieldDeviceBox.create(boxGraph, UUID.generate(), box => {
63
+ box.label.setValue(name);
64
+ box.icon.setValue(IconSymbol.toName(icon));
65
+ box.host.refer(deviceHost.inputField);
66
+ });
67
+ const files = [
68
+ useFile(boxGraph, UUID.parse("8bb2c6e8-9a6d-4d32-b7ec-1263594ef367"), "909 Bassdrum"),
69
+ useFile(boxGraph, UUID.parse("0017fa18-a5eb-4d9d-b6f2-e2ddd30a3010"), "909 Snare"),
70
+ useFile(boxGraph, UUID.parse("28d14cb9-1dc6-4193-9dd7-4e881f25f520"), "909 Low Tom"),
71
+ useFile(boxGraph, UUID.parse("21f92306-d6e7-446c-a34b-b79620acfefc"), "909 Mid Tom"),
72
+ useFile(boxGraph, UUID.parse("ad503883-8a72-46ab-a05b-a84149953e17"), "909 High Tom"),
73
+ useFile(boxGraph, UUID.parse("cfee850b-7658-4d08-9e3b-79d196188504"), "909 Rimshot"),
74
+ useFile(boxGraph, UUID.parse("32a6f36f-06eb-4b84-bb57-5f51103eb9e6"), "909 Clap"),
75
+ useFile(boxGraph, UUID.parse("e0ac4b39-23fb-4a56-841d-c9e0ff440cab"), "909 Closed Hat"),
76
+ useFile(boxGraph, UUID.parse("51c5eea4-391c-4743-896a-859692ec1105"), "909 Open Hat"),
77
+ useFile(boxGraph, UUID.parse("42a56ff6-89b6-4f2e-8a66-5a41d316f4cb"), "909 Crash"),
78
+ useFile(boxGraph, UUID.parse("87cde966-b799-4efc-a994-069e703478d3"), "909 Ride")
79
+ ];
80
+ const samples = files.map((file, index) => PlayfieldSampleBox.create(boxGraph, UUID.generate(), box => {
81
+ box.device.refer(deviceBox.samples);
82
+ box.file.refer(file);
83
+ box.index.setValue(60 + index);
84
+ }));
85
+ samples[7].exclude.setValue(true);
86
+ samples[8].exclude.setValue(true);
87
+ return deviceBox;
88
+ },
89
+ createTrack: (boxGraph, deviceHost) => TrackBox.create(boxGraph, UUID.generate(), box => {
90
+ box.index.setValue(0);
91
+ box.type.setValue(TrackType.Notes);
92
+ box.tracks.refer(deviceHost.tracksField);
93
+ box.target.refer(deviceHost.audioUnitBoxAdapter().box);
94
+ })
95
+ };
96
+ Instruments.Vaporisateur = {
97
+ defaultName: "Vaporisateur",
98
+ icon: IconSymbol.Piano,
99
+ description: "Classic subtractive synthesizer",
100
+ createDevice: (boxGraph, deviceHost, name, icon) => VaporisateurDeviceBox.create(boxGraph, UUID.generate(), box => {
101
+ box.label.setValue(name);
102
+ box.icon.setValue(IconSymbol.toName(icon));
103
+ box.tune.setInitValue(0.0);
104
+ box.cutoff.setInitValue(1000.0);
105
+ box.resonance.setInitValue(0.1);
106
+ box.attack.setInitValue(0.005);
107
+ box.release.setInitValue(0.1);
108
+ box.waveform.setInitValue(Waveform.sine);
109
+ box.host.refer(deviceHost.inputField);
110
+ }),
111
+ createTrack: (boxGraph, deviceHost) => TrackBox.create(boxGraph, UUID.generate(), box => {
112
+ box.index.setValue(0);
113
+ box.type.setValue(TrackType.Notes);
114
+ box.tracks.refer(deviceHost.tracksField);
115
+ box.target.refer(deviceHost.audioUnitBoxAdapter().box);
116
+ })
117
+ };
118
+ Instruments.create = (project, factory, { name, icon } = {}) => {
119
+ const { boxGraph, boxAdapters, rootBoxAdapter, userEditingManager } = project;
120
+ const existingNames = rootBoxAdapter.audioUnits.adapters()
121
+ .map(adapter => adapter.input.getValue().match({
122
+ none: () => "Untitled",
123
+ some: adapter => adapter.labelField.getValue()
124
+ }));
125
+ const audioUnitBox = Modifier.createAudioUnit(project, AudioUnitType.Instrument);
126
+ const audioUnitBoxAdapter = boxAdapters.adapterFor(audioUnitBox, AudioUnitBoxAdapter);
127
+ const uniqueName = Strings.getUniqueName(existingNames, name ?? factory.defaultName);
128
+ const iconSymbol = icon ?? factory.icon;
129
+ const device = factory.createDevice(boxGraph, audioUnitBoxAdapter, uniqueName, iconSymbol);
130
+ const track = factory.createTrack(boxGraph, audioUnitBoxAdapter);
131
+ userEditingManager.audioUnit.edit(audioUnitBox.editing);
132
+ return { device, track };
133
+ };
134
+ Instruments.Named = { Vaporisateur: Instruments.Vaporisateur, Playfield: Instruments.Playfield, Nano: Instruments.Nano, Tape: Instruments.Tape };
135
+ })(Instruments || (Instruments = {}));
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from "./Effects";
12
12
  export * from "./Engine";
13
13
  export * from "./EngineFacade";
14
14
  export * from "./EngineWorklet";
15
+ export * from "./Instruments";
15
16
  export * from "./Mixer";
16
17
  export * from "./Modifier";
17
18
  export * from "./Project";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,0BAA0B,CAAA;AAExC,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,OAAO,CAAA;AACrB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AAExC,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,0BAA0B,CAAA;AAExC,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA;AAC5B,cAAc,OAAO,CAAA;AACrB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ export * from "./Effects";
12
12
  export * from "./Engine";
13
13
  export * from "./EngineFacade";
14
14
  export * from "./EngineWorklet";
15
+ export * from "./Instruments";
15
16
  export * from "./Mixer";
16
17
  export * from "./Modifier";
17
18
  export * from "./Project";