mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-13 22:35:15 -04:00
Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d94f145649 | |||
| bf3fe605d9 | |||
| 54ebc97ddc | |||
| c689874bb4 | |||
| 23d4bfa9d9 | |||
| 91eb50f1c1 | |||
| 5838ade740 | |||
| 917d01c47d | |||
| 0a51718df3 | |||
| 774372a339 | |||
| 626a99ba5b | |||
| 8c3ee6db6b | |||
| c5c05ebadc | |||
| a8918d55fb | |||
| a9957b45e5 | |||
| 4bd103e612 | |||
| 466234bad6 | |||
| 97beaec25a | |||
| 2b3b638943 | |||
| e1629e8383 | |||
| 266cb614a8 | |||
| dfc4a0818c | |||
| 236ff577a6 | |||
| 66a32ac45d | |||
| 8b2c35b7a3 | |||
| f8f42565ae | |||
| 96981c3c1d | |||
| bd8d207a3d | |||
| e3741ae8fa | |||
| ef87f65bef | |||
| d3d9f23c3c | |||
| c474b8c92e | |||
| da81ba00fb | |||
| 28c94efaa9 | |||
| 0633954e24 | |||
| cedf09168f | |||
| 3373225f53 | |||
| 1eb9dc73fa | |||
| fdcdc3aaa0 | |||
| da926805b3 | |||
| 82893ffc22 | |||
| beafd9c700 | |||
| c5bd2a7487 | |||
| 118086aff5 | |||
| 452827630b | |||
| 86248328cc | |||
| 8833d623f7 | |||
| 3fff4609a0 | |||
| e2b5b92a0c | |||
| 1c3e07afd3 | |||
| c54fa7d266 | |||
| a25f763796 | |||
| 91ad3d729f | |||
| 4cb0488839 | |||
| 663229ecde | |||
| cdb623cb66 | |||
| 28d7e0e489 | |||
| aba594b72a | |||
| 5d7c6c3e4b | |||
| 820744dc27 | |||
| 5445f0812f | |||
| a68c784753 | |||
| f2b2f9f959 | |||
| 53dd53553a | |||
| 89b7eac789 | |||
| 9cdba1a50e | |||
| 98b7003504 | |||
| 9a8f8a051c | |||
| 3eb40ee7d3 | |||
| 46a45b4596 | |||
| 1205573bc6 | |||
| fe46e1da53 | |||
| d1869c18ba | |||
| 02cd79a6d9 |
+234
-27
@@ -87,6 +87,239 @@ export function registerControl(names, ...aliases) {
|
||||
*/
|
||||
export const { s, sound } = registerControl(['s', 'n', 'gain'], 'sound');
|
||||
|
||||
/**
|
||||
* Position in the wavetable of the wavetable oscillator
|
||||
*
|
||||
* @name wt
|
||||
* @param {number | Pattern} position Position in the wavetable from 0 to 1
|
||||
* @synonyms wavetablePosition
|
||||
* @example
|
||||
* s("squelch").bank("wt_digital").seg(8).note("F1").wt("0 0.25 0.5 0.75 1")
|
||||
*/
|
||||
export const { wt, wavetablePosition } = registerControl('wt', 'wavetablePosition');
|
||||
|
||||
/**
|
||||
* Amount of envelope applied wavetable oscillator's position envelope
|
||||
*
|
||||
* @name wtenv
|
||||
* @param {number | Pattern} amount between 0 and 1
|
||||
*/
|
||||
export const { wtenv } = registerControl('wtenv');
|
||||
/**
|
||||
* Attack time of the wavetable oscillator's position envelope
|
||||
*
|
||||
* @name wtattack
|
||||
* @synonyms wtatt
|
||||
* @param {number | Pattern} time attack time in seconds
|
||||
*/
|
||||
export const { wtattack, wtatt } = registerControl('wtattack', 'wtatt');
|
||||
|
||||
/**
|
||||
* Decay time of the wavetable oscillator's position envelope
|
||||
*
|
||||
* @name wtdecay
|
||||
* @synonyms wtdec
|
||||
* @param {number | Pattern} time decay time in seconds
|
||||
*/
|
||||
export const { wtdecay, wtdec } = registerControl('wtdecay', 'wtdec');
|
||||
|
||||
/**
|
||||
* Sustain time of the wavetable oscillator's position envelope
|
||||
*
|
||||
* @name wtsustain
|
||||
* @synonyms wtsus
|
||||
* @param {number | Pattern} gain sustain level (0 to 1)
|
||||
*/
|
||||
export const { wtsustain, wtsus } = registerControl('wtsustain', 'wtsus');
|
||||
|
||||
/**
|
||||
* Release time of the wavetable oscillator's position envelope
|
||||
*
|
||||
* @name wtrelease
|
||||
* @synonyms wtrel
|
||||
* @param {number | Pattern} time release time in seconds
|
||||
*/
|
||||
export const { wtrelease, wtrel } = registerControl('wtrelease', 'wtrel');
|
||||
|
||||
/**
|
||||
* Rate of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtrate
|
||||
* @param {number | Pattern} rate rate in hertz
|
||||
*/
|
||||
export const { wtrate } = registerControl('wtrate');
|
||||
/**
|
||||
* cycle synced rate of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtsync
|
||||
* @param {number | Pattern} rate rate in cycles
|
||||
*/
|
||||
export const { wtsync } = registerControl('wtsync');
|
||||
|
||||
/**
|
||||
* Depth of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtdepth
|
||||
* @param {number | Pattern} depth depth of modulation
|
||||
*/
|
||||
export const { wtdepth } = registerControl('wtdepth');
|
||||
|
||||
/**
|
||||
* Shape of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtshape
|
||||
* @param {number | Pattern} shape Shape of the lfo (0, 1, 2, ..)
|
||||
*/
|
||||
export const { wtshape } = registerControl('wtshape');
|
||||
|
||||
/**
|
||||
* DC offset of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtdc
|
||||
* @param {number | Pattern} dcoffset dc offset. set to 0 for unipolar
|
||||
*/
|
||||
export const { wtdc } = registerControl('wtdc');
|
||||
|
||||
/**
|
||||
* Skew of the LFO for the wavetable oscillator's position
|
||||
*
|
||||
* @name wtskew
|
||||
* @param {number | Pattern} skew How much to bend the LFO shape
|
||||
*/
|
||||
export const { wtskew } = registerControl('wtskew');
|
||||
|
||||
/**
|
||||
* Amount of warp (alteration of the waveform) to apply to the wavetable oscillator
|
||||
*
|
||||
* @name warp
|
||||
* @param {number | Pattern} amount Warp of the wavetable from 0 to 1
|
||||
* @synonyms wavetableWarp
|
||||
* @example
|
||||
* s("basique").bank("wt_digital").seg(8).note("F1").warp("0 0.25 0.5 0.75 1")
|
||||
* .warpmode("spin")
|
||||
*/
|
||||
export const { warp, wavetableWarp } = registerControl('warp', 'wavetableWarp');
|
||||
|
||||
/**
|
||||
* Attack time of the wavetable oscillator's warp envelope
|
||||
*
|
||||
* @name warpattack
|
||||
* @synonyms warpatt
|
||||
* @param {number | Pattern} time attack time in seconds
|
||||
*/
|
||||
export const { warpattack, warpatt } = registerControl('warpattack', 'warpatt');
|
||||
|
||||
/**
|
||||
* Decay time of the wavetable oscillator's warp envelope
|
||||
*
|
||||
* @name warpdecay
|
||||
* @synonyms warpdec
|
||||
* @param {number | Pattern} time decay time in seconds
|
||||
*/
|
||||
export const { warpdecay, warpdec } = registerControl('warpdecay', 'warpdec');
|
||||
|
||||
/**
|
||||
* Sustain time of the wavetable oscillator's warp envelope
|
||||
*
|
||||
* @name warpsustain
|
||||
* @synonyms warpsus
|
||||
* @param {number | Pattern} gain sustain level (0 to 1)
|
||||
*/
|
||||
export const { warpsustain, warpsus } = registerControl('warpsustain', 'warpsus');
|
||||
|
||||
/**
|
||||
* Release time of the wavetable oscillator's warp envelope
|
||||
*
|
||||
* @name warprelease
|
||||
* @synonyms warprel
|
||||
* @param {number | Pattern} time release time in seconds
|
||||
*/
|
||||
export const { warprelease, warprel } = registerControl('warprelease', 'warprel');
|
||||
|
||||
/**
|
||||
* Rate of the LFO for the wavetable oscillator's warp
|
||||
*
|
||||
* @name warprate
|
||||
* @param {number | Pattern} rate rate in hertz
|
||||
*/
|
||||
export const { warprate } = registerControl('warprate');
|
||||
|
||||
/**
|
||||
* Depth of the LFO for the wavetable oscillator's warp
|
||||
*
|
||||
* @name warpdepth
|
||||
* @param {number | Pattern} depth depth of modulation
|
||||
*/
|
||||
export const { warpdepth } = registerControl('warpdepth');
|
||||
|
||||
/**
|
||||
* Shape of the LFO for the wavetable oscillator's warp
|
||||
*
|
||||
* @name warpshape
|
||||
* @param {number | Pattern} shape Shape of the lfo (0, 1, 2, ..)
|
||||
*/
|
||||
export const { warpshape } = registerControl('warpshape');
|
||||
|
||||
/**
|
||||
* DC offset of the LFO for the wavetable oscillator's warp
|
||||
*
|
||||
* @name warpdc
|
||||
* @param {number | Pattern} dcoffset dc offset. set to 0 for unipolar
|
||||
*/
|
||||
export const { warpdc } = registerControl('warpdc');
|
||||
|
||||
/**
|
||||
* Skew of the LFO for the wavetable oscillator's warp
|
||||
*
|
||||
* @name warpskew
|
||||
* @param {number | Pattern} skew How much to bend the LFO shape
|
||||
*/
|
||||
export const { warpskew } = registerControl('warpskew');
|
||||
|
||||
/**
|
||||
* Type of warp (alteration of the waveform) to apply to the wavetable oscillator.
|
||||
*
|
||||
* The current options are: none, asym, bendp, bendm, bendmp, sync, quant, fold, pwm, orbit,
|
||||
* spin, chaos, primes, binary, brownian, reciprocal, wormhole, logistic, sigmoid, fractal, flip
|
||||
*
|
||||
* @name warpmode
|
||||
* @param {number | string | Pattern} mode Warp mode
|
||||
* @synonyms wavetableWarpMode
|
||||
* @example
|
||||
* s("morgana").bank("wt_digital").seg(8).note("F1").warp("0 0.25 0.5 0.75 1")
|
||||
* .warpmode("<asym bendp spin logistic sync wormhole brownian>*2")
|
||||
*
|
||||
*/
|
||||
export const { warpmode, wavetableWarpMode } = registerControl('warpmode', 'wavetableWarpMode');
|
||||
|
||||
/**
|
||||
* Amount of randomness of the initial phase of the wavetable oscillator.
|
||||
*
|
||||
* @name wtphaserand
|
||||
* @param {number | Pattern} amount Randomness of the initial phase. Between 0 (not random) and 1 (fully random)
|
||||
* @synonyms wavetablePhaseRand
|
||||
* @example
|
||||
* s("basique").bank("wt_digital").seg(16).wtphaserand("<0 1>")
|
||||
*
|
||||
*/
|
||||
export const { wtphaserand, wavetablePhaseRand } = registerControl('wtphaserand', 'wavetablePhaseRand');
|
||||
|
||||
/**
|
||||
* Amount of envelope applied wavetable oscillator's position envelope
|
||||
*
|
||||
* @name warpenv
|
||||
* @param {number | Pattern} amount between 0 and 1
|
||||
*/
|
||||
export const { warpenv } = registerControl('warpenv');
|
||||
|
||||
/**
|
||||
* cycle synced rate of the LFO for the wavetable warp position
|
||||
*
|
||||
* @name warpsync
|
||||
* @param {number | Pattern} rate rate in cycles
|
||||
*/
|
||||
export const { warpsync } = registerControl('warpsync');
|
||||
|
||||
/**
|
||||
* Define a custom webaudio node to use as a sound source.
|
||||
*
|
||||
@@ -413,32 +646,6 @@ export const { begin } = registerControl('begin');
|
||||
*
|
||||
*/
|
||||
export const { end } = registerControl('end');
|
||||
/**
|
||||
* the offset of the sample buffer in seconds
|
||||
*
|
||||
* @memberof Pattern
|
||||
* @name beginSeconds
|
||||
* @param {number | Pattern} seconds
|
||||
* @example
|
||||
* samples('github:switchangel/pad')
|
||||
* s("swpad!4").clip(1).beginSeconds("2 5 .2 3").fast(2)
|
||||
* @example
|
||||
* samples('github:switchangel/pad')
|
||||
* $: s("swpad!16").beginseconds(time).dec(.1)
|
||||
*
|
||||
*/
|
||||
export const { beginSeconds, beginseconds } = registerControl('beginSeconds', 'beginseconds');
|
||||
/**
|
||||
* The end of the sample buffer in seconds
|
||||
*
|
||||
* @memberof Pattern
|
||||
* @name endSeconds
|
||||
* @param {number | Pattern} seconds
|
||||
* @example
|
||||
* s("bd*2,oh*4").endSeconds("<.1 .05 .2 1>").fast(2)
|
||||
*
|
||||
*/
|
||||
export const { endSeconds, endseconds } = registerControl('endSeconds', 'endseconds');
|
||||
/**
|
||||
* Loops the sample.
|
||||
* Note that the tempo of the loop is not synced with the cycle tempo.
|
||||
@@ -1154,7 +1361,7 @@ export const { resonance, lpq } = registerControl('resonance', 'lpq');
|
||||
* @name djf
|
||||
* @param {number | Pattern} cutoff below 0.5 is low pass filter, above is high pass filter
|
||||
* @example
|
||||
* n("0 3 7 [10,24]").s('superzow').octave(3).djf("<.5 .25 .5 .75>").osc()
|
||||
* n(irand(16).seg(8)).scale("d:phrygian").s("supersaw").djf("<.5 .3 .2 .75>")
|
||||
*
|
||||
*/
|
||||
export const { djf } = registerControl('djf');
|
||||
|
||||
@@ -126,6 +126,8 @@ export const lcm = (...fractions) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const isFraction = (x) => x instanceof Fraction;
|
||||
|
||||
fraction._original = Fraction;
|
||||
|
||||
export default fraction;
|
||||
|
||||
@@ -5,8 +5,9 @@ let debounce = 1000,
|
||||
lastTime;
|
||||
|
||||
export function errorLogger(e, origin = 'cyclist') {
|
||||
//TODO: add some kind of debug flag that enables this while in dev mode
|
||||
// console.error(e);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.error(e);
|
||||
}
|
||||
logger(`[${origin}] error: ${e.message}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import TimeSpan from './timespan.mjs';
|
||||
import Fraction, { lcm } from './fraction.mjs';
|
||||
import Fraction, { isFraction, lcm } from './fraction.mjs';
|
||||
import Hap from './hap.mjs';
|
||||
import State from './state.mjs';
|
||||
import { unionWithObj } from './value.mjs';
|
||||
@@ -999,7 +999,7 @@ addToPrototype('weaveWith', function (t, ...funcs) {
|
||||
// compose matrix functions
|
||||
|
||||
function _nonArrayObject(x) {
|
||||
return !Array.isArray(x) && typeof x === 'object';
|
||||
return !Array.isArray(x) && typeof x === 'object' && !isFraction(x);
|
||||
}
|
||||
function _composeOp(a, b, func) {
|
||||
if (_nonArrayObject(a) || _nonArrayObject(b)) {
|
||||
|
||||
+16
-2
@@ -74,6 +74,14 @@ export function repl({
|
||||
return silence;
|
||||
};
|
||||
|
||||
// helper to get a patternified pure value out
|
||||
function unpure(pat) {
|
||||
if (pat._Pattern) {
|
||||
return pat.__pure;
|
||||
}
|
||||
return pat;
|
||||
}
|
||||
|
||||
const setPattern = async (pattern, autostart = true) => {
|
||||
pattern = editPattern?.(pattern) || pattern;
|
||||
await scheduler.setPattern(pattern, autostart);
|
||||
@@ -85,7 +93,10 @@ export function repl({
|
||||
const start = () => scheduler.start();
|
||||
const pause = () => scheduler.pause();
|
||||
const toggle = () => scheduler.toggle();
|
||||
const setCps = (cps) => scheduler.setCps(cps);
|
||||
const setCps = (cps) => {
|
||||
scheduler.setCps(unpure(cps));
|
||||
return silence;
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the global tempo to the given cycles per minute
|
||||
@@ -97,7 +108,10 @@ export function repl({
|
||||
* setcpm(140/4) // =140 bpm in 4/4
|
||||
* $: s("bd*4,[- sd]*2").bank('tr707')
|
||||
*/
|
||||
const setCpm = (cpm) => scheduler.setCps(cpm / 60);
|
||||
const setCpm = (cpm) => {
|
||||
scheduler.setCps(unpure(cpm) / 60);
|
||||
return silence;
|
||||
};
|
||||
|
||||
// TODO - not documented as jsdoc examples as the test framework doesn't simulate enough context for `each` and `all`..
|
||||
|
||||
|
||||
@@ -152,9 +152,7 @@ export const itri2 = fastcat(isaw2, saw2);
|
||||
*
|
||||
* @return {Pattern}
|
||||
*/
|
||||
export const time = signal((x) => {
|
||||
return x.valueOf();
|
||||
});
|
||||
export const time = signal(id);
|
||||
|
||||
/**
|
||||
* The mouse's x position value ranges from 0 to 1.
|
||||
|
||||
@@ -877,7 +877,7 @@ describe('Pattern', () => {
|
||||
.squeezeJoin()
|
||||
.queryArc(3, 4)
|
||||
.map((x) => x.value),
|
||||
).toStrictEqual([3]);
|
||||
).toStrictEqual([Fraction(3)]);
|
||||
});
|
||||
});
|
||||
describe('ply', () => {
|
||||
|
||||
@@ -85,7 +85,7 @@ function evaluator(node, scope) {
|
||||
let pat;
|
||||
if (type === 'plain' && typeof variable !== 'undefined') {
|
||||
// some function names are not patternable, so we skip reification here
|
||||
if (['!', 'extend', '@', 'expand', 'square', 'angle'].includes(value)) {
|
||||
if (['!', 'extend', '@', 'expand', 'square', 'angle', 'all', 'setcpm', 'setcps'].includes(value)) {
|
||||
return variable;
|
||||
}
|
||||
pat = reify(variable);
|
||||
|
||||
+27
-17
@@ -4,21 +4,13 @@ OSC output for strudel patterns! Currently only tested with super collider / sup
|
||||
|
||||
## Usage
|
||||
|
||||
OSC will only work if you run the REPL locally + the OSC server besides it:
|
||||
Assuming you have [node.js](https://nodejs.org/) installed, you can run the osc bridge server via:
|
||||
|
||||
From the project root:
|
||||
|
||||
```js
|
||||
npm run repl
|
||||
```sh
|
||||
npx @strudel/osc
|
||||
```
|
||||
|
||||
and in a seperate shell:
|
||||
|
||||
```js
|
||||
npm run osc
|
||||
```
|
||||
|
||||
This should give you
|
||||
You should see something like:
|
||||
|
||||
```log
|
||||
osc client running on port 57120
|
||||
@@ -26,14 +18,32 @@ osc server running on port 57121
|
||||
websocket server running on port 8080
|
||||
```
|
||||
|
||||
Now open Supercollider (with the super dirt startup file)
|
||||
### --port
|
||||
|
||||
Now open the REPL and type:
|
||||
By default it will use port 57120 for the osc client, which is what [superdirt](https://github.com/musikinformatik/SuperDirt) uses. You can change it via the `--port` option:
|
||||
|
||||
```js
|
||||
s("<bd sd> hh").osc()
|
||||
```sh
|
||||
npx @strudel/osc --port 7771 # classic dirt
|
||||
```
|
||||
|
||||
or just [click here](https://strudel.cc/#cygiPGJkIHNkPiBoaCIpLm9zYygp)...
|
||||
### --debug
|
||||
|
||||
To log all incoming osc messages, add the `--debug` flag:
|
||||
|
||||
```sh
|
||||
npx @strudel/osc --debug
|
||||
```
|
||||
|
||||
## Usage in Strudel
|
||||
|
||||
To test it in strudel, you have can use `all(osc)` to send all events through osc:
|
||||
|
||||
```js
|
||||
$: s("bd*4")
|
||||
|
||||
all(osc)
|
||||
```
|
||||
|
||||
[open in repl](https://strudel.cc/#JDogcygiYmQqNCIpCgphbGwob3NjKQ%3D%3D)
|
||||
|
||||
You can read more about [how to use Superdirt with Strudel the Tutorial](https://strudel.cc/learn/input-output/#superdirt-api)
|
||||
|
||||
@@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import OSC from 'osc-js';
|
||||
|
||||
import { logger, parseNumeral, Pattern, isNote, noteToMidi, ClockCollator } from '@strudel/core';
|
||||
import { logger, parseNumeral, register, isNote, noteToMidi, ClockCollator } from '@strudel/core';
|
||||
|
||||
let connection; // Promise<OSC>
|
||||
function connect() {
|
||||
@@ -81,6 +81,4 @@ export async function oscTrigger(hap, currentTime, cps = 1, targetTime) {
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
*/
|
||||
Pattern.prototype.osc = function () {
|
||||
return this.onTrigger(oscTrigger);
|
||||
};
|
||||
export const osc = register('osc', (pat) => pat.onTrigger(oscTrigger));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@strudel/osc",
|
||||
"version": "1.2.4",
|
||||
"version": "1.2.10",
|
||||
"description": "OSC messaging for strudel",
|
||||
"main": "osc.mjs",
|
||||
"bin": "./server.js",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"main": "dist/index.mjs"
|
||||
|
||||
+43
-2
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
server.js - <short description TODO>
|
||||
Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/osc/server.js>
|
||||
@@ -6,6 +8,19 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import OSC from 'osc-js';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
function getArgValue(flag) {
|
||||
const i = args.indexOf(flag);
|
||||
if (i !== -1) {
|
||||
const nextIsFlag = args[i + 1]?.startsWith('--') ?? true;
|
||||
if (nextIsFlag) return true;
|
||||
return args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
let udpClientPort = Number(getArgValue('--port')) || 57120;
|
||||
let debug = Number(getArgValue('--debug')) || 0;
|
||||
|
||||
const config = {
|
||||
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
|
||||
udpServer: {
|
||||
@@ -17,7 +32,7 @@ const config = {
|
||||
},
|
||||
udpClient: {
|
||||
host: 'localhost', // @param {string} Hostname of udp client for messaging
|
||||
port: 57120, // @param {number} Port of udp client for messaging
|
||||
port: udpClientPort, // @param {number} Port of udp client for messaging
|
||||
},
|
||||
wsServer: {
|
||||
host: 'localhost', // @param {string} Hostname of WebSocket server
|
||||
@@ -27,8 +42,34 @@ const config = {
|
||||
|
||||
const osc = new OSC({ plugin: new OSC.BridgePlugin(config) });
|
||||
|
||||
osc.open(); // start a WebSocket server on port 8080
|
||||
if (debug) {
|
||||
osc.on('*', (message) => {
|
||||
const { address, args } = message;
|
||||
let str = '';
|
||||
for (let i = 0; i < args.length; i += 2) {
|
||||
str += `${args[i]}: ${args[i + 1]} `;
|
||||
}
|
||||
console.log(`${address} ${str}`);
|
||||
});
|
||||
}
|
||||
|
||||
osc.on('error', (message) => {
|
||||
if (message.toString().includes('EADDRINUSE')) {
|
||||
console.log(`------ ERROR -------
|
||||
a server is already running on port 57121! to stop it:
|
||||
1. run "lsof -ti :57121 | xargs kill -9" (macos / linux)
|
||||
2. re-run the osc server
|
||||
`);
|
||||
} else {
|
||||
console.log(message);
|
||||
}
|
||||
});
|
||||
|
||||
osc.open();
|
||||
|
||||
console.log('osc client running on port', config.udpClient.port);
|
||||
console.log('osc server running on port', config.udpServer.port);
|
||||
console.log('websocket server running on port', config.wsServer.port);
|
||||
if (debug) {
|
||||
console.log('debug logs enabled. incoming messages will appear below');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getAudioContext } from './superdough.mjs';
|
||||
import { clamp, nanFallback } from './util.mjs';
|
||||
import { clamp, nanFallback, midiToFreq, noteToMidi } from './util.mjs';
|
||||
import { getNoiseBuffer } from './noise.mjs';
|
||||
|
||||
export const noises = ['pink', 'white', 'brown', 'crackle'];
|
||||
@@ -10,6 +10,13 @@ export function gainNode(value) {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function effectSend(input, effect, wet) {
|
||||
const send = gainNode(wet);
|
||||
input.connect(send);
|
||||
send.connect(effect);
|
||||
return send;
|
||||
}
|
||||
|
||||
const getSlope = (y1, y2, x1, x2) => {
|
||||
const denom = x2 - x1;
|
||||
if (denom === 0) {
|
||||
@@ -21,7 +28,9 @@ const getSlope = (y1, y2, x1, x2) => {
|
||||
export function getWorklet(ac, processor, params, config) {
|
||||
const node = new AudioWorkletNode(ac, processor, config);
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
node.parameters.get(key).value = value;
|
||||
if (value !== undefined) {
|
||||
node.parameters.get(key).value = value;
|
||||
}
|
||||
});
|
||||
return node;
|
||||
}
|
||||
@@ -88,6 +97,35 @@ export const getParamADSR = (
|
||||
param[ramp](min, end + release);
|
||||
};
|
||||
|
||||
function getModulationShapeInput(val) {
|
||||
if (typeof val === 'number') {
|
||||
return val % 5;
|
||||
}
|
||||
return { tri: 0, triangle: 0, sine: 1, ramp: 2, saw: 3, square: 4 }[val] ?? 0;
|
||||
}
|
||||
|
||||
export function getLfo(audioContext, begin, end, properties = {}) {
|
||||
const { shape = 0, ...props } = properties;
|
||||
const { dcoffset = -0.5, depth = 1 } = properties;
|
||||
const lfoprops = {
|
||||
frequency: 1,
|
||||
depth,
|
||||
skew: 0.5,
|
||||
phaseoffset: 0,
|
||||
time: begin,
|
||||
begin,
|
||||
end,
|
||||
shape: getModulationShapeInput(shape),
|
||||
dcoffset,
|
||||
min: dcoffset * depth,
|
||||
max: dcoffset * depth + depth,
|
||||
curve: 1,
|
||||
...props,
|
||||
};
|
||||
|
||||
return getWorklet(audioContext, 'lfo-processor', lfoprops);
|
||||
}
|
||||
|
||||
export function getCompressor(ac, threshold, ratio, knee, attack, release) {
|
||||
const options = {
|
||||
threshold: threshold ?? -3,
|
||||
@@ -115,6 +153,41 @@ export const getADSRValues = (params, curve = 'linear', defaultValues) => {
|
||||
return [Math.max(a ?? 0, envmin), Math.max(d ?? 0, envmin), Math.min(sustain, envmax), Math.max(r ?? 0, releaseMin)];
|
||||
};
|
||||
|
||||
// helper utility for applying standard modulators to a parameter
|
||||
export function applyParameterModulators(audioContext, param, start, end, envelopeValues, lfoValues) {
|
||||
let { amount, offset, defaultAmount = 1, curve = 'linear', values, holdEnd, defaultValues } = envelopeValues;
|
||||
|
||||
if (amount == null) {
|
||||
const hasADSRParams = values.some((p) => p != null);
|
||||
amount = hasADSRParams ? defaultAmount : 0;
|
||||
}
|
||||
|
||||
const min = offset ?? 0;
|
||||
const max = amount + min;
|
||||
const diff = Math.abs(max - min);
|
||||
if (diff) {
|
||||
const [attack, decay, sustain, release] = getADSRValues(values, curve, defaultValues);
|
||||
getParamADSR(param, attack, decay, sustain, release, min, max, start, holdEnd, curve);
|
||||
}
|
||||
let lfo;
|
||||
let { defaultDepth = 1, depth, dcoffset, ...getLfoInputs } = lfoValues;
|
||||
|
||||
if (depth == null) {
|
||||
const hasLFOParams = Object.values(getLfoInputs).some((v) => v != null);
|
||||
depth = hasLFOParams ? defaultDepth : 0;
|
||||
}
|
||||
if (depth) {
|
||||
lfo = getLfo(audioContext, start, end, {
|
||||
depth,
|
||||
dcoffset,
|
||||
...getLfoInputs,
|
||||
});
|
||||
lfo.connect(param);
|
||||
}
|
||||
|
||||
return { lfo, disconnect: () => lfo?.disconnect() };
|
||||
}
|
||||
|
||||
export function createFilter(context, type, frequency, Q, att, dec, sus, rel, fenv, start, end, fanchor, model, drive) {
|
||||
const curve = 'exponential';
|
||||
const [attack, decay, sustain, release] = getADSRValues([att, dec, sus, rel], curve, [0.005, 0.14, 0, 0.1]);
|
||||
@@ -307,3 +380,25 @@ export function applyFM(param, value, begin) {
|
||||
}
|
||||
return { stop };
|
||||
}
|
||||
|
||||
export const getFrequencyFromValue = (value, defaultNote = 36) => {
|
||||
let { note, freq } = value;
|
||||
note = note || defaultNote;
|
||||
if (typeof note === 'string') {
|
||||
note = noteToMidi(note); // e.g. c3 => 48
|
||||
}
|
||||
// get frequency
|
||||
if (!freq && typeof note === 'number') {
|
||||
freq = midiToFreq(note); // + 48);
|
||||
}
|
||||
|
||||
return Number(freq);
|
||||
};
|
||||
|
||||
export const destroyAudioWorkletNode = (node) => {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
node.disconnect();
|
||||
node.parameters.get('end')?.setValueAtTime(0, 0);
|
||||
};
|
||||
|
||||
@@ -11,3 +11,4 @@ export * from './synth.mjs';
|
||||
export * from './zzfx.mjs';
|
||||
export * from './logger.mjs';
|
||||
export * from './dspworklet.mjs';
|
||||
export * from './wavetable.mjs';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
let log = (msg) => console.log(msg);
|
||||
|
||||
export function errorLogger(e, origin = 'cyclist') {
|
||||
//TODO: add some kind of debug flag that enables this while in dev mode
|
||||
// console.error(e);
|
||||
export function errorLogger(e, origin = 'superdough') {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.error(e);
|
||||
}
|
||||
logger(`[${origin}] error: ${e.message}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { noteToMidi, valueToMidi, getSoundIndex } from './util.mjs';
|
||||
import { getAudioContext, registerSound } from './index.mjs';
|
||||
import { noteToMidi, valueToMidi, getSoundIndex, getCommonSampleInfo } from './util.mjs';
|
||||
import { getAudioContext, registerSound, registerWaveTable } from './index.mjs';
|
||||
import { getADSRValues, getParamADSR, getPitchEnvelope, getVibratoOscillator } from './helpers.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
@@ -22,39 +22,16 @@ function humanFileSize(bytes, si) {
|
||||
return bytes.toFixed(1) + ' ' + units[u];
|
||||
}
|
||||
|
||||
// deduces relevant info for sample loading from hap.value and sample definition
|
||||
// it encapsulates the core sampler logic into a pure and synchronous function
|
||||
// hapValue: Hap.value, bank: sample bank definition for sound "s" (values in strudel.json format)
|
||||
export function getSampleInfo(hapValue, bank) {
|
||||
const { s, n = 0, speed = 1.0 } = hapValue;
|
||||
let midi = valueToMidi(hapValue, 36);
|
||||
let transpose = midi - 36; // C3 is middle C;
|
||||
let sampleUrl;
|
||||
let index = 0;
|
||||
if (Array.isArray(bank)) {
|
||||
index = getSoundIndex(n, bank.length);
|
||||
sampleUrl = bank[index];
|
||||
} else {
|
||||
const midiDiff = (noteA) => noteToMidi(noteA) - midi;
|
||||
// object format will expect keys as notes
|
||||
const closest = Object.keys(bank)
|
||||
.filter((k) => !k.startsWith('_'))
|
||||
.reduce(
|
||||
(closest, key, j) => (!closest || Math.abs(midiDiff(key)) < Math.abs(midiDiff(closest)) ? key : closest),
|
||||
null,
|
||||
);
|
||||
transpose = -midiDiff(closest); // semitones to repitch
|
||||
index = getSoundIndex(n, bank[closest].length);
|
||||
sampleUrl = bank[closest][index];
|
||||
}
|
||||
const label = `${s}:${index}`;
|
||||
const { speed = 1.0 } = hapValue;
|
||||
const { transpose, url, index, midi, label } = getCommonSampleInfo(hapValue, bank);
|
||||
let playbackRate = Math.abs(speed) * Math.pow(2, transpose / 12);
|
||||
return { transpose, sampleUrl, index, midi, label, playbackRate };
|
||||
return { transpose, url, index, midi, label, playbackRate };
|
||||
}
|
||||
|
||||
// takes hapValue and returns buffer + playbackRate.
|
||||
export const getSampleBuffer = async (hapValue, bank, resolveUrl) => {
|
||||
let { sampleUrl, label, playbackRate } = getSampleInfo(hapValue, bank);
|
||||
let { url: sampleUrl, label, playbackRate } = getSampleInfo(hapValue, bank);
|
||||
if (resolveUrl) {
|
||||
sampleUrl = await resolveUrl(sampleUrl);
|
||||
}
|
||||
@@ -78,32 +55,22 @@ export const getSampleBufferSource = async (hapValue, bank, resolveUrl) => {
|
||||
const bufferSource = ac.createBufferSource();
|
||||
bufferSource.buffer = buffer;
|
||||
bufferSource.playbackRate.value = playbackRate;
|
||||
const { s, loopBegin = 0, loopEnd = 1, begin, end, beginSeconds, endSeconds } = hapValue;
|
||||
let offset = 0;
|
||||
let endTime = bufferSource.buffer.duration;
|
||||
|
||||
const { loopBegin = 0, loopEnd = 1, begin = 0, end = 1 } = hapValue;
|
||||
|
||||
// "The computation of the offset into the sound is performed using the sound buffer's natural sample rate,
|
||||
// rather than the current playback rate, so even if the sound is playing at twice its normal speed,
|
||||
// the midway point through a 10-second audio buffer is still 5."
|
||||
if (begin != null) {
|
||||
offset = begin * bufferSource.buffer.duration;
|
||||
} else if (beginSeconds != null) {
|
||||
offset = beginSeconds;
|
||||
}
|
||||
const offset = begin * bufferSource.buffer.duration;
|
||||
|
||||
if (end != null) {
|
||||
endTime = end * bufferSource.buffer.duration;
|
||||
} else if (endSeconds != null) {
|
||||
endTime = endSeconds;
|
||||
}
|
||||
|
||||
const loop = s.startsWith('wt_') ? 1 : hapValue.loop;
|
||||
const loop = hapValue.loop;
|
||||
if (loop) {
|
||||
bufferSource.loop = true;
|
||||
bufferSource.loopStart = loopBegin * bufferSource.buffer.duration - offset;
|
||||
bufferSource.loopEnd = loopEnd * bufferSource.buffer.duration - offset;
|
||||
}
|
||||
const bufferDuration = bufferSource.buffer.duration / bufferSource.playbackRate.value;
|
||||
const sliceDuration = (endTime - offset) / bufferSource.playbackRate.value;
|
||||
const sliceDuration = (end - begin) * bufferDuration;
|
||||
return { bufferSource, offset, bufferDuration, sliceDuration };
|
||||
};
|
||||
|
||||
@@ -277,16 +244,12 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '', option
|
||||
return samples(json, baseUrl || base, options);
|
||||
}
|
||||
const { prebake, tag } = options;
|
||||
|
||||
processSampleMap(
|
||||
sampleMap,
|
||||
(key, bank) =>
|
||||
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, bank), {
|
||||
type: 'sample',
|
||||
samples: bank,
|
||||
baseUrl,
|
||||
prebake,
|
||||
tag,
|
||||
}),
|
||||
(key, bank) => {
|
||||
registerSampleSource(key, bank, { baseUrl, prebake, tag });
|
||||
},
|
||||
baseUrl,
|
||||
);
|
||||
};
|
||||
@@ -357,7 +320,6 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||
out.disconnect();
|
||||
onended();
|
||||
};
|
||||
|
||||
let envEnd = holdEnd + release + 0.01;
|
||||
bufferSource.stop(envEnd);
|
||||
const stop = (endTime) => {
|
||||
@@ -377,3 +339,20 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
function registerSample(key, bank, params) {
|
||||
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, bank), {
|
||||
type: 'sample',
|
||||
samples: bank,
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
export function registerSampleSource(key, bank, params) {
|
||||
const isWavetable = key.startsWith('wt_');
|
||||
if (isWavetable) {
|
||||
registerWaveTable(key, bank, params);
|
||||
} else {
|
||||
registerSample(key, bank, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,13 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import './feedbackdelay.mjs';
|
||||
import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp, nanFallback, _mod, cycleToSeconds, secondsToCycle } from './util.mjs';
|
||||
import { nanFallback, _mod, cycleToSeconds } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?audioworklet';
|
||||
import { createFilter, gainNode, getCompressor, getWorklet, webAudioTimeout } from './helpers.mjs';
|
||||
import { createFilter, gainNode, getCompressor, getLfo, getWorklet, effectSend } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger, errorLogger } from './logger.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
import { loadBuffer } from './sampler.mjs';
|
||||
import { SuperdoughAudioController } from './superdoughoutput.mjs';
|
||||
|
||||
export const DEFAULT_MAX_POLYPHONY = 128;
|
||||
const DEFAULT_AUDIO_DEVICE_NAME = 'System Standard';
|
||||
@@ -28,13 +29,6 @@ export function setMultiChannelOrbits(bool) {
|
||||
multiChannelOrbits = bool == true;
|
||||
}
|
||||
|
||||
function getModulationShapeInput(val) {
|
||||
if (typeof val === 'number') {
|
||||
return val % 5;
|
||||
}
|
||||
return { tri: 0, triangle: 0, sine: 1, ramp: 2, saw: 3, square: 4 }[val] ?? 0;
|
||||
}
|
||||
|
||||
export const soundMap = map();
|
||||
|
||||
export function registerSound(key, onTrigger, data = {}) {
|
||||
@@ -301,87 +295,16 @@ export async function initAudioOnFirstClick(options) {
|
||||
return audioReady;
|
||||
}
|
||||
|
||||
const maxfeedback = 0.98;
|
||||
|
||||
let channelMerger, destinationGain;
|
||||
//update the output channel configuration to match user's audio device
|
||||
export function initializeAudioOutput() {
|
||||
const audioContext = getAudioContext();
|
||||
const maxChannelCount = audioContext.destination.maxChannelCount;
|
||||
audioContext.destination.channelCount = maxChannelCount;
|
||||
channelMerger = new ChannelMergerNode(audioContext, { numberOfInputs: audioContext.destination.channelCount });
|
||||
destinationGain = new GainNode(audioContext);
|
||||
channelMerger.connect(destinationGain);
|
||||
destinationGain.connect(audioContext.destination);
|
||||
let controller;
|
||||
function getSuperdoughAudioController() {
|
||||
if (controller == null) {
|
||||
controller = new SuperdoughAudioController(getAudioContext());
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
// input: AudioNode, channels: ?Array<int>
|
||||
export const connectToDestination = (input, channels = [0, 1]) => {
|
||||
const ctx = getAudioContext();
|
||||
if (channelMerger == null) {
|
||||
initializeAudioOutput();
|
||||
}
|
||||
//This upmix can be removed if correct channel counts are set throughout the app,
|
||||
// and then strudel could theoretically support surround sound audio files
|
||||
const stereoMix = new StereoPannerNode(ctx);
|
||||
input.connect(stereoMix);
|
||||
|
||||
const splitter = new ChannelSplitterNode(ctx, {
|
||||
numberOfOutputs: stereoMix.channelCount,
|
||||
});
|
||||
stereoMix.connect(splitter);
|
||||
channels.forEach((ch, i) => {
|
||||
splitter.connect(channelMerger, i % stereoMix.channelCount, ch % ctx.destination.channelCount);
|
||||
});
|
||||
};
|
||||
|
||||
export const panic = () => {
|
||||
if (destinationGain == null) {
|
||||
return;
|
||||
}
|
||||
destinationGain.gain.linearRampToValueAtTime(0, getAudioContext().currentTime + 0.01);
|
||||
destinationGain = null;
|
||||
channelMerger == null;
|
||||
};
|
||||
|
||||
function getDelay(orbit, delaytime, delayfeedback, t) {
|
||||
if (delayfeedback > maxfeedback) {
|
||||
//logger(`delayfeedback was clamped to ${maxfeedback} to save your ears`);
|
||||
}
|
||||
delayfeedback = clamp(delayfeedback, 0, 0.98);
|
||||
let delayNode = orbits[orbit].delayNode;
|
||||
if (delayNode === undefined) {
|
||||
const ac = getAudioContext();
|
||||
delayNode = ac.createFeedbackDelay(1, delaytime, delayfeedback);
|
||||
delayNode.start?.(t); // for some reason, this throws when audion extension is installed..
|
||||
connectToOrbit(delayNode, orbit);
|
||||
orbits[orbit].delayNode = delayNode;
|
||||
}
|
||||
delayNode.delayTime.value !== delaytime && delayNode.delayTime.setValueAtTime(delaytime, t);
|
||||
delayNode.feedback.value !== delayfeedback && delayNode.feedback.setValueAtTime(delayfeedback, t);
|
||||
return delayNode;
|
||||
}
|
||||
|
||||
export function getLfo(audioContext, begin, end, properties = {}) {
|
||||
const { shape = 0, ...props } = properties;
|
||||
const { dcoffset = -0.5, depth = 1 } = properties;
|
||||
const lfoprops = {
|
||||
frequency: 1,
|
||||
depth,
|
||||
skew: 0.5,
|
||||
phaseoffset: 0,
|
||||
time: begin,
|
||||
begin,
|
||||
end,
|
||||
shape: getModulationShapeInput(shape),
|
||||
dcoffset,
|
||||
min: dcoffset * depth,
|
||||
max: dcoffset * depth + depth,
|
||||
curve: 1,
|
||||
...props,
|
||||
};
|
||||
|
||||
return getWorklet(audioContext, 'lfo-processor', lfoprops);
|
||||
export function connectToDestination(input, channels) {
|
||||
const controller = getSuperdoughAudioController();
|
||||
controller.output.connectToDestination(input, channels);
|
||||
}
|
||||
|
||||
function getPhaser(time, end, frequency = 1, depth = 0.5, centerFrequency = 1000, sweep = 2000) {
|
||||
@@ -415,97 +338,6 @@ function getFilterType(ftype) {
|
||||
return typeof ftype === 'number' ? filterTypes[Math.floor(_mod(ftype, filterTypes.length))] : ftype;
|
||||
}
|
||||
|
||||
// type orbit {
|
||||
// output: GainNode,
|
||||
// reverbNode: ConvolverNode
|
||||
// delayNode: FeedbackDelayNode
|
||||
// }
|
||||
let orbits = {};
|
||||
function connectToOrbit(node, orbit) {
|
||||
if (orbits[orbit] == null) {
|
||||
errorLogger(new Error('target orbit does not exist'), 'superdough');
|
||||
}
|
||||
node.connect(orbits[orbit].output);
|
||||
}
|
||||
|
||||
function setOrbit(audioContext, orbit, channels) {
|
||||
if (orbits[orbit] == null) {
|
||||
orbits[orbit] = {
|
||||
// Setup output node through which all audio filters prior to hitting
|
||||
// the destination (and thus allows for global volume automation)
|
||||
output: new GainNode(audioContext, { gain: 1, channelCount: 2, channelCountMode: 'explicit' }),
|
||||
};
|
||||
connectToDestination(orbits[orbit].output, channels);
|
||||
}
|
||||
}
|
||||
|
||||
function duckOrbit(audioContext, targetOrbit, t, onsettime = 0, attacktime = 0.1, duckdepth = 1) {
|
||||
const targetArr = [targetOrbit].flat();
|
||||
const onsetArr = [onsettime].flat();
|
||||
const attackArr = [attacktime].flat();
|
||||
const depthArr = [duckdepth].flat();
|
||||
|
||||
targetArr.forEach((target, idx) => {
|
||||
if (orbits[target] == null) {
|
||||
errorLogger(new Error(`duck target orbit ${target} does not exist`), 'superdough');
|
||||
return;
|
||||
}
|
||||
const onset = onsetArr[idx] ?? onsetArr[0];
|
||||
const attack = Math.max(attackArr[idx] ?? attackArr[0], 0.002);
|
||||
const depth = depthArr[idx] ?? depthArr[0];
|
||||
const gainParam = orbits[target].output.gain;
|
||||
webAudioTimeout(
|
||||
audioContext,
|
||||
() => {
|
||||
const now = audioContext.currentTime;
|
||||
|
||||
// cancelScheduledValues and setValueAtTime together emulate cancelAndHoldAtTime
|
||||
// on browsers which lack that method
|
||||
const currVal = gainParam.value;
|
||||
gainParam.cancelScheduledValues(now);
|
||||
gainParam.setValueAtTime(currVal, now);
|
||||
|
||||
const t0 = Math.max(t, now); // guard against now > t
|
||||
const duckedVal = clamp(1 - Math.sqrt(depth), 0.01, currVal);
|
||||
gainParam.exponentialRampToValueAtTime(duckedVal, t0 + onset);
|
||||
gainParam.exponentialRampToValueAtTime(1, t0 + onset + attack);
|
||||
},
|
||||
0,
|
||||
t - 0.01,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
let hasChanged = (now, before) => now !== undefined && now !== before;
|
||||
function getReverb(orbit, duration, fade, lp, dim, ir, irspeed, irbegin) {
|
||||
// If no reverb has been created for a given orbit, create one
|
||||
let reverbNode = orbits[orbit].reverbNode;
|
||||
if (reverbNode === undefined) {
|
||||
const ac = getAudioContext();
|
||||
reverbNode = ac.createReverb(duration, fade, lp, dim, ir, irspeed, irbegin);
|
||||
connectToOrbit(reverbNode, orbit);
|
||||
orbits[orbit].reverbNode = reverbNode;
|
||||
}
|
||||
|
||||
if (
|
||||
hasChanged(duration, reverbNode.duration) ||
|
||||
hasChanged(fade, reverbNode.fade) ||
|
||||
hasChanged(lp, reverbNode.lp) ||
|
||||
hasChanged(dim, reverbNode.dim) ||
|
||||
hasChanged(irspeed, reverbNode.irspeed) ||
|
||||
hasChanged(irbegin, reverbNode.irbegin) ||
|
||||
reverbNode.ir !== ir
|
||||
) {
|
||||
// only regenerate when something has changed
|
||||
// avoids endless regeneration on things like
|
||||
// stack(s("a"), s("b").rsize(8)).room(.5)
|
||||
// this only works when args may stay undefined until here
|
||||
// setting default values breaks this
|
||||
reverbNode.generate(duration, fade, lp, dim, ir, irspeed, irbegin);
|
||||
}
|
||||
return reverbNode;
|
||||
}
|
||||
|
||||
export let analysers = {},
|
||||
analysersData = {};
|
||||
|
||||
@@ -538,15 +370,8 @@ export function getAnalyzerData(type = 'time', id = 1) {
|
||||
return analysersData[id];
|
||||
}
|
||||
|
||||
function effectSend(input, effect, wet) {
|
||||
const send = gainNode(wet);
|
||||
input.connect(send);
|
||||
send.connect(effect);
|
||||
return send;
|
||||
}
|
||||
|
||||
export function resetGlobalEffects() {
|
||||
orbits = {};
|
||||
controller?.reset();
|
||||
analysers = {};
|
||||
analysersData = {};
|
||||
}
|
||||
@@ -561,6 +386,7 @@ function mapChannelNumbers(channels) {
|
||||
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
|
||||
// new: t is always expected to be the absolute target onset time
|
||||
const ac = getAudioContext();
|
||||
const audioController = getSuperdoughAudioController();
|
||||
|
||||
let { stretch } = value;
|
||||
if (stretch != null) {
|
||||
@@ -603,6 +429,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
duckonset,
|
||||
duckattack,
|
||||
duckdepth,
|
||||
djf,
|
||||
// filters
|
||||
fanchor = getDefaultValue('fanchor'),
|
||||
drive = 0.69,
|
||||
@@ -679,10 +506,9 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
);
|
||||
|
||||
const channels = value.channels != null ? mapChannelNumbers(value.channels) : orbitChannels;
|
||||
setOrbit(ac, orbit, channels, t, cycle, cps);
|
||||
|
||||
const orbitBus = audioController.getOrbit(orbit, channels);
|
||||
if (duckorbit != null) {
|
||||
duckOrbit(ac, duckorbit, t, duckonset, duckattack, duckdepth);
|
||||
audioController.duck(duckorbit, t, duckonset, duckattack, duckdepth);
|
||||
}
|
||||
|
||||
gain = applyGainCurve(nanFallback(gain, 1));
|
||||
@@ -729,7 +555,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
audioNodes.forEach((n) => n?.disconnect());
|
||||
activeSoundSources.delete(chainID);
|
||||
};
|
||||
const soundHandle = await onTrigger(t, value, onEnded);
|
||||
const soundHandle = await onTrigger(t, value, onEnded, cps);
|
||||
|
||||
if (soundHandle) {
|
||||
sourceNode = soundHandle.node;
|
||||
@@ -827,6 +653,14 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
tremolo = cps * tremolosync;
|
||||
}
|
||||
|
||||
if (value.wtPosSynced != null) {
|
||||
value.wtPosRate /= cps;
|
||||
}
|
||||
|
||||
if (value.wtWarpSynced != null) {
|
||||
value.wtWarpRate /= cps;
|
||||
}
|
||||
|
||||
if (tremolo !== undefined) {
|
||||
// Allow clipping of modulator for more dynamic possiblities, and to prevent speaker overload
|
||||
// EX: a triangle waveform will clip like this /-\ when the depth is above 1
|
||||
@@ -872,14 +706,11 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
chain.push(post);
|
||||
|
||||
// delay
|
||||
let delaySend;
|
||||
if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
|
||||
const delayNode = getDelay(orbit, delaytime, delayfeedback, t);
|
||||
delaySend = effectSend(post, delayNode, delay);
|
||||
audioNodes.push(delaySend);
|
||||
orbitBus.getDelay(delaytime, delayfeedback, t);
|
||||
orbitBus.sendDelay(post, delay);
|
||||
}
|
||||
// reverb
|
||||
let reverbSend;
|
||||
if (room > 0) {
|
||||
let roomIR;
|
||||
if (ir !== undefined) {
|
||||
@@ -892,25 +723,27 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
}
|
||||
roomIR = await loadBuffer(url, ac, ir, 0);
|
||||
}
|
||||
const reverbNode = getReverb(orbit, roomsize, roomfade, roomlp, roomdim, roomIR, irspeed, irbegin);
|
||||
reverbSend = effectSend(post, reverbNode, room);
|
||||
audioNodes.push(reverbSend);
|
||||
orbitBus.getReverb(roomsize, roomfade, roomlp, roomdim, roomIR, irspeed, irbegin);
|
||||
orbitBus.sendReverb(post, room);
|
||||
}
|
||||
|
||||
if (djf != null) {
|
||||
orbitBus.getDjf(djf, t);
|
||||
}
|
||||
|
||||
// analyser
|
||||
let analyserSend;
|
||||
if (analyze) {
|
||||
const analyserNode = getAnalyserById(analyze, 2 ** (fft + 5));
|
||||
analyserSend = effectSend(post, analyserNode, 1);
|
||||
const analyserSend = effectSend(post, analyserNode, 1);
|
||||
audioNodes.push(analyserSend);
|
||||
}
|
||||
if (dry != null) {
|
||||
dry = applyGainCurve(dry);
|
||||
const dryGain = new GainNode(ac, { gain: dry });
|
||||
chain.push(dryGain);
|
||||
connectToOrbit(dryGain, orbit);
|
||||
orbitBus.connectToOutput(dryGain);
|
||||
} else {
|
||||
connectToOrbit(post, orbit);
|
||||
orbitBus.connectToOutput(post);
|
||||
}
|
||||
|
||||
// connect chain elements together
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
import { effectSend, getWorklet, webAudioTimeout } from './helpers.mjs';
|
||||
import { errorLogger } from './logger.mjs';
|
||||
import { clamp } from './util.mjs';
|
||||
|
||||
let hasChanged = (now, before) => now !== undefined && now !== before;
|
||||
|
||||
export class Orbit {
|
||||
reverbNode;
|
||||
delayNode;
|
||||
output;
|
||||
summingNode;
|
||||
djfNode;
|
||||
audioContext;
|
||||
constructor(audioContext) {
|
||||
this.audioContext = audioContext;
|
||||
this.output = new GainNode(audioContext, { gain: 1, channelCount: 2, channelCountMode: 'explicit' });
|
||||
this.summingNode = new GainNode(audioContext, { gain: 1, channelCount: 2, channelCountMode: 'explicit' });
|
||||
this.summingNode.connect(this.output);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.output.disconnect();
|
||||
this.summingNode.disconnect();
|
||||
this.delayNode?.disconnect();
|
||||
this.reverbNode?.disconnect();
|
||||
}
|
||||
|
||||
getDjf(value, t = 0) {
|
||||
if (this.djfNode == null) {
|
||||
this.djfNode = getWorklet(this.audioContext, 'djf-processor', { value });
|
||||
this.summingNode.disconnect();
|
||||
this.summingNode.connect(this.djfNode);
|
||||
this.djfNode.connect(this.output);
|
||||
}
|
||||
const val = this.djfNode.parameters.get('value');
|
||||
val.setValueAtTime(value, t);
|
||||
}
|
||||
|
||||
getDelay(delaytime = 0, feedback = 0.5, t) {
|
||||
const maxfeedback = 0.98;
|
||||
if (feedback > maxfeedback) {
|
||||
//logger(`feedback was clamped to ${maxfeedback} to save your ears`);
|
||||
}
|
||||
feedback = clamp(feedback, 0, 0.98);
|
||||
if (this.delayNode == null) {
|
||||
this.delayNode = this.audioContext.createFeedbackDelay(1, delaytime, feedback);
|
||||
this.delayNode.connect(this.summingNode);
|
||||
this.delayNode.start?.(t); // for some reason, this throws when audion extension is installed..
|
||||
}
|
||||
this.delayNode.delayTime.value !== delaytime && this.delayNode.delayTime.setValueAtTime(delaytime, t);
|
||||
this.delayNode.feedback.value !== feedback && this.delayNode.feedback.setValueAtTime(feedback, t);
|
||||
return this.delayNode;
|
||||
}
|
||||
|
||||
getReverb(duration, fade, lp, dim, ir, irspeed, irbegin) {
|
||||
// If no reverb has been created for a given orbit, create one
|
||||
if (this.reverbNode == null) {
|
||||
this.reverbNode = this.audioContext.createReverb(duration, fade, lp, dim, ir, irspeed, irbegin);
|
||||
this.reverbNode.connect(this.summingNode);
|
||||
}
|
||||
|
||||
if (
|
||||
hasChanged(duration, this.reverbNode.duration) ||
|
||||
hasChanged(fade, this.reverbNode.fade) ||
|
||||
hasChanged(lp, this.reverbNode.lp) ||
|
||||
hasChanged(dim, this.reverbNode.dim) ||
|
||||
hasChanged(irspeed, this.reverbNode.irspeed) ||
|
||||
hasChanged(irbegin, this.reverbNode.irbegin) ||
|
||||
this.reverbNode.ir !== ir
|
||||
) {
|
||||
// only regenerate when something has changed
|
||||
// avoids endless regeneration on things like
|
||||
// stack(s("a"), s("b").rsize(8)).room(.5)
|
||||
// this only works when args may stay undefined until here
|
||||
// setting default values breaks this
|
||||
this.reverbNode.generate(duration, fade, lp, dim, ir, irspeed, irbegin);
|
||||
}
|
||||
return this.reverbNode;
|
||||
}
|
||||
sendReverb(node, amount) {
|
||||
effectSend(node, this.reverbNode, amount);
|
||||
}
|
||||
|
||||
sendDelay(node, amount) {
|
||||
effectSend(node, this.delayNode, amount);
|
||||
}
|
||||
|
||||
duck(t, onsettime = 0, attacktime = 0.1, depth = 1) {
|
||||
const onset = onsettime;
|
||||
const attack = Math.max(attacktime, 0.002);
|
||||
const gainParam = this.output.gain;
|
||||
webAudioTimeout(
|
||||
this.audioContext,
|
||||
() => {
|
||||
const now = this.audioContext.currentTime;
|
||||
|
||||
// cancelScheduledValues and setValueAtTime together emulate cancelAndHoldAtTime
|
||||
// on browsers which lack that method
|
||||
const currVal = gainParam.value;
|
||||
gainParam.cancelScheduledValues(now);
|
||||
gainParam.setValueAtTime(currVal, now);
|
||||
|
||||
const t0 = Math.max(t, now); // guard against now > t
|
||||
const duckedVal = clamp(1 - Math.sqrt(depth), 0.01, currVal);
|
||||
gainParam.exponentialRampToValueAtTime(duckedVal, t0 + onset);
|
||||
gainParam.exponentialRampToValueAtTime(1, t0 + onset + attack);
|
||||
},
|
||||
0,
|
||||
t - 0.01,
|
||||
);
|
||||
}
|
||||
|
||||
connectToOutput(node) {
|
||||
node.connect(this.summingNode);
|
||||
}
|
||||
}
|
||||
|
||||
export class SuperdoughOutput {
|
||||
channelMerger;
|
||||
destinationGain;
|
||||
|
||||
constructor(audioContext) {
|
||||
this.audioContext = audioContext;
|
||||
this.initializeAudio();
|
||||
}
|
||||
|
||||
initializeAudio() {
|
||||
const audioContext = this.audioContext;
|
||||
const maxChannelCount = audioContext.destination.maxChannelCount;
|
||||
this.audioContext.destination.channelCount = maxChannelCount;
|
||||
this.channelMerger = new ChannelMergerNode(audioContext, { numberOfInputs: audioContext.destination.channelCount });
|
||||
this.destinationGain = new GainNode(audioContext);
|
||||
this.channelMerger.connect(this.destinationGain);
|
||||
this.destinationGain.connect(audioContext.destination);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.channelMerger.disconnect();
|
||||
this.destinationGain.disconnect();
|
||||
this.destinationGain = null;
|
||||
this.channelMerger = null;
|
||||
this.nodes = {};
|
||||
this.initializeAudio();
|
||||
}
|
||||
connectToDestination = (input, channels = [0, 1]) => {
|
||||
//This upmix can be removed if correct channel counts are set throughout the app,
|
||||
// and then strudel could theoretically support surround sound audio files
|
||||
const stereoMix = new StereoPannerNode(this.audioContext);
|
||||
input.connect(stereoMix);
|
||||
|
||||
const splitter = new ChannelSplitterNode(this.audioContext, {
|
||||
numberOfOutputs: stereoMix.channelCount,
|
||||
});
|
||||
stereoMix.connect(splitter);
|
||||
channels.forEach((ch, i) => {
|
||||
splitter.connect(this.channelMerger, i % stereoMix.channelCount, ch % this.audioContext.destination.channelCount);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export class SuperdoughAudioController {
|
||||
audioContext;
|
||||
output;
|
||||
nodes = {};
|
||||
|
||||
constructor(audioContext) {
|
||||
this.audioContext = audioContext;
|
||||
this.output = new SuperdoughOutput(audioContext);
|
||||
}
|
||||
|
||||
reset() {
|
||||
Array.from(this.nodes).forEach((node) => {
|
||||
node.disconnect();
|
||||
});
|
||||
this.output.reset();
|
||||
}
|
||||
|
||||
duck(targetOrbits, t, onsettime = 0, attacktime = 0.1, depth = 1) {
|
||||
const targetArr = [targetOrbits].flat();
|
||||
const onsetArr = [onsettime].flat();
|
||||
const attackArr = [attacktime].flat();
|
||||
const depthArr = [depth].flat();
|
||||
|
||||
targetArr.forEach((target, idx) => {
|
||||
const orbit = this.nodes[target];
|
||||
|
||||
if (orbit == null) {
|
||||
errorLogger(new Error(`duck target orbit ${target} does not exist`), 'superdough');
|
||||
return;
|
||||
}
|
||||
const onset = onsetArr[idx] ?? onsetArr[0];
|
||||
const attack = Math.max(attackArr[idx] ?? attackArr[0], 0.002);
|
||||
const depth = depthArr[idx] ?? depthArr[0];
|
||||
|
||||
orbit.duck(t, onset, attack, depth);
|
||||
});
|
||||
}
|
||||
|
||||
getOrbit(orbitNum, channels) {
|
||||
if (this.nodes[orbitNum] == null) {
|
||||
this.nodes[orbitNum] = new Orbit(this.audioContext);
|
||||
this.output.connectToDestination(this.nodes[orbitNum].output, channels);
|
||||
}
|
||||
return this.nodes[orbitNum];
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,21 @@
|
||||
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
|
||||
import { registerSound, getAudioContext, soundMap, getLfo } from './superdough.mjs';
|
||||
import { clamp } from './util.mjs';
|
||||
import { registerSound, getAudioContext, soundMap } from './superdough.mjs';
|
||||
import {
|
||||
applyFM,
|
||||
destroyAudioWorkletNode,
|
||||
gainNode,
|
||||
getADSRValues,
|
||||
getFrequencyFromValue,
|
||||
getLfo,
|
||||
getParamADSR,
|
||||
getPitchEnvelope,
|
||||
getVibratoOscillator,
|
||||
webAudioTimeout,
|
||||
getWorklet,
|
||||
noises,
|
||||
webAudioTimeout,
|
||||
} from './helpers.mjs';
|
||||
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
|
||||
|
||||
const getFrequencyFromValue = (value, defaultNote = 36) => {
|
||||
let { note, freq } = value;
|
||||
note = note || defaultNote;
|
||||
if (typeof note === 'string') {
|
||||
note = noteToMidi(note); // e.g. c3 => 48
|
||||
}
|
||||
// get frequency
|
||||
if (!freq && typeof note === 'number') {
|
||||
freq = midiToFreq(note); // + 48);
|
||||
}
|
||||
|
||||
return Number(freq);
|
||||
};
|
||||
function destroyAudioWorkletNode(node) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
node.disconnect();
|
||||
node.parameters.get('end')?.setValueAtTime(0, 0);
|
||||
}
|
||||
|
||||
const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
|
||||
const waveformAliases = [
|
||||
['tri', 'triangle'],
|
||||
|
||||
@@ -76,3 +76,32 @@ export function cycleToSeconds(cycle, cps) {
|
||||
export function secondsToCycle(t, cps) {
|
||||
return t * cps;
|
||||
}
|
||||
|
||||
// deduces relevant info for sample loading from hap.value and sample definition
|
||||
// it encapsulates the core sampler logic into a pure and synchronous function
|
||||
// hapValue: Hap.value, bank: sample bank definition for sound "s" (values in strudel.json format)
|
||||
export function getCommonSampleInfo(hapValue, bank) {
|
||||
const { s, n = 0 } = hapValue;
|
||||
let midi = valueToMidi(hapValue, 36);
|
||||
let transpose = midi - 36; // C3 is middle C;
|
||||
let url;
|
||||
let index = 0;
|
||||
if (Array.isArray(bank)) {
|
||||
index = getSoundIndex(n, bank.length);
|
||||
url = bank[index];
|
||||
} else {
|
||||
const midiDiff = (noteA) => noteToMidi(noteA) - midi;
|
||||
// object format will expect keys as notes
|
||||
const closest = Object.keys(bank)
|
||||
.filter((k) => !k.startsWith('_'))
|
||||
.reduce(
|
||||
(closest, key, j) => (!closest || Math.abs(midiDiff(key)) < Math.abs(midiDiff(closest)) ? key : closest),
|
||||
null,
|
||||
);
|
||||
transpose = -midiDiff(closest); // semitones to repitch
|
||||
index = getSoundIndex(n, bank[closest].length);
|
||||
url = bank[closest][index];
|
||||
}
|
||||
const label = `${s}:${index}`;
|
||||
return { transpose, url, index, midi, label };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
import { getAudioContext, registerSound } from './index.mjs';
|
||||
import { getCommonSampleInfo } from './util.mjs';
|
||||
import {
|
||||
applyParameterModulators,
|
||||
destroyAudioWorkletNode,
|
||||
getADSRValues,
|
||||
getFrequencyFromValue,
|
||||
getLfo,
|
||||
getParamADSR,
|
||||
getPitchEnvelope,
|
||||
getVibratoOscillator,
|
||||
getWorklet,
|
||||
webAudioTimeout,
|
||||
} from './helpers.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
const WT_MAX_MIP_LEVELS = 6;
|
||||
export const Warpmode = Object.freeze({
|
||||
NONE: 0,
|
||||
ASYM: 1,
|
||||
MIRROR: 2,
|
||||
BENDP: 3,
|
||||
BENDM: 4,
|
||||
BENDMP: 5,
|
||||
SYNC: 6,
|
||||
QUANT: 7,
|
||||
FOLD: 8,
|
||||
PWM: 9,
|
||||
ORBIT: 10,
|
||||
SPIN: 11,
|
||||
CHAOS: 12,
|
||||
PRIMES: 13,
|
||||
BINARY: 14,
|
||||
BROWNIAN: 15,
|
||||
RECIPROCAL: 16,
|
||||
WORMHOLE: 17,
|
||||
LOGISTIC: 18,
|
||||
SIGMOID: 19,
|
||||
FRACTAL: 20,
|
||||
FLIP: 21,
|
||||
});
|
||||
|
||||
async function loadWavetableFrames(url, label, frameLen = 2048) {
|
||||
const buf = await loadBuffer(url, label);
|
||||
const ch0 = buf.getChannelData(0);
|
||||
const total = ch0.length;
|
||||
const numFrames = Math.max(1, Math.floor(total / frameLen));
|
||||
const frames = new Array(numFrames);
|
||||
for (let i = 0; i < numFrames; i++) {
|
||||
const start = i * frameLen;
|
||||
frames[i] = ch0.subarray(start, start + frameLen);
|
||||
}
|
||||
|
||||
// build mipmaps
|
||||
const mipmaps = [frames];
|
||||
let levelFrames = frames;
|
||||
for (let level = 1; level < WT_MAX_MIP_LEVELS; level++) {
|
||||
const prevLen = levelFrames[0].length;
|
||||
if (prevLen <= 32) break;
|
||||
const nextLen = prevLen >> 1;
|
||||
const next = levelFrames.map((src) => {
|
||||
const out = new Float32Array(nextLen);
|
||||
for (let j = 0; j < nextLen; j++) {
|
||||
out[j] = (src[2 * j] + src[2 * j + 1]) / 2;
|
||||
}
|
||||
return out;
|
||||
});
|
||||
mipmaps.push(next);
|
||||
levelFrames = next;
|
||||
}
|
||||
return { frames, mipmaps, frameLen, numFrames };
|
||||
}
|
||||
|
||||
const loadCache = {};
|
||||
|
||||
function humanFileSize(bytes, si) {
|
||||
var thresh = si ? 1000 : 1024;
|
||||
if (bytes < thresh) return bytes + ' B';
|
||||
var units = si
|
||||
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||
var u = -1;
|
||||
do {
|
||||
bytes /= thresh;
|
||||
++u;
|
||||
} while (bytes >= thresh);
|
||||
return bytes.toFixed(1) + ' ' + units[u];
|
||||
}
|
||||
|
||||
// Extract the sample rate of a .wav file
|
||||
function parseWavSampleRate(arrBuf) {
|
||||
const dv = new DataView(arrBuf);
|
||||
// Header is "RIFF<chunk size (4 bytes)>WAVE", so 12 bytes
|
||||
let p = 12;
|
||||
// Look through chunks for the format header
|
||||
// (they will always have an 8 byte header (id and size) followed by a payload)
|
||||
while (p + 8 <= dv.byteLength) {
|
||||
// Parse id
|
||||
const id = String.fromCharCode(dv.getUint8(p), dv.getUint8(p + 1), dv.getUint8(p + 2), dv.getUint8(p + 3));
|
||||
// Parse chunk size
|
||||
const size = dv.getUint32(p + 4, true);
|
||||
if (id === 'fmt ') {
|
||||
// The format chunk contains the sample rate after
|
||||
// 8 bytes of header, 2 bytes of format tag, 2 bytes of num channels
|
||||
// (for a total of 12)
|
||||
return dv.getUint32(p + 12, true);
|
||||
}
|
||||
// Advance to next chunk
|
||||
p += 8 + size + (size & 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function decodeAtNativeRate(arr) {
|
||||
const sr = parseWavSampleRate(arr) || 44100;
|
||||
const tempAC = new OfflineAudioContext(1, 1, sr);
|
||||
return await tempAC.decodeAudioData(arr);
|
||||
}
|
||||
|
||||
const loadBuffer = (url, label) => {
|
||||
url = url.replace('#', '%23');
|
||||
if (!loadCache[url]) {
|
||||
logger(`[wavetable] load table ${label}..`, 'load-table', { url });
|
||||
const timestamp = Date.now();
|
||||
loadCache[url] = fetch(url)
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then(async (res) => {
|
||||
const took = Date.now() - timestamp;
|
||||
const size = humanFileSize(res.byteLength);
|
||||
logger(`[wavetable] load table ${label}... done! loaded ${size} in ${took}ms`, 'loaded-table', { url });
|
||||
const decoded = await decodeAtNativeRate(res);
|
||||
return decoded;
|
||||
});
|
||||
}
|
||||
return loadCache[url];
|
||||
};
|
||||
|
||||
function githubPath(base, subpath = '') {
|
||||
if (!base.startsWith('github:')) {
|
||||
throw new Error('expected "github:" at the start of pseudoUrl');
|
||||
}
|
||||
let [_, path] = base.split('github:');
|
||||
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
||||
if (path.split('/').length === 2) {
|
||||
// assume main as default branch if none set
|
||||
path += '/main';
|
||||
}
|
||||
return `https://raw.githubusercontent.com/${path}/${subpath}`;
|
||||
}
|
||||
|
||||
const _processTables = (json, baseUrl, frameLen, options = {}) => {
|
||||
baseUrl = json._base || baseUrl;
|
||||
return Object.entries(json).forEach(([key, tables]) => {
|
||||
if (key === '_base') return false;
|
||||
if (typeof tables === 'string') {
|
||||
tables = [tables];
|
||||
}
|
||||
if (typeof tables !== 'object') {
|
||||
throw new Error('wrong json format for ' + key);
|
||||
}
|
||||
let resolvedUrl = baseUrl;
|
||||
if (resolvedUrl.startsWith('github:')) {
|
||||
resolvedUrl = githubPath(resolvedUrl, '');
|
||||
}
|
||||
tables = tables
|
||||
.map((t) => resolvedUrl + t)
|
||||
.filter((t) => {
|
||||
if (!t.toLowerCase().endsWith('.wav')) {
|
||||
logger(`[wavetable] skipping ${t} -- wavetables must be ".wav" format`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (tables.length) {
|
||||
registerWaveTable(key, tables, { baseUrl, frameLen });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export function registerWaveTable(key, tables, params) {
|
||||
registerSound(
|
||||
key,
|
||||
(t, hapValue, onended, cps) => {
|
||||
return onTriggerSynth(t, hapValue, onended, tables, cps, params?.frameLen ?? 2048);
|
||||
},
|
||||
{
|
||||
type: 'wavetable',
|
||||
tables,
|
||||
...params,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a collection of wavetables to use with `s`
|
||||
*
|
||||
* @name tables
|
||||
*/
|
||||
export const tables = async (url, frameLen, json, options = {}) => {
|
||||
if (json !== undefined) return _processTables(json, url, frameLen);
|
||||
if (url.startsWith('github:')) {
|
||||
url = githubPath(url, 'strudel.json');
|
||||
}
|
||||
if (url.startsWith('local:')) {
|
||||
url = `http://localhost:5432`;
|
||||
}
|
||||
if (typeof fetch !== 'function') {
|
||||
// not a browser
|
||||
return;
|
||||
}
|
||||
if (typeof fetch === 'undefined') {
|
||||
// skip fetch when in node / testing
|
||||
return;
|
||||
}
|
||||
return fetch(url)
|
||||
.then((res) => res.json())
|
||||
.then((json) => _processTables(json, url, frameLen, options))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
throw new Error(`error loading "${url}"`);
|
||||
});
|
||||
};
|
||||
|
||||
export async function onTriggerSynth(t, value, onended, tables, cps, frameLen) {
|
||||
const { s, n = 0, duration } = value;
|
||||
const ac = getAudioContext();
|
||||
const [attack, decay, sustain, release] = getADSRValues([value.attack, value.decay, value.sustain, value.release]);
|
||||
let { warpmode } = value;
|
||||
if (typeof warpmode === 'string') {
|
||||
warpmode = Warpmode[warpmode.toUpperCase()] ?? Warpmode.NONE;
|
||||
}
|
||||
const frequency = getFrequencyFromValue(value);
|
||||
const { url, label } = getCommonSampleInfo(value, tables);
|
||||
const payload = await loadWavetableFrames(url, label, frameLen);
|
||||
const holdEnd = t + duration;
|
||||
const endWithRelease = holdEnd + release;
|
||||
const envEnd = endWithRelease + 0.01;
|
||||
const source = getWorklet(
|
||||
ac,
|
||||
'wavetable-oscillator-processor',
|
||||
{
|
||||
begin: t,
|
||||
end: envEnd,
|
||||
frequency,
|
||||
detune: value.detune,
|
||||
position: value.wt,
|
||||
warp: value.warp,
|
||||
warpMode: warpmode,
|
||||
voices: Math.max(value.unison ?? 1, 1),
|
||||
spread: value.spread,
|
||||
phaserand: (value.wtphaserand ?? value.unison > 1) ? 1 : 0,
|
||||
},
|
||||
{ outputChannelCount: [2] },
|
||||
);
|
||||
source.port.postMessage({ type: 'tables', payload });
|
||||
if (ac.currentTime > t) {
|
||||
logger(`[wavetable] still loading sound "${s}:${n}"`, 'highlight');
|
||||
return;
|
||||
}
|
||||
const posADSRParams = [value.wtattack, value.wtdecay, value.wtsustain, value.wtrelease];
|
||||
const warpADSRParams = [value.warpattack, value.warpdecay, value.warpsustain, value.warprelease];
|
||||
const wtParams = source.parameters;
|
||||
const positionParam = wtParams.get('position');
|
||||
const warpParam = wtParams.get('warp');
|
||||
|
||||
let wtrate = value.wtrate;
|
||||
if (value.wtsync != null) {
|
||||
wtrate = cps * value.wtsync;
|
||||
}
|
||||
|
||||
const wtPosModulators = applyParameterModulators(
|
||||
ac,
|
||||
positionParam,
|
||||
t,
|
||||
endWithRelease,
|
||||
{
|
||||
offset: value.wt,
|
||||
amount: value.wtenv,
|
||||
defaultAmount: 0.5,
|
||||
shape: 'linear',
|
||||
values: posADSRParams,
|
||||
holdEnd,
|
||||
defaultValues: [0, 0.5, 0, 0.1],
|
||||
},
|
||||
{
|
||||
frequency: wtrate,
|
||||
depth: value.wtdepth,
|
||||
defaultDepth: 0.5,
|
||||
shape: value.wtshape,
|
||||
skew: value.wtskew,
|
||||
dcoffset: value.wtdc ?? 0,
|
||||
},
|
||||
);
|
||||
|
||||
let warprate = value.warprate;
|
||||
if (value.warpsync != null) {
|
||||
warprate = warprate = cps * value.warpsync;
|
||||
}
|
||||
const wtWarpModulators = applyParameterModulators(
|
||||
ac,
|
||||
warpParam,
|
||||
t,
|
||||
endWithRelease,
|
||||
{
|
||||
offset: value.warp,
|
||||
amount: value.warpenv,
|
||||
defaultAmount: 0.5,
|
||||
shape: 'linear',
|
||||
values: warpADSRParams,
|
||||
holdEnd,
|
||||
defaultValues: [0, 0.5, 0, 0.1],
|
||||
},
|
||||
{
|
||||
frequency: warprate,
|
||||
depth: value.warpdepth,
|
||||
defaultDepth: 0.5,
|
||||
shape: value.warpshape,
|
||||
skew: value.warpskew,
|
||||
dcoffset: value.warpdc ?? 0,
|
||||
},
|
||||
);
|
||||
const vibratoOscillator = getVibratoOscillator(source.parameters.get('detune'), value, t);
|
||||
const envGain = ac.createGain();
|
||||
const node = source.connect(envGain);
|
||||
getParamADSR(node.gain, attack, decay, sustain, release, 0, 1, t, holdEnd, 'linear');
|
||||
getPitchEnvelope(source.parameters.get('detune'), value, t, holdEnd);
|
||||
const handle = { node, source };
|
||||
const timeoutNode = webAudioTimeout(
|
||||
ac,
|
||||
() => {
|
||||
source.disconnect();
|
||||
destroyAudioWorkletNode(source);
|
||||
vibratoOscillator?.stop();
|
||||
node.disconnect();
|
||||
wtPosModulators?.disconnect();
|
||||
wtWarpModulators?.disconnect();
|
||||
onended();
|
||||
},
|
||||
t,
|
||||
envEnd,
|
||||
);
|
||||
handle.stop = (time) => {
|
||||
timeoutNode.stop(time);
|
||||
};
|
||||
return handle;
|
||||
}
|
||||
@@ -6,7 +6,21 @@ import OLAProcessor from './ola-processor';
|
||||
import FFT from './fft.js';
|
||||
|
||||
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
||||
const _mod = (n, m) => ((n % m) + m) % m;
|
||||
const mod = (n, m) => ((n % m) + m) % m;
|
||||
const lerp = (a, b, n) => n * (b - a) + a;
|
||||
const pv = (arr, n) => arr[n] ?? arr[0];
|
||||
const frac = (x) => x - Math.floor(x);
|
||||
const ffloor = (x) => x | 0; // fast floor for non-negative
|
||||
|
||||
const getUnisonDetune = (unison, detune, voiceIndex) => {
|
||||
if (unison < 2) {
|
||||
return 0;
|
||||
}
|
||||
return lerp(-detune * 0.5, detune * 0.5, voiceIndex / (unison - 1));
|
||||
};
|
||||
const applySemitoneDetuneToFrequency = (frequency, detune) => {
|
||||
return frequency * Math.pow(2, detune / 12);
|
||||
};
|
||||
|
||||
// Restrict phase to the range [0, maxPhase) via wrapping
|
||||
function wrapPhase(phase, maxPhase = 1) {
|
||||
@@ -150,7 +164,7 @@ class LFOProcessor extends AudioWorkletProcessor {
|
||||
const blockSize = output[0].length ?? 0;
|
||||
|
||||
if (this.phase == null) {
|
||||
this.phase = _mod(time * frequency + phaseoffset, 1);
|
||||
this.phase = mod(time * frequency + phaseoffset, 1);
|
||||
}
|
||||
const dt = frequency / sampleRate;
|
||||
for (let n = 0; n < blockSize; n++) {
|
||||
@@ -271,6 +285,73 @@ class ShapeProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
registerProcessor('shape-processor', ShapeProcessor);
|
||||
|
||||
class TwoPoleFilter {
|
||||
s0 = 0;
|
||||
s1 = 0;
|
||||
update(s, cutoff, resonance = 0) {
|
||||
// Out of bound values can produce NaNs
|
||||
resonance = clamp(resonance, 0, 1);
|
||||
cutoff = clamp(cutoff, 0, sampleRate / 2 - 1);
|
||||
const c = clamp(2 * Math.sin(cutoff * (_PI / sampleRate)), 0, 1.14);
|
||||
const r = Math.pow(0.5, (resonance + 0.125) / 0.125);
|
||||
const mrc = 1 - r * c;
|
||||
this.s0 = mrc * this.s0 - c * this.s1 + c * s; // bpf
|
||||
this.s1 = mrc * this.s1 + c * this.s0; // lpf
|
||||
return this.s1; // return lpf by default
|
||||
}
|
||||
}
|
||||
|
||||
class DJFProcessor extends AudioWorkletProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [{ name: 'value', defaultValue: 0.5 }];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.filters = [new TwoPoleFilter(), new TwoPoleFilter()];
|
||||
}
|
||||
|
||||
process(inputs, outputs, parameters) {
|
||||
const input = inputs[0];
|
||||
const output = outputs[0];
|
||||
|
||||
const hasInput = !(input[0] === undefined);
|
||||
this.started = hasInput;
|
||||
|
||||
const value = clamp(parameters.value[0], 0, 1);
|
||||
let filterType = 'none';
|
||||
let cutoff;
|
||||
let v = 1;
|
||||
if (value > 0.51) {
|
||||
filterType = 'hipass';
|
||||
v = (value - 0.5) * 2;
|
||||
} else if (value < 0.49) {
|
||||
filterType = 'lopass';
|
||||
v = value * 2;
|
||||
}
|
||||
cutoff = Math.pow(v * 11, 4);
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
for (let n = 0; n < blockSize; n++) {
|
||||
if (filterType == 'none') {
|
||||
output[i][n] = input[i][n];
|
||||
} else {
|
||||
this.filters[i].update(input[i][n], cutoff, 0.1);
|
||||
if (filterType === 'lopass') {
|
||||
output[i][n] = this.filters[i].s1;
|
||||
} else if (filterType === 'hipass') {
|
||||
output[i][n] = input[i][n] - this.filters[i].s1;
|
||||
} else {
|
||||
output[i][n] = input[i][n];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
registerProcessor('djf-processor', DJFProcessor);
|
||||
|
||||
function fast_tanh(x) {
|
||||
const x2 = x * x;
|
||||
return (x * (27.0 + x2)) / (27.0 + 9.0 * x2);
|
||||
@@ -378,21 +459,6 @@ class DistortProcessor extends AudioWorkletProcessor {
|
||||
registerProcessor('distort-processor', DistortProcessor);
|
||||
|
||||
// SUPERSAW
|
||||
function lerp(a, b, n) {
|
||||
return n * (b - a) + a;
|
||||
}
|
||||
|
||||
function getUnisonDetune(unison, detune, voiceIndex) {
|
||||
if (unison < 2) {
|
||||
return 0;
|
||||
}
|
||||
return lerp(-detune * 0.5, detune * 0.5, voiceIndex / (unison - 1));
|
||||
}
|
||||
|
||||
function applySemitoneDetuneToFrequency(frequency, detune) {
|
||||
return frequency * Math.pow(2, detune / 12);
|
||||
}
|
||||
|
||||
class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
constructor() {
|
||||
super();
|
||||
@@ -454,29 +520,31 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
|
||||
const output = outputs[0];
|
||||
const voices = params.voices[0];
|
||||
const freqspread = params.freqspread[0];
|
||||
const panspread = params.panspread[0] * 0.5 + 0.5;
|
||||
const gain1 = Math.sqrt(1 - panspread);
|
||||
const gain2 = Math.sqrt(panspread);
|
||||
|
||||
for (let n = 0; n < voices; n++) {
|
||||
const isOdd = (n & 1) == 1;
|
||||
let gainL = gain1;
|
||||
let gainR = gain2;
|
||||
// invert right and left gain
|
||||
if (isOdd) {
|
||||
gainL = gain2;
|
||||
gainR = gain1;
|
||||
}
|
||||
for (let i = 0; i < output[0].length; i++) {
|
||||
// Main detuning
|
||||
let freq = applySemitoneDetuneToFrequency(params.frequency[i] ?? params.frequency[0], params.detune[0] / 100);
|
||||
for (let i = 0; i < output[0].length; i++) {
|
||||
const detune = pv(params.detune, i);
|
||||
const voices = pv(params.voices, i);
|
||||
const freqspread = pv(params.freqspread, i);
|
||||
const panspread = pv(params.panspread, i) * 0.5 + 0.5;
|
||||
const gain1 = Math.sqrt(1 - panspread);
|
||||
const gain2 = Math.sqrt(panspread);
|
||||
let freq = pv(params.frequency, i);
|
||||
// Main detuning
|
||||
freq = applySemitoneDetuneToFrequency(freq, detune / 100);
|
||||
for (let n = 0; n < voices; n++) {
|
||||
const isOdd = (n & 1) == 1;
|
||||
let gainL = gain1;
|
||||
let gainR = gain2;
|
||||
// invert right and left gain
|
||||
if (isOdd) {
|
||||
gainL = gain2;
|
||||
gainR = gain1;
|
||||
}
|
||||
// Individual voice detuning
|
||||
freq = applySemitoneDetuneToFrequency(freq, getUnisonDetune(voices, freqspread, n));
|
||||
const freqVoice = applySemitoneDetuneToFrequency(freq, getUnisonDetune(voices, freqspread, n));
|
||||
// We must wrap this here because it is passed into sawblep below which
|
||||
// has domain [0, 1]
|
||||
const dt = _mod(freq / sampleRate, 1);
|
||||
const dt = mod(freqVoice / sampleRate, 1);
|
||||
this.phase[n] = this.phase[n] ?? Math.random();
|
||||
const v = waveshapes.sawblep(this.phase[n], dt);
|
||||
|
||||
@@ -907,3 +975,323 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
|
||||
registerProcessor('byte-beat-processor', ByteBeatProcessor);
|
||||
|
||||
export const WarpMode = Object.freeze({
|
||||
NONE: 0,
|
||||
ASYM: 1,
|
||||
MIRROR: 2,
|
||||
BENDP: 3,
|
||||
BENDM: 4,
|
||||
BENDMP: 5,
|
||||
SYNC: 6,
|
||||
QUANT: 7,
|
||||
FOLD: 8,
|
||||
PWM: 9,
|
||||
ORBIT: 10,
|
||||
SPIN: 11,
|
||||
CHAOS: 12,
|
||||
PRIMES: 13,
|
||||
BINARY: 14,
|
||||
BROWNIAN: 15,
|
||||
RECIPROCAL: 16,
|
||||
WORMHOLE: 17,
|
||||
LOGISTIC: 18,
|
||||
SIGMOID: 19,
|
||||
FRACTAL: 20,
|
||||
FLIP: 21,
|
||||
});
|
||||
|
||||
function hash32(u) {
|
||||
u = u + 0x7ed55d16 + (u << 12);
|
||||
u = u ^ 0xc761c23c ^ (u >>> 19);
|
||||
u = u + 0x165667b1 + (u << 5);
|
||||
u = (u + 0xd3a2646c) ^ (u << 9);
|
||||
u = u + 0xfd7046c5 + (u << 3);
|
||||
u = u ^ 0xb55a4f09 ^ (u >>> 16);
|
||||
return u >>> 0;
|
||||
}
|
||||
const hash01 = (i) => (hash32(i) >>> 8) / 0x01000000;
|
||||
|
||||
function bitReverse(i, n) {
|
||||
let r = 0;
|
||||
for (let b = 0; b < n; b++) {
|
||||
r = (r << 1) | (i & 1);
|
||||
i >>>= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function noise(x) {
|
||||
const i = Math.floor(x),
|
||||
f = x - i;
|
||||
const a = hash01(i),
|
||||
b = hash01(i + 1);
|
||||
return a + (b - a) * f;
|
||||
}
|
||||
|
||||
function brownian(x, oct = 4) {
|
||||
let amp = 0.5,
|
||||
sum = 0,
|
||||
norm = 0,
|
||||
freq = 1;
|
||||
for (let o = 0; o < oct; o++) {
|
||||
sum += amp * noise(x * freq);
|
||||
norm += amp;
|
||||
amp *= 0.5;
|
||||
freq *= 2;
|
||||
}
|
||||
return (sum / norm) * 2 - 1;
|
||||
}
|
||||
|
||||
class WavetableOscillatorProcessor extends AudioWorkletProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [
|
||||
{ name: 'begin', defaultValue: 0, min: 0, max: Number.POSITIVE_INFINITY },
|
||||
{ name: 'end', defaultValue: 0, min: 0, max: Number.POSITIVE_INFINITY },
|
||||
{ name: 'frequency', defaultValue: 220, minValue: 0.01, maxValue: 20000 },
|
||||
{ name: 'detune', defaultValue: 0.18 },
|
||||
{ name: 'position', defaultValue: 0, minValue: 0, maxValue: 1 },
|
||||
{ name: 'warp', defaultValue: 0, minValue: 0, maxValue: 1 },
|
||||
{ name: 'warpMode', defaultValue: 0 },
|
||||
{ name: 'voices', defaultValue: 1, minValue: 1, maxValue: 32 },
|
||||
{ name: 'spread', defaultValue: 0.7, minValue: 0, maxValue: 1 },
|
||||
{ name: 'phaserand', defaultValue: 0, minValue: 0, maxValue: 1 },
|
||||
];
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.tables = null;
|
||||
this.frameLen = 0;
|
||||
this.numFrames = 0;
|
||||
this.phase = [];
|
||||
this.syncRatio = 1;
|
||||
|
||||
this.port.onmessage = (e) => {
|
||||
const { type, payload } = e.data || {};
|
||||
if (type === 'tables') {
|
||||
this.tables = payload.mipmaps;
|
||||
this.frameLen = payload.frameLen;
|
||||
this.numFrames = this.tables[0].length;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_chooseMip(dphi) {
|
||||
const approxHarm = Math.min(64, 1 / Math.max(1e-6, dphi));
|
||||
let level = 0;
|
||||
while (level + 1 < (this.tables?.length || 1) && approxHarm < this.tables[level][0].length / 8) {
|
||||
level++;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
_mirror(x) {
|
||||
return 1 - Math.abs(2 * x - 1);
|
||||
}
|
||||
|
||||
_toBits(amt, min = 2, max = 12) {
|
||||
const b = max + (min - max) * amt;
|
||||
return { b, n: Math.round(Math.pow(2, b)) };
|
||||
}
|
||||
|
||||
_warpPhase(phase, amt, mode) {
|
||||
switch (mode) {
|
||||
case WarpMode.NONE: {
|
||||
return phase;
|
||||
}
|
||||
case WarpMode.ASYM: {
|
||||
const a = 0.01 + 0.99 * amt;
|
||||
return phase < a ? (0.5 * phase) / a : 0.5 + (0.5 * (phase - a)) / (1 - a);
|
||||
}
|
||||
case WarpMode.MIRROR: {
|
||||
// Asym, then mirror
|
||||
return this._mirror(this._warpPhase(phase, amt, WarpMode.ASYM));
|
||||
}
|
||||
case WarpMode.BENDP: {
|
||||
return Math.pow(phase, 1 + 3 * amt);
|
||||
}
|
||||
case WarpMode.BENDM: {
|
||||
return Math.pow(phase, 1 / (1 + 3 * amt));
|
||||
}
|
||||
case WarpMode.BENDMP: {
|
||||
return amt < 0.5 ? this._warpPhase(phase, 1 - 2 * amt, 3) : this._warpPhase(phase, 2 * amt - 1, 2);
|
||||
}
|
||||
case WarpMode.SYNC: {
|
||||
const syncRatio = Math.pow(16, amt * amt);
|
||||
return (phase * syncRatio) % 1;
|
||||
}
|
||||
case WarpMode.QUANT: {
|
||||
const { n } = this._toBits(amt);
|
||||
return ffloor(phase * n) / n;
|
||||
}
|
||||
case WarpMode.FOLD: {
|
||||
const K = 7;
|
||||
const k = 1 + Math.max(1, Math.round(K * amt));
|
||||
return Math.abs(frac(k * phase) - 0.5) * 2;
|
||||
}
|
||||
case WarpMode.PWM: {
|
||||
const w = clamp(0.5 + 0.49 * (2 * amt - 1), 0, 1);
|
||||
if (phase < w) return (phase / w) * 0.5;
|
||||
return 0.5 + ((phase - w) / (1 - w)) * 0.5;
|
||||
}
|
||||
case WarpMode.ORBIT: {
|
||||
const depth = 0.5 * amt;
|
||||
const n = 3;
|
||||
return frac(phase + depth * Math.sin(2 * Math.PI * n * phase));
|
||||
}
|
||||
case WarpMode.SPIN: {
|
||||
const depth = 0.5 * amt;
|
||||
const { n } = this._toBits(amt, 1, 6);
|
||||
return frac(phase + depth * Math.sin(2 * Math.PI * n * phase));
|
||||
}
|
||||
case WarpMode.CHAOS: {
|
||||
const r = 3.7 + 0.3 * amt;
|
||||
const logistic = r * phase * (1 - phase);
|
||||
return clamp((1 - amt) * phase + amt * logistic, 0, 1);
|
||||
}
|
||||
case WarpMode.PRIMES: {
|
||||
const isPrime = (n) => {
|
||||
if (n < 2) return false;
|
||||
if (n % 2 === 0) return n === 2;
|
||||
for (let d = 3; d * d <= n; d += 2) if (n % d === 0) return false;
|
||||
return true;
|
||||
};
|
||||
let { n } = this._toBits(amt, 3);
|
||||
while (!isPrime(n)) n++;
|
||||
return ffloor(phase * n) / n;
|
||||
}
|
||||
case WarpMode.BINARY: {
|
||||
let { b } = this._toBits(amt, 3);
|
||||
b = Math.round(b);
|
||||
const n = 1 << b;
|
||||
const idx = ffloor(phase * n);
|
||||
const ridx = bitReverse(idx, b);
|
||||
return ridx / n;
|
||||
}
|
||||
case WarpMode.MODULAR: {
|
||||
const { n } = this._toBits(amt);
|
||||
const depth = 0.5 * amt;
|
||||
const jump = frac(phase * n) / n;
|
||||
return frac(phase + depth * jump);
|
||||
}
|
||||
case WarpMode.BROWNIAN: {
|
||||
const disp = 0.25 * amt * brownian(64 * phase, 4);
|
||||
return frac(phase + disp);
|
||||
}
|
||||
case WarpMode.RECIPROCAL: {
|
||||
const g = 2 + 4 * amt;
|
||||
const num = phase * g;
|
||||
const den = phase + (1 - phase) * g;
|
||||
const y = den > 1e-12 ? num / den : 0;
|
||||
return clamp(y, 0, 1);
|
||||
}
|
||||
case WarpMode.WORMHOLE: {
|
||||
const gap = clamp(0.8 * amt, 0, 1);
|
||||
const a = 0.5 * (1 - gap);
|
||||
const b = 0.5 * (1 + gap);
|
||||
if (phase < a) return (phase / a) * 0.5;
|
||||
if (phase > b) return 0.5 * (1 + (phase - b) / (1 - b));
|
||||
return 0.5;
|
||||
}
|
||||
case WarpMode.LOGISTIC: {
|
||||
let x = phase;
|
||||
const r = 3.6 + 0.4 * amt;
|
||||
const iters = 1 + Math.round(2 * amt);
|
||||
for (let i = 0; i < iters; i++) x = r * x * (1 - x);
|
||||
return clamp(x, 0, 1);
|
||||
}
|
||||
case WarpMode.SIGMOID: {
|
||||
const k = 1 + 10 * amt;
|
||||
const x = phase - 0.5;
|
||||
const y = 1 / (1 + Math.exp(-k * x));
|
||||
const y0 = 1 / (1 + Math.exp(0.5 * k));
|
||||
const y1 = 1 / (1 + Math.exp(-0.5 * k));
|
||||
return (y - y0) / (y1 - y0);
|
||||
}
|
||||
case WarpMode.FRACTAL: {
|
||||
const d = 0.5 * Math.sin(2 * Math.PI * phase) * amt;
|
||||
return frac(phase + d);
|
||||
}
|
||||
case WarpMode.FLIP: {
|
||||
return phase;
|
||||
}
|
||||
default:
|
||||
return phase;
|
||||
}
|
||||
}
|
||||
|
||||
_sampleFrame(frame, phase) {
|
||||
const pos = phase * frame.length;
|
||||
const i = pos | 0;
|
||||
const frac = pos - i;
|
||||
const a = frame[i % frame.length];
|
||||
const b = frame[(i + 1) % frame.length];
|
||||
return a + (b - a) * frac;
|
||||
}
|
||||
|
||||
process(_inputs, outputs, parameters) {
|
||||
if (currentTime >= parameters.end[0]) {
|
||||
return false;
|
||||
}
|
||||
if (currentTime <= parameters.begin[0]) {
|
||||
return true;
|
||||
}
|
||||
const outL = outputs[0][0];
|
||||
const outR = outputs[0][1] || outputs[0][0];
|
||||
|
||||
if (!this.tables) {
|
||||
outL.fill(0);
|
||||
if (outR !== outL) outR.set(outL);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < outL.length; i++) {
|
||||
const detune = pv(parameters.detune, i);
|
||||
const tablePos = pv(parameters.position, i);
|
||||
const idx = tablePos * (this.numFrames - 1);
|
||||
const fIdx = idx | 0;
|
||||
const frac = idx - fIdx;
|
||||
const warpAmount = pv(parameters.warp, i);
|
||||
const warpMode = pv(parameters.warpMode, i);
|
||||
const voices = pv(parameters.voices, i);
|
||||
const phaseRand = pv(parameters.phaserand, i);
|
||||
const spread = voices > 1 ? pv(parameters.spread, i) : 0;
|
||||
const gain1 = Math.sqrt(0.5 - 0.5 * spread);
|
||||
const gain2 = Math.sqrt(0.5 + 0.5 * spread);
|
||||
let f = pv(parameters.frequency, i);
|
||||
f = applySemitoneDetuneToFrequency(f, detune / 100); // overall detune
|
||||
const normalizer = 0.3 / Math.sqrt(voices);
|
||||
for (let n = 0; n < voices; n++) {
|
||||
const isOdd = (n & 1) == 1;
|
||||
let gainL = gain1;
|
||||
let gainR = gain2;
|
||||
// invert right and left gain
|
||||
if (isOdd) {
|
||||
gainL = gain2;
|
||||
gainR = gain1;
|
||||
}
|
||||
const fVoice = applySemitoneDetuneToFrequency(f, getUnisonDetune(voices, detune, n)); // voice detune
|
||||
const dPhase = fVoice / sampleRate;
|
||||
const level = this._chooseMip(dPhase);
|
||||
const table = this.tables[level];
|
||||
|
||||
// warp phase then sample
|
||||
this.phase[n] = this.phase[n] ?? Math.random() * phaseRand;
|
||||
const ph = this._warpPhase(this.phase[n], warpAmount, warpMode);
|
||||
const s0 = this._sampleFrame(table[fIdx], ph);
|
||||
const s1 = this._sampleFrame(table[Math.min(this.numFrames - 1, fIdx + 1)], ph);
|
||||
let s = s0 + (s1 - s0) * frac;
|
||||
if (warpMode === WarpMode.FLIP && this.phase[n] < warpAmount) {
|
||||
s = -s;
|
||||
}
|
||||
outL[i] += s * gainL * normalizer;
|
||||
outR[i] += s * gainR * normalizer;
|
||||
this.phase[n] = wrapPhase(this.phase[n] + dPhase);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor('wavetable-oscillator-processor', WavetableOscillatorProcessor);
|
||||
|
||||
@@ -1051,112 +1051,6 @@ exports[`runs examples > example "begin" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "beginSeconds" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 1/8 → 1/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 1/4 → 3/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 3/8 → 1/2 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 1/2 → 5/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 5/8 → 3/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 3/4 → 7/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 7/8 → 1/1 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 1/1 → 9/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 9/8 → 5/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 5/4 → 11/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 11/8 → 3/2 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 3/2 → 13/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 13/8 → 7/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 7/4 → 15/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 15/8 → 2/1 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 2/1 → 17/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 17/8 → 9/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 9/4 → 19/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 19/8 → 5/2 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 5/2 → 21/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 21/8 → 11/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 11/4 → 23/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 23/8 → 3/1 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 3/1 → 25/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 25/8 → 13/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 13/4 → 27/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 27/8 → 7/2 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
"[ 7/2 → 29/8 | s:swpad clip:1 beginSeconds:2 ]",
|
||||
"[ 29/8 → 15/4 | s:swpad clip:1 beginSeconds:5 ]",
|
||||
"[ 15/4 → 31/8 | s:swpad clip:1 beginSeconds:0.2 ]",
|
||||
"[ 31/8 → 4/1 | s:swpad clip:1 beginSeconds:3 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "beginSeconds" example index 1 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | s:swpad beginSeconds:0 decay:0.1 ]",
|
||||
"[ 1/16 → 1/8 | s:swpad beginSeconds:0.0625 decay:0.1 ]",
|
||||
"[ 1/8 → 3/16 | s:swpad beginSeconds:0.125 decay:0.1 ]",
|
||||
"[ 3/16 → 1/4 | s:swpad beginSeconds:0.1875 decay:0.1 ]",
|
||||
"[ 1/4 → 5/16 | s:swpad beginSeconds:0.25 decay:0.1 ]",
|
||||
"[ 5/16 → 3/8 | s:swpad beginSeconds:0.3125 decay:0.1 ]",
|
||||
"[ 3/8 → 7/16 | s:swpad beginSeconds:0.375 decay:0.1 ]",
|
||||
"[ 7/16 → 1/2 | s:swpad beginSeconds:0.4375 decay:0.1 ]",
|
||||
"[ 1/2 → 9/16 | s:swpad beginSeconds:0.5 decay:0.1 ]",
|
||||
"[ 9/16 → 5/8 | s:swpad beginSeconds:0.5625 decay:0.1 ]",
|
||||
"[ 5/8 → 11/16 | s:swpad beginSeconds:0.625 decay:0.1 ]",
|
||||
"[ 11/16 → 3/4 | s:swpad beginSeconds:0.6875 decay:0.1 ]",
|
||||
"[ 3/4 → 13/16 | s:swpad beginSeconds:0.75 decay:0.1 ]",
|
||||
"[ 13/16 → 7/8 | s:swpad beginSeconds:0.8125 decay:0.1 ]",
|
||||
"[ 7/8 → 15/16 | s:swpad beginSeconds:0.875 decay:0.1 ]",
|
||||
"[ 15/16 → 1/1 | s:swpad beginSeconds:0.9375 decay:0.1 ]",
|
||||
"[ 1/1 → 17/16 | s:swpad beginSeconds:1 decay:0.1 ]",
|
||||
"[ 17/16 → 9/8 | s:swpad beginSeconds:1.0625 decay:0.1 ]",
|
||||
"[ 9/8 → 19/16 | s:swpad beginSeconds:1.125 decay:0.1 ]",
|
||||
"[ 19/16 → 5/4 | s:swpad beginSeconds:1.1875 decay:0.1 ]",
|
||||
"[ 5/4 → 21/16 | s:swpad beginSeconds:1.25 decay:0.1 ]",
|
||||
"[ 21/16 → 11/8 | s:swpad beginSeconds:1.3125 decay:0.1 ]",
|
||||
"[ 11/8 → 23/16 | s:swpad beginSeconds:1.375 decay:0.1 ]",
|
||||
"[ 23/16 → 3/2 | s:swpad beginSeconds:1.4375 decay:0.1 ]",
|
||||
"[ 3/2 → 25/16 | s:swpad beginSeconds:1.5 decay:0.1 ]",
|
||||
"[ 25/16 → 13/8 | s:swpad beginSeconds:1.5625 decay:0.1 ]",
|
||||
"[ 13/8 → 27/16 | s:swpad beginSeconds:1.625 decay:0.1 ]",
|
||||
"[ 27/16 → 7/4 | s:swpad beginSeconds:1.6875 decay:0.1 ]",
|
||||
"[ 7/4 → 29/16 | s:swpad beginSeconds:1.75 decay:0.1 ]",
|
||||
"[ 29/16 → 15/8 | s:swpad beginSeconds:1.8125 decay:0.1 ]",
|
||||
"[ 15/8 → 31/16 | s:swpad beginSeconds:1.875 decay:0.1 ]",
|
||||
"[ 31/16 → 2/1 | s:swpad beginSeconds:1.9375 decay:0.1 ]",
|
||||
"[ 2/1 → 33/16 | s:swpad beginSeconds:2 decay:0.1 ]",
|
||||
"[ 33/16 → 17/8 | s:swpad beginSeconds:2.0625 decay:0.1 ]",
|
||||
"[ 17/8 → 35/16 | s:swpad beginSeconds:2.125 decay:0.1 ]",
|
||||
"[ 35/16 → 9/4 | s:swpad beginSeconds:2.1875 decay:0.1 ]",
|
||||
"[ 9/4 → 37/16 | s:swpad beginSeconds:2.25 decay:0.1 ]",
|
||||
"[ 37/16 → 19/8 | s:swpad beginSeconds:2.3125 decay:0.1 ]",
|
||||
"[ 19/8 → 39/16 | s:swpad beginSeconds:2.375 decay:0.1 ]",
|
||||
"[ 39/16 → 5/2 | s:swpad beginSeconds:2.4375 decay:0.1 ]",
|
||||
"[ 5/2 → 41/16 | s:swpad beginSeconds:2.5 decay:0.1 ]",
|
||||
"[ 41/16 → 21/8 | s:swpad beginSeconds:2.5625 decay:0.1 ]",
|
||||
"[ 21/8 → 43/16 | s:swpad beginSeconds:2.625 decay:0.1 ]",
|
||||
"[ 43/16 → 11/4 | s:swpad beginSeconds:2.6875 decay:0.1 ]",
|
||||
"[ 11/4 → 45/16 | s:swpad beginSeconds:2.75 decay:0.1 ]",
|
||||
"[ 45/16 → 23/8 | s:swpad beginSeconds:2.8125 decay:0.1 ]",
|
||||
"[ 23/8 → 47/16 | s:swpad beginSeconds:2.875 decay:0.1 ]",
|
||||
"[ 47/16 → 3/1 | s:swpad beginSeconds:2.9375 decay:0.1 ]",
|
||||
"[ 3/1 → 49/16 | s:swpad beginSeconds:3 decay:0.1 ]",
|
||||
"[ 49/16 → 25/8 | s:swpad beginSeconds:3.0625 decay:0.1 ]",
|
||||
"[ 25/8 → 51/16 | s:swpad beginSeconds:3.125 decay:0.1 ]",
|
||||
"[ 51/16 → 13/4 | s:swpad beginSeconds:3.1875 decay:0.1 ]",
|
||||
"[ 13/4 → 53/16 | s:swpad beginSeconds:3.25 decay:0.1 ]",
|
||||
"[ 53/16 → 27/8 | s:swpad beginSeconds:3.3125 decay:0.1 ]",
|
||||
"[ 27/8 → 55/16 | s:swpad beginSeconds:3.375 decay:0.1 ]",
|
||||
"[ 55/16 → 7/2 | s:swpad beginSeconds:3.4375 decay:0.1 ]",
|
||||
"[ 7/2 → 57/16 | s:swpad beginSeconds:3.5 decay:0.1 ]",
|
||||
"[ 57/16 → 29/8 | s:swpad beginSeconds:3.5625 decay:0.1 ]",
|
||||
"[ 29/8 → 59/16 | s:swpad beginSeconds:3.625 decay:0.1 ]",
|
||||
"[ 59/16 → 15/4 | s:swpad beginSeconds:3.6875 decay:0.1 ]",
|
||||
"[ 15/4 → 61/16 | s:swpad beginSeconds:3.75 decay:0.1 ]",
|
||||
"[ 61/16 → 31/8 | s:swpad beginSeconds:3.8125 decay:0.1 ]",
|
||||
"[ 31/8 → 63/16 | s:swpad beginSeconds:3.875 decay:0.1 ]",
|
||||
"[ 63/16 → 4/1 | s:swpad beginSeconds:3.9375 decay:0.1 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "berlin" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | note:D3 ]",
|
||||
@@ -2937,26 +2831,38 @@ exports[`runs examples > example "distort" example index 1 1`] = `
|
||||
|
||||
exports[`runs examples > example "djf" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | n:0 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 1/4 → 1/2 | n:3 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 1/2 → 3/4 | n:7 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 3/4 → 1/1 | n:10 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 3/4 → 1/1 | n:24 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 1/1 → 5/4 | n:0 s:superzow octave:3 djf:0.25 ]",
|
||||
"[ 5/4 → 3/2 | n:3 s:superzow octave:3 djf:0.25 ]",
|
||||
"[ 3/2 → 7/4 | n:7 s:superzow octave:3 djf:0.25 ]",
|
||||
"[ 7/4 → 2/1 | n:10 s:superzow octave:3 djf:0.25 ]",
|
||||
"[ 7/4 → 2/1 | n:24 s:superzow octave:3 djf:0.25 ]",
|
||||
"[ 2/1 → 9/4 | n:0 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 9/4 → 5/2 | n:3 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 5/2 → 11/4 | n:7 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 11/4 → 3/1 | n:10 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 11/4 → 3/1 | n:24 s:superzow octave:3 djf:0.5 ]",
|
||||
"[ 3/1 → 13/4 | n:0 s:superzow octave:3 djf:0.75 ]",
|
||||
"[ 13/4 → 7/2 | n:3 s:superzow octave:3 djf:0.75 ]",
|
||||
"[ 7/2 → 15/4 | n:7 s:superzow octave:3 djf:0.75 ]",
|
||||
"[ 15/4 → 4/1 | n:10 s:superzow octave:3 djf:0.75 ]",
|
||||
"[ 15/4 → 4/1 | n:24 s:superzow octave:3 djf:0.75 ]",
|
||||
"[ 0/1 → 1/8 | note:D3 s:supersaw djf:0.5 ]",
|
||||
"[ 1/8 → 1/4 | note:G4 s:supersaw djf:0.5 ]",
|
||||
"[ 1/4 → 3/8 | note:Bb3 s:supersaw djf:0.5 ]",
|
||||
"[ 3/8 → 1/2 | note:C4 s:supersaw djf:0.5 ]",
|
||||
"[ 1/2 → 5/8 | note:A3 s:supersaw djf:0.5 ]",
|
||||
"[ 5/8 → 3/4 | note:F3 s:supersaw djf:0.5 ]",
|
||||
"[ 3/4 → 7/8 | note:G3 s:supersaw djf:0.5 ]",
|
||||
"[ 7/8 → 1/1 | note:C4 s:supersaw djf:0.5 ]",
|
||||
"[ 1/1 → 9/8 | note:Eb4 s:supersaw djf:0.3 ]",
|
||||
"[ 9/8 → 5/4 | note:G4 s:supersaw djf:0.3 ]",
|
||||
"[ 5/4 → 11/8 | note:A4 s:supersaw djf:0.3 ]",
|
||||
"[ 11/8 → 3/2 | note:F3 s:supersaw djf:0.3 ]",
|
||||
"[ 3/2 → 13/8 | note:F4 s:supersaw djf:0.3 ]",
|
||||
"[ 13/8 → 7/4 | note:D4 s:supersaw djf:0.3 ]",
|
||||
"[ 7/4 → 15/8 | note:G3 s:supersaw djf:0.3 ]",
|
||||
"[ 15/8 → 2/1 | note:F4 s:supersaw djf:0.3 ]",
|
||||
"[ 2/1 → 17/8 | note:Eb5 s:supersaw djf:0.2 ]",
|
||||
"[ 17/8 → 9/4 | note:D5 s:supersaw djf:0.2 ]",
|
||||
"[ 9/4 → 19/8 | note:Bb3 s:supersaw djf:0.2 ]",
|
||||
"[ 19/8 → 5/2 | note:C5 s:supersaw djf:0.2 ]",
|
||||
"[ 5/2 → 21/8 | note:D4 s:supersaw djf:0.2 ]",
|
||||
"[ 21/8 → 11/4 | note:F3 s:supersaw djf:0.2 ]",
|
||||
"[ 11/4 → 23/8 | note:G4 s:supersaw djf:0.2 ]",
|
||||
"[ 23/8 → 3/1 | note:D3 s:supersaw djf:0.2 ]",
|
||||
"[ 3/1 → 25/8 | note:G3 s:supersaw djf:0.75 ]",
|
||||
"[ 25/8 → 13/4 | note:Bb3 s:supersaw djf:0.75 ]",
|
||||
"[ 13/4 → 27/8 | note:Eb5 s:supersaw djf:0.75 ]",
|
||||
"[ 27/8 → 7/2 | note:C4 s:supersaw djf:0.75 ]",
|
||||
"[ 7/2 → 29/8 | note:C4 s:supersaw djf:0.75 ]",
|
||||
"[ 29/8 → 15/4 | note:Eb5 s:supersaw djf:0.75 ]",
|
||||
"[ 15/4 → 31/8 | note:Bb4 s:supersaw djf:0.75 ]",
|
||||
"[ 31/8 → 4/1 | note:A4 s:supersaw djf:0.75 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -3607,59 +3513,6 @@ exports[`runs examples > example "end" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "endSeconds" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:oh endSeconds:0.1 ]",
|
||||
"[ 0/1 → 1/4 | s:bd endSeconds:0.1 ]",
|
||||
"[ 1/8 → 1/4 | s:oh endSeconds:0.1 ]",
|
||||
"[ 1/4 → 3/8 | s:oh endSeconds:0.1 ]",
|
||||
"[ 1/4 → 1/2 | s:bd endSeconds:0.1 ]",
|
||||
"[ 3/8 → 1/2 | s:oh endSeconds:0.1 ]",
|
||||
"[ 1/2 → 5/8 | s:oh endSeconds:0.05 ]",
|
||||
"[ 1/2 → 3/4 | s:bd endSeconds:0.05 ]",
|
||||
"[ 5/8 → 3/4 | s:oh endSeconds:0.05 ]",
|
||||
"[ 3/4 → 7/8 | s:oh endSeconds:0.05 ]",
|
||||
"[ 3/4 → 1/1 | s:bd endSeconds:0.05 ]",
|
||||
"[ 7/8 → 1/1 | s:oh endSeconds:0.05 ]",
|
||||
"[ 1/1 → 9/8 | s:oh endSeconds:0.2 ]",
|
||||
"[ 1/1 → 5/4 | s:bd endSeconds:0.2 ]",
|
||||
"[ 9/8 → 5/4 | s:oh endSeconds:0.2 ]",
|
||||
"[ 5/4 → 11/8 | s:oh endSeconds:0.2 ]",
|
||||
"[ 5/4 → 3/2 | s:bd endSeconds:0.2 ]",
|
||||
"[ 11/8 → 3/2 | s:oh endSeconds:0.2 ]",
|
||||
"[ 3/2 → 13/8 | s:oh endSeconds:1 ]",
|
||||
"[ 3/2 → 7/4 | s:bd endSeconds:1 ]",
|
||||
"[ 13/8 → 7/4 | s:oh endSeconds:1 ]",
|
||||
"[ 7/4 → 15/8 | s:oh endSeconds:1 ]",
|
||||
"[ 7/4 → 2/1 | s:bd endSeconds:1 ]",
|
||||
"[ 15/8 → 2/1 | s:oh endSeconds:1 ]",
|
||||
"[ 2/1 → 17/8 | s:oh endSeconds:0.1 ]",
|
||||
"[ 2/1 → 9/4 | s:bd endSeconds:0.1 ]",
|
||||
"[ 17/8 → 9/4 | s:oh endSeconds:0.1 ]",
|
||||
"[ 9/4 → 19/8 | s:oh endSeconds:0.1 ]",
|
||||
"[ 9/4 → 5/2 | s:bd endSeconds:0.1 ]",
|
||||
"[ 19/8 → 5/2 | s:oh endSeconds:0.1 ]",
|
||||
"[ 5/2 → 21/8 | s:oh endSeconds:0.05 ]",
|
||||
"[ 5/2 → 11/4 | s:bd endSeconds:0.05 ]",
|
||||
"[ 21/8 → 11/4 | s:oh endSeconds:0.05 ]",
|
||||
"[ 11/4 → 23/8 | s:oh endSeconds:0.05 ]",
|
||||
"[ 11/4 → 3/1 | s:bd endSeconds:0.05 ]",
|
||||
"[ 23/8 → 3/1 | s:oh endSeconds:0.05 ]",
|
||||
"[ 3/1 → 25/8 | s:oh endSeconds:0.2 ]",
|
||||
"[ 3/1 → 13/4 | s:bd endSeconds:0.2 ]",
|
||||
"[ 25/8 → 13/4 | s:oh endSeconds:0.2 ]",
|
||||
"[ 13/4 → 27/8 | s:oh endSeconds:0.2 ]",
|
||||
"[ 13/4 → 7/2 | s:bd endSeconds:0.2 ]",
|
||||
"[ 27/8 → 7/2 | s:oh endSeconds:0.2 ]",
|
||||
"[ 7/2 → 29/8 | s:oh endSeconds:1 ]",
|
||||
"[ 7/2 → 15/4 | s:bd endSeconds:1 ]",
|
||||
"[ 29/8 → 15/4 | s:oh endSeconds:1 ]",
|
||||
"[ 15/4 → 31/8 | s:oh endSeconds:1 ]",
|
||||
"[ 15/4 → 4/1 | s:bd endSeconds:1 ]",
|
||||
"[ 31/8 → 4/1 | s:oh endSeconds:1 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "euclid" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | note:c3 ]",
|
||||
@@ -11936,6 +11789,112 @@ exports[`runs examples > example "vowel" example index 1 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "warp" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ (1/8 → 1/5) ⇝ 1/4 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ 1/8 ⇜ (1/5 → 1/4) | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 1/4 → 3/8 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ (3/8 → 2/5) ⇝ 1/2 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 3/8 ⇜ (2/5 → 1/2) | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ (1/2 → 3/5) ⇝ 5/8 | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ 1/2 ⇜ (3/5 → 5/8) | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 5/8 → 3/4 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ (3/4 → 4/5) ⇝ 7/8 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 3/4 ⇜ (4/5 → 7/8) | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 7/8 → 1/1 | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 1/1 → 9/8 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ (9/8 → 6/5) ⇝ 5/4 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ 9/8 ⇜ (6/5 → 5/4) | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 5/4 → 11/8 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ (11/8 → 7/5) ⇝ 3/2 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 11/8 ⇜ (7/5 → 3/2) | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ (3/2 → 8/5) ⇝ 13/8 | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ 3/2 ⇜ (8/5 → 13/8) | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 13/8 → 7/4 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ (7/4 → 9/5) ⇝ 15/8 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 7/4 ⇜ (9/5 → 15/8) | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 15/8 → 2/1 | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 2/1 → 17/8 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ (17/8 → 11/5) ⇝ 9/4 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ 17/8 ⇜ (11/5 → 9/4) | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 9/4 → 19/8 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ (19/8 → 12/5) ⇝ 5/2 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 19/8 ⇜ (12/5 → 5/2) | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ (5/2 → 13/5) ⇝ 21/8 | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ 5/2 ⇜ (13/5 → 21/8) | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 21/8 → 11/4 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ (11/4 → 14/5) ⇝ 23/8 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 11/4 ⇜ (14/5 → 23/8) | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 23/8 → 3/1 | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 3/1 → 25/8 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ (25/8 → 16/5) ⇝ 13/4 | s:basique bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ 25/8 ⇜ (16/5 → 13/4) | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 13/4 → 27/8 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ (27/8 → 17/5) ⇝ 7/2 | s:basique bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 27/8 ⇜ (17/5 → 7/2) | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ (7/2 → 18/5) ⇝ 29/8 | s:basique bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ 7/2 ⇜ (18/5 → 29/8) | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 29/8 → 15/4 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ (15/4 → 19/5) ⇝ 31/8 | s:basique bank:wt_digital note:F1 warp:0.75 warpmode:spin ]",
|
||||
"[ 15/4 ⇜ (19/5 → 31/8) | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
"[ 31/8 → 4/1 | s:basique bank:wt_digital note:F1 warp:1 warpmode:spin ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "warpmode" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:asym ]",
|
||||
"[ (1/8 → 1/5) ⇝ 1/4 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:asym ]",
|
||||
"[ 1/8 ⇜ (1/5 → 1/4) | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:asym ]",
|
||||
"[ 1/4 → 3/8 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:asym ]",
|
||||
"[ (3/8 → 2/5) ⇝ 1/2 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:asym ]",
|
||||
"[ 3/8 ⇜ (2/5 → 1/2) | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:asym ]",
|
||||
"[ (1/2 → 3/5) ⇝ 5/8 | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:bendp ]",
|
||||
"[ 1/2 ⇜ (3/5 → 5/8) | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:bendp ]",
|
||||
"[ 5/8 → 3/4 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:bendp ]",
|
||||
"[ (3/4 → 4/5) ⇝ 7/8 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:bendp ]",
|
||||
"[ 3/4 ⇜ (4/5 → 7/8) | s:morgana bank:wt_digital note:F1 warp:1 warpmode:bendp ]",
|
||||
"[ 7/8 → 1/1 | s:morgana bank:wt_digital note:F1 warp:1 warpmode:bendp ]",
|
||||
"[ 1/1 → 9/8 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ (9/8 → 6/5) ⇝ 5/4 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:spin ]",
|
||||
"[ 9/8 ⇜ (6/5 → 5/4) | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 5/4 → 11/8 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ (11/8 → 7/5) ⇝ 3/2 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:spin ]",
|
||||
"[ 11/8 ⇜ (7/5 → 3/2) | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:spin ]",
|
||||
"[ (3/2 → 8/5) ⇝ 13/8 | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:logistic ]",
|
||||
"[ 3/2 ⇜ (8/5 → 13/8) | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:logistic ]",
|
||||
"[ 13/8 → 7/4 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:logistic ]",
|
||||
"[ (7/4 → 9/5) ⇝ 15/8 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:logistic ]",
|
||||
"[ 7/4 ⇜ (9/5 → 15/8) | s:morgana bank:wt_digital note:F1 warp:1 warpmode:logistic ]",
|
||||
"[ 15/8 → 2/1 | s:morgana bank:wt_digital note:F1 warp:1 warpmode:logistic ]",
|
||||
"[ 2/1 → 17/8 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:sync ]",
|
||||
"[ (17/8 → 11/5) ⇝ 9/4 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:sync ]",
|
||||
"[ 17/8 ⇜ (11/5 → 9/4) | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:sync ]",
|
||||
"[ 9/4 → 19/8 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:sync ]",
|
||||
"[ (19/8 → 12/5) ⇝ 5/2 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:sync ]",
|
||||
"[ 19/8 ⇜ (12/5 → 5/2) | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:sync ]",
|
||||
"[ (5/2 → 13/5) ⇝ 21/8 | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:wormhole ]",
|
||||
"[ 5/2 ⇜ (13/5 → 21/8) | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:wormhole ]",
|
||||
"[ 21/8 → 11/4 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:wormhole ]",
|
||||
"[ (11/4 → 14/5) ⇝ 23/8 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:wormhole ]",
|
||||
"[ 11/4 ⇜ (14/5 → 23/8) | s:morgana bank:wt_digital note:F1 warp:1 warpmode:wormhole ]",
|
||||
"[ 23/8 → 3/1 | s:morgana bank:wt_digital note:F1 warp:1 warpmode:wormhole ]",
|
||||
"[ 3/1 → 25/8 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:brownian ]",
|
||||
"[ (25/8 → 16/5) ⇝ 13/4 | s:morgana bank:wt_digital note:F1 warp:0 warpmode:brownian ]",
|
||||
"[ 25/8 ⇜ (16/5 → 13/4) | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:brownian ]",
|
||||
"[ 13/4 → 27/8 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:brownian ]",
|
||||
"[ (27/8 → 17/5) ⇝ 7/2 | s:morgana bank:wt_digital note:F1 warp:0.25 warpmode:brownian ]",
|
||||
"[ 27/8 ⇜ (17/5 → 7/2) | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:brownian ]",
|
||||
"[ (7/2 → 18/5) ⇝ 29/8 | s:morgana bank:wt_digital note:F1 warp:0.5 warpmode:asym ]",
|
||||
"[ 7/2 ⇜ (18/5 → 29/8) | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:asym ]",
|
||||
"[ 29/8 → 15/4 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:asym ]",
|
||||
"[ (15/4 → 19/5) ⇝ 31/8 | s:morgana bank:wt_digital note:F1 warp:0.75 warpmode:asym ]",
|
||||
"[ 15/4 ⇜ (19/5 → 31/8) | s:morgana bank:wt_digital note:F1 warp:1 warpmode:asym ]",
|
||||
"[ 31/8 → 4/1 | s:morgana bank:wt_digital note:F1 warp:1 warpmode:asym ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "wchoose" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/5 | note:c2 s:sine ]",
|
||||
@@ -12140,6 +12099,128 @@ exports[`runs examples > example "withValue" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "wt" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ (1/8 → 1/5) ⇝ 1/4 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ 1/8 ⇜ (1/5 → 1/4) | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 1/4 → 3/8 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ (3/8 → 2/5) ⇝ 1/2 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 3/8 ⇜ (2/5 → 1/2) | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ (1/2 → 3/5) ⇝ 5/8 | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ 1/2 ⇜ (3/5 → 5/8) | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 5/8 → 3/4 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ (3/4 → 4/5) ⇝ 7/8 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 3/4 ⇜ (4/5 → 7/8) | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 7/8 → 1/1 | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 1/1 → 9/8 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ (9/8 → 6/5) ⇝ 5/4 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ 9/8 ⇜ (6/5 → 5/4) | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 5/4 → 11/8 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ (11/8 → 7/5) ⇝ 3/2 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 11/8 ⇜ (7/5 → 3/2) | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ (3/2 → 8/5) ⇝ 13/8 | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ 3/2 ⇜ (8/5 → 13/8) | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 13/8 → 7/4 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ (7/4 → 9/5) ⇝ 15/8 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 7/4 ⇜ (9/5 → 15/8) | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 15/8 → 2/1 | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 2/1 → 17/8 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ (17/8 → 11/5) ⇝ 9/4 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ 17/8 ⇜ (11/5 → 9/4) | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 9/4 → 19/8 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ (19/8 → 12/5) ⇝ 5/2 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 19/8 ⇜ (12/5 → 5/2) | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ (5/2 → 13/5) ⇝ 21/8 | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ 5/2 ⇜ (13/5 → 21/8) | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 21/8 → 11/4 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ (11/4 → 14/5) ⇝ 23/8 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 11/4 ⇜ (14/5 → 23/8) | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 23/8 → 3/1 | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 3/1 → 25/8 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ (25/8 → 16/5) ⇝ 13/4 | s:squelch bank:wt_digital note:F1 wt:0 ]",
|
||||
"[ 25/8 ⇜ (16/5 → 13/4) | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 13/4 → 27/8 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ (27/8 → 17/5) ⇝ 7/2 | s:squelch bank:wt_digital note:F1 wt:0.25 ]",
|
||||
"[ 27/8 ⇜ (17/5 → 7/2) | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ (7/2 → 18/5) ⇝ 29/8 | s:squelch bank:wt_digital note:F1 wt:0.5 ]",
|
||||
"[ 7/2 ⇜ (18/5 → 29/8) | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 29/8 → 15/4 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ (15/4 → 19/5) ⇝ 31/8 | s:squelch bank:wt_digital note:F1 wt:0.75 ]",
|
||||
"[ 15/4 ⇜ (19/5 → 31/8) | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
"[ 31/8 → 4/1 | s:squelch bank:wt_digital note:F1 wt:1 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "wtphaserand" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 1/16 → 1/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 1/8 → 3/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 3/16 → 1/4 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 1/4 → 5/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 5/16 → 3/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 3/8 → 7/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 7/16 → 1/2 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 1/2 → 9/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 9/16 → 5/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 5/8 → 11/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 11/16 → 3/4 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 3/4 → 13/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 13/16 → 7/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 7/8 → 15/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 15/16 → 1/1 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 1/1 → 17/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 17/16 → 9/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 9/8 → 19/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 19/16 → 5/4 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 5/4 → 21/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 21/16 → 11/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 11/8 → 23/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 23/16 → 3/2 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 3/2 → 25/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 25/16 → 13/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 13/8 → 27/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 27/16 → 7/4 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 7/4 → 29/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 29/16 → 15/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 15/8 → 31/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 31/16 → 2/1 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 2/1 → 33/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 33/16 → 17/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 17/8 → 35/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 35/16 → 9/4 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 9/4 → 37/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 37/16 → 19/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 19/8 → 39/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 39/16 → 5/2 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 5/2 → 41/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 41/16 → 21/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 21/8 → 43/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 43/16 → 11/4 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 11/4 → 45/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 45/16 → 23/8 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 23/8 → 47/16 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 47/16 → 3/1 | s:basique bank:wt_digital wtphaserand:0 ]",
|
||||
"[ 3/1 → 49/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 49/16 → 25/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 25/8 → 51/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 51/16 → 13/4 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 13/4 → 53/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 53/16 → 27/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 27/8 → 55/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 55/16 → 7/2 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 7/2 → 57/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 57/16 → 29/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 29/8 → 59/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 59/16 → 15/4 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 15/4 → 61/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 61/16 → 31/8 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 31/8 → 63/16 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
"[ 63/16 → 4/1 | s:basique bank:wt_digital wtphaserand:1 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "xfade" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:hh gain:0 ]",
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"_base": "https://raw.githubusercontent.com/tidalcycles/uzu-wavetables/main/",
|
||||
"wt_digital": [
|
||||
"wt_digital/wt_bad_day.wav",
|
||||
"wt_digital/wt_basique.wav",
|
||||
"wt_digital/wt_crickets.wav",
|
||||
"wt_digital/wt_curses.wav",
|
||||
"wt_digital/wt_earl_grey.wav",
|
||||
"wt_digital/wt_echoes.wav",
|
||||
"wt_digital/wt_glimmer.wav",
|
||||
"wt_digital/wt_majick.wav",
|
||||
"wt_digital/wt_meditation.wav",
|
||||
"wt_digital/wt_morgana.wav",
|
||||
"wt_digital/wt_red_alert.wav",
|
||||
"wt_digital/wt_sad_piano.wav",
|
||||
"wt_digital/wt_shook.wav",
|
||||
"wt_digital/wt_sludge.wav",
|
||||
"wt_digital/wt_squelch.wav",
|
||||
"wt_digital/wt_summer.wav",
|
||||
"wt_digital/wt_wasp.wav"
|
||||
],
|
||||
"wt_digital_bad_day": ["wt_digital/wt_bad_day.wav"],
|
||||
"wt_digital_basique": ["wt_digital/wt_basique.wav"],
|
||||
"wt_digital_crickets": ["wt_digital/wt_crickets.wav"],
|
||||
"wt_digital_curses": ["wt_digital/wt_curses.wav"],
|
||||
"wt_digital_earl_grey": ["wt_digital/wt_earl_grey.wav"],
|
||||
"wt_digital_echoes": ["wt_digital/wt_echoes.wav"],
|
||||
"wt_digital_glimmer": ["wt_digital/wt_glimmer.wav"],
|
||||
"wt_digital_majick": ["wt_digital/wt_majick.wav"],
|
||||
"wt_digital_meditation": ["wt_digital/wt_meditation.wav"],
|
||||
"wt_digital_morgana": ["wt_digital/wt_morgana.wav"],
|
||||
"wt_digital_red_alert": ["wt_digital/wt_red_alert.wav"],
|
||||
"wt_digital_sad_piano": ["wt_digital/wt_sad_piano.wav"],
|
||||
"wt_digital_shook": ["wt_digital/wt_shook.wav"],
|
||||
"wt_digital_sludge": ["wt_digital/wt_sludge.wav"],
|
||||
"wt_digital_squelch": ["wt_digital/wt_squelch.wav"],
|
||||
"wt_digital_summer": ["wt_digital/wt_summer.wav"],
|
||||
"wt_digital_wasp": ["wt_digital/wt_wasp.wav"]
|
||||
}
|
||||
@@ -44,6 +44,9 @@ export function SoundsTab() {
|
||||
if (soundsFilter === soundFilterType.SYNTHS) {
|
||||
return filtered.filter(([_, { data }]) => ['synth', 'soundfont'].includes(data.type));
|
||||
}
|
||||
if (soundsFilter === soundFilterType.WAVETABLES) {
|
||||
return filtered.filter(([_, { data }]) => data.type === 'wavetable');
|
||||
}
|
||||
//TODO: tidy this up, it does not need to be saved in settings
|
||||
if (soundsFilter === 'importSounds') {
|
||||
return [];
|
||||
@@ -54,6 +57,9 @@ export function SoundsTab() {
|
||||
// holds mutable ref to current triggered sound
|
||||
const trigRef = useRef();
|
||||
|
||||
// Used to cycle through sound previews on banks with multiple sounds
|
||||
let soundPreviewIdx = 0;
|
||||
|
||||
// stop current sound on mouseup
|
||||
useEvent('mouseup', () => {
|
||||
const t = trigRef.current;
|
||||
@@ -74,6 +80,7 @@ export function SoundsTab() {
|
||||
samples: 'samples',
|
||||
drums: 'drum-machines',
|
||||
synths: 'Synths',
|
||||
wavetables: 'Wavetables',
|
||||
user: 'User',
|
||||
importSounds: 'import-sounds',
|
||||
}}
|
||||
@@ -110,11 +117,13 @@ export function SoundsTab() {
|
||||
const params = {
|
||||
note: ['synth', 'soundfont'].includes(data.type) ? 'a3' : undefined,
|
||||
s: name,
|
||||
n: soundPreviewIdx,
|
||||
clip: 1,
|
||||
release: 0.5,
|
||||
sustain: 1,
|
||||
duration: 0.5,
|
||||
};
|
||||
soundPreviewIdx++;
|
||||
const time = ctx.currentTime + 0.05;
|
||||
const onended = () => trigRef.current?.node?.disconnect();
|
||||
trigRef.current = Promise.resolve(onTrigger(time, params, onended));
|
||||
@@ -126,6 +135,7 @@ export function SoundsTab() {
|
||||
{' '}
|
||||
{name}
|
||||
{data?.type === 'sample' ? `(${getSamples(data.samples)})` : ''}
|
||||
{data?.type === 'wavetable' ? `(${getSamples(data.tables)})` : ''}
|
||||
{data?.type === 'soundfont' ? `(${data.fonts.length})` : ''}
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { registerSound, onTriggerSample } from '@strudel/webaudio';
|
||||
import { registerSampleSource } from '@strudel/webaudio';
|
||||
import { isAudioFile } from './files.mjs';
|
||||
import { logger } from '@strudel/core';
|
||||
|
||||
@@ -76,13 +76,7 @@ export function registerSamplesFromDB(config = userSamplesDBConfig, onComplete =
|
||||
})
|
||||
.map((title) => titlePathMap.get(title));
|
||||
|
||||
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, value), {
|
||||
type: 'sample',
|
||||
samples: value,
|
||||
baseUrl: undefined,
|
||||
prebake: false,
|
||||
tag: undefined,
|
||||
});
|
||||
registerSampleSource(key, value, { prebake: false });
|
||||
});
|
||||
|
||||
logger('imported sounds registered!', 'success');
|
||||
|
||||
@@ -32,6 +32,9 @@ export async function prebake() {
|
||||
prebake: true,
|
||||
tag: 'drum-machines',
|
||||
}),
|
||||
samples(`${baseNoTrailing}/uzu-wavetables.json`, undefined, {
|
||||
prebake: true,
|
||||
}),
|
||||
samples(`${baseNoTrailing}/mridangam.json`, undefined, { prebake: true, tag: 'drum-machines' }),
|
||||
samples(
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ export const soundFilterType = {
|
||||
DRUMS: 'drums',
|
||||
SAMPLES: 'samples',
|
||||
SYNTHS: 'synths',
|
||||
WAVETABLES: 'wavetables',
|
||||
ALL: 'all',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user