mirror of
https://codeberg.org/uzu/strudel
synced 2026-12-05 13:27:25 -05:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8390926531 |
@@ -1,22 +0,0 @@
|
||||
import { queryCode, testCycles } from '../test/runtime.mjs';
|
||||
import * as tunes from '../website/src/repl/tunes.mjs';
|
||||
import { describe, bench } from 'vitest';
|
||||
import { setCalculateSteps } from '../packages/core/index.mjs';
|
||||
|
||||
const tuneKeys = Object.keys(tunes);
|
||||
|
||||
describe('renders tunes', () => {
|
||||
tuneKeys.forEach((key) => {
|
||||
describe(key, () => {
|
||||
setCalculateSteps(true);
|
||||
bench(`+steps`, async () => {
|
||||
await queryCode(tunes[key], testCycles[key] || 1);
|
||||
});
|
||||
setCalculateSteps(false);
|
||||
bench(`-steps`, async () => {
|
||||
await queryCode(tunes[key], testCycles[key] || 1);
|
||||
});
|
||||
setCalculateSteps(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -4,19 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
Pattern,
|
||||
pure,
|
||||
register,
|
||||
reify,
|
||||
logger,
|
||||
stack,
|
||||
slowcat,
|
||||
Fraction,
|
||||
sequence,
|
||||
lcm,
|
||||
getCalculateSteps,
|
||||
} from '@strudel/pattern';
|
||||
import { Pattern, pure, register, reify, logger, stack, slowcat, Fraction, sequence, lcm } from '@strudel/pattern';
|
||||
|
||||
export function createParam(names) {
|
||||
let isMulti = Array.isArray(names);
|
||||
@@ -3756,7 +3744,7 @@ export const { juxBy, juxby } = register(['juxBy', 'juxby'], function (by, func,
|
||||
const left = pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) - by }));
|
||||
const right = func(pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) + by })));
|
||||
|
||||
return stack(left, right).setSteps(getCalculateSteps() ? lcm(left._steps, right._steps) : undefined);
|
||||
return stack(left, right).setSteps(lcm(left._steps, right._steps));
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -3888,7 +3876,7 @@ export const chop = register('chop', function (n, pat) {
|
||||
const func = function (o) {
|
||||
return sequence(slice_objects.map((slice_o) => merge(o, slice_o)));
|
||||
};
|
||||
return pat.squeezeBind(func).setSteps(getCalculateSteps() ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
return pat.squeezeBind(func).setSteps(Fraction(n).mulmaybe(pat._steps));
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -3904,10 +3892,7 @@ export const striate = register('striate', function (n, pat) {
|
||||
const slices = Array.from({ length: n }, (x, i) => i);
|
||||
const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n }));
|
||||
const slicePat = slowcat(...slice_objects);
|
||||
return pat
|
||||
.set(slicePat)
|
||||
._fast(n)
|
||||
.setSteps(getCalculateSteps() ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
return pat.set(slicePat)._fast(n).setSteps(Fraction(n).mulmaybe(pat._steps));
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { describe, bench } from 'vitest';
|
||||
|
||||
import { setCalculateSteps } from '@strudel/pattern';
|
||||
import { mini } from '../index.mjs';
|
||||
|
||||
describe('mini', () => {
|
||||
setCalculateSteps(true);
|
||||
bench(
|
||||
'+tactus',
|
||||
() => {
|
||||
mini('a b c*3 [c d e, f g] <a b [c d?]>').fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
|
||||
setCalculateSteps(false);
|
||||
bench(
|
||||
'-tactus',
|
||||
() => {
|
||||
mini('a b c*3 [c d e, f g] <a b [c d?]>').fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
setCalculateSteps(true);
|
||||
});
|
||||
@@ -1,46 +0,0 @@
|
||||
import { describe, bench } from 'vitest';
|
||||
|
||||
import { setCalculateSteps, sequence, stack } from '../index.mjs';
|
||||
|
||||
const pat64 = sequence(...Array(64).keys());
|
||||
|
||||
describe('steps', () => {
|
||||
setCalculateSteps(true);
|
||||
bench(
|
||||
'+tactus',
|
||||
() => {
|
||||
pat64.iter(64).fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
|
||||
setCalculateSteps(false);
|
||||
bench(
|
||||
'-tactus',
|
||||
() => {
|
||||
pat64.iter(64).fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
});
|
||||
|
||||
describe('stack', () => {
|
||||
setCalculateSteps(true);
|
||||
bench(
|
||||
'+tactus',
|
||||
() => {
|
||||
stack(pat64, pat64, pat64, pat64, pat64, pat64, pat64, pat64).fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
|
||||
setCalculateSteps(false);
|
||||
bench(
|
||||
'-tactus',
|
||||
() => {
|
||||
stack(pat64, pat64, pat64, pat64, pat64, pat64, pat64, pat64).fast(64).firstCycle();
|
||||
},
|
||||
{ time: 1000 },
|
||||
);
|
||||
});
|
||||
setCalculateSteps(true);
|
||||
@@ -1,49 +0,0 @@
|
||||
import { describe, bench } from 'vitest';
|
||||
|
||||
import { setCalculateSteps, rand, useRNG } from '../index.mjs';
|
||||
|
||||
const testingResolution = 128;
|
||||
|
||||
const _generateRandomPattern = () => rand.iter(testingResolution).fast(testingResolution).firstCycle();
|
||||
|
||||
describe('old random', () => {
|
||||
setCalculateSteps(true);
|
||||
bench(
|
||||
'+tactus',
|
||||
() => {
|
||||
useRNG('legacy');
|
||||
_generateRandomPattern();
|
||||
},
|
||||
{
|
||||
time: 1000,
|
||||
teardown() {
|
||||
useRNG('legacy');
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
setCalculateSteps(false);
|
||||
bench(
|
||||
'-tactus',
|
||||
() => {
|
||||
useRNG('precise');
|
||||
_generateRandomPattern();
|
||||
},
|
||||
{
|
||||
time: 1000,
|
||||
teardown() {
|
||||
useRNG('legacy');
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('random', () => {
|
||||
setCalculateSteps(true);
|
||||
bench('+tactus', _generateRandomPattern, { time: 1000 });
|
||||
|
||||
setCalculateSteps(false);
|
||||
bench('-tactus', _generateRandomPattern, { time: 1000 });
|
||||
});
|
||||
|
||||
setCalculateSteps(true);
|
||||
@@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import Fraction, { lcm } from './fraction.mjs';
|
||||
import { getCalculateSteps, Pattern } from './pattern.mjs';
|
||||
import { Pattern } from './pattern.mjs';
|
||||
import { reify, silence, pure } from './atoms.mjs';
|
||||
import { _mod, flatten, curry } from './util.mjs';
|
||||
import { errorLogger } from './logger.mjs';
|
||||
@@ -52,9 +52,7 @@ export function stack(...pats) {
|
||||
}),
|
||||
);
|
||||
const result = new Pattern(query);
|
||||
if (getCalculateSteps()) {
|
||||
result._steps = lcm(...pats.map((pat) => pat._steps));
|
||||
}
|
||||
result._steps = lcm(...pats.map((pat) => pat._steps));
|
||||
return result;
|
||||
}
|
||||
// aliases
|
||||
@@ -130,7 +128,7 @@ export function slowcat(...pats) {
|
||||
const offset = span.begin.floor().sub(span.begin.div(pats.length).floor());
|
||||
return pat.withHapTime((t) => t.add(offset)).query(state.setSpan(span.withTime((t) => t.sub(offset))));
|
||||
};
|
||||
const steps = getCalculateSteps() ? lcm(...pats.map((x) => x._steps)) : undefined;
|
||||
const steps = lcm(...pats.map((x) => x._steps));
|
||||
return new Pattern(query).splitQueries().setSteps(steps);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,19 +13,6 @@ import { removeUndefineds, flatten, id, parseNumeral, stringifyValues } from './
|
||||
import drawLine from './drawLine.mjs';
|
||||
import { errorLogger, logger } from './logger.mjs';
|
||||
|
||||
let __steps = true;
|
||||
|
||||
// Set whether pattern steps should be calculated in relevant operations.
|
||||
// Only used in benchmarking.
|
||||
export function setCalculateSteps(x) {
|
||||
__steps = x ? true : false;
|
||||
}
|
||||
|
||||
// Get whether pattern steps should be calculated in relevant operations.
|
||||
export function getCalculateSteps() {
|
||||
return __steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the given thing is an pattern
|
||||
* @param {*} thing
|
||||
@@ -81,9 +68,6 @@ export class Pattern {
|
||||
}
|
||||
|
||||
withSteps(f) {
|
||||
if (!getCalculateSteps()) {
|
||||
return this;
|
||||
}
|
||||
return new Pattern(this.query, this._steps === undefined ? undefined : f(this._steps));
|
||||
}
|
||||
|
||||
@@ -177,9 +161,7 @@ export class Pattern {
|
||||
return span_a.intersection_e(span_b);
|
||||
};
|
||||
const result = pat_func.appWhole(whole_func, pat_val);
|
||||
if (getCalculateSteps()) {
|
||||
result._steps = lcm(pat_val._steps, pat_func._steps);
|
||||
}
|
||||
result._steps = lcm(pat_val._steps, pat_func._steps);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import Fraction, { lcm } from './fraction.mjs';
|
||||
import TimeSpan from './timespan.mjs';
|
||||
import Hap from './hap.mjs';
|
||||
import { flatten, uniqsortr, pairs, removeUndefineds } from './util.mjs';
|
||||
import { Pattern, getCalculateSteps } from './pattern.mjs';
|
||||
import { Pattern } from './pattern.mjs';
|
||||
import { reify, gap, silence, nothing } from './atoms.mjs';
|
||||
import { register } from './register.mjs';
|
||||
import { fastcat, slowcat, stack, sequence } from './composers.mjs';
|
||||
@@ -239,7 +239,7 @@ function _stackWith(func, pats) {
|
||||
return pats[0];
|
||||
}
|
||||
const [left, ...right] = pats.map((pat) => pat._steps);
|
||||
const steps = getCalculateSteps() ? left.maximum(...right) : undefined;
|
||||
const steps = left.maximum(...right);
|
||||
return stack(...func(steps, pats));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import TimeSpan from './timespan.mjs';
|
||||
import Fraction from './fraction.mjs';
|
||||
import Hap from './hap.mjs';
|
||||
import { Pattern, getCalculateSteps } from './pattern.mjs';
|
||||
import { Pattern } from './pattern.mjs';
|
||||
import { silence, nothing, pure, reify } from './atoms.mjs';
|
||||
import { slowcatPrime, sequence, fastcat, slowcat, stack, seq, cat } from './composers.mjs';
|
||||
import { register } from './register.mjs';
|
||||
@@ -107,9 +107,7 @@ export const { focusSpan, focusspan } = register(['focusSpan', 'focusspan'], fun
|
||||
*/
|
||||
export const ply = register('ply', function (factor, pat) {
|
||||
const result = pat.fmap((x) => pure(x)._fast(factor)).squeezeJoin();
|
||||
if (getCalculateSteps()) {
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
}
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -333,7 +331,7 @@ export const zoom = register('zoom', function (s, e, pat) {
|
||||
return nothing;
|
||||
}
|
||||
const d = e.sub(s);
|
||||
const steps = getCalculateSteps() ? pat._steps?.mulmaybe(d) : undefined;
|
||||
const steps = pat._steps?.mulmaybe(d);
|
||||
return pat
|
||||
.withQuerySpan((span) => span.withCycle((t) => t.mul(d).add(s)))
|
||||
.withHapSpan((span) => span.withCycle((t) => t.sub(s).div(d)))
|
||||
@@ -726,9 +724,7 @@ export const plyWith = register(['plyWith', 'plywith'], function (factor, func,
|
||||
const result = pat
|
||||
.fmap((x) => cat(...listRange(0, factor - 1).map((i) => applyN(i, func, x)))._fast(factor))
|
||||
.squeezeJoin();
|
||||
if (getCalculateSteps()) {
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
}
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -750,9 +746,7 @@ export const plyForEach = register(['plyForEach', 'plyforeach'], function (facto
|
||||
const result = pat
|
||||
.fmap((x) => cat(cat(pure(x), ...listRange(1, factor - 1).map((i) => func(pure(x), i))))._fast(factor))
|
||||
.squeezeJoin();
|
||||
if (getCalculateSteps()) {
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
}
|
||||
result._steps = Fraction(factor).mulmaybe(pat._steps);
|
||||
return result;
|
||||
});
|
||||
|
||||
|
||||
@@ -284,7 +284,6 @@
|
||||
"getIsStarted"
|
||||
],
|
||||
"/packages/core/pattern.mjs": [
|
||||
"calculateSteps",
|
||||
"setStringParser",
|
||||
"polyrhythm",
|
||||
"pr",
|
||||
|
||||
Reference in New Issue
Block a user