now running smooth without memoization

This commit is contained in:
Felix Roos
2022-03-19 12:03:26 +01:00
parent 77fafd40fb
commit 61e81a4e60
8 changed files with 24 additions and 924 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ Pattern.prototype.draw = function (callback, cycleSpan, lookaheadCycles = 1) {
const end = (currentCycle + lookaheadCycles) * cycleSpan;
events = this._asNumber(true) // true = silent error
.query(new State(new TimeSpan(begin, end)))
.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf());
.filter((event) => event.part.begin.equals(event.whole.begin));
}
}
callback(ctx, events, t, cycleSpan, time);
+2 -1
View File
@@ -1,6 +1,7 @@
import { Pattern, timeCat } from '../../strudel.mjs';
import bjork from 'bjork';
import { rotate } from '../../util.mjs';
import Fraction from 'fraction.js';
const euclid = (pulses, steps, rotation = 0) => {
const b = bjork(steps, pulses);
@@ -22,7 +23,7 @@ Pattern.prototype.euclidLegato = function (pulses, steps, rotation = 0) {
.split('1')
.slice(1)
.map((s) => [s.length + 1, true]);
return this.struct(timeCat(...gapless)).late(firstOne / steps);
return this.struct(timeCat(...gapless)).late(Fraction(firstOne).div(steps));
};
export default euclid;
+5 -2
View File
@@ -12,7 +12,7 @@ const applyOptions = (parent: any) => (pat: any, i: number) => {
if (operator) {
switch (operator.type_) {
case 'stretch':
const speed = new Fraction(operator.arguments_.amount).inverse().valueOf();
const speed = new Fraction(operator.arguments_.amount).inverse();
return reify(pat).fast(speed);
case 'bjorklund':
return pat.euclid(operator.arguments_.pulse, operator.arguments_.step, operator.arguments_.rotation);
@@ -56,7 +56,9 @@ function resolveReplications(ast) {
options_: {
operator: {
type_: 'stretch',
arguments_: { amount: String(new Fraction(replicate).inverse().valueOf()) },
// valueOf should be ok here, as we turn it into a string
// fraction.js doc: "If you want to keep the number as it is, convert it to a string, as the string parser will not perform any further observations"
arguments_: { amount: String(new Fraction(replicate).inverse().valueOf()) },
},
},
},
@@ -103,6 +105,7 @@ export function patternifyAST(ast: any): any {
return ast.source_;
}
const { start, end } = ast.location_;
// should we really parse as number here? strings wont be fareyed...
const value = !isNaN(Number(ast.source_)) ? Number(ast.source_) : ast.source_;
// return ast.source_;
// the following line expects the shapeshifter to wrap this in withLocationOffset
+1 -1
View File
@@ -24,7 +24,7 @@ async function playStatic(code) {
start = performance.now();
const events = pat
?.query(new State(new TimeSpan(0, seconds)))
?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf())
?.filter((event) => event.part.begin.equals(event.whole.begin))
?.map((event) => ({
time: event.whole.begin.valueOf(),
duration: event.whole.end.sub(event.whole.begin).valueOf(),
+1
View File
@@ -7,6 +7,7 @@ export declare interface Fraction {
s: number;
sub: (f: Fraction) => Fraction;
sam: () => Fraction;
equals: (f: Fraction) => boolean;
}
export declare interface TimeSpan {
constructor: any; //?
+1 -1
View File
@@ -40,7 +40,7 @@ function useCycle(props: UseCycleProps) {
// schedule events for next cycle
events
?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf())
?.filter((event) => event.part.begin.equals(event.whole.begin))
.forEach((event) => {
Tone.getTransport().schedule((time) => {
const toneEvent = {