This commit is contained in:
Felix Roos 2022-03-12 21:58:47 +01:00
parent 92937fa72e
commit 04d14dea90
5 changed files with 18 additions and 17 deletions

12
docs/dist/draw.js vendored
View File

@ -12,7 +12,7 @@ export const getDrawContext = (id = "test-canvas") => {
} }
return canvas.getContext("2d"); return canvas.getContext("2d");
}; };
Pattern.prototype.draw = function(callback, queryDuration) { Pattern.prototype.draw = function(callback, cycleSpan, lookaheadCycles = 1) {
if (window.strudelAnimation) { if (window.strudelAnimation) {
cancelAnimationFrame(window.strudelAnimation); cancelAnimationFrame(window.strudelAnimation);
} }
@ -20,16 +20,16 @@ Pattern.prototype.draw = function(callback, queryDuration) {
let cycle, events = []; let cycle, events = [];
const animate = (time) => { const animate = (time) => {
const t = Tone.getTransport().seconds; const t = Tone.getTransport().seconds;
if (queryDuration) { if (cycleSpan) {
const currentCycle = Math.floor(t / queryDuration); const currentCycle = Math.floor(t / cycleSpan);
if (cycle !== currentCycle) { if (cycle !== currentCycle) {
cycle = currentCycle; cycle = currentCycle;
const begin = currentCycle * queryDuration; const begin = currentCycle * cycleSpan;
const end = (currentCycle + 1) * queryDuration; const end = (currentCycle + lookaheadCycles) * cycleSpan;
events = this.add(0).query(new State(new TimeSpan(begin, end))); events = this.add(0).query(new State(new TimeSpan(begin, end)));
} }
} }
callback(ctx, events, t, queryDuration, time); callback(ctx, events, t, cycleSpan, time);
window.strudelAnimation = requestAnimationFrame(animate); window.strudelAnimation = requestAnimationFrame(animate);
}; };
requestAnimationFrame(animate); requestAnimationFrame(animate);

View File

@ -24,6 +24,6 @@ Pattern.prototype.pianoroll = function({
const margin = 0; const margin = 0;
ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2); ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2);
}); });
}, timeframe * 2); }, timeframe, 2);
return this; return this;
}; };

View File

@ -136163,7 +136163,8 @@ _strudelMjs.Pattern.prototype.pianoroll = function({ timeframe =10 , inactive ='
const margin = 0; const margin = 0;
ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2); ctx.fillRect(x - offset + margin + 1, y + 1, width - 2, height - 2);
}); });
}, timeframe * 2); }, timeframe, 2 // lookaheadCycles
);
return this; return this;
}; };
@ -136188,22 +136189,22 @@ const getDrawContext = (id = 'test-canvas')=>{
} }
return canvas.getContext('2d'); return canvas.getContext('2d');
}; };
_strudelMjs.Pattern.prototype.draw = function(callback, queryDuration) { _strudelMjs.Pattern.prototype.draw = function(callback, cycleSpan, lookaheadCycles = 1) {
if (window.strudelAnimation) cancelAnimationFrame(window.strudelAnimation); if (window.strudelAnimation) cancelAnimationFrame(window.strudelAnimation);
const ctx = getDrawContext(); const ctx = getDrawContext();
let cycle, events = []; let cycle, events = [];
const animate = (time)=>{ const animate = (time)=>{
const t = _tone.getTransport().seconds; const t = _tone.getTransport().seconds;
if (queryDuration) { if (cycleSpan) {
const currentCycle = Math.floor(t / queryDuration); const currentCycle = Math.floor(t / cycleSpan);
if (cycle !== currentCycle) { if (cycle !== currentCycle) {
cycle = currentCycle; cycle = currentCycle;
const begin = currentCycle * queryDuration; const begin = currentCycle * cycleSpan;
const end = (currentCycle + 1) * queryDuration; const end = (currentCycle + lookaheadCycles) * cycleSpan;
events = this.add(0).query(new State(new TimeSpan(begin, end))); events = this.add(0).query(new State(new TimeSpan(begin, end)));
} }
} }
callback(ctx, events, t, queryDuration, time); callback(ctx, events, t, cycleSpan, time);
window.strudelAnimation = requestAnimationFrame(animate); window.strudelAnimation = requestAnimationFrame(animate);
}; };
requestAnimationFrame(animate); requestAnimationFrame(animate);
@ -182990,4 +182991,4 @@ exports.default = cx;
},{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["3uVTb"], "3uVTb", "parcelRequire94c2") },{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}]},["3uVTb"], "3uVTb", "parcelRequire94c2")
//# sourceMappingURL=index.9717dc33.js.map //# sourceMappingURL=index.a8828e57.js.map

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,6 @@
<body> <body>
<div id="root"></div> <div id="root"></div>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<script src="/tutorial/index.9717dc33.js" defer=""></script> <script src="/tutorial/index.a8828e57.js" defer=""></script>
</body> </body>
</html> </html>