Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

fix(engine): under music, tails land where the beat really ends

yzr3ce4d01b334a
diff --git a/engine/engine.js b/engine/engine.js
index b94d64c..65f7780 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/joke-collection/lib/engine.js b/site/joke-collection/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/joke-collection/lib/engine.js
+++ b/site/joke-collection/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/little-red-riding-hood/lib/engine.js b/site/little-red-riding-hood/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/little-red-riding-hood/lib/engine.js
+++ b/site/little-red-riding-hood/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/madness-shorts/lib/engine.js b/site/madness-shorts/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/madness-shorts/lib/engine.js
+++ b/site/madness-shorts/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/madness/lib/engine.js b/site/madness/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/madness/lib/engine.js
+++ b/site/madness/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/pandemic/ch01/index.html b/site/pandemic/ch01/index.html
index 515bd82..d7b337c 100644
--- a/site/pandemic/ch01/index.html
+++ b/site/pandemic/ch01/index.html
@@ -65,11 +65,11 @@ const BEATS = [
ground(p, NIGHT);
const glob = G(p, { o: 0 }), gb = blurOn(glob, 'x');
const lon0 = -30, spin = t => lon0 + t * 2.4, tA = m('one') - 1.9, tB = m('one') - .55; // the whip turn to China on "go back"
- globeShot(glob, D, t => {
+ globeShot(glob, D, (t, E) => { // E: where the beat really ends, so the dive lands there
const q = soft(span01(t, tA, tB)), lonA = spin(tA);
const lon = t < tA ? spin(t) : lonA + (WUHAN_LL[0] - lonA) * q, lat = 12 + (WUHAN_LL[1] - 12) * q;
const creep = 1.15 - .1 * span01(t, m('count') - 1, tA);
- const dive = span01(t, m('one') - .4, D + HOLD), H = creep * (.33 / creep) ** (dive ** 1.6);
+ const dive = span01(t, m('one') - .4, E), H = creep * (.33 / creep) ** (dive ** 1.6);
const gain = 1.6 - .5 * span01(t, m('real'), m('real') + .8) - .9 * span01(t, m('forget'), m('forget') + 1.6) + 1.4 * span01(t, tA, tB);
return { lon, lat, H, gain };
});
@@ -186,7 +186,7 @@ const BEATS = [
// push through the first case into red
cam.to({ x: CASES[0][0], y: CASES[0][1], z: 1600 }, D, HOLD, ease3);
const red = mk('rect', { x: 0, y: 0, width: SW, height: SH, fill: RED, opacity: 0 }, p);
- clockRun(t => red.setAttribute('opacity', span01(t, D + HOLD - .16, D + HOLD)), D, { tail: true });
+ clockRun((t, E) => red.setAttribute('opacity', span01(t, E - .16, E)), D, { tail: true }); // E: the beat's real end
}],
// 2. The doctor: his badge on the Wuhan map, his message and the letter as cards beside it, then eight badges
diff --git a/site/pandemic/lib/doc.js b/site/pandemic/lib/doc.js
index 9f44c71..c838860 100644
--- a/site/pandemic/lib/doc.js
+++ b/site/pandemic/lib/doc.js
@@ -250,7 +250,7 @@ function trackLabel(p, cam, str, [wx, wy], t0, D, { size = 30, fill = MAPINK, dy
// mount the shared WebGL canvas in this panel and draw view(t) every frame
function globeShot(p, D, view, dotsOn, arcsOn) {
const g = Globe.mount(p);
- clockRun(t => Globe.draw(view(t), dotsOn && (i => dotsOn(i, t)), arcsOn && (i => arcsOn(i, t))), D, { tail: true });
+ clockRun((t, E) => Globe.draw(view(t, E), dotsOn && (i => dotsOn(i, t)), arcsOn && (i => arcsOn(i, t))), D, { tail: true }); // E: the beat's real end
return g;
}
const WUHAN_LL = [114.268, 30.582];
diff --git a/site/pandemic/lib/engine.js b/site/pandemic/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/pandemic/lib/engine.js
+++ b/site/pandemic/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/shooting-an-elephant/lib/engine.js b/site/shooting-an-elephant/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/shooting-an-elephant/lib/engine.js
+++ b/site/shooting-an-elephant/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
index b94d64c..65f7780 100644
--- a/site/three-little-pigs/lib/engine.js
+++ b/site/three-little-pigs/lib/engine.js
@@ -623,9 +623,10 @@ const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camer
// after its narration and last tween; with { tail: true } f keeps running through that hold (t up to the beat's end)
// instead of freezing at D, for motion that never stops, as in a film. A camera runs through the hold too when anything
// in its beat does (its tail is 'follow'), so a follow shot keeps up with a tailed subject. f also gets the run's end
-// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does.
+// (for a tail, the beat's real end), so a move can land on it, as a whip at the end of a beat does. Under music that
+// end is where the beat really leaves, up to HOLD early (P.back, see frameStep), so the move is still seen landing.
// A tail's own D does not lengthen the beat: it runs to the end whatever it is (so D + HOLD adds no second hold).
-const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.dur); TW.push(w); };
+const clockRun = (f, D, { tail = false } = {}) => { const w = { t0: 0, dur: D, ease: lin, tail }; f(0, D); w.pf = q => f(q * w.dur, w.tail ? w.dur - P.back : w.dur); TW.push(w); };
// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
@@ -1313,7 +1314,7 @@ function soundTick(dt) {
}
/* ---------- player ---------- */
-const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+const P = { i: 0, t: 0, end: 1, back: 0, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
@@ -1384,7 +1385,7 @@ function start(i, play) {
stopAudio(); clearCards();
// P.gen counts starts: a done() kept from an earlier start of this same beat (a step replayed) no longer counts
const gen = P.gen = (P.gen || 0) + 1;
- Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0 });
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0, lost: 0, back: 0 });
P.end = runBeat(i);
evalTo(0);
const a = P.audio = beatClip(i, true);
@@ -1487,12 +1488,12 @@ function frameStep(now, most) {
if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
- evalTo(P.t);
// P.lost: how long the clock stood still while the film played (a clip getting going, buffering). Music runs on
// through it, so a beat under music gives that time back from its closing hold: each beat then lasts as long in
// real time as on the music's timeline, and the music stays with the picture instead of drifting ahead beat by beat.
P.lost += raw * P.rate - (P.t - t0); // real time: a long frame moves the music by all of it
- const back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ const back = P.back = SND.bgm.some(m => m.beats.includes(BEATS[P.i].id)) ? Math.max(0, Math.min(HOLD, P.lost)) : 0;
+ evalTo(P.t);
if (P.t >= P.end - back) beatDone();
}
soundTick(dt);