@tialro2/rnbokit 1.0.15 → 1.0.18

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/RNBO.svelte CHANGED
@@ -1,230 +1,230 @@
1
- <script>
2
- import './RNBO.css';
3
- import { onMount } from 'svelte';
4
- import rnbo from '@rnbo/js';
5
- const { BaseDevice, createDevice } = rnbo;
6
- import RNBOParam from './RNBOcomponents/RNBOParam.svelte';
7
- import RNBOOutport from './RNBOcomponents/RNBOOutport.svelte';
8
- import RNBOInport from './RNBOcomponents/RNBOInport.svelte';
9
- import RNBOInlet from './RNBOcomponents/RNBOInlet.svelte';
10
- import RNBOMidiIn from './RNBOcomponents/RNBOMidiIn.svelte';
11
- // import RNBOMidiOut from './RNBOcomponents/RNBOMidiOut.svelte';
12
- import path from 'path-browserify';
13
-
14
- // Create AudioContext
15
- /** @type {AudioContext|undefined} */
16
- let context = $state(undefined);
17
-
18
- const loadContext = () => {
19
- // @ts-ignore
20
- let WAContext = window.AudioContext || window.webkitAudioContext;
21
- context = new WAContext({ sampleRate: 44100 });
22
- };
23
-
24
- // Create device
25
-
26
- /** @type {import ('@rnbo/js').IPatcher|undefined} */
27
- let patcher = $state(undefined);
28
-
29
- /** @type {import ('@rnbo/js').ExternalDataInfo[]|undefined} */
30
- let dependencyFileCorrected = $state(undefined);
31
-
32
- /** @typedef {object} signalPort
33
- * @property {number} index - the port index
34
- * @property {string} tag - the tag
35
- * @property {'signal'} type - the type
36
- * @property {string} meta - the meta
37
- */
38
-
39
- /**
40
- * @typedef {Object} Props
41
- * @property {string} [patchName]
42
- * @property {import ('@rnbo/js').Device|undefined} [device]
43
- * @property {import ('@rnbo/js').Parameter[]} [parameters]
44
- * @property {import ('@rnbo/js').MessageInfo[]} [inports]
45
- * @property {signalPort[]} [inlets]
46
- * @property {Array<Number>} [midiOutports]
47
- * @property {import ('@rnbo/js').MessageInfo[]} [outports]
48
- * @property {signalPort[]} [outlets]
49
- * @property {Array<Number>} [midiInports]
50
- * @property {import('svelte').Snippet<[any]>} [children]
51
- */
52
-
53
- /** @type {Props} */
54
- let {
55
- patchName,
56
- device = $bindable(undefined),
57
- parameters = $bindable([]),
58
- inports = $bindable([]),
59
- inlets = $bindable([]),
60
- midiOutports = $bindable([]),
61
- outports = $bindable([]),
62
- outlets = $bindable([]),
63
- midiInports = $bindable([]),
64
- children
65
- } = $props();
66
-
67
- // set up device
68
- const deviceSetup = async () => {
69
- const modules = import.meta.glob('/src/RNBO/export/*'),
70
- exportPath = '/src/RNBO/export/';
71
-
72
- //import the patcher json dynamically!
73
- const patchPath = path.join(exportPath, patchName);
74
- patcher = await modules[patchPath]();
75
-
76
- if (patcher && context) {
77
- //import the dependency json dynamically!
78
- const dependenciesPath = path.join(exportPath, 'dependencies.json');
79
- const dependencyFile = (await modules[dependenciesPath]()).default;
80
-
81
- dependencyFileCorrected = dependencyFile.map((dependency) => {
82
- if (BaseDevice.bufferDescriptionHasRemoteURL(dependency)) {
83
- return dependency;
84
- }
85
- const newFile = path.join(exportPath, dependency.file);
86
- return Object.assign({}, dependency, { file: newFile });
87
- });
88
-
89
- device = await createDevice({ context, patcher });
90
-
91
- //load dependencies if they exist
92
- if (dependencyFileCorrected && dependencyFileCorrected.length) {
93
- device.loadDataBufferDependencies(dependencyFileCorrected);
94
- }
95
- device.node.connect(context.destination);
96
-
97
- parameters = device.parameters;
98
-
99
- inports = device.inports;
100
-
101
- // @ts-expect-error - desc.inlets does indeed exist
102
- inlets = patcher.desc.inlets.filter((inlet) => inlet.type === 'signal');
103
-
104
- midiInports = Array.from({ length: device.numMIDIInputPorts }, (_, i) => i + 1);
105
-
106
- outports = device.outports;
107
-
108
- // @ts-expect-error - desc.outlets does indeed exist
109
- outlets = patcher.desc.outlets.filter((outlet) => outlet.type === 'signal');
110
-
111
- midiOutports = Array.from({ length: device.numMIDIOutputPorts }, (_, i) => i + 1);
112
- } else if (!patcher) {
113
- throw new Error('No patcher found!');
114
- }
115
- if (!context) {
116
- throw new Error('No context found!');
117
- }
118
- };
119
-
120
- // load on client side only (no Window server side)
121
- onMount(async () => {
122
- loadContext();
123
- deviceSetup();
124
- });
125
- </script>
126
-
127
- <!-- html -->
128
- {#if patcher && device && context}
129
- <div
130
- onclick={() => context?.resume()}
131
- onkeydown={() => context?.resume()}
132
- role="button"
133
- tabindex="-2"
134
- >
135
- {#if children}{@render children({
136
- patcher,
137
- device,
138
- dependencyFileCorrected,
139
- parameters,
140
- context,
141
- inports,
142
- inlets,
143
- outports,
144
- outlets,
145
- midiInports,
146
- midiOutports
147
- })}{:else}
148
- <div class="RNBOsection">
149
- <!-- use the json file name as header -->
150
- <h1>patch.export.json</h1>
151
-
152
- <!-- create input for each MIDI input port -->
153
- {#if midiInports.length > 0}
154
- <div class="RNBOsection">
155
- <h2>MIDI inputs</h2>
156
- {#each midiInports as port}
157
- <RNBOMidiIn {port} {device} />
158
- {/each}
159
- </div>
160
- {/if}
161
-
162
- <!-- handle all signal inlets -->
163
- {#if inlets.length > 0}
164
- <div class="RNBOsection">
165
- <h2>signal inlets</h2>
166
- {#each inlets as inlet}
167
- <RNBOInlet {inlet} {device} />
168
- {/each}
169
- </div>
170
- {/if}
171
-
172
- <!-- handle all event inlets -->
173
- {#if inports.length > 0}
174
- <div class="RNBOsection">
175
- <!-- list only the event inlets (skip signal ones) -->
176
- <h2>message inlets</h2>
177
- {#each inports as inport}
178
- <RNBOInport tag={inport.tag} {device} />
179
- {/each}
180
- </div>
181
- {/if}
182
-
183
- <!-- handle all parameters -->
184
- {#if parameters.length > 0}
185
- <div class="RNBOsection">
186
- <h2>parameters</h2>
187
- {#each parameters as parameter}
188
- <RNBOParam {parameter} />
189
- {/each}
190
- </div>
191
- {/if}
192
-
193
- <!-- handle all event outlets -->
194
- {#if outports.length > 0}
195
- <div class="RNBOsection">
196
- <h2>message outlets</h2>
197
- {#each outports as outport}
198
- <RNBOOutport {outport} {device} />
199
- {/each}
200
- </div>
201
- {/if}
202
-
203
- <!-- midi outs not working yet (RNBO bug?????), exclude for now -->
204
- <!-- <div class="RNBOsection">
205
- <h2>MIDI outputs</h2>
206
- {#each Array(device.numMIDIOutputPorts) as _, port}
207
- <RNBOMidiOut {port} {device} />
208
- {/each}
209
- </div> -->
210
- </div>
211
- {/if}
212
- </div>
213
- {:else}
214
- <!-- show a placeholder skeleton when loading -->
215
- <div class="RNBOsection">
216
- <div class="RNBOplaceholder"></div>
217
- <div class="RNBOsection">
218
- <div class="RNBOplaceholder"></div>
219
- <div class="RNBOsection">
220
- <div class="RNBOplaceholder"></div>
221
- </div>
222
- </div>
223
- <div class="RNBOsection">
224
- <div class="RNBOplaceholder"></div>
225
- </div>
226
- <div class="RNBOsection">
227
- <div class="RNBOplaceholder"></div>
228
- </div>
229
- </div>
230
- {/if}
1
+ <script>
2
+ import './RNBO.css';
3
+ import { onMount } from 'svelte';
4
+ import rnbo from '@rnbo/js';
5
+ const { BaseDevice, createDevice } = rnbo;
6
+ import RNBOParam from './RNBOcomponents/RNBOParam.svelte';
7
+ import RNBOOutport from './RNBOcomponents/RNBOOutport.svelte';
8
+ import RNBOInport from './RNBOcomponents/RNBOInport.svelte';
9
+ import RNBOInlet from './RNBOcomponents/RNBOInlet.svelte';
10
+ import RNBOMidiIn from './RNBOcomponents/RNBOMidiIn.svelte';
11
+ // import RNBOMidiOut from './RNBOcomponents/RNBOMidiOut.svelte';
12
+ import path from 'path-browserify';
13
+
14
+ // Create AudioContext
15
+ /** @type {AudioContext|undefined} */
16
+ let context = $state(undefined);
17
+
18
+ const loadContext = () => {
19
+ // @ts-ignore
20
+ let WAContext = window.AudioContext || window.webkitAudioContext;
21
+ context = new WAContext({ sampleRate: 44100 });
22
+ };
23
+
24
+ // Create device
25
+
26
+ /** @type {import ('@rnbo/js').IPatcher|undefined} */
27
+ let patcher = $state(undefined);
28
+
29
+ /** @type {import ('@rnbo/js').ExternalDataInfo[]|undefined} */
30
+ let dependencyFileCorrected = $state(undefined);
31
+
32
+ /** @typedef {object} signalPort
33
+ * @property {number} index - the port index
34
+ * @property {string} tag - the tag
35
+ * @property {'signal'} type - the type
36
+ * @property {string} meta - the meta
37
+ */
38
+
39
+ /**
40
+ * @typedef {Object} Props
41
+ * @property {string} [patchName]
42
+ * @property {import ('@rnbo/js').Device|undefined} [device]
43
+ * @property {import ('@rnbo/js').Parameter[]} [parameters]
44
+ * @property {import ('@rnbo/js').MessageInfo[]} [inports]
45
+ * @property {signalPort[]} [inlets]
46
+ * @property {Array<Number>} [midiOutports]
47
+ * @property {import ('@rnbo/js').MessageInfo[]} [outports]
48
+ * @property {signalPort[]} [outlets]
49
+ * @property {Array<Number>} [midiInports]
50
+ * @property {import('svelte').Snippet<[any]>} [children]
51
+ */
52
+
53
+ /** @type {Props} */
54
+ let {
55
+ patchName,
56
+ device = $bindable(undefined),
57
+ parameters = $bindable([]),
58
+ inports = $bindable([]),
59
+ inlets = $bindable([]),
60
+ midiOutports = $bindable([]),
61
+ outports = $bindable([]),
62
+ outlets = $bindable([]),
63
+ midiInports = $bindable([]),
64
+ children
65
+ } = $props();
66
+
67
+ // set up device
68
+ const deviceSetup = async () => {
69
+ const modules = import.meta.glob('/src/RNBO/export/*'),
70
+ exportPath = '/src/RNBO/export/';
71
+
72
+ //import the patcher json dynamically!
73
+ const patchPath = path.join(exportPath, patchName);
74
+ patcher = await modules[patchPath]();
75
+
76
+ if (patcher && context) {
77
+ //import the dependency json dynamically!
78
+ const dependenciesPath = path.join(exportPath, 'dependencies.json');
79
+ const dependencyFile = (await modules[dependenciesPath]()).default;
80
+
81
+ dependencyFileCorrected = dependencyFile.map((dependency) => {
82
+ if (BaseDevice.bufferDescriptionHasRemoteURL(dependency)) {
83
+ return dependency;
84
+ }
85
+ const newFile = path.join(exportPath, dependency.file);
86
+ return Object.assign({}, dependency, { file: newFile });
87
+ });
88
+
89
+ device = await createDevice({ context, patcher });
90
+
91
+ //load dependencies if they exist
92
+ if (dependencyFileCorrected && dependencyFileCorrected.length) {
93
+ device.loadDataBufferDependencies(dependencyFileCorrected);
94
+ }
95
+ device.node.connect(context.destination);
96
+
97
+ parameters = device.parameters;
98
+
99
+ inports = device.inports;
100
+
101
+ // @ts-expect-error - desc.inlets does indeed exist
102
+ inlets = patcher.desc.inlets.filter((inlet) => inlet.type === 'signal');
103
+
104
+ midiInports = Array.from({ length: device.numMIDIInputPorts }, (_, i) => i + 1);
105
+
106
+ outports = device.outports;
107
+
108
+ // @ts-expect-error - desc.outlets does indeed exist
109
+ outlets = patcher.desc.outlets.filter((outlet) => outlet.type === 'signal');
110
+
111
+ midiOutports = Array.from({ length: device.numMIDIOutputPorts }, (_, i) => i + 1);
112
+ } else if (!patcher) {
113
+ throw new Error('No patcher found!');
114
+ }
115
+ if (!context) {
116
+ throw new Error('No context found!');
117
+ }
118
+ };
119
+
120
+ // load on client side only (no Window server side)
121
+ onMount(async () => {
122
+ loadContext();
123
+ deviceSetup();
124
+ });
125
+ </script>
126
+
127
+ <!-- html -->
128
+ {#if patcher && device && context}
129
+ <div
130
+ onclick={() => context?.resume()}
131
+ onkeydown={() => context?.resume()}
132
+ role="button"
133
+ tabindex="-2"
134
+ >
135
+ {#if children}{@render children({
136
+ patcher,
137
+ device,
138
+ dependencyFileCorrected,
139
+ parameters,
140
+ context,
141
+ inports,
142
+ inlets,
143
+ outports,
144
+ outlets,
145
+ midiInports,
146
+ midiOutports
147
+ })}{:else}
148
+ <div class="RNBOsection">
149
+ <!-- use the json file name as header -->
150
+ <h1>patch.export.json</h1>
151
+
152
+ <!-- create input for each MIDI input port -->
153
+ {#if midiInports.length > 0}
154
+ <div class="RNBOsection">
155
+ <h2>MIDI inputs</h2>
156
+ {#each midiInports as port}
157
+ <RNBOMidiIn {port} {device} />
158
+ {/each}
159
+ </div>
160
+ {/if}
161
+
162
+ <!-- handle all signal inlets -->
163
+ {#if inlets.length > 0}
164
+ <div class="RNBOsection">
165
+ <h2>signal inlets</h2>
166
+ {#each inlets as inlet}
167
+ <RNBOInlet {inlet} {device} />
168
+ {/each}
169
+ </div>
170
+ {/if}
171
+
172
+ <!-- handle all event inlets -->
173
+ {#if inports.length > 0}
174
+ <div class="RNBOsection">
175
+ <!-- list only the event inlets (skip signal ones) -->
176
+ <h2>message inlets</h2>
177
+ {#each inports as inport}
178
+ <RNBOInport tag={inport.tag} {device} />
179
+ {/each}
180
+ </div>
181
+ {/if}
182
+
183
+ <!-- handle all parameters -->
184
+ {#if parameters.length > 0}
185
+ <div class="RNBOsection">
186
+ <h2>parameters</h2>
187
+ {#each parameters as parameter}
188
+ <RNBOParam {parameter} />
189
+ {/each}
190
+ </div>
191
+ {/if}
192
+
193
+ <!-- handle all event outlets -->
194
+ {#if outports.length > 0}
195
+ <div class="RNBOsection">
196
+ <h2>message outlets</h2>
197
+ {#each outports as outport}
198
+ <RNBOOutport {outport} {device} />
199
+ {/each}
200
+ </div>
201
+ {/if}
202
+
203
+ <!-- midi outs not working yet (RNBO bug?????), exclude for now -->
204
+ <!-- <div class="RNBOsection">
205
+ <h2>MIDI outputs</h2>
206
+ {#each Array(device.numMIDIOutputPorts) as _, port}
207
+ <RNBOMidiOut {port} {device} />
208
+ {/each}
209
+ </div> -->
210
+ </div>
211
+ {/if}
212
+ </div>
213
+ {:else}
214
+ <!-- show a placeholder skeleton when loading -->
215
+ <div class="RNBOsection">
216
+ <div class="RNBOplaceholder"></div>
217
+ <div class="RNBOsection">
218
+ <div class="RNBOplaceholder"></div>
219
+ <div class="RNBOsection">
220
+ <div class="RNBOplaceholder"></div>
221
+ </div>
222
+ </div>
223
+ <div class="RNBOsection">
224
+ <div class="RNBOplaceholder"></div>
225
+ </div>
226
+ <div class="RNBOsection">
227
+ <div class="RNBOplaceholder"></div>
228
+ </div>
229
+ </div>
230
+ {/if}