Top level functions
This commit is contained in:
parent
7a3bea6f90
commit
f5ed6dbe79
4 changed files with 56 additions and 28 deletions
|
|
@ -3644,35 +3644,51 @@ export const parray = (pats) => {
|
|||
* 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)
|
||||
* @param {number[] | Pattern} magnitudes List of [0, 1] magnitudes for partials. 0th entry is the fundamental 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))
|
||||
* .partials(randL(16))
|
||||
*/
|
||||
export const { partials } = register('partials', (list, pat) => {
|
||||
debugger;
|
||||
register('partials', (list, pat) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return pat.withValue((v) => (l) => ({...v, partials: l})).appLeft(list);
|
||||
return pat.withValue((v) => (l) => ({ ...v, partials: l })).appLeft(list);
|
||||
});
|
||||
|
||||
// Also create a top-level function
|
||||
export const partials = (list) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return list.as('partials');
|
||||
};
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* @param {number[] | Pattern} phases List of [0, 1) phases for partials. 0th entry is the fundamental phase (i.e. DC offset is skipped)
|
||||
* @example
|
||||
* s("saw").seg(8).n(irand(12)).scale("G#:minor")
|
||||
* .partials(binaryL(256))
|
||||
* .phases(randL(20))
|
||||
* .partials(randL(16))
|
||||
* .phases(randL(16))
|
||||
*/
|
||||
export const { phases } = register('phases', (list, pat) => {
|
||||
register('phases', (list, pat) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return pat.withValue((v) => (l) => ({...v, phases: l})).appLeft(list);
|
||||
pat = pat ?? pure({});
|
||||
return pat.withValue((v) => (l) => ({ ...v, phases: l })).appLeft(list);
|
||||
});
|
||||
|
||||
// Also create a top-level function
|
||||
export const phases = (list) => {
|
||||
if (Array.isArray(list)) {
|
||||
list = parray(list);
|
||||
}
|
||||
return list.as('phases');
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue