Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve new draw logic #372

Merged
merged 11 commits into from
Jan 14, 2023
Merged
6 changes: 6 additions & 0 deletions packages/core/draw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ export const cleanupDraw = (clearScreen = true) => {
clearInterval(window.strudelScheduler);
}
};

Pattern.prototype.onPaint = function (onPaint) {
// this is evil! TODO: add pattern.context
this.context = { onPaint };
return this;
};
1 change: 1 addition & 0 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,7 @@ export const velocity = register('velocity', function (velocity, pat) {
*/
// TODO - fix
export const legato = register('legato', function (value, pat) {
value = Fraction(value);
return pat.withHapSpan((span) => new TimeSpan(span.begin, span.begin.add(span.end.sub(span.begin).mul(value))));
});

Expand Down
12 changes: 12 additions & 0 deletions packages/core/pianoroll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,15 @@ export function pianoroll({
ctx.stroke();
return this;
}

function getOptions(drawTime, options = {}) {
let [lookbehind, lookahead] = drawTime;
lookbehind = Math.abs(lookbehind);
const cycles = lookahead + lookbehind;
const playhead = lookbehind / cycles;
return { fold: 1, ...options, cycles, playhead };
}

Pattern.prototype.punchcard = function (options) {
return this.onPaint((ctx, time, haps, drawTime) => pianoroll({ ctx, time, haps, ...getOptions(drawTime, options) }));
};
4 changes: 2 additions & 2 deletions packages/core/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export function repl({
afterEval,
getTime,
transpiler,
editPattern,
onToggle,
editPattern,
}) {
const scheduler = new Cyclist({
interval,
Expand All @@ -35,7 +35,7 @@ export function repl({
getTime,
onToggle,
});
setTime(() => scheduler.getPhase()); // TODO: refactor?
setTime(() => scheduler.now()); // TODO: refactor?
const evaluate = async (code, autostart = true) => {
if (!code) {
throw new Error('no code to evaluate');
Expand Down
2 changes: 1 addition & 1 deletion packages/react/dist/index.cjs.js

Large diffs are not rendered by default.