mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 05:38:34 +00:00
Patternify range (#231)
* patternify range * patternify range * fix test
This commit is contained in:
parent
2ed290a214
commit
5f381cf153
@ -526,7 +526,7 @@ export class Pattern {
|
||||
* @example
|
||||
* s("bd sd,hh*4").cutoff(sine.range(500,2000).slow(4)).out()
|
||||
*/
|
||||
range(min, max) {
|
||||
_range(min, max) {
|
||||
return this.mul(max - min).add(min);
|
||||
}
|
||||
|
||||
@ -538,8 +538,8 @@ export class Pattern {
|
||||
* @param {Number} max
|
||||
* @returns Pattern
|
||||
*/
|
||||
rangex(min, max) {
|
||||
return this.range(Math.log(min), Math.log(max)).fmap(Math.exp);
|
||||
_rangex(min, max) {
|
||||
return this._range(Math.log(min), Math.log(max)).fmap(Math.exp);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,8 +549,8 @@ export class Pattern {
|
||||
* @param {Number} max
|
||||
* @returns Pattern
|
||||
*/
|
||||
range2(min, max) {
|
||||
return this._fromBipolar().range(min, max);
|
||||
_range2(min, max) {
|
||||
return this._fromBipolar()._range(min, max);
|
||||
}
|
||||
|
||||
_bindWhole(choose_whole, func) {
|
||||
@ -1754,6 +1754,7 @@ export const mul = curry((a, pat) => pat.mul(a));
|
||||
export const off = curry((t, f, pat) => pat.off(t, f));
|
||||
export const ply = curry((a, pat) => pat.ply(a));
|
||||
export const range = curry((a, b, pat) => pat.range(a, b));
|
||||
export const rangex = curry((a, b, pat) => pat.rangex(a, b));
|
||||
export const range2 = curry((a, b, pat) => pat.range2(a, b));
|
||||
export const rev = (pat) => pat.rev();
|
||||
export const slow = curry((a, pat) => pat.slow(a));
|
||||
@ -1840,6 +1841,18 @@ Pattern.prototype.inside = function (...args) {
|
||||
args = args.map(reify);
|
||||
return patternify2(Pattern.prototype._inside)(...args, this);
|
||||
};
|
||||
Pattern.prototype.range = function (...args) {
|
||||
args = args.map(reify);
|
||||
return patternify2(Pattern.prototype._range)(...args, this);
|
||||
};
|
||||
Pattern.prototype.rangex = function (...args) {
|
||||
args = args.map(reify);
|
||||
return patternify2(Pattern.prototype._rangex)(...args, this);
|
||||
};
|
||||
Pattern.prototype.range2 = function (...args) {
|
||||
args = args.map(reify);
|
||||
return patternify2(Pattern.prototype._range2)(...args, this);
|
||||
};
|
||||
|
||||
// call this after all Patter.prototype.define calls have been executed! (right before evaluate)
|
||||
Pattern.prototype.bootstrap = function () {
|
||||
|
||||
@ -853,6 +853,13 @@ describe('Pattern', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('range', () => {
|
||||
it('Can be patterned', () => {
|
||||
expect(sequence(0, 0).range(sequence(0, 0.5), 1).firstCycle()).toStrictEqual(
|
||||
sequence(0, 0.5).firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('range2', () => {
|
||||
it('Can change the range of a bipolar pattern', () => {
|
||||
expect(sequence(-1, -0.5, 0, 0.5).range2(1000, 1100).firstCycle()).toStrictEqual(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user