Testing out approach to allow list patterns in partials
This commit is contained in:
parent
b66c0d18b3
commit
cc10122b71
3 changed files with 101 additions and 35 deletions
|
|
@ -3624,3 +3624,54 @@ for (const name of distAlgoNames) {
|
|||
return this.distort(argsPat);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns a list of patterns into a single pattern which outputs list-values
|
||||
*
|
||||
* @name parray
|
||||
* @returns Pattern
|
||||
*/
|
||||
export const parray = (pats) => {
|
||||
const pack = (...xs) => xs;
|
||||
let acc = pure(curry(pack, null, pats.length));
|
||||
for (const p of pats) acc = acc.appBoth(reify(p));
|
||||
return acc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Scale the magnitude of the harmonics of one of the core synths ('sine', 'tri', 'saw', ..)
|
||||
*
|
||||
* Can also be used to create a new synth via `s('user').partials(...)`
|
||||
*
|
||||
* @name partials
|
||||
* @param {number[] | Pattern} partials List of [0, 1] magnitudes for partials. 0th entry is the first harmonic (i.e. DC offset is skipped)
|
||||
* @example
|
||||
* s("user").seg(16).n(irand(8)).scale("A:major")
|
||||
* .partials([1, 0, 1, 0, 0, 1])
|
||||
* @example
|
||||
* s("saw").seg(8).n(irand(12)).scale("G#:minor")
|
||||
* .partials(binaryL(256))
|
||||
*/
|
||||
export const { partials } = register('partials', (list, pat) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return pat.withValue((v) => ({...v, partials: list}));
|
||||
});
|
||||
|
||||
/**
|
||||
* Rotates the harmonics of one of the core synths ('sine', 'tri', 'saw', 'user', ..) by a list of phases
|
||||
*
|
||||
* @name phases
|
||||
* @param {number[] | Pattern} phases List of [0, 1) phases for partials. 0th entry is the first phase (i.e. DC offset is skipped)
|
||||
* @example
|
||||
* s("saw").seg(8).n(irand(12)).scale("G#:minor")
|
||||
* .partials(binaryL(256))
|
||||
* .phases(randL(20))
|
||||
*/
|
||||
export const { phases } = register('phases', (list, pat) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return pat.withValue((v) => ({...v, phases: list}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue