An easily extendable Sveltekit component library for seamlessly importing Cycling74's Max RNBO~ patches into your Svelte app.
~ warning #1: this package is still work in progress ~
~ 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! ~
First set up a Sveltekit project.
Once you've created and installed your project add RNBOKit to your packages
npm install rnbokit
Or using pnpm:
pnpm install rnbokit
To start running RNBO patches in your Sveltekit project, you will need to export your RNBO~ patch for the web.
![Screenshot 2023-05-26 at 17 20 39](https://private-user-images.githubusercontent.com/34664737/241957293-c48b537f-79a1-4a4f-beef-cc5bf72addfc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3MDE3MTQsIm5iZiI6MTcyNTcwMTQxNCwicGF0aCI6Ii8zNDY2NDczNy8yNDE5NTcyOTMtYzQ4YjUzN2YtNzlhMS00YTRmLWJlZWYtY2M1YmY3MmFkZGZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDA5MzAxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxNWFhZjMxYzA1NTVjZjY3YjVkYTk4ZTlkN2Q2NTFiNGMwYzZiYzRkYWYzYzJhNjM3M2ZkYTIzNTBiYjM1YjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.APLklyaE6TmkQvwYzaBxEqyd2Rmy-JODtbUrKob8akQ)
It will create a folder which contains a .JSON file. You can export it directly into your project directory.
![Screenshot 2023-05-26 at 17 22 03](https://private-user-images.githubusercontent.com/34664737/241958967-534588d2-7bfe-4fa3-b686-3a2d5dca54d4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3MDE3MTQsIm5iZiI6MTcyNTcwMTQxNCwicGF0aCI6Ii8zNDY2NDczNy8yNDE5NTg5NjctNTM0NTg4ZDItN2JmZS00ZmEzLWI2ODYtM2EyZDVkY2E1NGQ0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDA5MzAxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNkNGZiMmQyNTYwYzhhMmNlYmViNWY4M2JmMTE4MzJkMGJiMDQ4NjE5NjI2YWNkYzMzMmM0NTgyYzY1YzI2NzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DvE2mZSg9sccYh8dCBucbYxqUZ3GrM6vyPN4efKOSz4)
By default the 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
).
Next you will need to import the RNBO component into your +page.svelte
file.
<script>
import { RNBO } from 'rnbokit';
</script>
<RNBO />
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.)
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.
<script>
import { RNBO, RNBOParam } from 'rnbokit';
</script>
<RNBO let:parameters>
{#each parameters as parameter}
<!-- create custom components -->
<p>{parameter.name}</p>
<p>{parameter.value}</p>
<!-- or use the included UI components -->
<RNBOParam {parameter} />
{/each}
</RNBO>
Here is the full list of all available variables:
<script>
import { RNBO } from 'rnbokit';
</script>
<RNBO let:device <!-- type: Device - the device object, check RNBO js documentation -->
let:dependencyFileCorrected <!-- type: ExternalDataInfo[] - represents the json with dependencies of the patch, check RNBO js documentation -->
let:parameters <!-- type: Parameter[] - an array containing all RNBO parameters, check RNBO js documentation -->
let:context <!-- type: AudioContext - the audio context, see https://developer.mozilla.org/Web/API/AudioContext -->
let:inports <!-- type: MessageInfo[] - an array of objects containing info on each message inlet -->
let:inlets <!-- type: signalPort[] - an array of objects containing info on each signal inlet -->
let:outports <!-- type: MessageInfo[] - an array of objects containing info on each message outlet -->
let:outlets <!-- type: signalPort[] - an array of objects containing info on each signal outlet -->
let:midiInports <!-- type: Array<Number> - an array representing each midiInport as an index number -->
let:midiOutports <!-- type: Array<Number> - an array representing each midiOutport as an index number -->
>
<!-- do something with it here -->
</RNBO>
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.
<script>
import { RNBO } from 'rnbokit';
//this example uses JSDoc for typing
/** @type {import ('@rnbo/js').Parameter[]} */
let patchParams;
</script>
<RNBO bind:parameters={patchParams}>
<div class="slidecontainer">
<input
type="range"
min={patchParams[1].min}
max={patchParams[1].max}
id={patchParams[1].name}
bind:value={patchParams[1].value}
class="RNBOslider"
/>
<p class="RNBOval">{patchParams[1].value}</p>
</div>
</RNBO>
Here is the list of available RNBO components, to be used as slots of the <RNBO>
component:
import { RNBOParam } from 'rnbokit'; //required props: {parameters}
import { RNBOInport } from 'rnbokit'; //required props: {inport} {device} - optional props: {min}, {max}
import { RNBOOutport } from 'rnbokit'; //required props: {outport} {device} - optional props: {min}, {max}
import { RNBOInlet } from 'rnbokit'; //required props: {inlet} {device} - optional props: {mode} options: 'mic', 'dropIn'
import { RNBOMidiIn } from 'rnbokit'; //required props: {port} {device} - optional props: {mode} options: 'xy', 'external'
//not working, RNBO bug
//import { RNBOMidiOut } from 'rnbokit'; //required props: {port} {device}
These are some internally used utility components which are not dependent on RNBO:
import { AudioDropIn } from 'rnbokit';
import { MicIn } from 'rnbokit';
import { XYMidiIn } from 'rnbokit';
import { ExtMidiIn } from 'rnbokit';
// work in progress
// import { ExtMidiOut } from 'rnbokit';
Internally used UI components, that can also be reused in different contexts:
import { FileDropZone } from 'rnbokit';
import { ProgressBar } from 'rnbokit';
import { Radiogroup, RadioItem } from 'rnbokit';
import { RangeSlider } from 'rnbokit';
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:
:root {
/* =~= Theme Properties =~= */
--theme-font-family: system-ui;
--theme-rounded-base: 9999px;
--theme-rounded-container: 6px;
--theme-border-base: 1px;
/* =~= Color Properties =~= */
--theme-accent-color: 39, 145, 142;
--theme-surface-color: 38, 38, 38;
--theme-bg-color: 255, 255, 255;
--theme-font-color-base: 38, 38, 38;
/* =~= Animation Properties =~= */
--theme-animation-duration: 0.1s;
--theme-animation: all;
--theme-animation-function: ease-out;
}
Here is what it could look like if you'd recreate the RNBO component's default slot, for inspiration:
<RNBO let:device let:midiInports let:inlets let:inports let:parameters let:outports>
<div class="RNBOsection">
<h1>patch.export.json</h1>
<!-- create input for each MIDI input port -->
{#if midiInports.length > 0}
<div class="RNBOsection">
<h2>MIDI inputs</h2>
{#each midiInports as port}
<RNBOMidiIn {port} {device} />
{/each}
</div>
{/if}
<!-- handle all signal inlets -->
{#if inlets.length > 0}
<div class="RNBOsection">
<h2>signal inlets</h2>
{#each inlets as inlet}
<RNBOInlet {inlet} {device} />
{/each}
</div>
{/if}
<!-- handle all event inlets -->
{#if inports.length > 0}
<div class="RNBOsection">
<!-- list only the event inlets (skip signal ones) -->
<h2>message inlets</h2>
{#each inports as inport}
<RNBOInport {inport.tag} {device} />
{/each}
</div>
{/if}
<!-- handle all parameters -->
{#if parameters.length > 0}
<div class="RNBOsection">
<h2>parameters</h2>
{#each parameters as parameter}
<RNBOParam {parameter} />
{/each}
</div>
{/if}
<!-- handle all event outlets -->
{#if outports.length > 0}
<div class="RNBOsection">
<h2>outport events</h2>
{#each outports as outport}
<RNBOOutport {outport} {device} />
{/each}
</div>
{/if}
</div>
</RNBO>