Merge branch 'main' into pump

This commit is contained in:
daslyfe 2025-08-03 18:57:19 +02:00
commit 784c711870
3 changed files with 24 additions and 18 deletions

View file

@ -320,6 +320,7 @@ export const { fft } = registerControl('fft');
* *
* @name decay * @name decay
* @param {number | Pattern} time decay time in seconds * @param {number | Pattern} time decay time in seconds
* @synonyms dec
* @example * @example
* note("c3 e3 f3 g3").decay("<.1 .2 .3 .4>").sustain(0) * note("c3 e3 f3 g3").decay("<.1 .2 .3 .4>").sustain(0)
* *

View file

@ -1569,7 +1569,7 @@ export const func = curry((a, b) => reify(b).func(a));
/** /**
* Registers a new pattern method. The method is added to the Pattern class + the standalone function is returned from register. * Registers a new pattern method. The method is added to the Pattern class + the standalone function is returned from register.
* *
* @param {string} name name of the function * @param {string | string[]} name name of the function, or an array of names to be used as synonyms
* @param {function} func function with 1 or more params, where last is the current pattern * @param {function} func function with 1 or more params, where last is the current pattern
* @noAutocomplete * @noAutocomplete
* *

View file

@ -88,13 +88,14 @@ function scaleOffset(scale, offset, note) {
* @returns Pattern * @returns Pattern
* @memberof Pattern * @memberof Pattern
* @name transpose * @name transpose
* @synonyms trans
* @example * @example
* "c2 c3".fast(2).transpose("<0 -2 5 3>".slow(2)).note() * "c2 c3".fast(2).transpose("<0 -2 5 3>".slow(2)).note()
* @example * @example
* "c2 c3".fast(2).transpose("<1P -2M 4P 3m>".slow(2)).note() * "c2 c3".fast(2).transpose("<1P -2M 4P 3m>".slow(2)).note()
*/ */
export const transpose = register('transpose', function (intervalOrSemitones, pat) { export const transpose = register(['transpose', 'trans'], function transposeFn(intervalOrSemitones, pat) {
return pat.withHap((hap) => { return pat.withHap((hap) => {
const note = hap.value.note ?? hap.value; const note = hap.value.note ?? hap.value;
if (typeof note === 'number') { if (typeof note === 'number') {
@ -142,6 +143,7 @@ export const transpose = register('transpose', function (intervalOrSemitones, pa
* @name scaleTranspose * @name scaleTranspose
* @param {offset} offset number of steps inside the scale * @param {offset} offset number of steps inside the scale
* @returns Pattern * @returns Pattern
* @synonyms scaleTrans, strans
* @example * @example
* "-8 [2,4,6]" * "-8 [2,4,6]"
* .scale('C4 bebop major') * .scale('C4 bebop major')
@ -149,22 +151,25 @@ export const transpose = register('transpose', function (intervalOrSemitones, pa
* .note() * .note()
*/ */
export const scaleTranspose = register('scaleTranspose', function (offset /* : number | string */, pat) { export const scaleTranspose = register(
return pat.withHap((hap) => { ['scaleTranspose', 'scaleTrans', 'strans'],
if (!hap.context.scale) { function (offset /* : number | string */, pat) {
throw new Error('can only use scaleTranspose after .scale'); return pat.withHap((hap) => {
} if (!hap.context.scale) {
if (typeof hap.value === 'object') throw new Error('can only use scaleTranspose after .scale');
return hap.withValue(() => ({ }
...hap.value, if (typeof hap.value === 'object')
note: scaleOffset(hap.context.scale, Number(offset), hap.value.note), return hap.withValue(() => ({
})); ...hap.value,
if (typeof hap.value !== 'string') { note: scaleOffset(hap.context.scale, Number(offset), hap.value.note),
throw new Error('can only use scaleTranspose with notes'); }));
} if (typeof hap.value !== 'string') {
return hap.withValue(() => scaleOffset(hap.context.scale, Number(offset), hap.value)); throw new Error('can only use scaleTranspose with notes');
}); }
}); return hap.withValue(() => scaleOffset(hap.context.scale, Number(offset), hap.value));
});
},
);
/** /**
* Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}. * Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.