mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
doc: in source value modifiers
This commit is contained in:
parent
c4b482634f
commit
603c55fda7
@ -468,7 +468,11 @@ export class Pattern {
|
|||||||
/**
|
/**
|
||||||
* Assumes a numerical pattern. Returns a new pattern with all values rounded
|
* Assumes a numerical pattern. Returns a new pattern with all values rounded
|
||||||
* to the nearest integer.
|
* to the nearest integer.
|
||||||
|
* @name round
|
||||||
|
* @memberof Pattern
|
||||||
* @returns Pattern
|
* @returns Pattern
|
||||||
|
* @example
|
||||||
|
* "0.5 1.5 2.5".round().scale('C major')
|
||||||
*/
|
*/
|
||||||
round() {
|
round() {
|
||||||
return this._asNumber().fmap((v) => Math.round(v));
|
return this._asNumber().fmap((v) => Math.round(v));
|
||||||
@ -695,6 +699,13 @@ export class Pattern {
|
|||||||
return this.fmap(func)._squeezeJoin();
|
return this.fmap(func)._squeezeJoin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like layer, but with a single function:
|
||||||
|
* @name apply
|
||||||
|
* @memberof Pattern
|
||||||
|
* @example
|
||||||
|
* "<c3 eb3 g3>".scale('C minor').apply(scaleTranspose("0,2,4"))
|
||||||
|
*/
|
||||||
_apply(func) {
|
_apply(func) {
|
||||||
return func(this);
|
return func(this);
|
||||||
}
|
}
|
||||||
@ -1360,9 +1371,48 @@ function _composeOp(a, b, func) {
|
|||||||
keepif: [(a, b) => (b ? a : undefined)],
|
keepif: [(a, b) => (b ? a : undefined)],
|
||||||
|
|
||||||
// numerical functions
|
// numerical functions
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Assumes a pattern of numbers. Adds the given number to each item in the pattern.
|
||||||
|
* @name add
|
||||||
|
* @memberof Pattern
|
||||||
|
* @example
|
||||||
|
* // Here, the triad 0, 2, 4 is shifted by different amounts
|
||||||
|
* "0 2 4".add("<0 3 4 0>").scale('C major')
|
||||||
|
* // Without add, the equivalent would be:
|
||||||
|
* // "<[0 2 4] [3 5 7] [4 6 8] [0 2 4]>".scale('C major')
|
||||||
|
* @example
|
||||||
|
* // You can also use add with notes:
|
||||||
|
* "c3 e3 g3".add("<0 5 7 0>")
|
||||||
|
* // Behind the scenes, the notes are converted to midi numbers:
|
||||||
|
* // "48 52 55".add("<0 5 7 0>")
|
||||||
|
*/
|
||||||
add: [(a, b) => a + b, numOrString], // support string concatenation
|
add: [(a, b) => a + b, numOrString], // support string concatenation
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Like add, but the given numbers are subtracted.
|
||||||
|
* @name sub
|
||||||
|
* @memberof Pattern
|
||||||
|
* @example
|
||||||
|
* "0 2 4".sub("<0 1 2 3>").scale('C4 minor')
|
||||||
|
* // See add for more information.
|
||||||
|
*/
|
||||||
sub: [(a, b) => a - b, num],
|
sub: [(a, b) => a - b, num],
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Multiplies each number by the given factor.
|
||||||
|
* @name mul
|
||||||
|
* @memberof Pattern
|
||||||
|
* @example
|
||||||
|
* "1 1.5 [1.66, <2 2.33>]".mul(150).freq().out()
|
||||||
|
*/
|
||||||
mul: [(a, b) => a * b, num],
|
mul: [(a, b) => a * b, num],
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Divides each number by the given factor.
|
||||||
|
* @name div
|
||||||
|
* @memberof Pattern
|
||||||
|
*/
|
||||||
div: [(a, b) => a / b, num],
|
div: [(a, b) => a / b, num],
|
||||||
mod: [mod, num],
|
mod: [mod, num],
|
||||||
pow: [Math.pow, num],
|
pow: [Math.pow, num],
|
||||||
|
|||||||
@ -554,63 +554,17 @@ The following functions modify a pattern temporal structure in some way.
|
|||||||
|
|
||||||
## Value Modifiers
|
## Value Modifiers
|
||||||
|
|
||||||
### add(n)
|
{{ 'Pattern.add' | jsdoc }}
|
||||||
|
|
||||||
Adds the given number to each item in the pattern:
|
{{ 'Pattern.sub' | jsdoc }}
|
||||||
|
|
||||||
<MiniRepl tune={`"0 2 4".add("<0 3 4 0>").scale('C major')`} />
|
{{ 'Pattern.mul' | jsdoc }}
|
||||||
|
|
||||||
Here, the triad `0, 2, 4` is shifted by different amounts. Without add, the equivalent would be:
|
{{ 'Pattern.div' | jsdoc }}
|
||||||
|
|
||||||
<MiniRepl tune={`"<[0 2 4] [3 5 7] [4 6 8] [0 2 4]>".scale('C major')`} />
|
{{ 'Pattern.round' | jsdoc }}
|
||||||
|
|
||||||
You can also use add with notes:
|
{{ 'Pattern.apply' | jsdoc }}
|
||||||
|
|
||||||
<MiniRepl tune={`"c3 e3 g3".add("<0 5 7 0>")`} />
|
|
||||||
|
|
||||||
Behind the scenes, the notes are converted to midi numbers as soon before add is applied, which is equivalent to:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"48 52 55".add("<0 5 7 0>")`} />
|
|
||||||
|
|
||||||
### sub(n)
|
|
||||||
|
|
||||||
Like add, but the given numbers are subtracted:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"0 2 4".sub("<0 1 2 3>").scale('C4 minor')`} />
|
|
||||||
|
|
||||||
See add for more information.
|
|
||||||
|
|
||||||
### mul(n)
|
|
||||||
|
|
||||||
Multiplies each number by the given factor:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"0,1,2".mul("<2 3 4 3>").scale('C4 minor')`} />
|
|
||||||
|
|
||||||
... is equivalent to:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"<[0,2,4] [0,3,6] [0,4,8] [0,3,6]>".scale('C4 minor')`} />
|
|
||||||
|
|
||||||
This function is really useful in combination with signals:
|
|
||||||
|
|
||||||
<MiniRepl tune={`sine.struct("x*16").mul(7).round().scale('C major')`} />
|
|
||||||
|
|
||||||
Here, we sample a sine wave 16 times, and multiply each sample by 7. This way, we let values oscillate between 0 and 7.
|
|
||||||
|
|
||||||
### div(n)
|
|
||||||
|
|
||||||
Like mul, but dividing by the given number.
|
|
||||||
|
|
||||||
### round()
|
|
||||||
|
|
||||||
Rounds all values to the nearest integer:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"0.5 1.5 2.5".round().scale('C major')`} />
|
|
||||||
|
|
||||||
### apply(func)
|
|
||||||
|
|
||||||
Like layer, but with a single function:
|
|
||||||
|
|
||||||
<MiniRepl tune={`"<c3 eb3 g3>".scale('C minor').apply(scaleTranspose("0,2,4"))`} />
|
|
||||||
|
|
||||||
{{ 'Pattern.range' | jsdoc }}
|
{{ 'Pattern.range' | jsdoc }}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user