Respond to glossing's review
This commit is contained in:
parent
92a82ce4bd
commit
8cbe4b945c
2 changed files with 33 additions and 6 deletions
|
|
@ -8,24 +8,48 @@ import { register, reify, Pattern } from './pattern.mjs';
|
||||||
|
|
||||||
let timelines = {};
|
let timelines = {};
|
||||||
|
|
||||||
|
export const reset_state = function () {
|
||||||
|
reset_timelines();
|
||||||
|
};
|
||||||
|
|
||||||
export const reset_timelines = function () {
|
export const reset_timelines = function () {
|
||||||
timelines = {};
|
timelines = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Allows you to switch a pattern between different 'timelines'. This is particularly useful when
|
||||||
|
* live coding, for example when you want to cue a pattern up to play from its start.
|
||||||
|
*
|
||||||
|
* Timelines are specified by number, so that if you had a pattern like
|
||||||
|
* `n("<0 1 2 3>").s("num").timeline(1)` playing, then changed the '1'
|
||||||
|
* to '2', it would always align '0' to the nearest cycle. You will likely want to trigger
|
||||||
|
* an evaluation a little bit before the cycle starts, to avoid missing events.
|
||||||
|
*
|
||||||
|
* If you change and evaluate a pattern without changing the timeline, it will stay on that timeline
|
||||||
|
* without resetting.
|
||||||
|
*
|
||||||
|
* Rather than incrementing a timeline to reset it, it's easier to negate it, e.g. by switching between `-2`
|
||||||
|
* and `2`. This is because when you negate a timeline it will always reset.
|
||||||
|
*
|
||||||
|
* You can also pattern the timeline if you want, to create strange resetting patterns.
|
||||||
|
*/
|
||||||
|
|
||||||
export const timeline = register(
|
export const timeline = register(
|
||||||
'timeline',
|
'timeline',
|
||||||
function (tpat, pat) {
|
function (tpat, pat) {
|
||||||
tpat = reify(tpat);
|
tpat = reify(tpat);
|
||||||
const f = function (state) {
|
const f = function (state) {
|
||||||
let scheduler = !!state.controls._cps;
|
// Is this called from the scheduler? (rather than from e.g. the visualiser)
|
||||||
|
const scheduler = !!state.controls._cyclist;
|
||||||
|
|
||||||
const timehaps = tpat.query(state);
|
const timehaps = tpat.query(state);
|
||||||
const result = [];
|
const result = [];
|
||||||
for (const timehap of timehaps) {
|
for (const timehap of timehaps) {
|
||||||
const tlid = timehap.value;
|
const tlid = timehap.value;
|
||||||
const ignore = false;
|
|
||||||
let offset;
|
let offset;
|
||||||
if (tlid in timelines) {
|
if (tlid === 0) {
|
||||||
|
offset = 0;
|
||||||
|
} else if (tlid in timelines) {
|
||||||
offset = timelines[tlid];
|
offset = timelines[tlid];
|
||||||
} else {
|
} else {
|
||||||
const timearc = timehap.wholeOrPart();
|
const timearc = timehap.wholeOrPart();
|
||||||
|
|
@ -40,9 +64,8 @@ export const timeline = register(
|
||||||
if (scheduler) {
|
if (scheduler) {
|
||||||
// update state
|
// update state
|
||||||
timelines[tlid] = offset;
|
timelines[tlid] = offset;
|
||||||
const negative = 0 - tlid;
|
if (tlid !== 0) {
|
||||||
if (negative in timelines) {
|
delete timelines[-tlid];
|
||||||
delete timelines[negative];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { errorLogger, logger } from './logger.mjs';
|
||||||
import { setTime } from './time.mjs';
|
import { setTime } from './time.mjs';
|
||||||
import { evalScope } from './evaluate.mjs';
|
import { evalScope } from './evaluate.mjs';
|
||||||
import { register, Pattern, isPattern, silence, stack } from './pattern.mjs';
|
import { register, Pattern, isPattern, silence, stack } from './pattern.mjs';
|
||||||
|
import { reset_state } from './impure.mjs';
|
||||||
|
|
||||||
export function repl({
|
export function repl({
|
||||||
defaultOutput,
|
defaultOutput,
|
||||||
|
|
@ -52,6 +53,9 @@ export function repl({
|
||||||
onToggle: (started) => {
|
onToggle: (started) => {
|
||||||
updateState({ started });
|
updateState({ started });
|
||||||
onToggle?.(started);
|
onToggle?.(started);
|
||||||
|
if (!started) {
|
||||||
|
reset_state();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setInterval,
|
setInterval,
|
||||||
clearInterval,
|
clearInterval,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue