diff --git a/packages/codemirror/widget.mjs b/packages/codemirror/widget.mjs index 3171d0df..c0bd9a24 100644 --- a/packages/codemirror/widget.mjs +++ b/packages/codemirror/widget.mjs @@ -14,13 +14,18 @@ export const updateWidgets = (view, widgets) => { }; function getWidgets(widgetConfigs) { - return widgetConfigs.map(({ to, type }) => { - return Decoration.widget({ - widget: new BlockWidget(to, type), - side: 0, - block: true, - }).range(to); - }); + return ( + widgetConfigs + // codemirror throws an error if we don't sort + .sort((a, b) => a.to - b.to) + .map(({ to, type }) => { + return Decoration.widget({ + widget: new BlockWidget(to, type), + side: 0, + block: true, + }).range(to); + }) + ); } const widgetField = StateField.define( diff --git a/packages/draw/draw.mjs b/packages/draw/draw.mjs index 2ea531cf..63245baf 100644 --- a/packages/draw/draw.mjs +++ b/packages/draw/draw.mjs @@ -29,14 +29,14 @@ export const getDrawContext = (id = 'test-canvas', options) => { return canvas.getContext(contextType); }; -Pattern.prototype.draw = function (callback, { from, to, onQuery } = {}) { +Pattern.prototype.draw = function (callback, { from, to, onQuery, ctx } = {}) { if (typeof window === 'undefined') { return this; } if (window.strudelAnimation) { cancelAnimationFrame(window.strudelAnimation); } - const ctx = getDrawContext(); + ctx = ctx || getDrawContext(); let cycle, events = []; const animate = (time) => { diff --git a/packages/draw/pianoroll.mjs b/packages/draw/pianoroll.mjs index 74b1480e..b032ef1a 100644 --- a/packages/draw/pianoroll.mjs +++ b/packages/draw/pianoroll.mjs @@ -30,7 +30,7 @@ const getValue = (e) => { }; Pattern.prototype.pianoroll = function (options = {}) { - let { cycles = 4, playhead = 0.5, overscan = 1, hideNegative = false } = options; + let { cycles = 4, playhead = 0.5, overscan = 1, hideNegative = false, ctx } = options; let from = -cycles * playhead; let to = cycles * (1 - playhead); @@ -49,6 +49,7 @@ Pattern.prototype.pianoroll = function (options = {}) { { from: from - overscan, to: to + overscan, + ctx, }, ); return this; diff --git a/packages/widgets/Claviature.jsx b/packages/widgets/Claviature.jsx index e4ebfec6..33777be4 100644 --- a/packages/widgets/Claviature.jsx +++ b/packages/widgets/Claviature.jsx @@ -17,19 +17,17 @@ customElement('strudel-claviature', { options: JSON.stringify(defaultOptions) }, return c; }; return ( -