@tialro2/rnbokit 1.0.0
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/README.md +243 -0
- package/dist/RNBO.css +113 -0
- package/dist/RNBO.svelte +230 -0
- package/dist/RNBO.svelte.d.ts +97 -0
- package/dist/RNBOcomponents/AudioDropIn.svelte +133 -0
- package/dist/RNBOcomponents/AudioDropIn.svelte.d.ts +17 -0
- package/dist/RNBOcomponents/ExtMidiIn.svelte +93 -0
- package/dist/RNBOcomponents/ExtMidiIn.svelte.d.ts +13 -0
- package/dist/RNBOcomponents/ExtMidiOut.svelte +93 -0
- package/dist/RNBOcomponents/ExtMidiOut.svelte.d.ts +13 -0
- package/dist/RNBOcomponents/MicIn.svelte +88 -0
- package/dist/RNBOcomponents/MicIn.svelte.d.ts +17 -0
- package/dist/RNBOcomponents/RNBOInlet.svelte +66 -0
- package/dist/RNBOcomponents/RNBOInlet.svelte.d.ts +55 -0
- package/dist/RNBOcomponents/RNBOInport.svelte +21 -0
- package/dist/RNBOcomponents/RNBOInport.svelte.d.ts +13 -0
- package/dist/RNBOcomponents/RNBOMidiIn.svelte +63 -0
- package/dist/RNBOcomponents/RNBOMidiIn.svelte.d.ts +31 -0
- package/dist/RNBOcomponents/RNBOMidiOut.svelte +38 -0
- package/dist/RNBOcomponents/RNBOMidiOut.svelte.d.ts +27 -0
- package/dist/RNBOcomponents/RNBOOutport.svelte +36 -0
- package/dist/RNBOcomponents/RNBOOutport.svelte.d.ts +21 -0
- package/dist/RNBOcomponents/RNBOParam.svelte +37 -0
- package/dist/RNBOcomponents/RNBOParam.svelte.d.ts +15 -0
- package/dist/RNBOcomponents/XYMidiIn.svelte +101 -0
- package/dist/RNBOcomponents/XYMidiIn.svelte.d.ts +17 -0
- package/dist/UIcomponents/Controls.svelte +12 -0
- package/dist/UIcomponents/Controls.svelte.d.ts +7 -0
- package/dist/UIcomponents/FileDropZone.svelte +118 -0
- package/dist/UIcomponents/FileDropZone.svelte.d.ts +37 -0
- package/dist/UIcomponents/ProgressBar.svelte +50 -0
- package/dist/UIcomponents/ProgressBar.svelte.d.ts +17 -0
- package/dist/UIcomponents/RadioGroup.svelte +35 -0
- package/dist/UIcomponents/RadioGroup.svelte.d.ts +13 -0
- package/dist/UIcomponents/RadioItem.svelte +96 -0
- package/dist/UIcomponents/RadioItem.svelte.d.ts +21 -0
- package/dist/UIcomponents/RangeSlider.svelte +38 -0
- package/dist/UIcomponents/RangeSlider.svelte.d.ts +21 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +20 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<img width="493" alt="Screenshot 2023-11-24 at 15 43 41" src="static/sreenshot.jpeg">
|
|
2
|
+
|
|
3
|
+
# RNBOKit
|
|
4
|
+
|
|
5
|
+
An easily extendable Sveltekit component library for seamlessly importing Cycling74's Max RNBO~ patches into your Svelte app.
|
|
6
|
+
|
|
7
|
+
## Disclaimer
|
|
8
|
+
|
|
9
|
+
~ warning #1: this package is still work in progress ~
|
|
10
|
+
|
|
11
|
+
~ warning #2: this is my very first library & open source project, mistakes are bound to be made, so please do correct me on any mistake or practice I can do better! ~
|
|
12
|
+
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
First set up a [Sveltekit project](https://kit.svelte.dev/docs/quick-start).
|
|
16
|
+
|
|
17
|
+
Once you've created and installed your project add RNBOKit to your packages
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install rnbokit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or using pnpm:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm install rnbokit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Using RNBOKit in your project
|
|
30
|
+
|
|
31
|
+
To start running RNBO patches in your Sveltekit project, you will need to export your RNBO~ patch for the web.
|
|
32
|
+
|
|
33
|
+
<img width="597" alt="Screenshot 2023-05-26 at 17 20 39" src="https://github.com/SanderNotenbaert/RNBOKit/assets/34664737/c48b537f-79a1-4a4f-beef-cc5bf72addfc">
|
|
34
|
+
|
|
35
|
+
It will create a folder which contains a .JSON file. You can export it directly into your project directory.
|
|
36
|
+
|
|
37
|
+
<img width="567" alt="Screenshot 2023-05-26 at 17 22 03" src="https://github.com/SanderNotenbaert/RNBOKit/assets/34664737/534588d2-7bfe-4fa3-b686-3a2d5dca54d4">
|
|
38
|
+
|
|
39
|
+
By default the <RNBO> component will look for a `patch.export.json` file in a `src/RNBO/` folder. For each inport, you have to provide a PNG file with the same name as the inport in the `static` directory (e.g. the file `in2.png` for an inport with the tag `in2`).
|
|
40
|
+
Next you will need to import the RNBO component into your `+page.svelte` file.
|
|
41
|
+
|
|
42
|
+
```svelte
|
|
43
|
+
<script>
|
|
44
|
+
import { RNBO } from 'rnbokit';
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<RNBO />
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This is enough to start running the RNBO patch in your Sveltekit project. It will generate all the parameters and visualise any number messages from the outlet (0.-1.)
|
|
51
|
+
|
|
52
|
+
## extending with custom slots
|
|
53
|
+
|
|
54
|
+
You can customize how parameters or messages are handled by adding your own components in the RNBO tag. You can pass information from the RNBO component down to the child components by using Svelte's `let:` syntax. Some available objects are `dependencyFileCorrected` (ExternalDataInfo[]), `context` (AudioContext), `device` (Device), or `parameters` (Parameter[]). You can find more information on these in the [RNBO JS documentation](https://rnbo.cycling74.com/js).
|
|
55
|
+
|
|
56
|
+
```svelte
|
|
57
|
+
<script>
|
|
58
|
+
import { RNBO, RNBOParam } from 'rnbokit';
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<RNBO let:parameters>
|
|
62
|
+
{#each parameters as parameter}
|
|
63
|
+
<!-- create custom components -->
|
|
64
|
+
<p>{parameter.name}</p>
|
|
65
|
+
<p>{parameter.value}</p>
|
|
66
|
+
<!-- or use the included UI components -->
|
|
67
|
+
<RNBOParam {parameter} />
|
|
68
|
+
{/each}
|
|
69
|
+
</RNBO>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Here is the full list of all available variables:
|
|
73
|
+
|
|
74
|
+
```svelte
|
|
75
|
+
<script>
|
|
76
|
+
import { RNBO } from 'rnbokit';
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<RNBO let:device <!-- type: Device - the device object, check RNBO js documentation -->
|
|
80
|
+
let:dependencyFileCorrected <!-- type: ExternalDataInfo[] - represents the json with dependencies of the patch, check RNBO js documentation -->
|
|
81
|
+
let:parameters <!-- type: Parameter[] - an array containing all RNBO parameters, check RNBO js documentation -->
|
|
82
|
+
let:context <!-- type: AudioContext - the audio context, see https://developer.mozilla.org/Web/API/AudioContext -->
|
|
83
|
+
let:inports <!-- type: MessageInfo[] - an array of objects containing info on each message inlet -->
|
|
84
|
+
let:inlets <!-- type: signalPort[] - an array of objects containing info on each signal inlet -->
|
|
85
|
+
let:outports <!-- type: MessageInfo[] - an array of objects containing info on each message outlet -->
|
|
86
|
+
let:outlets <!-- type: signalPort[] - an array of objects containing info on each signal outlet -->
|
|
87
|
+
let:midiInports <!-- type: Array<Number> - an array representing each midiInport as an index number -->
|
|
88
|
+
let:midiOutports <!-- type: Array<Number> - an array representing each midiOutport as an index number -->
|
|
89
|
+
>
|
|
90
|
+
<!-- do something with it here -->
|
|
91
|
+
</RNBO>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
In order to be able to change parameter values or send messages to inlets with custom parameter components, you'll need to bind `parameters` or `device` in the `<RNBO\>` component to a declared variable in the top level script. To control the value, bind the value of your own component to it as well.
|
|
95
|
+
|
|
96
|
+
```svelte
|
|
97
|
+
<script>
|
|
98
|
+
import { RNBO } from 'rnbokit';
|
|
99
|
+
//this example uses JSDoc for typing
|
|
100
|
+
/** @type {import ('@rnbo/js').Parameter[]} */
|
|
101
|
+
let patchParams;
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<RNBO bind:parameters={patchParams}>
|
|
105
|
+
<div class="slidecontainer">
|
|
106
|
+
<input
|
|
107
|
+
type="range"
|
|
108
|
+
min={patchParams[1].min}
|
|
109
|
+
max={patchParams[1].max}
|
|
110
|
+
id={patchParams[1].name}
|
|
111
|
+
bind:value={patchParams[1].value}
|
|
112
|
+
class="RNBOslider"
|
|
113
|
+
/>
|
|
114
|
+
<p class="RNBOval">{patchParams[1].value}</p>
|
|
115
|
+
</div>
|
|
116
|
+
</RNBO>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Available components
|
|
120
|
+
|
|
121
|
+
### RNBO specific components
|
|
122
|
+
|
|
123
|
+
Here is the list of available RNBO components, to be used as slots of the `<RNBO>` component:
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { RNBOParam } from 'rnbokit'; //required props: {parameters}
|
|
127
|
+
import { RNBOInport } from 'rnbokit'; //required props: {inport} {device} - optional props: {min}, {max}
|
|
128
|
+
import { RNBOOutport } from 'rnbokit'; //required props: {outport} {device} - optional props: {min}, {max}
|
|
129
|
+
import { RNBOInlet } from 'rnbokit'; //required props: {inlet} {device} - optional props: {mode} options: 'mic', 'dropIn'
|
|
130
|
+
import { RNBOMidiIn } from 'rnbokit'; //required props: {port} {device} - optional props: {mode} options: 'xy', 'external'
|
|
131
|
+
//not working, RNBO bug
|
|
132
|
+
//import { RNBOMidiOut } from 'rnbokit'; //required props: {port} {device}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Utility components
|
|
136
|
+
|
|
137
|
+
These are some internally used utility components which are not dependent on RNBO:
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
import { AudioDropIn } from 'rnbokit';
|
|
141
|
+
import { MicIn } from 'rnbokit';
|
|
142
|
+
import { XYMidiIn } from 'rnbokit';
|
|
143
|
+
import { ExtMidiIn } from 'rnbokit';
|
|
144
|
+
// work in progress
|
|
145
|
+
// import { ExtMidiOut } from 'rnbokit';
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### UI components
|
|
149
|
+
|
|
150
|
+
Internally used UI components, that can also be reused in different contexts:
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
import { FileDropZone } from 'rnbokit';
|
|
154
|
+
import { ProgressBar } from 'rnbokit';
|
|
155
|
+
import { Radiogroup, RadioItem } from 'rnbokit';
|
|
156
|
+
import { RangeSlider } from 'rnbokit';
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Styling
|
|
160
|
+
|
|
161
|
+
The default styling is done with the internal RNBO.css stylesheet. If you want to change really fundamental styling you can edit/replace that one, but you can also simply declare the following css variables in your own global stylesheet:
|
|
162
|
+
|
|
163
|
+
```css
|
|
164
|
+
:root {
|
|
165
|
+
/* =~= Theme Properties =~= */
|
|
166
|
+
--theme-font-family: system-ui;
|
|
167
|
+
--theme-rounded-base: 9999px;
|
|
168
|
+
--theme-rounded-container: 6px;
|
|
169
|
+
--theme-border-base: 1px;
|
|
170
|
+
/* =~= Color Properties =~= */
|
|
171
|
+
--theme-accent-color: 39, 145, 142;
|
|
172
|
+
--theme-surface-color: 38, 38, 38;
|
|
173
|
+
--theme-bg-color: 255, 255, 255;
|
|
174
|
+
--theme-font-color-base: 38, 38, 38;
|
|
175
|
+
/* =~= Animation Properties =~= */
|
|
176
|
+
--theme-animation-duration: 0.1s;
|
|
177
|
+
--theme-animation: all;
|
|
178
|
+
--theme-animation-function: ease-out;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Defaults
|
|
183
|
+
|
|
184
|
+
Here is what it could look like if you'd recreate the RNBO component's default slot, for inspiration:
|
|
185
|
+
|
|
186
|
+
```svelte
|
|
187
|
+
<RNBO let:device let:midiInports let:inlets let:inports let:parameters let:outports>
|
|
188
|
+
<div class="RNBOsection">
|
|
189
|
+
<h1>patch.export.json</h1>
|
|
190
|
+
|
|
191
|
+
<!-- create input for each MIDI input port -->
|
|
192
|
+
{#if midiInports.length > 0}
|
|
193
|
+
<div class="RNBOsection">
|
|
194
|
+
<h2>MIDI inputs</h2>
|
|
195
|
+
{#each midiInports as port}
|
|
196
|
+
<RNBOMidiIn {port} {device} />
|
|
197
|
+
{/each}
|
|
198
|
+
</div>
|
|
199
|
+
{/if}
|
|
200
|
+
|
|
201
|
+
<!-- handle all signal inlets -->
|
|
202
|
+
{#if inlets.length > 0}
|
|
203
|
+
<div class="RNBOsection">
|
|
204
|
+
<h2>signal inlets</h2>
|
|
205
|
+
{#each inlets as inlet}
|
|
206
|
+
<RNBOInlet {inlet} {device} />
|
|
207
|
+
{/each}
|
|
208
|
+
</div>
|
|
209
|
+
{/if}
|
|
210
|
+
|
|
211
|
+
<!-- handle all event inlets -->
|
|
212
|
+
{#if inports.length > 0}
|
|
213
|
+
<div class="RNBOsection">
|
|
214
|
+
<!-- list only the event inlets (skip signal ones) -->
|
|
215
|
+
<h2>message inlets</h2>
|
|
216
|
+
{#each inports as inport}
|
|
217
|
+
<RNBOInport {inport.tag} {device} />
|
|
218
|
+
{/each}
|
|
219
|
+
</div>
|
|
220
|
+
{/if}
|
|
221
|
+
|
|
222
|
+
<!-- handle all parameters -->
|
|
223
|
+
{#if parameters.length > 0}
|
|
224
|
+
<div class="RNBOsection">
|
|
225
|
+
<h2>parameters</h2>
|
|
226
|
+
{#each parameters as parameter}
|
|
227
|
+
<RNBOParam {parameter} />
|
|
228
|
+
{/each}
|
|
229
|
+
</div>
|
|
230
|
+
{/if}
|
|
231
|
+
|
|
232
|
+
<!-- handle all event outlets -->
|
|
233
|
+
{#if outports.length > 0}
|
|
234
|
+
<div class="RNBOsection">
|
|
235
|
+
<h2>outport events</h2>
|
|
236
|
+
{#each outports as outport}
|
|
237
|
+
<RNBOOutport {outport} {device} />
|
|
238
|
+
{/each}
|
|
239
|
+
</div>
|
|
240
|
+
{/if}
|
|
241
|
+
</div>
|
|
242
|
+
</RNBO>
|
|
243
|
+
```
|
package/dist/RNBO.css
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* RNBO.css */
|
|
2
|
+
body {
|
|
3
|
+
font-family: var(--local-font-family);
|
|
4
|
+
color: rgb(var(--local-font-color));
|
|
5
|
+
accent-color: rgb(var(--local-accent-color));
|
|
6
|
+
background-color: rgb(var(--local-bg-color));
|
|
7
|
+
}
|
|
8
|
+
h1 {
|
|
9
|
+
/* @apply text-4xl p-2 m-2 font-bold; */
|
|
10
|
+
font-size: 2.25rem; /* 36px */
|
|
11
|
+
line-height: 2.5rem; /* 40px */
|
|
12
|
+
font-weight: 700;
|
|
13
|
+
padding: 0.5rem;
|
|
14
|
+
margin: 0.5rem;
|
|
15
|
+
}
|
|
16
|
+
h2 {
|
|
17
|
+
/* @apply text-2xl p-2 m-2 font-bold; */
|
|
18
|
+
font-size: 1.5rem; /* 24px */
|
|
19
|
+
line-height: 2rem; /* 32px */
|
|
20
|
+
font-weight: 700;
|
|
21
|
+
padding: 0.5rem;
|
|
22
|
+
margin: 0.5rem;
|
|
23
|
+
}
|
|
24
|
+
.RNBOtext {
|
|
25
|
+
/* @apply p-2 m-2; */
|
|
26
|
+
padding-top: 0.5rem;
|
|
27
|
+
padding-bottom: 0.5rem;
|
|
28
|
+
margin-top: 0.5rem;
|
|
29
|
+
margin-bottom: 0.5rem;
|
|
30
|
+
}
|
|
31
|
+
.RNBOsection {
|
|
32
|
+
box-shadow: 0 0 0.1rem rgba(0, 0, 0, 0.5);
|
|
33
|
+
padding: 1rem;
|
|
34
|
+
margin: 1rem;
|
|
35
|
+
border-radius: var(--local-rounded-container);
|
|
36
|
+
background-image: linear-gradient(rgb(0 0 0/5%) 0 0);
|
|
37
|
+
}
|
|
38
|
+
.RNBOcomponent {
|
|
39
|
+
/* @apply p-2 m-2; */
|
|
40
|
+
padding: 1rem;
|
|
41
|
+
margin: 1rem;
|
|
42
|
+
}
|
|
43
|
+
.RNBOsubcomponent {
|
|
44
|
+
/* @apply p-2 m-2; */
|
|
45
|
+
padding-top: 0.5rem;
|
|
46
|
+
padding-bottom: 0.5rem;
|
|
47
|
+
margin-top: 0.5rem;
|
|
48
|
+
margin-bottom: 0.5rem;
|
|
49
|
+
}
|
|
50
|
+
.RNBOtag {
|
|
51
|
+
/* @apply font-bold; */
|
|
52
|
+
font-weight: 700;
|
|
53
|
+
padding-top: 0.25rem;
|
|
54
|
+
padding-bottom: 0.25rem;
|
|
55
|
+
margin-top: 0.25rem;
|
|
56
|
+
margin-bottom: 0.25rem;
|
|
57
|
+
}
|
|
58
|
+
.RNBOval {
|
|
59
|
+
/* @apply text-xs; */
|
|
60
|
+
font-size: 0.75rem; /* 12px */
|
|
61
|
+
line-height: 1rem; /* 16px */
|
|
62
|
+
}
|
|
63
|
+
.RNBOalign {
|
|
64
|
+
/* @apply flex justify-between items-center */
|
|
65
|
+
display: flex;
|
|
66
|
+
justify-content: space-between;
|
|
67
|
+
align-items: center;
|
|
68
|
+
padding-top: 0.5rem;
|
|
69
|
+
padding-bottom: 0.5rem;
|
|
70
|
+
margin-top: 0.5rem;
|
|
71
|
+
margin-bottom: 0.5rem;
|
|
72
|
+
}
|
|
73
|
+
.RNBOslider {
|
|
74
|
+
width: 100%;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
/* transition: var(--local-animation) var(--local-animation-duration); */
|
|
77
|
+
/* transition-timing-function: var(--local-animation-function); */
|
|
78
|
+
}
|
|
79
|
+
.RNBOplaceholder {
|
|
80
|
+
background-color: rgba(var(--local-surface-color), 0.2);
|
|
81
|
+
border-radius: var(--local-rounded-base);
|
|
82
|
+
height: 2rem;
|
|
83
|
+
padding: 0.5rem;
|
|
84
|
+
margin: 0.5rem;
|
|
85
|
+
animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@keyframes pulse {
|
|
89
|
+
0%,
|
|
90
|
+
100% {
|
|
91
|
+
opacity: 1;
|
|
92
|
+
}
|
|
93
|
+
50% {
|
|
94
|
+
opacity: 0.5;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
:root {
|
|
98
|
+
/* =~= Theme Properties =~= */
|
|
99
|
+
--local-font-family: var(--theme-font-family, system-ui);
|
|
100
|
+
/* --theme-font-color-dark: 255 255 255; */
|
|
101
|
+
--local-rounded-base: var(--theme-rounded-base, 20px);
|
|
102
|
+
--local-rounded-container: var(--theme-rounded-container, 6px);
|
|
103
|
+
--local-border-base: var(--theme-border-base, 1px);
|
|
104
|
+
/* =~= Color Properties =~= */
|
|
105
|
+
--local-accent-color: var(--theme-accent-color, 39, 145, 142);
|
|
106
|
+
--local-surface-color: var(--theme-surface-color, 38, 38, 38);
|
|
107
|
+
--local-bg-color: var(--theme-bg-color, 255, 255, 255);
|
|
108
|
+
--local-font-color: var(--theme-font-color-base, 38, 38, 38);
|
|
109
|
+
/* =~= Animation Properties =~= */
|
|
110
|
+
--local-animation-duration: var(--theme-animation-duration, 0.1s);
|
|
111
|
+
--local-animation: var(--theme-animation, all);
|
|
112
|
+
--local-animation-function: var(--theme-animation-function, ease-out);
|
|
113
|
+
}
|
package/dist/RNBO.svelte
ADDED
|
@@ -0,0 +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}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export default RNBO;
|
|
2
|
+
type RNBO = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<Props>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const RNBO: import("svelte").Component<{
|
|
7
|
+
patchName?: string;
|
|
8
|
+
device?: import("@rnbo/js").Device | undefined;
|
|
9
|
+
parameters?: import("@rnbo/js").Parameter[];
|
|
10
|
+
inports?: import("@rnbo/js").MessageInfo[];
|
|
11
|
+
inlets?: {
|
|
12
|
+
/**
|
|
13
|
+
* - the port index
|
|
14
|
+
*/
|
|
15
|
+
index: number;
|
|
16
|
+
/**
|
|
17
|
+
* - the tag
|
|
18
|
+
*/
|
|
19
|
+
tag: string;
|
|
20
|
+
/**
|
|
21
|
+
* - the type
|
|
22
|
+
*/
|
|
23
|
+
type: "signal";
|
|
24
|
+
/**
|
|
25
|
+
* - the meta
|
|
26
|
+
*/
|
|
27
|
+
meta: string;
|
|
28
|
+
}[];
|
|
29
|
+
midiOutports?: Array<number>;
|
|
30
|
+
outports?: import("@rnbo/js").MessageInfo[];
|
|
31
|
+
outlets?: {
|
|
32
|
+
/**
|
|
33
|
+
* - the port index
|
|
34
|
+
*/
|
|
35
|
+
index: number;
|
|
36
|
+
/**
|
|
37
|
+
* - the tag
|
|
38
|
+
*/
|
|
39
|
+
tag: string;
|
|
40
|
+
/**
|
|
41
|
+
* - the type
|
|
42
|
+
*/
|
|
43
|
+
type: "signal";
|
|
44
|
+
/**
|
|
45
|
+
* - the meta
|
|
46
|
+
*/
|
|
47
|
+
meta: string;
|
|
48
|
+
}[];
|
|
49
|
+
midiInports?: Array<number>;
|
|
50
|
+
children?: import("svelte").Snippet<[any]>;
|
|
51
|
+
}, {}, "device" | "inports" | "parameters" | "inlets" | "midiOutports" | "outports" | "outlets" | "midiInports">;
|
|
52
|
+
type Props = {
|
|
53
|
+
patchName?: string;
|
|
54
|
+
device?: import("@rnbo/js").Device | undefined;
|
|
55
|
+
parameters?: import("@rnbo/js").Parameter[];
|
|
56
|
+
inports?: import("@rnbo/js").MessageInfo[];
|
|
57
|
+
inlets?: {
|
|
58
|
+
/**
|
|
59
|
+
* - the port index
|
|
60
|
+
*/
|
|
61
|
+
index: number;
|
|
62
|
+
/**
|
|
63
|
+
* - the tag
|
|
64
|
+
*/
|
|
65
|
+
tag: string;
|
|
66
|
+
/**
|
|
67
|
+
* - the type
|
|
68
|
+
*/
|
|
69
|
+
type: "signal";
|
|
70
|
+
/**
|
|
71
|
+
* - the meta
|
|
72
|
+
*/
|
|
73
|
+
meta: string;
|
|
74
|
+
}[];
|
|
75
|
+
midiOutports?: Array<number>;
|
|
76
|
+
outports?: import("@rnbo/js").MessageInfo[];
|
|
77
|
+
outlets?: {
|
|
78
|
+
/**
|
|
79
|
+
* - the port index
|
|
80
|
+
*/
|
|
81
|
+
index: number;
|
|
82
|
+
/**
|
|
83
|
+
* - the tag
|
|
84
|
+
*/
|
|
85
|
+
tag: string;
|
|
86
|
+
/**
|
|
87
|
+
* - the type
|
|
88
|
+
*/
|
|
89
|
+
type: "signal";
|
|
90
|
+
/**
|
|
91
|
+
* - the meta
|
|
92
|
+
*/
|
|
93
|
+
meta: string;
|
|
94
|
+
}[];
|
|
95
|
+
midiInports?: Array<number>;
|
|
96
|
+
children?: import("svelte").Snippet<[any]>;
|
|
97
|
+
};
|