mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-21 18:48:36 +00:00
fix _fastGap, add compressSpan
This commit is contained in:
parent
ab2cfdeeec
commit
f5fb5857df
18
strudel.mjs
18
strudel.mjs
@ -434,19 +434,29 @@ class Pattern {
|
|||||||
// }
|
// }
|
||||||
const qf = function(span) {
|
const qf = function(span) {
|
||||||
const cycle = span.begin.sam()
|
const cycle = span.begin.sam()
|
||||||
const begin = cycle.add(span.begin.sub(span.cycle).mul(factor).min(1))
|
const begin = cycle.add(span.begin.sub(cycle).mul(factor).min(1))
|
||||||
const end = cycle.add(span.end.sub(span.cycle).mul(factor).min(1))
|
const end = cycle.add(span.end.sub(cycle).mul(factor).min(1))
|
||||||
return new TimeSpan(begin, end)
|
return new TimeSpan(begin, end)
|
||||||
}
|
}
|
||||||
const ef = function(span) {
|
const ef = function(span) {
|
||||||
const cycle = span.begin.sam()
|
const cycle = span.begin.sam()
|
||||||
const begin = cycle.add(span.begin.sub(span.cycle).div(factor).min(1))
|
const begin = cycle.add(span.begin.sub(cycle).div(factor).min(1))
|
||||||
const end = cycle.add(span.end.sub(span.cycle).div(factor).min(1))
|
const end = cycle.add(span.end.sub(cycle).div(factor).min(1))
|
||||||
return new TimeSpan(begin, end)
|
return new TimeSpan(begin, end)
|
||||||
}
|
}
|
||||||
return this.withQuerySpan(qf).withEventSpan(ef)._splitQueries()
|
return this.withQuerySpan(qf).withEventSpan(ef)._splitQueries()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_compressSpan(span) {
|
||||||
|
const b = span.begin
|
||||||
|
const e = span.end
|
||||||
|
if (b > e || b > 1 || e > 1 || b < 0 || e < 0) {
|
||||||
|
return silence
|
||||||
|
}
|
||||||
|
return this._fastGap(Fraction(1).div(e.sub(b)))._late(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_fast(factor) {
|
_fast(factor) {
|
||||||
const fastQuery = this.withQueryTime(t => t.mul(factor))
|
const fastQuery = this.withQueryTime(t => t.mul(factor))
|
||||||
return fastQuery.withEventTime(t => t.div(factor))
|
return fastQuery.withEventTime(t => t.div(factor))
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import Fraction from 'fraction.js'
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
|
|
||||||
import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast} from "../strudel.mjs";
|
import {TimeSpan, Hap, Pattern, pure, stack, fastcat, slowcat, cat, sequence, polyrhythm, silence, fast} from "../strudel.mjs";
|
||||||
|
//import { Time } from 'tone';
|
||||||
|
import pkg from 'tone';
|
||||||
|
const { Time } = pkg;
|
||||||
|
|
||||||
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
||||||
const hap = (whole, part, value) => new Hap(whole, part, value)
|
const hap = (whole, part, value) => new Hap(whole, part, value)
|
||||||
@ -107,6 +110,14 @@ describe('Pattern', function() {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe('_compressSpan()', function () {
|
||||||
|
it('Can squash cycles of a pattern into a given timespan', function () {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
pure("a")._compressSpan(new TimeSpan(0.25, 0.5)).firstCycle,
|
||||||
|
sequence(silence, "a", silence, silence).firstCycle
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
describe('fast()', function () {
|
describe('fast()', function () {
|
||||||
it('Makes things faster', function () {
|
it('Makes things faster', function () {
|
||||||
assert.equal(pure("a").fast(2).firstCycle.length, 2)
|
assert.equal(pure("a").fast(2).firstCycle.length, 2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user