This commit is contained in:
Felix Roos 2022-02-10 08:30:38 +01:00
parent ad777ed183
commit fabfee5976
3 changed files with 58 additions and 1 deletions

View File

@ -294,6 +294,29 @@ class Pattern {
};
return patterned;
}
_fastGap(factor) {
const qf = function(span) {
const cycle = span.begin.sam();
const begin = cycle.add(span.begin.sub(cycle).mul(factor).min(1));
const end = cycle.add(span.end.sub(cycle).mul(factor).min(1));
return new TimeSpan(begin, end);
};
const ef = function(span) {
const cycle = span.begin.sam();
const begin = cycle.add(span.begin.sub(cycle).div(factor).min(1));
const end = cycle.add(span.end.sub(cycle).div(factor).min(1));
return new TimeSpan(begin, end);
};
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) {
const fastQuery = this.withQueryTime((t) => t.mul(factor));
return fastQuery.withEventTime((t) => t.div(factor));
@ -405,6 +428,17 @@ function fastcat(...pats) {
function cat(...pats) {
return fastcat(...pats);
}
function timeCat(...timepats) {
const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0));
let begin = Fraction(0);
const pats = [];
for (const [time, pat] of timepats) {
const end = begin.add(time);
pats.push(reify(pat)._compressSpan(new TimeSpan(begin.div(total), end.div(total))));
begin = end;
}
return stack(...pats);
}
function _sequenceCount(x) {
if (Array.isArray(x)) {
if (x.length == 0) {
@ -469,6 +503,7 @@ export {
slowcat,
fastcat,
cat,
timeCat,
sequence,
polymeter,
pm,

16
docs/dist/parse.js vendored
View File

@ -5,7 +5,21 @@ import "./tone.js";
import "./midi.js";
import * as toneStuff from "./tone.js";
import shapeshifter from "./shapeshifter.js";
const {pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, silence, Fraction} = strudel;
const {
pure,
stack,
slowcat,
fastcat,
cat,
sequence,
polymeter,
pm,
polyrhythm,
pr,
silence,
Fraction,
timeCat
} = strudel;
const {autofilter, filter, gain} = toneStuff;
function reify(thing) {
if (thing?.constructor?.name === "Pattern") {

8
docs/dist/tunes.js vendored
View File

@ -1,3 +1,11 @@
export const timeCat = `stack(
timeCat([3, c3], [1, stack(eb3, g3, m(c4, d4).slow(2))]),
m(c2, g2),
sequence(
timeCat([5, eb4], [3, m(f4, eb4, d4)]),
m(eb4, c4).slow(2)
).slow(4)
)`;
export const shapeShifted = `stack(
sequence(
e5, [b4, c5], d5, [c5, b4],