mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
Merge branch 'main' of github.com:daslyfe/strudel
This commit is contained in:
commit
686247f0cb
@ -1383,6 +1383,17 @@ export const { compressorRelease } = registerControl('compressorRelease');
|
||||
*
|
||||
*/
|
||||
export const { speed } = registerControl('speed');
|
||||
|
||||
/**
|
||||
* Changes the speed of sample playback, i.e. a cheap way of changing pitch.
|
||||
*
|
||||
* @name stretch
|
||||
* @param {number | Pattern} factor -inf to inf, negative numbers play the sample backwards.
|
||||
* @example
|
||||
* s("gm_flute").stretch("1 2 .5")
|
||||
*
|
||||
*/
|
||||
export const { stretch } = registerControl('stretch');
|
||||
/**
|
||||
* Used in conjunction with `speed`, accepts values of "r" (rate, default behavior), "c" (cycles), or "s" (seconds). Using `unit "c"` means `speed` will be interpreted in units of cycles, e.g. `speed "1"` means samples will be stretched to fill a cycle. Using `unit "s"` means the playback speed will be adjusted so that the duration is the number of seconds specified by `speed`.
|
||||
*
|
||||
@ -1393,6 +1404,7 @@ export const { speed } = registerControl('speed');
|
||||
* @superdirtOnly
|
||||
*
|
||||
*/
|
||||
|
||||
export const { unit } = registerControl('unit');
|
||||
/**
|
||||
* Made by Calum Gunn. Reminiscent of some weird mixture of filter, ring-modulator and pitch-shifter. The SuperCollider manual defines Squiz as:
|
||||
|
||||
@ -4,8 +4,6 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { isPattern } from './index.mjs';
|
||||
|
||||
export const evalScope = async (...args) => {
|
||||
const results = await Promise.allSettled(args);
|
||||
const modules = results.filter((result) => result.status === 'fulfilled').map((r) => r.value);
|
||||
@ -39,6 +37,7 @@ function safeEval(str, options = {}) {
|
||||
|
||||
export const evaluate = async (code, transpiler, transpilerOptions) => {
|
||||
let meta = {};
|
||||
|
||||
if (transpiler) {
|
||||
// transform syntactically correct js code to semantically usable code
|
||||
const transpiled = transpiler(code, transpilerOptions);
|
||||
|
||||
@ -1423,6 +1423,9 @@ export function fastcat(...pats) {
|
||||
result = result._fast(pats.length);
|
||||
result.tactus = pats.length;
|
||||
}
|
||||
if (pats.length == 1 && pats[0].__tactus_source) {
|
||||
pats.tactus = pats[0].tactus;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1566,7 +1569,11 @@ export function register(name, func, patternify = true, preserveTactus = false,
|
||||
// There are patternified args, so lets make an unpatternified
|
||||
// version, prefixed by '_'
|
||||
Pattern.prototype['_' + name] = function (...args) {
|
||||
return func(...args, this);
|
||||
const result = func(...args, this);
|
||||
if (preserveTactus) {
|
||||
result.setTactus(this.tactus);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
@ -2612,8 +2619,7 @@ export function s_cat(...timepats) {
|
||||
}
|
||||
if (timepats.length == 1) {
|
||||
const result = reify(timepats[0][1]);
|
||||
result.tactus = timepats[0][0];
|
||||
return result;
|
||||
return result.withTactus((_) => timepats[0][0]);
|
||||
}
|
||||
|
||||
const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0));
|
||||
@ -2706,6 +2712,10 @@ export const s_sub = stepRegister('s_sub', function (i, pat) {
|
||||
return pat.s_add(pat.tactus.sub(i));
|
||||
});
|
||||
|
||||
export const s_cycles = stepRegister('s_extend', function (factor, pat) {
|
||||
return pat.fast(factor).s_expand(factor);
|
||||
});
|
||||
|
||||
export const s_expand = stepRegister('s_expand', function (factor, pat) {
|
||||
return pat.withTactus((t) => t.mul(Fraction(factor)));
|
||||
});
|
||||
@ -2919,7 +2929,8 @@ export const splice = register(
|
||||
);
|
||||
|
||||
export const { loopAt, loopat } = register(['loopAt', 'loopat'], function (factor, pat) {
|
||||
return new Pattern((state) => _loopAt(factor, pat, state.controls._cps).query(state));
|
||||
const tactus = pat.tactus ? pat.tactus.div(factor) : undefined;
|
||||
return new Pattern((state) => _loopAt(factor, pat, state.controls._cps).query(state), tactus);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -1248,4 +1248,9 @@ describe('Pattern', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('loopAt', () => {
|
||||
it('maintains tactus', () => {
|
||||
expect(s('bev').chop(8).loopAt(2).tactus).toStrictEqual(Fraction(4));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -14,7 +14,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
|
||||
const ast = parent.source_[i];
|
||||
const options = ast.options_;
|
||||
const ops = options?.ops;
|
||||
|
||||
const tactus_source = pat.__tactus_source;
|
||||
if (ops) {
|
||||
for (const op of ops) {
|
||||
switch (op.type_) {
|
||||
@ -69,7 +69,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pat.__tactus_source = pat.__tactus_source || tactus_source;
|
||||
return pat;
|
||||
};
|
||||
|
||||
|
||||
@ -210,12 +210,14 @@ describe('mini', () => {
|
||||
});
|
||||
it('supports ^ tactus marking', () => {
|
||||
expect(mini('a [^b c]').tactus).toEqual(Fraction(4));
|
||||
expect(mini('[^b c]!3').tactus).toEqual(Fraction(6));
|
||||
expect(mini('[a b c] [d [e f]]').tactus).toEqual(Fraction(2));
|
||||
expect(mini('^[a b c] [d [e f]]').tactus).toEqual(Fraction(2));
|
||||
expect(mini('[a b c] [d [^e f]]').tactus).toEqual(Fraction(8));
|
||||
expect(mini('[a b c] [^d [e f]]').tactus).toEqual(Fraction(4));
|
||||
expect(mini('[^a b c] [^d [e f]]').tactus).toEqual(Fraction(12));
|
||||
expect(mini('[^a b c] [d [^e f]]').tactus).toEqual(Fraction(24));
|
||||
expect(mini('[^a b c d e]').tactus).toEqual(Fraction(5));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
488
packages/superdough/fft.js
Normal file
488
packages/superdough/fft.js
Normal file
@ -0,0 +1,488 @@
|
||||
'use strict';
|
||||
// sourced from https://github.com/indutny/fft.js/
|
||||
// LICENSE
|
||||
// This software is licensed under the MIT License.
|
||||
// Copyright Fedor Indutny, 2017.
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
export default class FFT {
|
||||
constructor(size) {
|
||||
this.size = size | 0;
|
||||
if (this.size <= 1 || (this.size & (this.size - 1)) !== 0)
|
||||
throw new Error('FFT size must be a power of two and bigger than 1');
|
||||
|
||||
this._csize = size << 1;
|
||||
|
||||
// NOTE: Use of `var` is intentional for old V8 versions
|
||||
var table = new Array(this.size * 2);
|
||||
for (var i = 0; i < table.length; i += 2) {
|
||||
const angle = (Math.PI * i) / this.size;
|
||||
table[i] = Math.cos(angle);
|
||||
table[i + 1] = -Math.sin(angle);
|
||||
}
|
||||
this.table = table;
|
||||
|
||||
// Find size's power of two
|
||||
var power = 0;
|
||||
for (var t = 1; this.size > t; t <<= 1) power++;
|
||||
|
||||
// Calculate initial step's width:
|
||||
// * If we are full radix-4 - it is 2x smaller to give inital len=8
|
||||
// * Otherwise it is the same as `power` to give len=4
|
||||
this._width = power % 2 === 0 ? power - 1 : power;
|
||||
|
||||
// Pre-compute bit-reversal patterns
|
||||
this._bitrev = new Array(1 << this._width);
|
||||
for (var j = 0; j < this._bitrev.length; j++) {
|
||||
this._bitrev[j] = 0;
|
||||
for (var shift = 0; shift < this._width; shift += 2) {
|
||||
var revShift = this._width - shift - 2;
|
||||
this._bitrev[j] |= ((j >>> shift) & 3) << revShift;
|
||||
}
|
||||
}
|
||||
|
||||
this._out = null;
|
||||
this._data = null;
|
||||
this._inv = 0;
|
||||
}
|
||||
fromComplexArray(complex, storage) {
|
||||
var res = storage || new Array(complex.length >>> 1);
|
||||
for (var i = 0; i < complex.length; i += 2) res[i >>> 1] = complex[i];
|
||||
return res;
|
||||
}
|
||||
createComplexArray() {
|
||||
const res = new Array(this._csize);
|
||||
for (var i = 0; i < res.length; i++) res[i] = 0;
|
||||
return res;
|
||||
}
|
||||
toComplexArray(input, storage) {
|
||||
var res = storage || this.createComplexArray();
|
||||
for (var i = 0; i < res.length; i += 2) {
|
||||
res[i] = input[i >>> 1];
|
||||
res[i + 1] = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
completeSpectrum(spectrum) {
|
||||
var size = this._csize;
|
||||
var half = size >>> 1;
|
||||
for (var i = 2; i < half; i += 2) {
|
||||
spectrum[size - i] = spectrum[i];
|
||||
spectrum[size - i + 1] = -spectrum[i + 1];
|
||||
}
|
||||
}
|
||||
transform(out, data) {
|
||||
if (out === data) throw new Error('Input and output buffers must be different');
|
||||
|
||||
this._out = out;
|
||||
this._data = data;
|
||||
this._inv = 0;
|
||||
this._transform4();
|
||||
this._out = null;
|
||||
this._data = null;
|
||||
}
|
||||
realTransform(out, data) {
|
||||
if (out === data) throw new Error('Input and output buffers must be different');
|
||||
|
||||
this._out = out;
|
||||
this._data = data;
|
||||
this._inv = 0;
|
||||
this._realTransform4();
|
||||
this._out = null;
|
||||
this._data = null;
|
||||
}
|
||||
inverseTransform(out, data) {
|
||||
if (out === data) throw new Error('Input and output buffers must be different');
|
||||
|
||||
this._out = out;
|
||||
this._data = data;
|
||||
this._inv = 1;
|
||||
this._transform4();
|
||||
for (var i = 0; i < out.length; i++) out[i] /= this.size;
|
||||
this._out = null;
|
||||
this._data = null;
|
||||
}
|
||||
// radix-4 implementation
|
||||
//
|
||||
// NOTE: Uses of `var` are intentional for older V8 version that do not
|
||||
// support both `let compound assignments` and `const phi`
|
||||
_transform4() {
|
||||
var out = this._out;
|
||||
var size = this._csize;
|
||||
|
||||
// Initial step (permute and transform)
|
||||
var width = this._width;
|
||||
var step = 1 << width;
|
||||
var len = (size / step) << 1;
|
||||
|
||||
var outOff;
|
||||
var t;
|
||||
var bitrev = this._bitrev;
|
||||
if (len === 4) {
|
||||
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
||||
const off = bitrev[t];
|
||||
this._singleTransform2(outOff, off, step);
|
||||
}
|
||||
} else {
|
||||
// len === 8
|
||||
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
||||
const off = bitrev[t];
|
||||
this._singleTransform4(outOff, off, step);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through steps in decreasing order
|
||||
var inv = this._inv ? -1 : 1;
|
||||
var table = this.table;
|
||||
for (step >>= 2; step >= 2; step >>= 2) {
|
||||
len = (size / step) << 1;
|
||||
var quarterLen = len >>> 2;
|
||||
|
||||
// Loop through offsets in the data
|
||||
for (outOff = 0; outOff < size; outOff += len) {
|
||||
// Full case
|
||||
var limit = outOff + quarterLen;
|
||||
for (var i = outOff, k = 0; i < limit; i += 2, k += step) {
|
||||
const A = i;
|
||||
const B = A + quarterLen;
|
||||
const C = B + quarterLen;
|
||||
const D = C + quarterLen;
|
||||
|
||||
// Original values
|
||||
const Ar = out[A];
|
||||
const Ai = out[A + 1];
|
||||
const Br = out[B];
|
||||
const Bi = out[B + 1];
|
||||
const Cr = out[C];
|
||||
const Ci = out[C + 1];
|
||||
const Dr = out[D];
|
||||
const Di = out[D + 1];
|
||||
|
||||
// Middle values
|
||||
const MAr = Ar;
|
||||
const MAi = Ai;
|
||||
|
||||
const tableBr = table[k];
|
||||
const tableBi = inv * table[k + 1];
|
||||
const MBr = Br * tableBr - Bi * tableBi;
|
||||
const MBi = Br * tableBi + Bi * tableBr;
|
||||
|
||||
const tableCr = table[2 * k];
|
||||
const tableCi = inv * table[2 * k + 1];
|
||||
const MCr = Cr * tableCr - Ci * tableCi;
|
||||
const MCi = Cr * tableCi + Ci * tableCr;
|
||||
|
||||
const tableDr = table[3 * k];
|
||||
const tableDi = inv * table[3 * k + 1];
|
||||
const MDr = Dr * tableDr - Di * tableDi;
|
||||
const MDi = Dr * tableDi + Di * tableDr;
|
||||
|
||||
// Pre-Final values
|
||||
const T0r = MAr + MCr;
|
||||
const T0i = MAi + MCi;
|
||||
const T1r = MAr - MCr;
|
||||
const T1i = MAi - MCi;
|
||||
const T2r = MBr + MDr;
|
||||
const T2i = MBi + MDi;
|
||||
const T3r = inv * (MBr - MDr);
|
||||
const T3i = inv * (MBi - MDi);
|
||||
|
||||
// Final values
|
||||
const FAr = T0r + T2r;
|
||||
const FAi = T0i + T2i;
|
||||
|
||||
const FCr = T0r - T2r;
|
||||
const FCi = T0i - T2i;
|
||||
|
||||
const FBr = T1r + T3i;
|
||||
const FBi = T1i - T3r;
|
||||
|
||||
const FDr = T1r - T3i;
|
||||
const FDi = T1i + T3r;
|
||||
|
||||
out[A] = FAr;
|
||||
out[A + 1] = FAi;
|
||||
out[B] = FBr;
|
||||
out[B + 1] = FBi;
|
||||
out[C] = FCr;
|
||||
out[C + 1] = FCi;
|
||||
out[D] = FDr;
|
||||
out[D + 1] = FDi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// radix-2 implementation
|
||||
//
|
||||
// NOTE: Only called for len=4
|
||||
_singleTransform2(outOff, off, step) {
|
||||
const out = this._out;
|
||||
const data = this._data;
|
||||
|
||||
const evenR = data[off];
|
||||
const evenI = data[off + 1];
|
||||
const oddR = data[off + step];
|
||||
const oddI = data[off + step + 1];
|
||||
|
||||
const leftR = evenR + oddR;
|
||||
const leftI = evenI + oddI;
|
||||
const rightR = evenR - oddR;
|
||||
const rightI = evenI - oddI;
|
||||
|
||||
out[outOff] = leftR;
|
||||
out[outOff + 1] = leftI;
|
||||
out[outOff + 2] = rightR;
|
||||
out[outOff + 3] = rightI;
|
||||
}
|
||||
// radix-4
|
||||
//
|
||||
// NOTE: Only called for len=8
|
||||
_singleTransform4(outOff, off, step) {
|
||||
const out = this._out;
|
||||
const data = this._data;
|
||||
const inv = this._inv ? -1 : 1;
|
||||
const step2 = step * 2;
|
||||
const step3 = step * 3;
|
||||
|
||||
// Original values
|
||||
const Ar = data[off];
|
||||
const Ai = data[off + 1];
|
||||
const Br = data[off + step];
|
||||
const Bi = data[off + step + 1];
|
||||
const Cr = data[off + step2];
|
||||
const Ci = data[off + step2 + 1];
|
||||
const Dr = data[off + step3];
|
||||
const Di = data[off + step3 + 1];
|
||||
|
||||
// Pre-Final values
|
||||
const T0r = Ar + Cr;
|
||||
const T0i = Ai + Ci;
|
||||
const T1r = Ar - Cr;
|
||||
const T1i = Ai - Ci;
|
||||
const T2r = Br + Dr;
|
||||
const T2i = Bi + Di;
|
||||
const T3r = inv * (Br - Dr);
|
||||
const T3i = inv * (Bi - Di);
|
||||
|
||||
// Final values
|
||||
const FAr = T0r + T2r;
|
||||
const FAi = T0i + T2i;
|
||||
|
||||
const FBr = T1r + T3i;
|
||||
const FBi = T1i - T3r;
|
||||
|
||||
const FCr = T0r - T2r;
|
||||
const FCi = T0i - T2i;
|
||||
|
||||
const FDr = T1r - T3i;
|
||||
const FDi = T1i + T3r;
|
||||
|
||||
out[outOff] = FAr;
|
||||
out[outOff + 1] = FAi;
|
||||
out[outOff + 2] = FBr;
|
||||
out[outOff + 3] = FBi;
|
||||
out[outOff + 4] = FCr;
|
||||
out[outOff + 5] = FCi;
|
||||
out[outOff + 6] = FDr;
|
||||
out[outOff + 7] = FDi;
|
||||
}
|
||||
// Real input radix-4 implementation
|
||||
_realTransform4() {
|
||||
var out = this._out;
|
||||
var size = this._csize;
|
||||
|
||||
// Initial step (permute and transform)
|
||||
var width = this._width;
|
||||
var step = 1 << width;
|
||||
var len = (size / step) << 1;
|
||||
|
||||
var outOff;
|
||||
var t;
|
||||
var bitrev = this._bitrev;
|
||||
if (len === 4) {
|
||||
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
||||
const off = bitrev[t];
|
||||
this._singleRealTransform2(outOff, off >>> 1, step >>> 1);
|
||||
}
|
||||
} else {
|
||||
// len === 8
|
||||
for (outOff = 0, t = 0; outOff < size; outOff += len, t++) {
|
||||
const off = bitrev[t];
|
||||
this._singleRealTransform4(outOff, off >>> 1, step >>> 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through steps in decreasing order
|
||||
var inv = this._inv ? -1 : 1;
|
||||
var table = this.table;
|
||||
for (step >>= 2; step >= 2; step >>= 2) {
|
||||
len = (size / step) << 1;
|
||||
var halfLen = len >>> 1;
|
||||
var quarterLen = halfLen >>> 1;
|
||||
var hquarterLen = quarterLen >>> 1;
|
||||
|
||||
// Loop through offsets in the data
|
||||
for (outOff = 0; outOff < size; outOff += len) {
|
||||
for (var i = 0, k = 0; i <= hquarterLen; i += 2, k += step) {
|
||||
var A = outOff + i;
|
||||
var B = A + quarterLen;
|
||||
var C = B + quarterLen;
|
||||
var D = C + quarterLen;
|
||||
|
||||
// Original values
|
||||
var Ar = out[A];
|
||||
var Ai = out[A + 1];
|
||||
var Br = out[B];
|
||||
var Bi = out[B + 1];
|
||||
var Cr = out[C];
|
||||
var Ci = out[C + 1];
|
||||
var Dr = out[D];
|
||||
var Di = out[D + 1];
|
||||
|
||||
// Middle values
|
||||
var MAr = Ar;
|
||||
var MAi = Ai;
|
||||
|
||||
var tableBr = table[k];
|
||||
var tableBi = inv * table[k + 1];
|
||||
var MBr = Br * tableBr - Bi * tableBi;
|
||||
var MBi = Br * tableBi + Bi * tableBr;
|
||||
|
||||
var tableCr = table[2 * k];
|
||||
var tableCi = inv * table[2 * k + 1];
|
||||
var MCr = Cr * tableCr - Ci * tableCi;
|
||||
var MCi = Cr * tableCi + Ci * tableCr;
|
||||
|
||||
var tableDr = table[3 * k];
|
||||
var tableDi = inv * table[3 * k + 1];
|
||||
var MDr = Dr * tableDr - Di * tableDi;
|
||||
var MDi = Dr * tableDi + Di * tableDr;
|
||||
|
||||
// Pre-Final values
|
||||
var T0r = MAr + MCr;
|
||||
var T0i = MAi + MCi;
|
||||
var T1r = MAr - MCr;
|
||||
var T1i = MAi - MCi;
|
||||
var T2r = MBr + MDr;
|
||||
var T2i = MBi + MDi;
|
||||
var T3r = inv * (MBr - MDr);
|
||||
var T3i = inv * (MBi - MDi);
|
||||
|
||||
// Final values
|
||||
var FAr = T0r + T2r;
|
||||
var FAi = T0i + T2i;
|
||||
|
||||
var FBr = T1r + T3i;
|
||||
var FBi = T1i - T3r;
|
||||
|
||||
out[A] = FAr;
|
||||
out[A + 1] = FAi;
|
||||
out[B] = FBr;
|
||||
out[B + 1] = FBi;
|
||||
|
||||
// Output final middle point
|
||||
if (i === 0) {
|
||||
var FCr = T0r - T2r;
|
||||
var FCi = T0i - T2i;
|
||||
out[C] = FCr;
|
||||
out[C + 1] = FCi;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not overwrite ourselves
|
||||
if (i === hquarterLen) continue;
|
||||
|
||||
// In the flipped case:
|
||||
// MAi = -MAi
|
||||
// MBr=-MBi, MBi=-MBr
|
||||
// MCr=-MCr
|
||||
// MDr=MDi, MDi=MDr
|
||||
var ST0r = T1r;
|
||||
var ST0i = -T1i;
|
||||
var ST1r = T0r;
|
||||
var ST1i = -T0i;
|
||||
var ST2r = -inv * T3i;
|
||||
var ST2i = -inv * T3r;
|
||||
var ST3r = -inv * T2i;
|
||||
var ST3i = -inv * T2r;
|
||||
|
||||
var SFAr = ST0r + ST2r;
|
||||
var SFAi = ST0i + ST2i;
|
||||
|
||||
var SFBr = ST1r + ST3i;
|
||||
var SFBi = ST1i - ST3r;
|
||||
|
||||
var SA = outOff + quarterLen - i;
|
||||
var SB = outOff + halfLen - i;
|
||||
|
||||
out[SA] = SFAr;
|
||||
out[SA + 1] = SFAi;
|
||||
out[SB] = SFBr;
|
||||
out[SB + 1] = SFBi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// radix-2 implementation
|
||||
//
|
||||
// NOTE: Only called for len=4
|
||||
_singleRealTransform2(outOff, off, step) {
|
||||
const out = this._out;
|
||||
const data = this._data;
|
||||
|
||||
const evenR = data[off];
|
||||
const oddR = data[off + step];
|
||||
|
||||
const leftR = evenR + oddR;
|
||||
const rightR = evenR - oddR;
|
||||
|
||||
out[outOff] = leftR;
|
||||
out[outOff + 1] = 0;
|
||||
out[outOff + 2] = rightR;
|
||||
out[outOff + 3] = 0;
|
||||
}
|
||||
// radix-4
|
||||
//
|
||||
// NOTE: Only called for len=8
|
||||
_singleRealTransform4(outOff, off, step) {
|
||||
const out = this._out;
|
||||
const data = this._data;
|
||||
const inv = this._inv ? -1 : 1;
|
||||
const step2 = step * 2;
|
||||
const step3 = step * 3;
|
||||
|
||||
// Original values
|
||||
const Ar = data[off];
|
||||
const Br = data[off + step];
|
||||
const Cr = data[off + step2];
|
||||
const Dr = data[off + step3];
|
||||
|
||||
// Pre-Final values
|
||||
const T0r = Ar + Cr;
|
||||
const T1r = Ar - Cr;
|
||||
const T2r = Br + Dr;
|
||||
const T3r = inv * (Br - Dr);
|
||||
|
||||
// Final values
|
||||
const FAr = T0r + T2r;
|
||||
|
||||
const FBr = T1r;
|
||||
const FBi = -T3r;
|
||||
|
||||
const FCr = T0r - T2r;
|
||||
|
||||
const FDr = T1r;
|
||||
const FDi = T3r;
|
||||
|
||||
out[outOff] = FAr;
|
||||
out[outOff + 1] = 0;
|
||||
out[outOff + 2] = FBr;
|
||||
out[outOff + 3] = FBi;
|
||||
out[outOff + 4] = FCr;
|
||||
out[outOff + 5] = 0;
|
||||
out[outOff + 6] = FDr;
|
||||
out[outOff + 7] = FDi;
|
||||
}
|
||||
}
|
||||
185
packages/superdough/ola-processor.js
Normal file
185
packages/superdough/ola-processor.js
Normal file
@ -0,0 +1,185 @@
|
||||
'use strict';
|
||||
|
||||
// sourced from https://github.com/olvb/phaze/tree/master?tab=readme-ov-file
|
||||
const WEBAUDIO_BLOCK_SIZE = 128;
|
||||
|
||||
/** Overlap-Add Node */
|
||||
class OLAProcessor extends AudioWorkletProcessor {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.started = false;
|
||||
this.nbInputs = options.numberOfInputs;
|
||||
this.nbOutputs = options.numberOfOutputs;
|
||||
|
||||
this.blockSize = options.processorOptions.blockSize;
|
||||
// TODO for now, the only support hop size is the size of a web audio block
|
||||
this.hopSize = WEBAUDIO_BLOCK_SIZE;
|
||||
|
||||
this.nbOverlaps = this.blockSize / this.hopSize;
|
||||
|
||||
// pre-allocate input buffers (will be reallocated if needed)
|
||||
this.inputBuffers = new Array(this.nbInputs);
|
||||
this.inputBuffersHead = new Array(this.nbInputs);
|
||||
this.inputBuffersToSend = new Array(this.nbInputs);
|
||||
// default to 1 channel per input until we know more
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
this.allocateInputChannels(i, 1);
|
||||
}
|
||||
// pre-allocate input buffers (will be reallocated if needed)
|
||||
this.outputBuffers = new Array(this.nbOutputs);
|
||||
this.outputBuffersToRetrieve = new Array(this.nbOutputs);
|
||||
// default to 1 channel per output until we know more
|
||||
for (let i = 0; i < this.nbOutputs; i++) {
|
||||
this.allocateOutputChannels(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** Handles dynamic reallocation of input/output channels buffer
|
||||
(channel numbers may lety during lifecycle) **/
|
||||
reallocateChannelsIfNeeded(inputs, outputs) {
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
let nbChannels = inputs[i].length;
|
||||
if (nbChannels != this.inputBuffers[i].length) {
|
||||
this.allocateInputChannels(i, nbChannels);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.nbOutputs; i++) {
|
||||
let nbChannels = outputs[i].length;
|
||||
if (nbChannels != this.outputBuffers[i].length) {
|
||||
this.allocateOutputChannels(i, nbChannels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allocateInputChannels(inputIndex, nbChannels) {
|
||||
// allocate input buffers
|
||||
|
||||
this.inputBuffers[inputIndex] = new Array(nbChannels);
|
||||
for (let i = 0; i < nbChannels; i++) {
|
||||
this.inputBuffers[inputIndex][i] = new Float32Array(this.blockSize + WEBAUDIO_BLOCK_SIZE);
|
||||
this.inputBuffers[inputIndex][i].fill(0);
|
||||
}
|
||||
|
||||
// allocate input buffers to send and head pointers to copy from
|
||||
// (cannot directly send a pointer/subarray because input may be modified)
|
||||
this.inputBuffersHead[inputIndex] = new Array(nbChannels);
|
||||
this.inputBuffersToSend[inputIndex] = new Array(nbChannels);
|
||||
for (let i = 0; i < nbChannels; i++) {
|
||||
this.inputBuffersHead[inputIndex][i] = this.inputBuffers[inputIndex][i].subarray(0, this.blockSize);
|
||||
this.inputBuffersToSend[inputIndex][i] = new Float32Array(this.blockSize);
|
||||
}
|
||||
}
|
||||
|
||||
allocateOutputChannels(outputIndex, nbChannels) {
|
||||
// allocate output buffers
|
||||
this.outputBuffers[outputIndex] = new Array(nbChannels);
|
||||
for (let i = 0; i < nbChannels; i++) {
|
||||
this.outputBuffers[outputIndex][i] = new Float32Array(this.blockSize);
|
||||
this.outputBuffers[outputIndex][i].fill(0);
|
||||
}
|
||||
|
||||
// allocate output buffers to retrieve
|
||||
// (cannot send a pointer/subarray because new output has to be add to exising output)
|
||||
this.outputBuffersToRetrieve[outputIndex] = new Array(nbChannels);
|
||||
for (let i = 0; i < nbChannels; i++) {
|
||||
this.outputBuffersToRetrieve[outputIndex][i] = new Float32Array(this.blockSize);
|
||||
this.outputBuffersToRetrieve[outputIndex][i].fill(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Read next web audio block to input buffers **/
|
||||
readInputs(inputs) {
|
||||
// when playback is paused, we may stop receiving new samples
|
||||
if (inputs[0].length && inputs[0][0].length == 0) {
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
for (let j = 0; j < this.inputBuffers[i].length; j++) {
|
||||
this.inputBuffers[i][j].fill(0, this.blockSize);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
for (let j = 0; j < this.inputBuffers[i].length; j++) {
|
||||
let webAudioBlock = inputs[i][j];
|
||||
this.inputBuffers[i][j].set(webAudioBlock, this.blockSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Write next web audio block from output buffers **/
|
||||
writeOutputs(outputs) {
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
for (let j = 0; j < this.inputBuffers[i].length; j++) {
|
||||
let webAudioBlock = this.outputBuffers[i][j].subarray(0, WEBAUDIO_BLOCK_SIZE);
|
||||
outputs[i][j].set(webAudioBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Shift left content of input buffers to receive new web audio block **/
|
||||
shiftInputBuffers() {
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
for (let j = 0; j < this.inputBuffers[i].length; j++) {
|
||||
this.inputBuffers[i][j].copyWithin(0, WEBAUDIO_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Shift left content of output buffers to receive new web audio block **/
|
||||
shiftOutputBuffers() {
|
||||
for (let i = 0; i < this.nbOutputs; i++) {
|
||||
for (let j = 0; j < this.outputBuffers[i].length; j++) {
|
||||
this.outputBuffers[i][j].copyWithin(0, WEBAUDIO_BLOCK_SIZE);
|
||||
this.outputBuffers[i][j].subarray(this.blockSize - WEBAUDIO_BLOCK_SIZE).fill(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy contents of input buffers to buffer actually sent to process **/
|
||||
prepareInputBuffersToSend() {
|
||||
for (let i = 0; i < this.nbInputs; i++) {
|
||||
for (let j = 0; j < this.inputBuffers[i].length; j++) {
|
||||
this.inputBuffersToSend[i][j].set(this.inputBuffersHead[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Add contents of output buffers just processed to output buffers **/
|
||||
handleOutputBuffersToRetrieve() {
|
||||
for (let i = 0; i < this.nbOutputs; i++) {
|
||||
for (let j = 0; j < this.outputBuffers[i].length; j++) {
|
||||
for (let k = 0; k < this.blockSize; k++) {
|
||||
this.outputBuffers[i][j][k] += this.outputBuffersToRetrieve[i][j][k] / this.nbOverlaps;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process(inputs, outputs, params) {
|
||||
const input = inputs[0];
|
||||
const hasInput = !(input[0] === undefined);
|
||||
if (this.started && !hasInput) {
|
||||
return false;
|
||||
}
|
||||
this.started = hasInput;
|
||||
this.reallocateChannelsIfNeeded(inputs, outputs);
|
||||
|
||||
this.readInputs(inputs);
|
||||
this.shiftInputBuffers();
|
||||
this.prepareInputBuffersToSend();
|
||||
this.processOLA(this.inputBuffersToSend, this.outputBuffersToRetrieve, params);
|
||||
this.handleOutputBuffersToRetrieve();
|
||||
this.writeOutputs(outputs);
|
||||
this.shiftOutputBuffers();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
processOLA(inputs, outputs, params) {
|
||||
console.assert(false, 'Not overriden');
|
||||
}
|
||||
}
|
||||
|
||||
export default OLAProcessor;
|
||||
@ -8,7 +8,7 @@ import './feedbackdelay.mjs';
|
||||
import './reverb.mjs';
|
||||
import './vowel.mjs';
|
||||
import { clamp, nanFallback, _mod } from './util.mjs';
|
||||
import workletsUrl from './worklets.mjs?url';
|
||||
import workletsUrl from './worklets.mjs?worker&url';
|
||||
import { createFilter, gainNode, getCompressor, getWorklet } from './helpers.mjs';
|
||||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
@ -309,6 +309,13 @@ export function resetGlobalEffects() {
|
||||
}
|
||||
|
||||
export const superdough = async (value, t, hapDuration) => {
|
||||
t = typeof t === 'string' && t.startsWith('=') ? Number(t.slice(1)) : ac.currentTime + t;
|
||||
let { stretch } = value;
|
||||
if (stretch != null) {
|
||||
//account for phase vocoder latency
|
||||
const latency = 0.04;
|
||||
t = t - latency;
|
||||
}
|
||||
const ac = getAudioContext();
|
||||
if (typeof value !== 'object') {
|
||||
throw new Error(
|
||||
@ -320,7 +327,7 @@ export const superdough = async (value, t, hapDuration) => {
|
||||
// duration is passed as value too..
|
||||
value.duration = hapDuration;
|
||||
// calculate absolute time
|
||||
t = typeof t === 'string' && t.startsWith('=') ? Number(t.slice(1)) : ac.currentTime + t;
|
||||
|
||||
if (t < ac.currentTime) {
|
||||
console.warn(
|
||||
`[superdough]: cannot schedule sounds in the past (target: ${t.toFixed(2)}, now: ${ac.currentTime.toFixed(2)})`,
|
||||
@ -438,6 +445,7 @@ export const superdough = async (value, t, hapDuration) => {
|
||||
}
|
||||
const chain = []; // audio nodes that will be connected to each other sequentially
|
||||
chain.push(sourceNode);
|
||||
stretch !== undefined && chain.push(getWorklet(ac, 'phase-vocoder-processor', { pitchFactor: stretch }));
|
||||
|
||||
// gain stage
|
||||
chain.push(gainNode(gain));
|
||||
@ -584,4 +592,6 @@ export const superdough = async (value, t, hapDuration) => {
|
||||
toDisconnect = chain.concat([delaySend, reverbSend, analyserSend]);
|
||||
};
|
||||
|
||||
export const superdoughTrigger = (t, hap, ct, cps) => superdough(hap, t - ct, hap.duration / cps, cps);
|
||||
export const superdoughTrigger = (t, hap, ct, cps) => {
|
||||
superdough(hap, t - ct, hap.duration / cps, cps);
|
||||
};
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
// coarse, crush, and shape processors adapted from dktr0's webdirt: https://github.com/dktr0/WebDirt/blob/5ce3d698362c54d6e1b68acc47eb2955ac62c793/dist/AudioWorklets.js
|
||||
// LICENSE GNU General Public License v3.0 see https://github.com/dktr0/WebDirt/blob/main/LICENSE
|
||||
// TOFIX: THIS FILE DOES NOT SUPPORT IMPORTS ON DEPOLYMENT
|
||||
|
||||
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;
|
||||
|
||||
@ -463,4 +467,184 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor);
|
||||
registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor);
|
||||
|
||||
// Phase Vocoder sourced from // sourced from https://github.com/olvb/phaze/tree/master?tab=readme-ov-file
|
||||
const BUFFERED_BLOCK_SIZE = 2048;
|
||||
|
||||
function genHannWindow(length) {
|
||||
let win = new Float32Array(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
win[i] = 0.5 * (1 - Math.cos((2 * Math.PI * i) / length));
|
||||
}
|
||||
return win;
|
||||
}
|
||||
|
||||
class PhaseVocoderProcessor extends OLAProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [
|
||||
{
|
||||
name: 'pitchFactor',
|
||||
defaultValue: 1.0,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
options.processorOptions = {
|
||||
blockSize: BUFFERED_BLOCK_SIZE,
|
||||
};
|
||||
super(options);
|
||||
|
||||
this.fftSize = this.blockSize;
|
||||
this.timeCursor = 0;
|
||||
|
||||
this.hannWindow = genHannWindow(this.blockSize);
|
||||
// prepare FFT and pre-allocate buffers
|
||||
this.fft = new FFT(this.fftSize);
|
||||
this.freqComplexBuffer = this.fft.createComplexArray();
|
||||
this.freqComplexBufferShifted = this.fft.createComplexArray();
|
||||
this.timeComplexBuffer = this.fft.createComplexArray();
|
||||
this.magnitudes = new Float32Array(this.fftSize / 2 + 1);
|
||||
this.peakIndexes = new Int32Array(this.magnitudes.length);
|
||||
this.nbPeaks = 0;
|
||||
}
|
||||
|
||||
processOLA(inputs, outputs, parameters) {
|
||||
// no automation, take last value
|
||||
|
||||
let pitchFactor = parameters.pitchFactor[parameters.pitchFactor.length - 1];
|
||||
|
||||
if (pitchFactor < 0) {
|
||||
pitchFactor = pitchFactor * 0.25;
|
||||
}
|
||||
pitchFactor = Math.max(0, pitchFactor + 1);
|
||||
|
||||
for (var i = 0; i < this.nbInputs; i++) {
|
||||
for (var j = 0; j < inputs[i].length; j++) {
|
||||
// big assumption here: output is symetric to input
|
||||
var input = inputs[i][j];
|
||||
var output = outputs[i][j];
|
||||
|
||||
this.applyHannWindow(input);
|
||||
|
||||
this.fft.realTransform(this.freqComplexBuffer, input);
|
||||
|
||||
this.computeMagnitudes();
|
||||
this.findPeaks();
|
||||
this.shiftPeaks(pitchFactor);
|
||||
|
||||
this.fft.completeSpectrum(this.freqComplexBufferShifted);
|
||||
this.fft.inverseTransform(this.timeComplexBuffer, this.freqComplexBufferShifted);
|
||||
this.fft.fromComplexArray(this.timeComplexBuffer, output);
|
||||
this.applyHannWindow(output);
|
||||
}
|
||||
}
|
||||
|
||||
this.timeCursor += this.hopSize;
|
||||
}
|
||||
|
||||
/** Apply Hann window in-place */
|
||||
applyHannWindow(input) {
|
||||
for (var i = 0; i < this.blockSize; i++) {
|
||||
input[i] = input[i] * this.hannWindow[i] * 1.62;
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute squared magnitudes for peak finding **/
|
||||
computeMagnitudes() {
|
||||
var i = 0,
|
||||
j = 0;
|
||||
while (i < this.magnitudes.length) {
|
||||
let real = this.freqComplexBuffer[j];
|
||||
let imag = this.freqComplexBuffer[j + 1];
|
||||
// no need to sqrt for peak finding
|
||||
this.magnitudes[i] = real ** 2 + imag ** 2;
|
||||
i += 1;
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/** Find peaks in spectrum magnitudes **/
|
||||
findPeaks() {
|
||||
this.nbPeaks = 0;
|
||||
var i = 2;
|
||||
let end = this.magnitudes.length - 2;
|
||||
|
||||
while (i < end) {
|
||||
let mag = this.magnitudes[i];
|
||||
|
||||
if (this.magnitudes[i - 1] >= mag || this.magnitudes[i - 2] >= mag) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (this.magnitudes[i + 1] >= mag || this.magnitudes[i + 2] >= mag) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.peakIndexes[this.nbPeaks] = i;
|
||||
this.nbPeaks++;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/** Shift peaks and regions of influence by pitchFactor into new specturm */
|
||||
shiftPeaks(pitchFactor) {
|
||||
// zero-fill new spectrum
|
||||
this.freqComplexBufferShifted.fill(0);
|
||||
|
||||
for (var i = 0; i < this.nbPeaks; i++) {
|
||||
let peakIndex = this.peakIndexes[i];
|
||||
let peakIndexShifted = Math.round(peakIndex * pitchFactor);
|
||||
|
||||
if (peakIndexShifted > this.magnitudes.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
// find region of influence
|
||||
var startIndex = 0;
|
||||
var endIndex = this.fftSize;
|
||||
if (i > 0) {
|
||||
let peakIndexBefore = this.peakIndexes[i - 1];
|
||||
startIndex = peakIndex - Math.floor((peakIndex - peakIndexBefore) / 2);
|
||||
}
|
||||
if (i < this.nbPeaks - 1) {
|
||||
let peakIndexAfter = this.peakIndexes[i + 1];
|
||||
endIndex = peakIndex + Math.ceil((peakIndexAfter - peakIndex) / 2);
|
||||
}
|
||||
|
||||
// shift whole region of influence around peak to shifted peak
|
||||
let startOffset = startIndex - peakIndex;
|
||||
let endOffset = endIndex - peakIndex;
|
||||
for (var j = startOffset; j < endOffset; j++) {
|
||||
let binIndex = peakIndex + j;
|
||||
let binIndexShifted = peakIndexShifted + j;
|
||||
|
||||
if (binIndexShifted >= this.magnitudes.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
// apply phase correction
|
||||
let omegaDelta = (2 * Math.PI * (binIndexShifted - binIndex)) / this.fftSize;
|
||||
let phaseShiftReal = Math.cos(omegaDelta * this.timeCursor);
|
||||
let phaseShiftImag = Math.sin(omegaDelta * this.timeCursor);
|
||||
|
||||
let indexReal = binIndex * 2;
|
||||
let indexImag = indexReal + 1;
|
||||
let valueReal = this.freqComplexBuffer[indexReal];
|
||||
let valueImag = this.freqComplexBuffer[indexImag];
|
||||
|
||||
let valueShiftedReal = valueReal * phaseShiftReal - valueImag * phaseShiftImag;
|
||||
let valueShiftedImag = valueReal * phaseShiftImag + valueImag * phaseShiftReal;
|
||||
|
||||
let indexShiftedReal = binIndexShifted * 2;
|
||||
let indexShiftedImag = indexShiftedReal + 1;
|
||||
this.freqComplexBufferShifted[indexShiftedReal] += valueShiftedReal;
|
||||
this.freqComplexBufferShifted[indexShiftedImag] += valueShiftedImag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor('phase-vocoder-processor', PhaseVocoderProcessor);
|
||||
|
||||
@ -7486,6 +7486,23 @@ exports[`runs examples > example "steps" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "stretch" example index 0 1`] = `
|
||||
[
|
||||
"[ (0/1 → 1/3) ⇝ 1/1 | s:gm_flute stretch:1 ]",
|
||||
"[ 0/1 ⇜ (1/3 → 2/3) ⇝ 1/1 | s:gm_flute stretch:2 ]",
|
||||
"[ 0/1 ⇜ (2/3 → 1/1) | s:gm_flute stretch:0.5 ]",
|
||||
"[ (1/1 → 4/3) ⇝ 2/1 | s:gm_flute stretch:1 ]",
|
||||
"[ 1/1 ⇜ (4/3 → 5/3) ⇝ 2/1 | s:gm_flute stretch:2 ]",
|
||||
"[ 1/1 ⇜ (5/3 → 2/1) | s:gm_flute stretch:0.5 ]",
|
||||
"[ (2/1 → 7/3) ⇝ 3/1 | s:gm_flute stretch:1 ]",
|
||||
"[ 2/1 ⇜ (7/3 → 8/3) ⇝ 3/1 | s:gm_flute stretch:2 ]",
|
||||
"[ 2/1 ⇜ (8/3 → 3/1) | s:gm_flute stretch:0.5 ]",
|
||||
"[ (3/1 → 10/3) ⇝ 4/1 | s:gm_flute stretch:1 ]",
|
||||
"[ 3/1 ⇜ (10/3 → 11/3) ⇝ 4/1 | s:gm_flute stretch:2 ]",
|
||||
"[ 3/1 ⇜ (11/3 → 4/1) | s:gm_flute stretch:0.5 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "striate" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/6 | s:numbers n:0 begin:0 end:0.16666666666666666 ]",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { loadFeaturedPatterns, loadPublicPatterns } from '@src/user_pattern_utils.mjs';
|
||||
import { MiniRepl } from '@src/docs/MiniRepl';
|
||||
import { PatternLabel } from '@src/repl/panel/PatternsTab';
|
||||
import { PatternLabel } from '@src/repl/components/panel/PatternsTab';
|
||||
|
||||
function PatternList({ patterns }) {
|
||||
return (
|
||||
|
||||
32
website/src/components/Udels/UdelFrame.jsx
Normal file
32
website/src/components/Udels/UdelFrame.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
export function UdelFrame({ onEvaluate, hash, instance }) {
|
||||
const ref = useRef();
|
||||
window.addEventListener('message', (message) => {
|
||||
const childWindow = ref?.current?.contentWindow;
|
||||
if (message == null || message.source !== childWindow) {
|
||||
return; // Skip message in this event listener
|
||||
}
|
||||
onEvaluate(message.data);
|
||||
});
|
||||
|
||||
const url = new URL(window.location.origin);
|
||||
url.hash = hash;
|
||||
url.searchParams.append('instance', instance);
|
||||
const source = url.toString();
|
||||
|
||||
return (
|
||||
<iframe
|
||||
ref={ref}
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexGrow: 1,
|
||||
minWidth: '50%',
|
||||
boxSizing: 'border-box',
|
||||
border: '0px',
|
||||
}}
|
||||
title="strudel embed"
|
||||
src={source}
|
||||
></iframe>
|
||||
);
|
||||
}
|
||||
72
website/src/components/Udels/Udels.jsx
Normal file
72
website/src/components/Udels/Udels.jsx
Normal file
@ -0,0 +1,72 @@
|
||||
import { code2hash } from '@strudel/core';
|
||||
|
||||
import { UdelFrame } from './UdelFrame';
|
||||
import { useState } from 'react';
|
||||
import UdelsHeader from './UdelsHeader';
|
||||
|
||||
const defaultHash = 'c3RhY2soCiAgCik%3D';
|
||||
|
||||
const getHashesFromUrl = () => {
|
||||
return window.location.hash?.slice(1).split(',');
|
||||
};
|
||||
const updateURLHashes = (hashes) => {
|
||||
const newHash = '#' + hashes.join(',');
|
||||
window.location.hash = newHash;
|
||||
};
|
||||
export function Udels() {
|
||||
const hashes = getHashesFromUrl();
|
||||
|
||||
const [numWindows, setNumWindows] = useState(hashes?.length ?? 1);
|
||||
const numWindowsOnChange = (num) => {
|
||||
setNumWindows(num);
|
||||
const hashes = getHashesFromUrl();
|
||||
const newHashes = [];
|
||||
for (let i = 0; i < num; i++) {
|
||||
newHashes[i] = hashes[i] ?? defaultHash;
|
||||
}
|
||||
updateURLHashes(newHashes);
|
||||
};
|
||||
|
||||
const onEvaluate = (key, code) => {
|
||||
const hashes = getHashesFromUrl();
|
||||
hashes[key] = code2hash(code);
|
||||
|
||||
updateURLHashes(hashes);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
margin: 0,
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
height: '100vh',
|
||||
width: '100%',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<UdelsHeader numWindows={numWindows} setNumWindows={numWindowsOnChange} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
flexDirection: 'row',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
{hashes.map((hash, key) => {
|
||||
return (
|
||||
<UdelFrame
|
||||
instance={key}
|
||||
onEvaluate={(code) => {
|
||||
onEvaluate(key, code);
|
||||
}}
|
||||
hash={hash}
|
||||
key={key}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
34
website/src/components/Udels/UdelsEditor.jsx
Normal file
34
website/src/components/Udels/UdelsEditor.jsx
Normal file
@ -0,0 +1,34 @@
|
||||
import { ReplContext } from '@src/repl/util.mjs';
|
||||
|
||||
import Loader from '@src/repl/components/Loader';
|
||||
import { Panel } from '@src/repl/components/panel/Panel';
|
||||
import { Code } from '@src/repl/components/Code';
|
||||
import BigPlayButton from '@src/repl/components/BigPlayButton';
|
||||
import UserFacingErrorMessage from '@src/repl/components/UserFacingErrorMessage';
|
||||
|
||||
// type Props = {
|
||||
// context: replcontext,
|
||||
// containerRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// editorRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// error: Error
|
||||
// init: () => void
|
||||
// }
|
||||
|
||||
export default function UdelsEditor(Props) {
|
||||
const { context, containerRef, editorRef, error, init } = Props;
|
||||
const { pending, started, handleTogglePlay } = context;
|
||||
return (
|
||||
<ReplContext.Provider value={context}>
|
||||
<div className={'h-full flex w-full flex-col relative'}>
|
||||
<Loader active={pending} />
|
||||
{/* <Header context={context} /> */}
|
||||
<BigPlayButton started={started} handleTogglePlay={handleTogglePlay} />
|
||||
<div className="grow flex relative overflow-hidden">
|
||||
<Code containerRef={containerRef} editorRef={editorRef} init={init} />
|
||||
</div>
|
||||
<UserFacingErrorMessage error={error} />
|
||||
<Panel context={context} />
|
||||
</div>
|
||||
</ReplContext.Provider>
|
||||
);
|
||||
}
|
||||
20
website/src/components/Udels/UdelsHeader.jsx
Normal file
20
website/src/components/Udels/UdelsHeader.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import NumberInput from '@src/repl/components/NumberInput';
|
||||
|
||||
export default function UdelsHeader(Props) {
|
||||
const { numWindows, setNumWindows } = Props;
|
||||
|
||||
return (
|
||||
<header id="header" className="flex text-white z-[100] text-lg select-none bg-neutral-900">
|
||||
<div className="px-4 items-center gap-2 flex space-x-2 md:pt-0 select-none">
|
||||
<h1 onClick={() => {}} className={'text-l cursor-pointer flex gap-4'}>
|
||||
<div className={'mt-[1px] cursor-pointer'}>🌀</div>
|
||||
|
||||
<div className={'animate-pulse'}>
|
||||
<span className="">strudel</span> <span className="text-sm">-UDELS</span>
|
||||
</div>
|
||||
</h1>
|
||||
<NumberInput value={numWindows} setValue={setNumWindows} />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@ -30,7 +30,7 @@ const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`;
|
||||
</title>
|
||||
</head>
|
||||
|
||||
<body class="h-app-height text-gray-50 bg-background">
|
||||
<body class="h-app-height m-0 text-gray-50 bg-background">
|
||||
<div class="w-full h-full space-y-4 flex flex-col">
|
||||
<header class="max-w-full fixed top-0 w-full z-[100]">
|
||||
<Header currentPage={currentPage} />
|
||||
|
||||
@ -3,12 +3,12 @@ import HeadCommon from '../components/HeadCommon.astro';
|
||||
import { Repl } from '../repl/Repl';
|
||||
---
|
||||
|
||||
<html lang="en" class="dark">
|
||||
<html lang="en" class="m-0 dark">
|
||||
<head>
|
||||
<HeadCommon />
|
||||
<title>Strudel REPL</title>
|
||||
</head>
|
||||
<body class="h-app-height bg-background">
|
||||
<body class="h-app-height bg-background m-0">
|
||||
<Repl client:only="react" />
|
||||
<a rel="me" href="https://social.toplap.org/@strudel" target="_blank" class="hidden">mastodon</a>
|
||||
</body>
|
||||
|
||||
12
website/src/pages/udels/index.astro
Normal file
12
website/src/pages/udels/index.astro
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
import { Udels } from '../../components/Udels/Udels.jsx';
|
||||
|
||||
|
||||
const { BASE_URL } = import.meta.env;
|
||||
const baseNoTrailing = BASE_URL.endsWith('/') ? BASE_URL.slice(0, -1) : BASE_URL;
|
||||
---
|
||||
|
||||
|
||||
<body class="m-0">
|
||||
<Udels client:only="react" />
|
||||
</body>
|
||||
@ -6,7 +6,6 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import { code2hash, logger, silence } from '@strudel/core';
|
||||
import { getDrawContext } from '@strudel/draw';
|
||||
import cx from '@src/cx.mjs';
|
||||
import { transpiler } from '@strudel/transpiler';
|
||||
import {
|
||||
getAudioContext,
|
||||
@ -29,16 +28,15 @@ import {
|
||||
getViewingPatternData,
|
||||
setViewingPatternData,
|
||||
} from '../user_pattern_utils.mjs';
|
||||
import { Header } from './Header';
|
||||
import Loader from './Loader';
|
||||
import { Panel } from './panel/Panel';
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { prebake } from './prebake.mjs';
|
||||
import { getRandomTune, initCode, loadModules, shareCode, ReplContext } from './util.mjs';
|
||||
import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
|
||||
import { getRandomTune, initCode, loadModules, shareCode, ReplContext, isUdels } from './util.mjs';
|
||||
import './Repl.css';
|
||||
import { setInterval, clearInterval } from 'worker-timers';
|
||||
import { getMetadata } from '../metadata_parser';
|
||||
import UdelsEditor from '@components/Udels/UdelsEditor';
|
||||
|
||||
import ReplEditor from './components/ReplEditor';
|
||||
|
||||
const { latestCode } = settingsMap.get();
|
||||
|
||||
@ -92,6 +90,9 @@ export function Repl({ embedded = false }) {
|
||||
beforeEval: () => audioReady,
|
||||
afterEval: (all) => {
|
||||
const { code } = all;
|
||||
//post to iframe parent (like Udels) if it exists...
|
||||
window.parent?.postMessage(code);
|
||||
|
||||
setLatestCode(code);
|
||||
window.location.hash = '#' + code2hash(code);
|
||||
setDocumentTitle(code);
|
||||
@ -234,38 +235,21 @@ export function Repl({ embedded = false }) {
|
||||
handleEvaluate,
|
||||
};
|
||||
|
||||
if (isUdels()) {
|
||||
return (
|
||||
<UdelsEditor context={context} error={error} init={init} editorRef={editorRef} containerRef={containerRef} />
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ReplContext.Provider value={context}>
|
||||
<div className={cx('h-full flex flex-col relative')}>
|
||||
<Loader active={pending} />
|
||||
<Header context={context} />
|
||||
{isEmbedded && !started && (
|
||||
<button
|
||||
onClick={() => handleTogglePlay()}
|
||||
className="text-white text-2xl fixed left-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%] z-[1000] m-auto p-4 bg-black rounded-md flex items-center space-x-2"
|
||||
>
|
||||
<PlayCircleIcon className="w-6 h-6" />
|
||||
<span>play</span>
|
||||
</button>
|
||||
)}
|
||||
<div className="grow flex relative overflow-hidden">
|
||||
<section
|
||||
className={'text-gray-100 cursor-text pb-0 overflow-auto grow' + (isZen ? ' px-10' : '')}
|
||||
id="code"
|
||||
ref={(el) => {
|
||||
containerRef.current = el;
|
||||
if (!editorRef.current) {
|
||||
init();
|
||||
}
|
||||
}}
|
||||
></section>
|
||||
{panelPosition === 'right' && !isEmbedded && <Panel context={context} />}
|
||||
</div>
|
||||
{error && (
|
||||
<div className="text-red-500 p-4 bg-lineHighlight animate-pulse">{error.message || 'Unknown Error :-/'}</div>
|
||||
)}
|
||||
{panelPosition === 'bottom' && !isEmbedded && <Panel context={context} />}
|
||||
</div>
|
||||
</ReplContext.Provider>
|
||||
<ReplEditor
|
||||
panelPosition={panelPosition}
|
||||
isEmbedded={isEmbedded}
|
||||
context={context}
|
||||
error={error}
|
||||
init={init}
|
||||
editorRef={editorRef}
|
||||
containerRef={containerRef}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
22
website/src/repl/components/BigPlayButton.jsx
Normal file
22
website/src/repl/components/BigPlayButton.jsx
Normal file
@ -0,0 +1,22 @@
|
||||
import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
|
||||
|
||||
// type Props = {
|
||||
// started: boolean;
|
||||
// handleTogglePlay: () => void;
|
||||
// };
|
||||
export default function BigPlayButton(Props) {
|
||||
const { started, handleTogglePlay } = Props;
|
||||
if (started) {
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={() => handleTogglePlay()}
|
||||
className="text-white text-2xl fixed left-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%] z-[1000] m-auto p-4 bg-black rounded-md flex items-center space-x-2"
|
||||
>
|
||||
<PlayCircleIcon className="w-6 h-6" />
|
||||
<span>play</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
21
website/src/repl/components/Code.jsx
Normal file
21
website/src/repl/components/Code.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
// type Props = {
|
||||
// containerRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// editorRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// init: () => void
|
||||
// }
|
||||
export function Code(Props) {
|
||||
const { editorRef, containerRef, init } = Props;
|
||||
|
||||
return (
|
||||
<section
|
||||
className={'text-gray-100 cursor-text pb-0 overflow-auto grow'}
|
||||
id="code"
|
||||
ref={(el) => {
|
||||
containerRef.current = el;
|
||||
if (!editorRef.current) {
|
||||
init();
|
||||
}
|
||||
}}
|
||||
></section>
|
||||
);
|
||||
}
|
||||
@ -5,9 +5,9 @@ import PlayCircleIcon from '@heroicons/react/20/solid/PlayCircleIcon';
|
||||
import SparklesIcon from '@heroicons/react/20/solid/SparklesIcon';
|
||||
import StopCircleIcon from '@heroicons/react/20/solid/StopCircleIcon';
|
||||
import cx from '@src/cx.mjs';
|
||||
import { useSettings, setIsZen } from '../settings.mjs';
|
||||
import { useSettings, setIsZen } from '../../settings.mjs';
|
||||
// import { ReplContext } from './Repl';
|
||||
import './Repl.css';
|
||||
import '../Repl.css';
|
||||
const { BASE_URL } = import.meta.env;
|
||||
const baseNoTrailing = BASE_URL.endsWith('/') ? BASE_URL.slice(0, -1) : BASE_URL;
|
||||
|
||||
54
website/src/repl/components/NumberInput.jsx
Normal file
54
website/src/repl/components/NumberInput.jsx
Normal file
@ -0,0 +1,54 @@
|
||||
function Button(Props) {
|
||||
const { children, onClick } = Props;
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
type="button"
|
||||
data-input-counter-increment="counter-input"
|
||||
className="flex-shrink-0 bg-gray-700 hover:bg-gray-600 border-gray-600 inline-flex items-center justify-center border rounded-md h-5 w-5 focus:ring-gray-700 focus:ring-2 focus:outline-none"
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
export default function NumberInput(Props) {
|
||||
const { value = 0, setValue, max, min } = Props;
|
||||
|
||||
return (
|
||||
<div className="relative flex items-center">
|
||||
<Button onClick={() => setValue(value - 1)}>
|
||||
<svg
|
||||
className="w-2.5 h-2.5 text-white"
|
||||
aria-hidden="true"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 18 2"
|
||||
>
|
||||
<path stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M1 1h16" />
|
||||
</svg>
|
||||
</Button>
|
||||
<input
|
||||
min={min}
|
||||
max={max}
|
||||
type="text"
|
||||
data-input-counter
|
||||
className="flex-shrink-0 text-white border-0 bg-transparent text-sm font-normal focus:outline-none focus:ring-0 max-w-[2.5rem] text-center"
|
||||
placeholder=""
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
/>
|
||||
<Button onClick={() => setValue(value + 1)}>
|
||||
<svg
|
||||
className="w-2.5 h-2.5 text-white"
|
||||
aria-hidden="true"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 18 18"
|
||||
>
|
||||
<path strokeLinecap="round" stroke="currentColor" strokeLinejoin="round" strokeWidth="2" d="M9 1v16M1 9h16" />
|
||||
</svg>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
38
website/src/repl/components/ReplEditor.jsx
Normal file
38
website/src/repl/components/ReplEditor.jsx
Normal file
@ -0,0 +1,38 @@
|
||||
import { ReplContext } from '@src/repl/util.mjs';
|
||||
|
||||
import Loader from '@src/repl/components/Loader';
|
||||
import { Panel } from '@src/repl/components/panel/Panel';
|
||||
import { Code } from '@src/repl/components/Code';
|
||||
import BigPlayButton from '@src/repl/components/BigPlayButton';
|
||||
import UserFacingErrorMessage from '@src/repl/components/UserFacingErrorMessage';
|
||||
import { Header } from './Header';
|
||||
|
||||
// type Props = {
|
||||
// context: replcontext,
|
||||
// containerRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// editorRef: React.MutableRefObject<HTMLElement | null>,
|
||||
// error: Error
|
||||
// init: () => void
|
||||
// isEmbedded: boolean
|
||||
// }
|
||||
|
||||
export default function ReplEditor(Props) {
|
||||
const { context, containerRef, editorRef, error, init, panelPosition } = Props;
|
||||
const { pending, started, handleTogglePlay, isEmbedded } = context;
|
||||
const showPanel = !isEmbedded;
|
||||
return (
|
||||
<ReplContext.Provider value={context}>
|
||||
<div className="h-full flex flex-col relative">
|
||||
<Loader active={pending} />
|
||||
<Header context={context} />
|
||||
{isEmbedded && <BigPlayButton started={started} handleTogglePlay={handleTogglePlay} />}
|
||||
<div className="grow flex relative overflow-hidden">
|
||||
<Code containerRef={containerRef} editorRef={editorRef} init={init} />
|
||||
{panelPosition === 'right' && showPanel && <Panel context={context} />}
|
||||
</div>
|
||||
<UserFacingErrorMessage error={error} />
|
||||
{panelPosition === 'bottom' && showPanel && <Panel context={context} />}
|
||||
</div>
|
||||
</ReplContext.Provider>
|
||||
);
|
||||
}
|
||||
8
website/src/repl/components/UserFacingErrorMessage.jsx
Normal file
8
website/src/repl/components/UserFacingErrorMessage.jsx
Normal file
@ -0,0 +1,8 @@
|
||||
// type Props = { error: Error | null };
|
||||
export default function UserFacingErrorMessage(Props) {
|
||||
const { error } = Props;
|
||||
if (error == null) {
|
||||
return;
|
||||
}
|
||||
return <div className="text-red-500 p-4 bg-lineHighlight animate-pulse">{error.message || 'Unknown Error :-/'}</div>;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { getAudioDevices, setAudioDevice } from '../util.mjs';
|
||||
import { getAudioDevices, setAudioDevice } from '../../util.mjs';
|
||||
import { SelectInput } from './SelectInput';
|
||||
|
||||
const initdevices = new Map();
|
||||
@ -1,6 +1,6 @@
|
||||
import { Fragment, useEffect } from 'react';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { isAudioFile, readDir, dir, playFile } from '../files.mjs';
|
||||
import { isAudioFile, readDir, dir, playFile } from '../../files.mjs';
|
||||
|
||||
export function FilesTab() {
|
||||
const [path, setPath] = useState([]);
|
||||
@ -1,5 +1,5 @@
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { registerSamplesFromDB, uploadSamplesToDB, userSamplesDBConfig } from '../idbutils.mjs';
|
||||
import { registerSamplesFromDB, uploadSamplesToDB, userSamplesDBConfig } from '../../idbutils.mjs';
|
||||
|
||||
//choose a directory to locally import samples
|
||||
export default function ImportSoundsButton({ onComplete }) {
|
||||
@ -4,7 +4,7 @@ import useEvent from '@src/useEvent.mjs';
|
||||
import cx from '@src/cx.mjs';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { useCallback, useLayoutEffect, useEffect, useRef, useState } from 'react';
|
||||
import { setActiveFooter, useSettings } from '../../settings.mjs';
|
||||
import { setActiveFooter, useSettings } from '../../../settings.mjs';
|
||||
import { ConsoleTab } from './ConsoleTab';
|
||||
import { FilesTab } from './FilesTab';
|
||||
import { Reference } from './Reference';
|
||||
@ -5,13 +5,13 @@ import {
|
||||
useActivePattern,
|
||||
useViewingPatternData,
|
||||
userPattern,
|
||||
} from '../../user_pattern_utils.mjs';
|
||||
} from '../../../user_pattern_utils.mjs';
|
||||
import { useMemo } from 'react';
|
||||
import { getMetadata } from '../../metadata_parser';
|
||||
import { useExamplePatterns } from '../useExamplePatterns';
|
||||
import { parseJSON } from '../util.mjs';
|
||||
import { getMetadata } from '../../../metadata_parser.js';
|
||||
import { useExamplePatterns } from '../../useExamplePatterns.jsx';
|
||||
import { parseJSON, isUdels } from '../../util.mjs';
|
||||
import { ButtonGroup } from './Forms.jsx';
|
||||
import { settingsMap, useSettings } from '../../settings.mjs';
|
||||
import { settingsMap, useSettings } from '../../../settings.mjs';
|
||||
|
||||
function classNames(...classes) {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
@ -99,7 +99,7 @@ export function PatternsTab({ context }) {
|
||||
};
|
||||
const viewingPatternID = viewingPatternData?.id;
|
||||
|
||||
const autoResetPatternOnChange = !window.parent?.location.pathname.includes('oodles');
|
||||
const autoResetPatternOnChange = !isUdels();
|
||||
|
||||
return (
|
||||
<div className="px-4 w-full dark:text-white text-stone-900 space-y-2 pb-4 flex flex-col overflow-hidden max-h-full">
|
||||
@ -1,4 +1,4 @@
|
||||
import jsdocJson from '../../../../doc.json';
|
||||
import jsdocJson from '../../../../../doc.json';
|
||||
const visibleFunctions = jsdocJson.docs
|
||||
.filter(({ name, description }) => name && !name.startsWith('_') && !!description)
|
||||
.sort((a, b) => /* a.meta.filename.localeCompare(b.meta.filename) + */ a.name.localeCompare(b.name));
|
||||
@ -1,12 +1,13 @@
|
||||
import { defaultSettings, settingsMap, useSettings } from '../../settings.mjs';
|
||||
import { defaultSettings, settingsMap, useSettings } from '../../../settings.mjs';
|
||||
import { themes } from '@strudel/codemirror';
|
||||
import { isUdels } from '../../util.mjs';
|
||||
import { ButtonGroup } from './Forms.jsx';
|
||||
import { AudioDeviceSelector } from './AudioDeviceSelector.jsx';
|
||||
|
||||
function Checkbox({ label, value, onChange }) {
|
||||
function Checkbox({ label, value, onChange, disabled = false }) {
|
||||
return (
|
||||
<label>
|
||||
<input type="checkbox" checked={value} onChange={onChange} />
|
||||
<input disabled={disabled} type="checkbox" checked={value} onChange={onChange} />
|
||||
{' ' + label}
|
||||
</label>
|
||||
);
|
||||
@ -96,7 +97,7 @@ export function SettingsTab({ started }) {
|
||||
panelPosition,
|
||||
audioDeviceName,
|
||||
} = useSettings();
|
||||
|
||||
const shouldAlwaysSync = isUdels();
|
||||
return (
|
||||
<div className="text-foreground p-4 space-y-4">
|
||||
{AudioContext.prototype.setSinkId != null && (
|
||||
@ -197,6 +198,7 @@ export function SettingsTab({ started }) {
|
||||
window.location.reload();
|
||||
}
|
||||
}}
|
||||
disabled={shouldAlwaysSync}
|
||||
value={isSyncEnabled}
|
||||
/>
|
||||
</FormItem>
|
||||
@ -2,7 +2,7 @@ import useEvent from '@src/useEvent.mjs';
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { getAudioContext, soundMap, connectToDestination } from '@strudel/webaudio';
|
||||
import React, { useMemo, useRef } from 'react';
|
||||
import { settingsMap, useSettings } from '../../settings.mjs';
|
||||
import { settingsMap, useSettings } from '../../../settings.mjs';
|
||||
import { ButtonGroup } from './Forms.jsx';
|
||||
import ImportSoundsButton from './ImportSoundsButton.jsx';
|
||||
|
||||
@ -134,6 +134,10 @@ export async function shareCode(codeToShare) {
|
||||
|
||||
export const ReplContext = createContext(null);
|
||||
|
||||
export const isUdels = () => {
|
||||
return window.parent?.location.pathname.includes('udels');
|
||||
};
|
||||
|
||||
export const getAudioDevices = async () => {
|
||||
await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
let mediaDevices = await navigator.mediaDevices.enumerateDevices();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { persistentMap } from '@nanostores/persistent';
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { register } from '@strudel/core';
|
||||
import { isUdels } from './repl/util.mjs';
|
||||
|
||||
export const defaultAudioDeviceName = 'System Standard';
|
||||
|
||||
@ -29,7 +30,15 @@ export const defaultSettings = {
|
||||
audioDeviceName: defaultAudioDeviceName,
|
||||
};
|
||||
|
||||
export const settingsMap = persistentMap('strudel-settings', defaultSettings);
|
||||
let search = null;
|
||||
if (typeof window !== 'undefined') {
|
||||
search = new URLSearchParams(window.location.search);
|
||||
}
|
||||
// if running multiple instance in one window, it will use the settings for that instance. else default to normal
|
||||
const instance = parseInt(search?.get('instance') ?? '0');
|
||||
const settings_key = `strudel-settings${instance > 0 ? instance : ''}`;
|
||||
|
||||
export const settingsMap = persistentMap(settings_key, defaultSettings);
|
||||
|
||||
const parseBoolean = (booleanlike) => ([true, 'true'].includes(booleanlike) ? true : false);
|
||||
|
||||
@ -54,9 +63,9 @@ export function useSettings() {
|
||||
isTooltipEnabled: parseBoolean(state.isTooltipEnabled),
|
||||
isLineWrappingEnabled: parseBoolean(state.isLineWrappingEnabled),
|
||||
isFlashEnabled: parseBoolean(state.isFlashEnabled),
|
||||
isSyncEnabled: parseBoolean(state.isSyncEnabled),
|
||||
isSyncEnabled: isUdels() ? true : parseBoolean(state.isSyncEnabled),
|
||||
fontSize: Number(state.fontSize),
|
||||
panelPosition: state.activeFooter !== '' ? state.panelPosition : 'bottom', // <-- keep this 'bottom' where it is!
|
||||
panelPosition: state.activeFooter !== '' && !isUdels() ? state.panelPosition : 'bottom', // <-- keep this 'bottom' where it is!
|
||||
userPatterns: userPatterns,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user