Compare commits

...

1 Commits

Author SHA1 Message Date
alex 0447d4d5dc add impure edges 2026-12-04 09:08:45 +00:00
+27 -1
View File
@@ -4,9 +4,10 @@ Copyright (C) 2025 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 { register, reify, Pattern } from './pattern.mjs';
import { register, reify, Pattern, Hap } from './pattern.mjs';
let timelines = {};
let edges_prev = {};
export const reset_state = function () {
reset_timelines();
@@ -16,6 +17,10 @@ export const reset_timelines = function () {
timelines = {};
};
export const reset_edges = function () {
edges_prev = {};
};
/***
* 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.
@@ -88,3 +93,24 @@ export const timeline = register(
},
false,
);
export const edges = register('edges', function (id, pat) {
edges_prev[id] = undefined;
const f = function (state) {
const scheduler = !!state.controls.cyclist;
const haps = pat.query(state);
const result = [];
for (const hap of haps) {
if (edges_prev[id] !== hap.value) {
result.push(new Hap(hap.part, hap.part, hap.value, hap.context));
if (scheduler) {
edges_prev[id] = hap.value;
}
} else {
result.push(hap);
}
}
return result;
};
return new Pattern(f);
});