This commit is contained in:
Felix Roos 2022-02-06 13:01:43 +01:00
parent 06ebcfff89
commit 174c0135ac
5 changed files with 1987 additions and 8 deletions

File diff suppressed because it is too large Load Diff

View File

@ -292,20 +292,40 @@ class Pattern {
outerJoin() {
return this.outerBind(id);
}
_patternify(func) {
const pat = this;
const patterned = function(...args) {
const pat_arg = sequence(...args);
return pat_arg.fmap((arg) => func.call(pat, arg)).outerJoin();
};
return patterned;
}
_fast(factor) {
var fastQuery = this.withQueryTime((t) => t.mul(factor));
return fastQuery.withEventTime((t) => t.div(factor));
}
fast(factor) {
return this._patternify(Pattern.prototype._fast)(factor);
}
_slow(factor) {
return this._fast(1 / factor);
}
slow(factor) {
return this._patternify(Pattern.prototype._slow)(factor);
}
_early(offset) {
offset = Fraction(offset);
return this.withQueryTime((t) => t.add(offset)).withEventTime((t) => t.sub(offset));
}
early(factor) {
return this._patternify(Pattern.prototype._early)(factor);
}
_late(offset) {
return this._early(0 - offset);
}
late(factor) {
return this._patternify(Pattern.prototype._late)(factor);
}
when(binary_pat, func) {
var true_pat = binary_pat._filterValues(id);
var false_pat = binary_pat._filterValues((val) => !val);

11
docs/dist/App.js vendored
View File

@ -5,13 +5,10 @@ import cx from "./cx.js";
import * as Tone from "../_snowpack/pkg/tone.js";
import useCycle from "./useCycle.js";
import {tetris} from "./tunes.js";
const {Fraction, TimeSpan} = strudel;
const fr = (v) => new Fraction(v);
const ts = (start, end) => new TimeSpan(fr(start), fr(end));
const parse = (code) => {
const {sequence, pure, reify, slowcat, fastcat, cat, stack, silence} = strudel;
return eval(code);
};
import _mini from "./mini.js";
const {sequence, pure, reify, slowcat, fastcat, cat, stack, silence} = strudel;
const mini = _mini;
const parse = (code) => eval(code);
const synth = new Tone.PolySynth().toDestination();
synth.set({
oscillator: {type: "triangle"},

20
docs/dist/mini.js vendored Normal file
View File

@ -0,0 +1,20 @@
import * as krill from "../_snowpack/link/repl/krill-parser.js";
import * as strudel from "../_snowpack/link/strudel.js";
const {sequence, silence} = strudel;
export function patternifyAST(ast) {
switch (ast.type_) {
case "pattern":
return sequence(...ast.source_.map(patternifyAST));
case "element":
if (ast.source_ === "~") {
return silence;
}
if (typeof ast.source_ !== "object") {
return ast.source_;
}
return patternifyAST(ast.source_);
}
}
export default (...strings) => {
return sequence(...strings.map((str) => patternifyAST(krill.parse(`"${str}"`))));
};

28
docs/dist/tunes.js vendored
View File

@ -1,4 +1,4 @@
export const tetris = `stack(sequence(
export const tetrisWithFunctions = `stack(sequence(
'e5', sequence('b4', 'c5'), 'd5', sequence('c5', 'b4'),
'a4', sequence('a4', 'c5'), 'e5', sequence('d5', 'c5'),
'b4', sequence(silence, 'c5'), 'd5', 'e5',
@ -18,6 +18,32 @@ export const tetris = `stack(sequence(
'a1', 'a2', 'a1', 'a2', 'a1', 'a2', 'a1', 'a2',
)
)._slow(16)`;
export const tetris = `stack(
sequence(
mini(
'e5 [b4 c5] d5 [c5 b4]',
'a4 [a4 c5] e5 [d5 c5]',
'b4 [~ c5] d5 e5',
'c5 a4 a4 ~',
'[~ d5] [~ f5] a5 [g5 f5]',
'e5 [~ c5] e5 [d5 c5]',
'b4 [b4 c5] d5 e5',
'c5 a4 a4 ~'
)
),
sequence(
mini(
'e2 e3 e2 e3 e2 e3 e2 e3',
'a2 a3 a2 a3 a2 a3 a2 a3',
'g#2 g#3 g#2 g#3 e2 e3 e2 e3',
'a2 a3 a2 a3 a2 a3 b1 c2',
'd2 d3 d2 d3 d2 d3 d2 d3',
'c2 c3 c2 c3 c2 c3 c2 c3',
'b1 b2 b1 b2 e2 e3 e2 e3',
'a1 a2 a1 a2 a1 a2 a1 a2'
)
)
)._slow(16);`;
export const spanish = `slowcat(
stack('c4','eb4','g4'),
stack('bb3','d4','f4'),