From 2060e868750c649bc84f67d1d0b330b925dd4262 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 13 Apr 2022 00:25:53 +0200 Subject: [PATCH] add queryArc + update readme --- packages/core/README.md | 8 +++++--- packages/core/strudel.mjs | 16 ++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/core/README.md b/packages/core/README.md index d570c09e..c4abf087 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -15,14 +15,14 @@ import { sequence, State, TimeSpan } from '@strudel.cycles/core'; const pattern = sequence('a', ['b', 'c']); -const events = pattern.query(new State(new TimeSpan(0, 2))); +const events = pattern.queryArc(0, 1); const spans = events.map( (event) => `${event.value}: ${event.whole.begin.toFraction()} - ${event.whole.end.toFraction()} `, ); ``` -spans: +yields: ```log a: 0 - 1/2 @@ -33,4 +33,6 @@ b: 3/2 - 7/4 c: 7/4 - 2 ``` -[play with @strudel.cycles/core on codesandbox](https://codesandbox.io/s/strudel-core-test-qmz6qr?file=/src/index.js). +- [play with @strudel.cycles/core on codesandbox](https://codesandbox.io/s/strudel-core-test-qmz6qr?file=/src/index.js). +- [open color pattern example](https://raw.githack.com/tidalcycles/strudel/package-examples/packages/core/examples/canvas.html) +- [open minimal repl example](https://raw.githack.com/tidalcycles/strudel/package-examples/packages/core/examples/metro.html) diff --git a/packages/core/strudel.mjs b/packages/core/strudel.mjs index ec1eaa2e..7fa58859 100644 --- a/packages/core/strudel.mjs +++ b/packages/core/strudel.mjs @@ -236,6 +236,10 @@ class Pattern { this.query = query; } + queryArc(begin, end) { + return this.query(new State(new TimeSpan(begin, end))); + } + _splitQueries() { // Splits queries at cycle boundaries. This makes some calculations // easier to express, as all events are then constrained to happen within @@ -686,12 +690,12 @@ class Pattern { } _chop(n) { - const slices = Array.from({length: n}, (x, i) => i); - const slice_objects = slices.map(i => ({begin: i/n, end: (i+1)/n})); - const func = function(o) { - return(sequence(slice_objects.map(slice_o => Object.assign({}, o, slice_o)))) - } - return(this._squeezeBind(func)); + const slices = Array.from({ length: n }, (x, i) => i); + const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n })); + const func = function (o) { + return sequence(slice_objects.map((slice_o) => Object.assign({}, o, slice_o))); + }; + return this._squeezeBind(func); } // cpm = cycles per minute