This commit is contained in:
alex 2022-02-06 21:34:57 +00:00
parent 7812eb49f2
commit cf9d6fb699
5 changed files with 63 additions and 29 deletions

View File

@ -1 +1 @@
strudel.tidalcycles.org
strudel.tidalcycles.org

View File

@ -6,6 +6,17 @@ function flatten(arr) {
return [].concat(...arr);
}
var id = (a) => a;
function curry(func) {
return function curried(...args) {
if (args.length >= func.length) {
return func.apply(this, args);
} else {
return function(...args2) {
return curried.apply(this, args.concat(args2));
};
}
};
}
Fraction.prototype.sam = function() {
return Fraction(Math.floor(this));
};
@ -27,6 +38,9 @@ Fraction.prototype.lte = function(other) {
Fraction.prototype.gte = function(other) {
return this.compare(other) >= 0;
};
Fraction.prototype.eq = function(other) {
return this.compare(other) == 0;
};
Fraction.prototype.max = function(other) {
return this.gt(other) ? this : other;
};
@ -36,6 +50,9 @@ Fraction.prototype.min = function(other) {
Fraction.prototype.show = function() {
return this.n + "/" + this.d;
};
Fraction.prototype.or = function(other) {
return this.eq(0) ? other : this;
};
class TimeSpan {
constructor(begin, end) {
this.begin = Fraction(begin);
@ -141,6 +158,9 @@ class Pattern {
withEventTime(func) {
return this.withEventSpan((span) => span.withTime(func));
}
_withEvents(func) {
return new Pattern((span) => func(this.query(span)));
}
withValue(func) {
return new Pattern((span) => this.query(span).map((hap) => hap.withValue(func)));
}
@ -220,6 +240,9 @@ class Pattern {
get firstCycle() {
return this.query(new TimeSpan(Fraction(0), Fraction(1)));
}
_sortEventsByPart() {
return this._withEvents((events) => events.sort((a, b) => a.part.begin.sub(b.part.begin).or(a.part.end.sub(b.part.end)).or(a.whole.begin.sub(b.whole.begin).or(a.whole.end.sub(b.whole.end)))));
}
_opleft(other, func) {
return this.fmap(func).appLeft(reify(other));
}
@ -241,7 +264,7 @@ class Pattern {
var match = function(a) {
return func(a.value).query(a.part).map((b) => withWhole(a, b));
};
return flatten(pat_val.query(span).map(match));
return flatten(pat_val.query(span).map((a) => match(a)));
};
return new Pattern(query2);
}
@ -288,16 +311,13 @@ class Pattern {
var false_pat = binary_pat._filterValues((val) => !val);
var with_pat = true_pat.fmap((_) => (y) => y).appRight(func(this));
var without_pat = false_pat.fmap((_) => (y) => y).appRight(this);
return stack([with_pat, without_pat]);
return stack(with_pat, without_pat);
}
off(time_pat, func) {
return stack([this, func(this._early(time_pat))]);
}
off(time_pat, func) {
return stack(this, func(this.early(time_pat)));
}
every(n, func) {
const pats = Array(n - 1).fill(this);
var pats = Array(n - 1).fill(this);
pats.unshift(this);
return slowcat(...pats);
}
@ -334,12 +354,7 @@ class Pattern {
return stack([left, func(right)]);
}
}
function reify(thing) {
if (thing.constructor.name == "Pattern") {
return thing;
}
return pure(thing);
}
const silence = new Pattern((_) => []);
function pure(value) {
function query2(span) {
return span.spanCycles.map((subspan) => new Hap(Fraction(subspan.begin).wholeCycle(), subspan, value));
@ -349,8 +364,14 @@ function pure(value) {
function steady(value) {
return new Pattern((span) => Hap(void 0, span, value));
}
function reify(thing) {
if (thing.constructor.name == "Pattern") {
return thing;
}
return pure(thing);
}
function stack(...pats) {
pats = pats.map(reify);
var pats = pats.map((pat) => reify(pat));
var query2 = function(span) {
return flatten(pats.map((pat) => pat.query(span)));
};
@ -373,7 +394,7 @@ function cat(...pats) {
function _sequenceCount(x) {
if (Array.isArray(x)) {
if (x.length == 0) {
return [silence(), 0];
return [silence, 0];
}
if (x.length == 1) {
return _sequenceCount(x[0]);
@ -386,9 +407,9 @@ function sequence(...xs) {
return _sequenceCount(xs)[0];
}
function polymeter(steps = 0, ...args) {
var seqs = args.map(_sequenceCount);
var seqs = args.map((a) => _sequenceCount(a));
if (seqs.length == 0) {
return silence();
return silence;
}
if (steps == 0) {
steps = seqs[0][1];
@ -406,8 +427,18 @@ function polymeter(steps = 0, ...args) {
}
return stack(pats);
}
function silence() {
return new Pattern((_) => []);
function pm(args) {
polymeter(args);
}
function polyrhythm(...xs) {
var seqs = xs.map((a) => sequence(a));
if (seqs.length == 0) {
return silence;
}
return stack(...seqs);
}
function pr(args) {
polyrhythm(args);
}
export {
Fraction,
@ -415,12 +446,15 @@ export {
Hap,
Pattern,
pure,
reify,
stack,
slowcat,
fastcat,
cat,
sequence,
polymeter,
pm,
polyrhythm,
pr,
reify,
silence
};

View File

@ -1 +1 @@
export default "/strudel/dist/logo.svg";
export default "/dist/logo.svg";

10
docs/dist/tunes.js vendored
View File

@ -1,12 +1,12 @@
export const tetris = `stack(sequence(
'e5', sequence('b4', 'c5'), 'd5', sequence('c5', 'b4'),
'a4', sequence('a4', 'c5'), 'e5', sequence('d5', 'c5'),
'b4', sequence(silence(), 'c5'), 'd5', 'e5',
'c5', 'a4', 'a4', silence(),
sequence(silence(), 'd5'), sequence(silence(), 'f5'), 'a5', sequence('g5', 'f5'),
'e5', sequence(silence(), 'c5'), 'e5', sequence('d5', 'c5'),
'b4', sequence(silence, 'c5'), 'd5', 'e5',
'c5', 'a4', 'a4', silence,
sequence(silence, 'd5'), sequence(silence, 'f5'), 'a5', sequence('g5', 'f5'),
'e5', sequence(silence, 'c5'), 'e5', sequence('d5', 'c5'),
'b4', sequence('b4', 'c5'), 'd5', 'e5',
'c5', 'a4', 'a4', silence()),
'c5', 'a4', 'a4', silence),
sequence(
'e2', 'e3', 'e2', 'e3', 'e2', 'e3', 'e2', 'e3',
'a2', 'a3', 'a2', 'a3', 'a2', 'a3', 'a2', 'a3',

View File

@ -2,8 +2,8 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/strudel/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/strudel/global.css" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/global.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Strudel REPL" />
<title>Strudel REPL</title>
@ -11,6 +11,6 @@
<body>
<div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/strudel/dist/index.js"></script>
<script type="module" src="/dist/index.js"></script>
</body>
</html>