diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 9f4910a9..6b7fb7a7 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -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 () { diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index 25088ecf..b37ee286 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -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 () {