mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 21:18:49 +00:00
Merge pull request #973 from tidalcycles/nested-controls
Nested controls
This commit is contained in:
commit
7d01764a30
@ -7,26 +7,32 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
import { Pattern, register, sequence } from './pattern.mjs';
|
import { Pattern, register, sequence } from './pattern.mjs';
|
||||||
|
|
||||||
export function createParam(names) {
|
export function createParam(names) {
|
||||||
const name = Array.isArray(names) ? names[0] : names;
|
let isMulti = Array.isArray(names);
|
||||||
|
names = !isMulti ? [names] : names;
|
||||||
|
const name = names[0];
|
||||||
|
|
||||||
var withVal;
|
const withVal = (xs) => {
|
||||||
if (Array.isArray(names)) {
|
let bag;
|
||||||
withVal = (xs) => {
|
// check if we have an object with an unnamed control (.value)
|
||||||
if (Array.isArray(xs)) {
|
if (typeof xs === 'object' && xs.value !== undefined) {
|
||||||
const result = {};
|
bag = xs; // grab props that are already there
|
||||||
xs.forEach((x, i) => {
|
xs = xs.value; // grab the unnamed control for this one
|
||||||
if (i < names.length) {
|
delete bag.value;
|
||||||
result[names[i]] = x;
|
}
|
||||||
}
|
if (isMulti && Array.isArray(xs)) {
|
||||||
});
|
const result = bag || {};
|
||||||
return result;
|
xs.forEach((x, i) => {
|
||||||
} else {
|
if (i < names.length) {
|
||||||
return { [name]: xs };
|
result[names[i]] = x;
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
} else {
|
return result;
|
||||||
withVal = (x) => ({ [name]: x });
|
} else if (bag) {
|
||||||
}
|
return { ...bag, [name]: xs };
|
||||||
|
} else {
|
||||||
|
return { [name]: xs };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const func = (...pats) => sequence(...pats).withValue(withVal);
|
const func = (...pats) => sequence(...pats).withValue(withVal);
|
||||||
|
|
||||||
|
|||||||
@ -896,16 +896,15 @@ addToPrototype('weaveWith', function (t, ...funcs) {
|
|||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// compose matrix functions
|
// compose matrix functions
|
||||||
|
|
||||||
// TODO - adopt value.mjs fully..
|
function _nonArrayObject(x) {
|
||||||
|
return !Array.isArray(x) && typeof x === 'object';
|
||||||
|
}
|
||||||
function _composeOp(a, b, func) {
|
function _composeOp(a, b, func) {
|
||||||
function _nonFunctionObject(x) {
|
if (_nonArrayObject(a) || _nonArrayObject(b)) {
|
||||||
return x instanceof Object && !(x instanceof Function);
|
if (!_nonArrayObject(a)) {
|
||||||
}
|
|
||||||
if (_nonFunctionObject(a) || _nonFunctionObject(b)) {
|
|
||||||
if (!_nonFunctionObject(a)) {
|
|
||||||
a = { value: a };
|
a = { value: a };
|
||||||
}
|
}
|
||||||
if (!_nonFunctionObject(b)) {
|
if (!_nonArrayObject(b)) {
|
||||||
b = { value: b };
|
b = { value: b };
|
||||||
}
|
}
|
||||||
return unionWithObj(a, b, func);
|
return unionWithObj(a, b, func);
|
||||||
|
|||||||
@ -25,4 +25,8 @@ describe('controls', () => {
|
|||||||
{ s: 'sd', n: 4, gain: 0.5 },
|
{ s: 'sd', n: 4, gain: 0.5 },
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
it('should support nested controls', () => {
|
||||||
|
expect(s(mini('bd').pan(1)).firstCycleValues).toEqual([{ s: 'bd', pan: 1 }]);
|
||||||
|
expect(s(mini('bd:1').pan(1)).firstCycleValues).toEqual([{ s: 'bd', n: 1, pan: 1 }]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user