animader-cli 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/show.mjs +29 -19
- package/package.json +4 -4
- package/player/boot.mjs +88 -5
- package/player/controller.mjs +262 -17
- package/player/devchannel.mjs +15 -10
- package/player/transport.mjs +56 -71
- package/resources/editor/.animader/schemas/metadata.json +3 -3
- package/resources/editor/.animader/schemas/pngine.sjon +128 -7
- package/src/commands/dev.mjs +3 -2
- package/toolchain/manifest.json +17 -17
- package/toolchain/uniform-type-name.js +17 -4
package/lib/show.mjs
CHANGED
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
// ticks through the run core's own reset, returns every held control to
|
|
35
35
|
// the document default, and resets the visual feedback state through
|
|
36
36
|
// the renderer's public restart verb — never by patching private
|
|
37
|
-
// workers. `seconds` is
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
37
|
+
// workers. `seconds` is the effective show length (the shorter of the host
|
|
38
|
+
// policy and the score's own tempo-integrated end), received here on the run
|
|
39
|
+
// core's whole-tick grid; a score's own `:end loop|hold` stays authored and is
|
|
40
|
+
// not acted on by this transport.
|
|
41
41
|
//
|
|
42
42
|
// Ownership: the state machine, the clock arithmetic, the serialization.
|
|
43
43
|
// The audio graph, the wake source, the renderer and the driver belong
|
|
@@ -61,8 +61,9 @@ export const SHOW_STATES = Object.freeze([
|
|
|
61
61
|
/**
|
|
62
62
|
* @param {object} options
|
|
63
63
|
* @param {number} options.seconds
|
|
64
|
-
* the
|
|
65
|
-
*
|
|
64
|
+
* the effective show length (no longer than the host or the score);
|
|
65
|
+
* must be positive, finite and on the tick grid to within the transport's
|
|
66
|
+
* own sub-tick guard.
|
|
66
67
|
* @param {() => Promise<{driver: object, player: object, renderer: object}>} options.prepare
|
|
67
68
|
* composes the show: renderer ready, score compiled (a `loadShow`
|
|
68
69
|
* result wired through `createPlayer`). READY waits for this.
|
|
@@ -115,7 +116,14 @@ export function createShow({
|
|
|
115
116
|
stage: 'transport',
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
+
// A score end lands on the 100-tick grid as a hundredth-of-a-second value
|
|
120
|
+
// (35.12), whose binary product can sit a few ulps below the whole tick.
|
|
121
|
+
// The same 1e-6-tick guard the pump uses keeps that representation detail
|
|
122
|
+
// from refusing a real show length; a genuinely off-grid value (8.001) is
|
|
123
|
+
// still refused.
|
|
124
|
+
const rawTicks = seconds * ticksPerSecond;
|
|
125
|
+
const totalTicks = Math.round(rawTicks);
|
|
126
|
+
if (!(Math.abs(rawTicks - totalTicks) <= 1e-6)) {
|
|
119
127
|
throw new ShowError(
|
|
120
128
|
'seconds_not_representable',
|
|
121
129
|
`--seconds ${seconds} is not a whole number of ticks on the ${ticksPerSecond}-tick grid; pass a length the grid represents exactly instead of rounding forever`,
|
|
@@ -124,7 +132,6 @@ export function createShow({
|
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
const clock = readClock ?? audio.now;
|
|
127
|
-
const totalTicks = seconds * ticksPerSecond;
|
|
128
135
|
|
|
129
136
|
let state = 'loading';
|
|
130
137
|
let failure = null;
|
|
@@ -423,10 +430,10 @@ export function createShow({
|
|
|
423
430
|
* silently to the landed tick, and take the landing state from the spec's
|
|
424
431
|
* table. A playing seek rebases the origin, restarts the source at the
|
|
425
432
|
* offset and reschedules the pump; a paused landing suspends the context
|
|
426
|
-
* (so the clock is frozen) and starts no sound; the
|
|
427
|
-
* terminal landing. A failure takes the transport's
|
|
428
|
-
* and a host failure that arrives during a platform
|
|
429
|
-
* original identity.
|
|
433
|
+
* (so the clock is frozen) and starts no sound; the effective end is the
|
|
434
|
+
* one terminal landing from every row. A failure takes the transport's
|
|
435
|
+
* existing error path, and a host failure that arrives during a platform
|
|
436
|
+
* await keeps its original identity.
|
|
430
437
|
*/
|
|
431
438
|
function seek(tick) {
|
|
432
439
|
return enqueue(async () => {
|
|
@@ -480,7 +487,7 @@ export function createShow({
|
|
|
480
487
|
return state;
|
|
481
488
|
}
|
|
482
489
|
|
|
483
|
-
// A playing seek to the
|
|
490
|
+
// A playing seek to the effective end is the direct ENDED landing.
|
|
484
491
|
if (from === 'playing' && target === totalTicks) {
|
|
485
492
|
const now = seekClock('at the end seek');
|
|
486
493
|
origin = now - position;
|
|
@@ -489,8 +496,11 @@ export function createShow({
|
|
|
489
496
|
return state;
|
|
490
497
|
}
|
|
491
498
|
|
|
492
|
-
// Every
|
|
493
|
-
//
|
|
499
|
+
// Every non-playing row lands silently. The effective end is one
|
|
500
|
+
// terminal landing from every row: the show has stopped, the last frame
|
|
501
|
+
// stays, and no source or wake survives. A paused seek short of it is
|
|
502
|
+
// still the paused still frame; a press-to-resume seek keeps the owed
|
|
503
|
+
// gesture.
|
|
494
504
|
try {
|
|
495
505
|
await audio.suspend();
|
|
496
506
|
} catch (cause) {
|
|
@@ -501,12 +511,12 @@ export function createShow({
|
|
|
501
511
|
const now = seekClock('at the paused seek');
|
|
502
512
|
origin = now - position;
|
|
503
513
|
lastNow = now;
|
|
504
|
-
if (
|
|
505
|
-
announce('
|
|
514
|
+
if (target === totalTicks) {
|
|
515
|
+
announce('ended');
|
|
506
516
|
return state;
|
|
507
517
|
}
|
|
508
|
-
if (from === '
|
|
509
|
-
announce(
|
|
518
|
+
if (from === 'press-to-resume') {
|
|
519
|
+
announce('press-to-resume');
|
|
510
520
|
return state;
|
|
511
521
|
}
|
|
512
522
|
announce('paused');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "animader-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The animader command line: project creation, dev server, build, standalone export and host/project doctor checks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "CC0-1.0",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"animader": "0.
|
|
14
|
+
"animader": "0.6.0",
|
|
15
15
|
"esbuild": "0.24.2",
|
|
16
16
|
"@mr_hugo/pacer": "0.2.0",
|
|
17
|
-
"pngine": "4.
|
|
17
|
+
"pngine": "4.3.1"
|
|
18
18
|
},
|
|
19
19
|
"optionalDependencies": {
|
|
20
20
|
"@mr_hugo/pacer-darwin-arm64": "0.2.0",
|
|
21
|
-
"@pngine/darwin-arm64": "4.
|
|
21
|
+
"@pngine/darwin-arm64": "4.3.1"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"bin",
|
package/player/boot.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// One implementation, not two players: the transport, score compile, route
|
|
9
9
|
// pair and pngine wiring below are the same code on both spellings.
|
|
10
10
|
|
|
11
|
-
import { formatElapsed, formatPosition, readoutPieces } from './controller.mjs';
|
|
11
|
+
import { formatElapsed, formatPosition, readoutPieces, readResume, resumeKey, scoreSeconds, showEndSeconds, writeResume } from './controller.mjs';
|
|
12
12
|
|
|
13
13
|
const canvas = document.getElementById('canvas');
|
|
14
14
|
const performanceElement = document.getElementById('performance');
|
|
@@ -27,6 +27,8 @@ let context = null;
|
|
|
27
27
|
let port = null;
|
|
28
28
|
let stageScale = 1;
|
|
29
29
|
let hostSeconds = null;
|
|
30
|
+
let scoreEndSeconds = null;
|
|
31
|
+
let effectiveSeconds = null;
|
|
30
32
|
let decodedDuration = null;
|
|
31
33
|
let reflection = null;
|
|
32
34
|
let join = null;
|
|
@@ -53,6 +55,10 @@ let ShowErrorClass = Error;
|
|
|
53
55
|
const DEVICE_DESKTOP = Object.freeze({ presetLabel: 'Desktop · 1280×720', width: 1280, height: 720 });
|
|
54
56
|
const DEVICE_MOBILE = Object.freeze({ presetLabel: 'Mobile · 720×1280', width: 720, height: 1280 });
|
|
55
57
|
const SHOW_TICKS_PER_SECOND = 100;
|
|
58
|
+
// The states whose visible frame is a moment worth restoring. READY is the
|
|
59
|
+
// fresh page (a seek to 0 stays READY anyway); loading and error have no
|
|
60
|
+
// position to keep.
|
|
61
|
+
const RESUME_STATES = new Set(['playing', 'paused', 'press-to-resume', 'ended', 'stopped']);
|
|
56
62
|
let devicePreset = DEVICE_DESKTOP;
|
|
57
63
|
// The preset whose CSS box the stage is currently fitted to. It moves with
|
|
58
64
|
// setDeviceBox (before a flip settles) so an in-flight ResizeObserver callback
|
|
@@ -127,6 +133,60 @@ function renderChrome() {
|
|
|
127
133
|
if (chrome && show) chrome.render(show.state, show.tick);
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
function pageLocation() {
|
|
137
|
+
return window.location ?? globalThis.location ?? null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The session store, or null when the browser exposes or denies nothing. */
|
|
141
|
+
function resumeStorage() {
|
|
142
|
+
try {
|
|
143
|
+
return window.sessionStorage ?? globalThis.sessionStorage ?? null;
|
|
144
|
+
} catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Write the visible moment on the way out (pagehide, and the hidden edge as
|
|
151
|
+
* the belt for engines that skip it). Only the dev profile keeps a moment; a
|
|
152
|
+
* published player has no reload to survive.
|
|
153
|
+
*/
|
|
154
|
+
function rememberMoment(profile) {
|
|
155
|
+
if (profile.name !== 'dev' || !show || !RESUME_STATES.has(show.state)) return;
|
|
156
|
+
const location = pageLocation();
|
|
157
|
+
writeResume(resumeStorage(), resumeKey(location?.pathname ?? ''), show.tick);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The URL's `?t=<seconds>` moment in ticks, or null when malformed. */
|
|
161
|
+
function urlMoment(search) {
|
|
162
|
+
const raw = new URLSearchParams(search ?? '').get('t');
|
|
163
|
+
if (raw === null) return null;
|
|
164
|
+
const text = raw.trim();
|
|
165
|
+
if (!/^(?:\d+(?:\.\d*)?|\.\d+)$/.test(text)) return null;
|
|
166
|
+
const seconds = Number(text);
|
|
167
|
+
if (!Number.isFinite(seconds) || seconds < 0) return null;
|
|
168
|
+
return Math.round(seconds * SHOW_TICKS_PER_SECOND);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Bring the dev page back to the moment it left: the URL's shareable moment
|
|
173
|
+
* wins over the stored tick, and the show's own seek clamps at the effective
|
|
174
|
+
* end. A position short of the end is the paused still frame; the end itself
|
|
175
|
+
* is the show's terminal `ended` landing. Either way the show never starts or
|
|
176
|
+
* resumes here. The release profile never reads the store.
|
|
177
|
+
*/
|
|
178
|
+
async function restoreMoment(profile) {
|
|
179
|
+
if (profile.name !== 'dev' || !show || show.state === 'error') return null;
|
|
180
|
+
const location = pageLocation();
|
|
181
|
+
const fromUrl = urlMoment(location?.search ?? '');
|
|
182
|
+
const tick = fromUrl ?? readResume(resumeStorage(), resumeKey(location?.pathname ?? ''));
|
|
183
|
+
if (tick === null) return null;
|
|
184
|
+
const end = Number.isFinite(show.totalTicks) ? show.totalTicks : Infinity;
|
|
185
|
+
const target = Math.min(end, Math.max(0, Math.round(tick)));
|
|
186
|
+
await show.seek(target);
|
|
187
|
+
return target;
|
|
188
|
+
}
|
|
189
|
+
|
|
130
190
|
// The release player shows the musical position and the elapsed time and
|
|
131
191
|
// nothing else from the dev chrome. This mount fills the one shared #readout
|
|
132
192
|
// row the static markup already carries; it never creates a second element.
|
|
@@ -587,6 +647,8 @@ window.animaderDemo = Object.freeze({
|
|
|
587
647
|
get origin() { return show?.origin ?? null; },
|
|
588
648
|
get mode() { return activeProfile?.name ?? null; },
|
|
589
649
|
get hostSeconds() { return hostSeconds; },
|
|
650
|
+
get scoreSeconds() { return scoreEndSeconds; },
|
|
651
|
+
get effectiveSeconds() { return effectiveSeconds; },
|
|
590
652
|
get decodedDuration() { return decodedDuration; },
|
|
591
653
|
get audioContext() { return context; },
|
|
592
654
|
get audioContextState() { return context?.state ?? null; },
|
|
@@ -952,6 +1014,13 @@ async function load(controllerModule, profile) {
|
|
|
952
1014
|
: new TextEncoder().encode(scoreText).byteLength;
|
|
953
1015
|
join = loaded.join;
|
|
954
1016
|
metaSafe = jsonSafe(loaded.meta);
|
|
1017
|
+
// The score's own bars, integrated from its tempo map, bound the show: the
|
|
1018
|
+
// effective end is the shorter of the host policy and that score end, on the
|
|
1019
|
+
// show's 100-tick grid. One value feeds the show, the chrome's range and
|
|
1020
|
+
// readout, the release readout and the status, so no surface can disagree.
|
|
1021
|
+
scoreEndSeconds = scoreSeconds(metaSafe);
|
|
1022
|
+
effectiveSeconds = showEndSeconds(hostSeconds, metaSafe);
|
|
1023
|
+
controller.setSeconds(effectiveSeconds);
|
|
955
1024
|
hashes.score = await safeHash(loaded.score);
|
|
956
1025
|
|
|
957
1026
|
controller.setLoading('player');
|
|
@@ -977,7 +1046,7 @@ async function load(controllerModule, profile) {
|
|
|
977
1046
|
|
|
978
1047
|
controller.setLoading('audio decode');
|
|
979
1048
|
show = createShow({
|
|
980
|
-
seconds:
|
|
1049
|
+
seconds: effectiveSeconds,
|
|
981
1050
|
prepare: async () => ({
|
|
982
1051
|
driver: loaded.driver,
|
|
983
1052
|
player,
|
|
@@ -1006,7 +1075,7 @@ async function load(controllerModule, profile) {
|
|
|
1006
1075
|
);
|
|
1007
1076
|
}
|
|
1008
1077
|
decodedDuration = decoded.duration;
|
|
1009
|
-
const note = audioDurationNote(decoded.duration,
|
|
1078
|
+
const note = audioDurationNote(decoded.duration, effectiveSeconds);
|
|
1010
1079
|
if (note) controller.addNote(note);
|
|
1011
1080
|
return decoded;
|
|
1012
1081
|
},
|
|
@@ -1038,7 +1107,7 @@ async function load(controllerModule, profile) {
|
|
|
1038
1107
|
chrome = await profile.loadChrome?.({
|
|
1039
1108
|
host: document.getElementById('controls'),
|
|
1040
1109
|
readout: document.getElementById('readout'),
|
|
1041
|
-
seconds:
|
|
1110
|
+
seconds: effectiveSeconds,
|
|
1042
1111
|
meta: metaSafe,
|
|
1043
1112
|
decodedSeconds: decodedDuration,
|
|
1044
1113
|
device: devicePreset,
|
|
@@ -1050,6 +1119,12 @@ async function load(controllerModule, profile) {
|
|
|
1050
1119
|
}
|
|
1051
1120
|
}
|
|
1052
1121
|
|
|
1122
|
+
// The dev page comes back at the moment it left (a rebuild reload
|
|
1123
|
+
// included), paused and never playing. The chrome is already mounted, so
|
|
1124
|
+
// the restored tick is painted by the same render path. The release profile
|
|
1125
|
+
// has nothing to restore.
|
|
1126
|
+
if (show.state !== 'error') await restoreMoment(profile);
|
|
1127
|
+
|
|
1053
1128
|
// The release player carries the readout row and nothing else from the
|
|
1054
1129
|
// chrome. It mounts on the same static element the dev chrome owns, and the
|
|
1055
1130
|
// release entry is untouched: boot already knows the profile.
|
|
@@ -1061,7 +1136,7 @@ async function load(controllerModule, profile) {
|
|
|
1061
1136
|
elapsed: document.getElementById('readout-elapsed'),
|
|
1062
1137
|
show,
|
|
1063
1138
|
meta: metaSafe,
|
|
1064
|
-
seconds:
|
|
1139
|
+
seconds: effectiveSeconds,
|
|
1065
1140
|
formatPosition,
|
|
1066
1141
|
formatElapsed,
|
|
1067
1142
|
});
|
|
@@ -1101,6 +1176,12 @@ export async function boot(profile) {
|
|
|
1101
1176
|
view,
|
|
1102
1177
|
seconds: null,
|
|
1103
1178
|
fullscreenAvailable: Boolean(document.fullscreenEnabled),
|
|
1179
|
+
// The score metadata is only known after the compile; the getter keeps the
|
|
1180
|
+
// controller current without rebuilding it. Position and the host end are
|
|
1181
|
+
// the show's own clock values, read at the key press.
|
|
1182
|
+
meta: () => metaSafe,
|
|
1183
|
+
position: () => (show ? show.tick : 0),
|
|
1184
|
+
totalTicks: () => (show ? show.totalTicks : undefined),
|
|
1104
1185
|
});
|
|
1105
1186
|
|
|
1106
1187
|
// A rejecting action must be observable: route it through the page's
|
|
@@ -1120,8 +1201,10 @@ export async function boot(profile) {
|
|
|
1120
1201
|
controller.handleKey(event);
|
|
1121
1202
|
});
|
|
1122
1203
|
document.addEventListener('visibilitychange', () => {
|
|
1204
|
+
if (document.hidden) rememberMoment(profile);
|
|
1123
1205
|
void controller.setVisibility(document.hidden);
|
|
1124
1206
|
});
|
|
1207
|
+
window.addEventListener('pagehide', () => rememberMoment(profile));
|
|
1125
1208
|
document.addEventListener('fullscreenchange', () => {
|
|
1126
1209
|
updateStageScale();
|
|
1127
1210
|
syncFullscreenLabel();
|