mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 12:08:28 +00:00
remove old .draw, rename .onFrame to .draw
+ breaking: from, to are now called lookbehind, lookahead + migrate .pianoroll
This commit is contained in:
parent
eb8ac29136
commit
ab015ff48a
@ -39,41 +39,9 @@ function stopAnimationFrame(id) {
|
|||||||
function stopAllAnimations() {
|
function stopAllAnimations() {
|
||||||
Object.keys(animationFrames).forEach((id) => stopAnimationFrame(id));
|
Object.keys(animationFrames).forEach((id) => stopAnimationFrame(id));
|
||||||
}
|
}
|
||||||
Pattern.prototype.draw = function (callback, { id = 'std', from, to, onQuery, ctx } = {}) {
|
|
||||||
if (typeof window === 'undefined') {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
stopAnimationFrame(id);
|
|
||||||
ctx = ctx || getDrawContext();
|
|
||||||
let cycle,
|
|
||||||
events = [];
|
|
||||||
const animate = (time) => {
|
|
||||||
const t = getTime();
|
|
||||||
if (from !== undefined && to !== undefined) {
|
|
||||||
const currentCycle = Math.floor(t);
|
|
||||||
if (cycle !== currentCycle) {
|
|
||||||
cycle = currentCycle;
|
|
||||||
const begin = currentCycle + from;
|
|
||||||
const end = currentCycle + to;
|
|
||||||
setTimeout(() => {
|
|
||||||
events = this.query(new State(new TimeSpan(begin, end)))
|
|
||||||
.filter(Boolean)
|
|
||||||
.filter((event) => event.part.begin.equals(event.whole.begin));
|
|
||||||
onQuery?.(events);
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callback(ctx, events, t, time);
|
|
||||||
animationFrames[id] = requestAnimationFrame(animate);
|
|
||||||
};
|
|
||||||
requestAnimationFrame(animate);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
// this is a more generic helper to get a rendering callback for the currently active haps
|
|
||||||
// maybe this could also use Drawer internally? might need to support setting a custom pattern in Drawer
|
|
||||||
let memory = {};
|
let memory = {};
|
||||||
Pattern.prototype.onFrame = function (fn, options) {
|
Pattern.prototype.draw = function (fn, options) {
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,26 +36,23 @@ const getValue = (e) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pattern.prototype.pianoroll = function (options = {}) {
|
Pattern.prototype.pianoroll = function (options = {}) {
|
||||||
let { cycles = 4, playhead = 0.5, overscan = 1, hideNegative = false, ctx, id } = options;
|
let { cycles = 4, playhead = 0.5, overscan = 0, hideNegative = false, ctx = getDrawContext(), id = 1 } = options;
|
||||||
|
|
||||||
let from = -cycles * playhead;
|
let from = -cycles * playhead;
|
||||||
let to = cycles * (1 - playhead);
|
let to = cycles * (1 - playhead);
|
||||||
|
const inFrame = (hap, t) => (!hideNegative || hap.whole.begin >= 0) && hap.isWithinTime(t + from, t + to);
|
||||||
this.draw(
|
this.draw(
|
||||||
(ctx, haps, t) => {
|
(haps, time) => {
|
||||||
const inFrame = (event) =>
|
|
||||||
(!hideNegative || event.whole.begin >= 0) && event.whole.begin <= t + to && event.endClipped >= t + from;
|
|
||||||
pianoroll({
|
pianoroll({
|
||||||
...options,
|
...options,
|
||||||
time: t,
|
time,
|
||||||
ctx,
|
ctx,
|
||||||
haps: haps.filter(inFrame),
|
haps: haps.filter((hap) => inFrame(hap, time)),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
from: from - overscan,
|
lookbehind: from - overscan,
|
||||||
to: to + overscan,
|
lookahead: to + overscan,
|
||||||
ctx,
|
|
||||||
id,
|
id,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user