mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
Merge pull request #9 from tidalcycles/More-functions
Bugfix every, and create more top level functions
This commit is contained in:
commit
063289b435
32
strudel.mjs
32
strudel.mjs
@ -507,9 +507,10 @@ class Pattern {
|
||||
}
|
||||
|
||||
every(n, func) {
|
||||
const pats = Array(n-1).fill(this)
|
||||
pats.unshift(func(this))
|
||||
return slowcat(...pats)
|
||||
const pat = this
|
||||
const pats = Array(n-1).fill(pat)
|
||||
pats.unshift(func(pat))
|
||||
return slowcatPrime(...pats)
|
||||
}
|
||||
|
||||
append(other) {
|
||||
@ -593,6 +594,18 @@ function slowcat(...pats) {
|
||||
return new Pattern(query)._splitQueries()
|
||||
}
|
||||
|
||||
function slowcatPrime(...pats) {
|
||||
// Concatenation: combines a list of patterns, switching between them
|
||||
// successively, one per cycle. Unlike slowcat, this version will skip cycles.
|
||||
pats = pats.map(reify)
|
||||
const query = function(span) {
|
||||
const pat_n = Math.floor(span.begin) % pats.length
|
||||
const pat = pats[pat_n]
|
||||
return pat.query(span)
|
||||
}
|
||||
return new Pattern(query)._splitQueries()
|
||||
}
|
||||
|
||||
function fastcat(...pats) {
|
||||
// Concatenation: as with slowcat, but squashes a cycle from each
|
||||
// pattern into one cycle
|
||||
@ -679,9 +692,20 @@ const slow = curry((a, pat) => pat.slow(a))
|
||||
const early = curry((a, pat) => pat.early(a))
|
||||
const late = curry((a, pat) => pat.late(a))
|
||||
const rev = pat => pat.rev()
|
||||
const add = curry((a, pat) => pat.add(a))
|
||||
const sub = curry((a, pat) => pat.sub(a))
|
||||
const mul = curry((a, pat) => pat.mul(a))
|
||||
const div = curry((a, pat) => pat.div(a))
|
||||
const union = curry((a, pat) => pat.union(a))
|
||||
const every = curry((i, f, pat) => pat.every(i, f))
|
||||
const when = curry((binary, f, pat) => pat.when(binary, f))
|
||||
const off = curry((t, f, pat) => pat.off(t,f))
|
||||
const jux = curry((f, pat) => pat.jux(f))
|
||||
const append = curry((a, pat) => pat.append(a))
|
||||
|
||||
export {Fraction, TimeSpan, Hap, Pattern,
|
||||
pure, stack, slowcat, fastcat, cat, timeCat, sequence, polymeter, pm, polyrhythm, pr, reify, silence,
|
||||
fast, slow, early, late, rev
|
||||
fast, slow, early, late, rev,
|
||||
add, sub, mul, div, union, every, when, off, jux, append
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import Fraction from 'fraction.js'
|
||||
|
||||
import { strict as assert } from 'assert';
|
||||
|
||||
import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast, timeCat} from "../strudel.mjs";
|
||||
import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast, timeCat,add,sub,mul,div} from "../strudel.mjs";
|
||||
//import { Time } from 'tone';
|
||||
import pkg from 'tone';
|
||||
const { Time } = pkg;
|
||||
@ -221,7 +221,19 @@ describe('Pattern', function() {
|
||||
assert.deepStrictEqual(
|
||||
pure("a").every(3, fast(2))._fast(3).firstCycle,
|
||||
sequence(sequence("a", "a"), "a", "a").firstCycle
|
||||
)
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
sequence(3,4,5).every(3, add(3)).fast(5).firstCycle,
|
||||
sequence(6,7,8,3,4,5,3,4,5,6,7,8,3,4,5).firstCycle
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
sequence(3,4,5).every(2, sub(1)).fast(5).firstCycle,
|
||||
sequence(2,3,4,3,4,5,2,3,4,3,4,5,2,3,4).firstCycle
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
sequence(3,4,5).every(3, add(3)).every(2, sub(1)).fast(2).firstCycle,
|
||||
sequence(5,6,7,3,4,5).firstCycle
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('timeCat()', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user