mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
document some mathematical pattern methods
This commit is contained in:
parent
73b0a3a0ef
commit
d5a1832f31
@ -467,35 +467,83 @@ export class Pattern {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern. Returns a new pattern with all values rounded
|
||||
* to the nearest integer.
|
||||
* @returns Pattern
|
||||
*/
|
||||
round() {
|
||||
return this._asNumber().fmap((v) => Math.round(v));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern. Returns a new pattern with all values set to
|
||||
* their mathematical floor. E.g. `3.7` replaced with to `3`, and `-4.2`
|
||||
* replaced with `-5`.
|
||||
* @returns Pattern
|
||||
*/
|
||||
floor() {
|
||||
return this._asNumber().fmap((v) => Math.floor(v));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern. Returns a new pattern with all values set to
|
||||
* their mathematical ceiling. E.g. `3.2` replaced with `4`, and `-4.2`
|
||||
* replaced with `-4`.
|
||||
* @returns Pattern
|
||||
*/
|
||||
ceil() {
|
||||
return this._asNumber().fmap((v) => Math.ceil(v));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern, containing unipolar values in the range 0 ..
|
||||
* 1. Returns a new pattern with values scaled to the bipolar range -1 .. 1
|
||||
* @returns Pattern
|
||||
*/
|
||||
_toBipolar() {
|
||||
return this.fmap((x) => x * 2 - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern, containing bipolar values in the range -1 ..
|
||||
* 1. Returns a new pattern with values scaled to the unipolar range 0 .. 1
|
||||
* @returns Pattern
|
||||
*/
|
||||
_fromBipolar() {
|
||||
return this.fmap((x) => (x + 1) / 2);
|
||||
}
|
||||
|
||||
// Assumes source pattern of numbers in range 0..1
|
||||
/**
|
||||
* Assumes a numerical pattern, containing unipolar values in the range 0 ..
|
||||
* 1. Returns a new pattern with values scaled to the given min/max range.
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns Pattern
|
||||
*/
|
||||
range(min, max) {
|
||||
return this.mul(max - min).add(min);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a numerical pattern, containing unipolar values in the range 0 ..
|
||||
* 1. Returns a new pattern with values scaled to the given min/max range,
|
||||
* following an exponential curve.
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns Pattern
|
||||
*/
|
||||
rangex(min, max) {
|
||||
return this.range(Math.log(min), Math.log(max)).fmap(Math.exp);
|
||||
}
|
||||
|
||||
// Assumes source pattern of numbers in range -1..1
|
||||
/**
|
||||
* Assumes a numerical pattern, containing bipolar values in the range -1 ..
|
||||
* 1. Returns a new pattern with values scaled to the given min/max range.
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns Pattern
|
||||
*/
|
||||
range2(min, max) {
|
||||
return this._fromBipolar().range(min, max);
|
||||
}
|
||||
@ -979,7 +1027,7 @@ function _composeOp(a, b, func) {
|
||||
}
|
||||
|
||||
// Make composers
|
||||
(function() {
|
||||
(function () {
|
||||
const num = (pat) => pat._asNumber();
|
||||
const numOrString = (pat) => pat._asNumber(false, true);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user