Implement inside/outside

This commit is contained in:
alex 2022-05-09 18:43:02 +01:00
parent a8d676641b
commit aca3bea56b
2 changed files with 32 additions and 4 deletions

View File

@ -696,6 +696,14 @@ export class Pattern {
return this._fast(Fraction(1).div(factor));
}
_inside(factor, f) {
return f(this._slow(factor))._fast(factor);
}
_outside(factor, f) {
return f(this._fast(factor))._slow(factor);
}
_ply(factor) {
return this.fmap((x) => pure(x)._fast(factor))._squeezeJoin();
}
@ -1400,6 +1408,14 @@ Pattern.prototype.compress = function (...args) {
args = args.map(reify);
return patternify2(Pattern.prototype._compress)(...args, this);
};
Pattern.prototype.outside = function (...args) {
args = args.map(reify);
return patternify2(Pattern.prototype._outside)(...args, this);
};
Pattern.prototype.inside = function (...args) {
args = args.map(reify);
return patternify2(Pattern.prototype._inside)(...args, this);
};
// call this after all Patter.prototype.define calls have been executed! (right before evaluate)
Pattern.prototype.bootstrap = function () {

View File

@ -41,6 +41,7 @@ import {
tri2,
id,
ply,
rev
} from '../index.mjs';
import { steady } from '../signal.mjs';
@ -436,6 +437,20 @@ describe('Pattern', function () {
// mini('eb3 [c3 g3]/2 ') always plays [c3 g3]
});
});
describe('inside', () => {
it('can rev inside a cycle', () => {
sameFirst(sequence('a', 'b', 'c', 'd').inside(2, rev),
sequence('b', 'a', 'd', 'c')
);
});
});
describe('outside', () => {
it('can rev outside a cycle', () => {
sameFirst(sequence('a', 'b', 'c', 'd')._slow(2).outside(2, rev),
sequence('d', 'c')
);
});
});
describe('_filterValues()', function () {
it('Filters true', function () {
assert.equal(
@ -588,10 +603,7 @@ describe('Pattern', function () {
});
describe('brak()', () => {
it('Can make something a bit breakbeaty', () => {
sameFirst(
sequence('a', 'b').brak()._fast(2),
sequence('a', 'b', fastcat(silence, 'a'), fastcat('b', silence))
)
sameFirst(sequence('a', 'b').brak()._fast(2), sequence('a', 'b', fastcat(silence, 'a'), fastcat('b', silence)));
});
});
describe('timeCat()', function () {