mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 19:18:31 +00:00
Merge pull request #1247 from tidalcycles/get-control
add "as" function + getControlName
This commit is contained in:
commit
dbbe2d7c98
@ -47,12 +47,16 @@ export function createParam(names) {
|
|||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// maps control alias names to the "main" control name
|
||||||
|
const controlAlias = new Map();
|
||||||
|
|
||||||
export function registerControl(names, ...aliases) {
|
export function registerControl(names, ...aliases) {
|
||||||
const name = Array.isArray(names) ? names[0] : names;
|
const name = Array.isArray(names) ? names[0] : names;
|
||||||
let bag = {};
|
let bag = {};
|
||||||
bag[name] = createParam(names);
|
bag[name] = createParam(names);
|
||||||
aliases.forEach((alias) => {
|
aliases.forEach((alias) => {
|
||||||
bag[alias] = bag[name];
|
bag[alias] = bag[name];
|
||||||
|
controlAlias.set(alias, name);
|
||||||
Pattern.prototype[alias] = Pattern.prototype[name];
|
Pattern.prototype[alias] = Pattern.prototype[name];
|
||||||
});
|
});
|
||||||
return bag;
|
return bag;
|
||||||
@ -1614,3 +1618,26 @@ export const ar = register('ar', (t, pat) => {
|
|||||||
const [attack, release = attack] = t;
|
const [attack, release = attack] = t;
|
||||||
return pat.set({ attack, release });
|
return pat.set({ attack, release });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const getControlName = (alias) => {
|
||||||
|
if (controlAlias.has(alias)) {
|
||||||
|
return controlAlias.get(alias);
|
||||||
|
}
|
||||||
|
return alias;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets properties in a batch.
|
||||||
|
*
|
||||||
|
* @name as
|
||||||
|
* @param {Array} mapping the control names that are set
|
||||||
|
* @example
|
||||||
|
* "c:.5 a:1 f:.25 e:.8".as("note:clip")
|
||||||
|
*/
|
||||||
|
export const as = register('as', (mapping, pat) => {
|
||||||
|
return pat.fmap((v) => {
|
||||||
|
v = Array.isArray(v) ? v : [v];
|
||||||
|
v = Object.fromEntries(mapping.map((prop, i) => [getControlName(prop), v[i]]));
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -4,7 +4,7 @@ Copyright (C) 2023 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/>.
|
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 { s, pan } from '../controls.mjs';
|
import { s, pan, getControlName } from '../controls.mjs';
|
||||||
import { mini } from '../../mini/mini.mjs';
|
import { mini } from '../../mini/mini.mjs';
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import Fraction from '../fraction.mjs';
|
import Fraction from '../fraction.mjs';
|
||||||
@ -39,4 +39,8 @@ describe('controls', () => {
|
|||||||
it('combines tactus of the pattern for .mix as lcm', () => {
|
it('combines tactus of the pattern for .mix as lcm', () => {
|
||||||
expect(s(mini('bd cp mt').set.mix(pan(mini('1 2 3 4')))).tactus).toEqual(Fraction(12));
|
expect(s(mini('bd cp mt').set.mix(pan(mini('1 2 3 4')))).tactus).toEqual(Fraction(12));
|
||||||
});
|
});
|
||||||
|
it('finds control name by alias', () => {
|
||||||
|
expect(getControlName('lpf')).toEqual('cutoff');
|
||||||
|
expect(getControlName('cutoff')).toEqual('cutoff');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -912,6 +912,27 @@ exports[`runs examples > example "arrange" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "as" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/4 | note:c clip:0.5 ]",
|
||||||
|
"[ 1/4 → 1/2 | note:a clip:1 ]",
|
||||||
|
"[ 1/2 → 3/4 | note:f clip:0.25 ]",
|
||||||
|
"[ 3/4 → 1/1 | note:e clip:0.8 ]",
|
||||||
|
"[ 1/1 → 5/4 | note:c clip:0.5 ]",
|
||||||
|
"[ 5/4 → 3/2 | note:a clip:1 ]",
|
||||||
|
"[ 3/2 → 7/4 | note:f clip:0.25 ]",
|
||||||
|
"[ 7/4 → 2/1 | note:e clip:0.8 ]",
|
||||||
|
"[ 2/1 → 9/4 | note:c clip:0.5 ]",
|
||||||
|
"[ 9/4 → 5/2 | note:a clip:1 ]",
|
||||||
|
"[ 5/2 → 11/4 | note:f clip:0.25 ]",
|
||||||
|
"[ 11/4 → 3/1 | note:e clip:0.8 ]",
|
||||||
|
"[ 3/1 → 13/4 | note:c clip:0.5 ]",
|
||||||
|
"[ 13/4 → 7/2 | note:a clip:1 ]",
|
||||||
|
"[ 7/2 → 15/4 | note:f clip:0.25 ]",
|
||||||
|
"[ 15/4 → 4/1 | note:e clip:0.8 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "attack" example index 0 1`] = `
|
exports[`runs examples > example "attack" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/4 | note:c3 attack:0 ]",
|
"[ 0/1 → 1/4 | note:c3 attack:0 ]",
|
||||||
|
|||||||
@ -132,6 +132,10 @@ This group of functions allows to modify the value of events.
|
|||||||
|
|
||||||
<JsDoc client:idle name="Pattern.ratio" h={0} />
|
<JsDoc client:idle name="Pattern.ratio" h={0} />
|
||||||
|
|
||||||
|
## as
|
||||||
|
|
||||||
|
<JsDoc client:idle name="as" h={0} />
|
||||||
|
|
||||||
# Custom Parameters
|
# Custom Parameters
|
||||||
|
|
||||||
You can also create your own parameters:
|
You can also create your own parameters:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user