fix minor bugs
This commit is contained in:
parent
3744ea6218
commit
49bcb5e19f
5 changed files with 31 additions and 28 deletions
2
packages/react/dist/index.cjs.js
vendored
2
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
47
packages/react/dist/index.es.js
vendored
47
packages/react/dist/index.es.js
vendored
|
|
@ -119,13 +119,14 @@ function Y(...e) {
|
||||||
return e.filter(Boolean).join(" ");
|
return e.filter(Boolean).join(" ");
|
||||||
}
|
}
|
||||||
function _e({ view: e, pattern: r, active: t, getTime: n }) {
|
function _e({ view: e, pattern: r, active: t, getTime: n }) {
|
||||||
const c = N([]), m = N();
|
const c = N([]), m = N(0);
|
||||||
k(() => {
|
k(() => {
|
||||||
if (e)
|
if (e)
|
||||||
if (r && t) {
|
if (r && t) {
|
||||||
|
m.current = 0;
|
||||||
let s = requestAnimationFrame(function a() {
|
let s = requestAnimationFrame(function a() {
|
||||||
try {
|
try {
|
||||||
const i = n(), b = [Math.max(m.current || i, i - 1 / 10, 0), i + 1 / 60];
|
const i = n(), b = [Math.max(m.current ?? i, i - 1 / 10, -0.01), i + 1 / 60];
|
||||||
m.current = b[1], c.current = c.current.filter((h) => h.whole.end > i);
|
m.current = b[1], c.current = c.current.filter((h) => h.whole.end > i);
|
||||||
const l = r.queryArc(...b).filter((h) => h.hasOnset());
|
const l = r.queryArc(...b).filter((h) => h.hasOnset());
|
||||||
c.current = c.current.concat(l), e.dispatch({ effects: B.of(c.current) });
|
c.current = c.current.concat(l), e.dispatch({ effects: B.of(c.current) });
|
||||||
|
|
@ -166,7 +167,7 @@ function Ae({ pattern: e, started: r, getTime: t, onDraw: n, drawTime: c = [-2,
|
||||||
let a = N([]), i = N(null);
|
let a = N([]), i = N(null);
|
||||||
k(() => {
|
k(() => {
|
||||||
if (e) {
|
if (e) {
|
||||||
const l = t(), h = e.queryArc(l, l + s + 0.1);
|
const l = t(), h = e.queryArc(Math.max(l, 0), l + s + 0.1);
|
||||||
a.current = a.current.filter((v) => v.whole.begin < l), a.current = a.current.concat(h);
|
a.current = a.current.filter((v) => v.whole.begin < l), a.current = a.current.concat(h);
|
||||||
}
|
}
|
||||||
}, [e]);
|
}, [e]);
|
||||||
|
|
@ -210,7 +211,7 @@ function De({
|
||||||
}) {
|
}) {
|
||||||
const F = G(() => Ce(), []);
|
const F = G(() => Ce(), []);
|
||||||
l = l || `canvas-${F}`;
|
l = l || `canvas-${F}`;
|
||||||
const [x, z] = M(), [R, H] = M(), [E, C] = M(c), [P, I] = M(), [D, S] = M(), [L, V] = M(!1), K = E !== P, { scheduler: o, evaluate: p, start: Q, stop: O, pause: ne } = G(
|
const [q, z] = M(), [R, H] = M(), [E, C] = M(c), [P, I] = M(), [D, S] = M(), [x, V] = M(!1), K = E !== P, { scheduler: o, evaluate: p, start: Q, stop: O, pause: ne } = G(
|
||||||
() => ge({
|
() => ge({
|
||||||
interval: r,
|
interval: r,
|
||||||
defaultOutput: e,
|
defaultOutput: e,
|
||||||
|
|
@ -241,7 +242,7 @@ function De({
|
||||||
return oe({ type: "start", from: F }), y;
|
return oe({ type: "start", from: F }), y;
|
||||||
},
|
},
|
||||||
[p, E]
|
[p, E]
|
||||||
), q = w(
|
), L = w(
|
||||||
(f, y, W, $) => {
|
(f, y, W, $) => {
|
||||||
const { onPaint: se } = f.context || {}, ie = typeof h == "function" ? h(l) : h;
|
const { onPaint: se } = f.context || {}, ie = typeof h == "function" ? h(l) : h;
|
||||||
se?.(ie, y, W, $);
|
se?.(ie, y, W, $);
|
||||||
|
|
@ -249,34 +250,34 @@ function De({
|
||||||
[h, l]
|
[h, l]
|
||||||
), U = w(
|
), U = w(
|
||||||
(f) => {
|
(f) => {
|
||||||
if (h && q) {
|
if (h && L) {
|
||||||
const [y, W] = v, $ = f.queryArc(0, W);
|
const [y, W] = v, $ = f.queryArc(0, W);
|
||||||
q(f, 0, $, v);
|
L(f, -1e-3, $, v);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[v, q]
|
[v, L]
|
||||||
), X = N();
|
), X = N();
|
||||||
k(() => {
|
k(() => {
|
||||||
!X.current && h && q && n && E && (X.current = !0, p(E, !1).then((f) => U(f)));
|
!X.current && h && L && n && E && (X.current = !0, p(E, !1).then((f) => U(f)));
|
||||||
}, [j, n, E, U]), k(() => () => {
|
}, [j, n, E, U]), k(() => () => {
|
||||||
o.stop();
|
o.stop();
|
||||||
}, [o]);
|
}, [o]);
|
||||||
const ae = async () => {
|
const ae = async () => {
|
||||||
L ? (o.stop(), U(D)) : await j();
|
x ? (o.stop(), U(D)) : await j();
|
||||||
}, ce = x || R;
|
}, ce = q || R;
|
||||||
return Ae({
|
return Ae({
|
||||||
pattern: D,
|
pattern: D,
|
||||||
started: h && L,
|
started: h && x,
|
||||||
getTime: () => o.now(),
|
getTime: () => o.now(),
|
||||||
drawTime: v,
|
drawTime: v,
|
||||||
onDraw: q
|
onDraw: L
|
||||||
}), {
|
}), {
|
||||||
id: F,
|
id: F,
|
||||||
canvasId: l,
|
canvasId: l,
|
||||||
code: E,
|
code: E,
|
||||||
setCode: C,
|
setCode: C,
|
||||||
error: ce,
|
error: ce,
|
||||||
schedulerError: x,
|
schedulerError: q,
|
||||||
scheduler: o,
|
scheduler: o,
|
||||||
evalError: R,
|
evalError: R,
|
||||||
evaluate: p,
|
evaluate: p,
|
||||||
|
|
@ -284,7 +285,7 @@ function De({
|
||||||
activeCode: P,
|
activeCode: P,
|
||||||
isDirty: K,
|
isDirty: K,
|
||||||
pattern: D,
|
pattern: D,
|
||||||
started: L,
|
started: x,
|
||||||
start: Q,
|
start: Q,
|
||||||
stop: O,
|
stop: O,
|
||||||
pause: ne,
|
pause: ne,
|
||||||
|
|
@ -323,11 +324,11 @@ function Z({ type: e }) {
|
||||||
})
|
})
|
||||||
}[e]);
|
}[e]);
|
||||||
}
|
}
|
||||||
const Re = "_container_3i85k_1", Le = "_header_3i85k_5", qe = "_buttons_3i85k_9", xe = "_button_3i85k_9", ze = "_buttonDisabled_3i85k_17", He = "_error_3i85k_21", Pe = "_body_3i85k_25", _ = {
|
const Re = "_container_3i85k_1", xe = "_header_3i85k_5", Le = "_buttons_3i85k_9", qe = "_button_3i85k_9", ze = "_buttonDisabled_3i85k_17", He = "_error_3i85k_21", Pe = "_body_3i85k_25", _ = {
|
||||||
container: Re,
|
container: Re,
|
||||||
header: Le,
|
header: xe,
|
||||||
buttons: qe,
|
buttons: Le,
|
||||||
button: xe,
|
button: qe,
|
||||||
buttonDisabled: ze,
|
buttonDisabled: ze,
|
||||||
error: He,
|
error: He,
|
||||||
body: Pe
|
body: Pe
|
||||||
|
|
@ -344,7 +345,7 @@ function Ye({ tune: e, hideOutsideView: r = !1, enableKeyboard: t, drawTime: n,
|
||||||
activeCode: h,
|
activeCode: h,
|
||||||
pattern: v,
|
pattern: v,
|
||||||
started: F,
|
started: F,
|
||||||
scheduler: x,
|
scheduler: q,
|
||||||
togglePlay: z,
|
togglePlay: z,
|
||||||
stop: R,
|
stop: R,
|
||||||
canvasId: H,
|
canvasId: H,
|
||||||
|
|
@ -359,12 +360,12 @@ function Ye({ tune: e, hideOutsideView: r = !1, enableKeyboard: t, drawTime: n,
|
||||||
drawTime: n
|
drawTime: n
|
||||||
}), [C, P] = M(), [I, D] = he({
|
}), [C, P] = M(), [I, D] = he({
|
||||||
threshold: 0.01
|
threshold: 0.01
|
||||||
}), S = N(), L = G(() => ((D || !r) && (S.current = !0), D || S.current), [D, r]);
|
}), S = N(), x = G(() => ((D || !r) && (S.current = !0), D || S.current), [D, r]);
|
||||||
_e({
|
_e({
|
||||||
view: C,
|
view: C,
|
||||||
pattern: v,
|
pattern: v,
|
||||||
active: F && !h?.includes("strudel disable-highlighting"),
|
active: F && !h?.includes("strudel disable-highlighting"),
|
||||||
getTime: () => x.now()
|
getTime: () => q.now()
|
||||||
}), T(() => {
|
}), T(() => {
|
||||||
if (t) {
|
if (t) {
|
||||||
const o = async (p) => {
|
const o = async (p) => {
|
||||||
|
|
@ -400,7 +401,7 @@ function Ye({ tune: e, hideOutsideView: r = !1, enableKeyboard: t, drawTime: n,
|
||||||
className: _.error
|
className: _.error
|
||||||
}, b.message)), /* @__PURE__ */ d.createElement("div", {
|
}, b.message)), /* @__PURE__ */ d.createElement("div", {
|
||||||
className: _.body
|
className: _.body
|
||||||
}, L && /* @__PURE__ */ d.createElement(Fe, {
|
}, x && /* @__PURE__ */ d.createElement(Fe, {
|
||||||
value: s,
|
value: s,
|
||||||
onChange: a,
|
onChange: a,
|
||||||
onViewChanged: P
|
onViewChanged: P
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,17 @@ import { setHighlights } from '../components/CodeMirror6';
|
||||||
|
|
||||||
function useHighlighting({ view, pattern, active, getTime }) {
|
function useHighlighting({ view, pattern, active, getTime }) {
|
||||||
const highlights = useRef([]);
|
const highlights = useRef([]);
|
||||||
const lastEnd = useRef();
|
const lastEnd = useRef(0);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (view) {
|
if (view) {
|
||||||
if (pattern && active) {
|
if (pattern && active) {
|
||||||
|
lastEnd.current = 0;
|
||||||
let frame = requestAnimationFrame(function updateHighlights() {
|
let frame = requestAnimationFrame(function updateHighlights() {
|
||||||
try {
|
try {
|
||||||
const audioTime = getTime();
|
const audioTime = getTime();
|
||||||
// force min framerate of 10 fps => fixes crash on tab refocus, where lastEnd could be far away
|
// force min framerate of 10 fps => fixes crash on tab refocus, where lastEnd could be far away
|
||||||
// see https://github.com/tidalcycles/strudel/issues/108
|
// see https://github.com/tidalcycles/strudel/issues/108
|
||||||
const begin = Math.max(lastEnd.current || audioTime, audioTime - 1 / 10, 0); // negative time seems buggy
|
const begin = Math.max(lastEnd.current ?? audioTime, audioTime - 1 / 10, -0.01); // negative time seems buggy
|
||||||
const span = [begin, audioTime + 1 / 60];
|
const span = [begin, audioTime + 1 / 60];
|
||||||
lastEnd.current = span[1];
|
lastEnd.current = span[1];
|
||||||
highlights.current = highlights.current.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
highlights.current = highlights.current.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function usePatternFrame({ pattern, started, getTime, onDraw, drawTime = [-2, 2]
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
const t = getTime();
|
const t = getTime();
|
||||||
const futureHaps = pattern.queryArc(t, t + lookahead + 0.1); // +0.1 = workaround for weird holes in query..
|
const futureHaps = pattern.queryArc(Math.max(t, 0), t + lookahead + 0.1); // +0.1 = workaround for weird holes in query..
|
||||||
visibleHaps.current = visibleHaps.current.filter((h) => h.whole.begin < t);
|
visibleHaps.current = visibleHaps.current.filter((h) => h.whole.begin < t);
|
||||||
visibleHaps.current = visibleHaps.current.concat(futureHaps);
|
visibleHaps.current = visibleHaps.current.concat(futureHaps);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,8 @@ function useStrudel({
|
||||||
if (drawContext && onDraw) {
|
if (drawContext && onDraw) {
|
||||||
const [_, lookahead] = drawTime;
|
const [_, lookahead] = drawTime;
|
||||||
const haps = pat.queryArc(0, lookahead);
|
const haps = pat.queryArc(0, lookahead);
|
||||||
onDraw(pat, 0, haps, drawTime);
|
// draw at -0.001 to avoid activating haps at 0
|
||||||
|
onDraw(pat, -0.001, haps, drawTime);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[drawTime, onDraw],
|
[drawTime, onDraw],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue