canvas-recorder-lib 0.5.0 → 0.7.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.
Files changed (347) hide show
  1. package/BREAKING-CHANGES.md +24 -0
  2. package/README.md +131 -25
  3. package/dev/audio-builder.ts +69 -161
  4. package/dev/canvas-recorder.css +59 -0
  5. package/dev/canvas-recorder.ts +1006 -212
  6. package/dev/delay-files.ts +1 -1
  7. package/dev/font-utils.ts +8 -1
  8. package/dev/format-editor.ts +734 -0
  9. package/dev/format-string.ts +110 -0
  10. package/dev/local-file-row.ts +107 -0
  11. package/dev/multi-text-dialog.ts +360 -0
  12. package/dev/multi-text-panel.ts +11 -0
  13. package/dev/player-body.ts +94 -6
  14. package/dev/rect-snap.ts +9 -9
  15. package/dev/slide-panel.ts +1 -1
  16. package/dev/sound-clips.ts +3 -2
  17. package/dev/soundtrack.ts +434 -0
  18. package/dev/split-dialog.ts +13 -2
  19. package/dev/static-image-panel.ts +35 -5
  20. package/dev/timeline-display.ts +50 -5
  21. package/dev/transcripts.ts +5 -3
  22. package/dev/video-clip-panel.ts +202 -16
  23. package/dev/voice/chirp.ts +129 -0
  24. package/dev/voice/folder.ts +84 -0
  25. package/dev/voice/voice-panel.ts +513 -0
  26. package/dev/voice/voice-recorder.ts +603 -0
  27. package/dist/dev/audio-builder.d.ts +14 -31
  28. package/dist/dev/audio-builder.d.ts.map +1 -1
  29. package/dist/dev/audio-builder.js +62 -134
  30. package/dist/dev/audio-builder.js.map +1 -1
  31. package/dist/dev/canvas-recorder.css +59 -0
  32. package/dist/dev/canvas-recorder.js +926 -198
  33. package/dist/dev/canvas-recorder.js.map +1 -1
  34. package/dist/dev/delay-files.js +1 -1
  35. package/dist/dev/delay-files.js.map +1 -1
  36. package/dist/dev/font-utils.d.ts.map +1 -1
  37. package/dist/dev/font-utils.js +9 -1
  38. package/dist/dev/font-utils.js.map +1 -1
  39. package/dist/dev/format-editor.d.ts +75 -0
  40. package/dist/dev/format-editor.d.ts.map +1 -0
  41. package/dist/dev/format-editor.js +642 -0
  42. package/dist/dev/format-editor.js.map +1 -0
  43. package/dist/dev/format-string.d.ts +62 -0
  44. package/dist/dev/format-string.d.ts.map +1 -0
  45. package/dist/dev/format-string.js +86 -0
  46. package/dist/dev/format-string.js.map +1 -0
  47. package/dist/dev/local-file-row.d.ts +22 -0
  48. package/dist/dev/local-file-row.d.ts.map +1 -0
  49. package/dist/dev/local-file-row.js +84 -0
  50. package/dist/dev/local-file-row.js.map +1 -0
  51. package/dist/dev/multi-text-dialog.d.ts +30 -0
  52. package/dist/dev/multi-text-dialog.d.ts.map +1 -0
  53. package/dist/dev/multi-text-dialog.js +297 -0
  54. package/dist/dev/multi-text-dialog.js.map +1 -0
  55. package/dist/dev/multi-text-panel.d.ts +2 -0
  56. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  57. package/dist/dev/multi-text-panel.js +4 -0
  58. package/dist/dev/multi-text-panel.js.map +1 -1
  59. package/dist/dev/player-body.d.ts +1 -1
  60. package/dist/dev/player-body.d.ts.map +1 -1
  61. package/dist/dev/player-body.js +94 -6
  62. package/dist/dev/player-body.js.map +1 -1
  63. package/dist/dev/rect-snap.d.ts +1 -1
  64. package/dist/dev/rect-snap.js +7 -7
  65. package/dist/dev/rect-snap.js.map +1 -1
  66. package/dist/dev/slide-panel.d.ts +1 -1
  67. package/dist/dev/slide-panel.d.ts.map +1 -1
  68. package/dist/dev/slide-panel.js +1 -1
  69. package/dist/dev/slide-panel.js.map +1 -1
  70. package/dist/dev/sound-clips.d.ts +3 -2
  71. package/dist/dev/sound-clips.d.ts.map +1 -1
  72. package/dist/dev/sound-clips.js +3 -2
  73. package/dist/dev/sound-clips.js.map +1 -1
  74. package/dist/dev/soundtrack.d.ts +115 -0
  75. package/dist/dev/soundtrack.d.ts.map +1 -0
  76. package/dist/dev/soundtrack.js +369 -0
  77. package/dist/dev/soundtrack.js.map +1 -0
  78. package/dist/dev/split-dialog.d.ts.map +1 -1
  79. package/dist/dev/split-dialog.js +14 -2
  80. package/dist/dev/split-dialog.js.map +1 -1
  81. package/dist/dev/static-image-panel.d.ts +2 -0
  82. package/dist/dev/static-image-panel.d.ts.map +1 -1
  83. package/dist/dev/static-image-panel.js +29 -5
  84. package/dist/dev/static-image-panel.js.map +1 -1
  85. package/dist/dev/timeline-display.d.ts +23 -2
  86. package/dist/dev/timeline-display.d.ts.map +1 -1
  87. package/dist/dev/timeline-display.js +47 -5
  88. package/dist/dev/timeline-display.js.map +1 -1
  89. package/dist/dev/transcripts.d.ts.map +1 -1
  90. package/dist/dev/transcripts.js +5 -3
  91. package/dist/dev/transcripts.js.map +1 -1
  92. package/dist/dev/video-clip-panel.d.ts +8 -0
  93. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  94. package/dist/dev/video-clip-panel.js +176 -10
  95. package/dist/dev/video-clip-panel.js.map +1 -1
  96. package/dist/dev/voice/chirp.d.ts +27 -0
  97. package/dist/dev/voice/chirp.d.ts.map +1 -0
  98. package/dist/dev/voice/chirp.js +107 -0
  99. package/dist/dev/voice/chirp.js.map +1 -0
  100. package/dist/dev/voice/folder.d.ts +18 -0
  101. package/dist/dev/voice/folder.d.ts.map +1 -0
  102. package/dist/dev/voice/folder.js +68 -0
  103. package/dist/dev/voice/folder.js.map +1 -0
  104. package/dist/dev/voice/voice-panel.d.ts +44 -0
  105. package/dist/dev/voice/voice-panel.d.ts.map +1 -0
  106. package/dist/dev/voice/voice-panel.js +418 -0
  107. package/dist/dev/voice/voice-panel.js.map +1 -0
  108. package/dist/dev/voice/voice-recorder.d.ts +141 -0
  109. package/dist/dev/voice/voice-recorder.d.ts.map +1 -0
  110. package/dist/dev/voice/voice-recorder.js +506 -0
  111. package/dist/dev/voice/voice-recorder.js.map +1 -0
  112. package/dist/lib/index.d.ts +3 -0
  113. package/dist/lib/index.d.ts.map +1 -1
  114. package/dist/lib/index.js +3 -0
  115. package/dist/lib/index.js.map +1 -1
  116. package/dist/lib/main-control.d.ts +50 -4
  117. package/dist/lib/main-control.d.ts.map +1 -1
  118. package/dist/lib/main-control.js +94 -12
  119. package/dist/lib/main-control.js.map +1 -1
  120. package/dist/src/binary-search.js +1 -1
  121. package/dist/src/binary-search.js.map +1 -1
  122. package/dist/src/corner-rounder.d.ts +17 -0
  123. package/dist/src/corner-rounder.d.ts.map +1 -0
  124. package/dist/src/corner-rounder.js +89 -0
  125. package/dist/src/corner-rounder.js.map +1 -0
  126. package/dist/src/cross-fade.d.ts +1 -1
  127. package/dist/src/cross-fade.d.ts.map +1 -1
  128. package/dist/src/cross-fade.js +3 -3
  129. package/dist/src/cross-fade.js.map +1 -1
  130. package/dist/src/fancy-text.d.ts +116 -0
  131. package/dist/src/fancy-text.d.ts.map +1 -0
  132. package/dist/src/fancy-text.js +211 -0
  133. package/dist/src/fancy-text.js.map +1 -0
  134. package/dist/src/glib/letters-base.d.ts +1 -1
  135. package/dist/src/glib/letters-base.d.ts.map +1 -1
  136. package/dist/src/glib/letters-base.js +4 -3
  137. package/dist/src/glib/letters-base.js.map +1 -1
  138. package/dist/src/glib/line-font.d.ts +2 -2
  139. package/dist/src/glib/line-font.d.ts.map +1 -1
  140. package/dist/src/glib/line-font.js +2 -2
  141. package/dist/src/glib/line-font.js.map +1 -1
  142. package/dist/src/glib/paragraph-layout.d.ts +2 -2
  143. package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
  144. package/dist/src/glib/paragraph-layout.js +1 -1
  145. package/dist/src/glib/paragraph-layout.js.map +1 -1
  146. package/dist/src/glib/path-shape-splitter.d.ts +1 -1
  147. package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
  148. package/dist/src/glib/path-shape-splitter.js +1 -1
  149. package/dist/src/glib/path-shape-splitter.js.map +1 -1
  150. package/dist/src/glib/path-shape.js +2 -2
  151. package/dist/src/glib/path-shape.js.map +1 -1
  152. package/dist/src/interpolate.d.ts +2 -2
  153. package/dist/src/interpolate.d.ts.map +1 -1
  154. package/dist/src/interpolate.js +1 -1
  155. package/dist/src/interpolate.js.map +1 -1
  156. package/dist/src/lattice.d.ts +1 -1
  157. package/dist/src/lattice.d.ts.map +1 -1
  158. package/dist/src/local-files.d.ts +129 -0
  159. package/dist/src/local-files.d.ts.map +1 -0
  160. package/dist/src/local-files.js +327 -0
  161. package/dist/src/local-files.js.map +1 -0
  162. package/dist/src/morph-animation.d.ts +1 -1
  163. package/dist/src/morph-animation.d.ts.map +1 -1
  164. package/dist/src/morph-animation.js +2 -2
  165. package/dist/src/morph-animation.js.map +1 -1
  166. package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
  167. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  168. package/dist/src/peano-fourier/fourier-shared.js +17 -4
  169. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  170. package/dist/src/schedule-helper.d.ts +4 -4
  171. package/dist/src/schedule-helper.d.ts.map +1 -1
  172. package/dist/src/schedule-helper.js +2 -2
  173. package/dist/src/schedule-helper.js.map +1 -1
  174. package/dist/src/showable.d.ts +45 -4
  175. package/dist/src/showable.d.ts.map +1 -1
  176. package/dist/src/showable.js +37 -1
  177. package/dist/src/showable.js.map +1 -1
  178. package/dist/src/slide-components/arrow.d.ts +4 -4
  179. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  180. package/dist/src/slide-components/arrow.js +2 -2
  181. package/dist/src/slide-components/arrow.js.map +1 -1
  182. package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
  183. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  184. package/dist/src/slide-components/cross-fade-transition.js +3 -3
  185. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  186. package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
  187. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  188. package/dist/src/slide-components/duration-agnostic.js +1 -1
  189. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  190. package/dist/src/slide-components/fixed-duration.d.ts +1 -1
  191. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  192. package/dist/src/slide-components/fixed-duration.js +1 -1
  193. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  194. package/dist/src/slide-components/fourier.d.ts +6 -6
  195. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  196. package/dist/src/slide-components/fourier.js +6 -6
  197. package/dist/src/slide-components/fourier.js.map +1 -1
  198. package/dist/src/slide-components/frame-counter.d.ts +2 -2
  199. package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
  200. package/dist/src/slide-components/frame-counter.js +1 -1
  201. package/dist/src/slide-components/frame-counter.js.map +1 -1
  202. package/dist/src/slide-components/function-graph.d.ts +2 -2
  203. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  204. package/dist/src/slide-components/function-graph.js +3 -3
  205. package/dist/src/slide-components/function-graph.js.map +1 -1
  206. package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
  207. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  208. package/dist/src/slide-components/halftone-shadow.js +2 -2
  209. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  210. package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
  211. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  212. package/dist/src/slide-components/handwriting-effect.js +5 -5
  213. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  214. package/dist/src/slide-components/hold.d.ts +3 -3
  215. package/dist/src/slide-components/hold.d.ts.map +1 -1
  216. package/dist/src/slide-components/hold.js +3 -3
  217. package/dist/src/slide-components/hold.js.map +1 -1
  218. package/dist/src/slide-components/image.d.ts +3 -3
  219. package/dist/src/slide-components/image.d.ts.map +1 -1
  220. package/dist/src/slide-components/image.js +3 -3
  221. package/dist/src/slide-components/image.js.map +1 -1
  222. package/dist/src/slide-components/in-parallel.d.ts +3 -3
  223. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  224. package/dist/src/slide-components/in-parallel.js +2 -2
  225. package/dist/src/slide-components/in-parallel.js.map +1 -1
  226. package/dist/src/slide-components/in-series.d.ts +4 -4
  227. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  228. package/dist/src/slide-components/in-series.js +5 -1
  229. package/dist/src/slide-components/in-series.js.map +1 -1
  230. package/dist/src/slide-components/live-duration.d.ts +1 -1
  231. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  232. package/dist/src/slide-components/live-duration.js +1 -1
  233. package/dist/src/slide-components/live-duration.js.map +1 -1
  234. package/dist/src/slide-components/multi-text.d.ts +76 -15
  235. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  236. package/dist/src/slide-components/multi-text.js +170 -25
  237. package/dist/src/slide-components/multi-text.js.map +1 -1
  238. package/dist/src/slide-components/rectangle.d.ts +3 -3
  239. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  240. package/dist/src/slide-components/rectangle.js +1 -1
  241. package/dist/src/slide-components/rectangle.js.map +1 -1
  242. package/dist/src/slide-components/registry.d.ts +1 -1
  243. package/dist/src/slide-components/registry.d.ts.map +1 -1
  244. package/dist/src/slide-components/registry.js +18 -18
  245. package/dist/src/slide-components/registry.js.map +1 -1
  246. package/dist/src/slide-components/serialize.d.ts +1 -1
  247. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  248. package/dist/src/slide-components/serialize.js +2 -2
  249. package/dist/src/slide-components/serialize.js.map +1 -1
  250. package/dist/src/slide-components/show-error.js +2 -2
  251. package/dist/src/slide-components/show-error.js.map +1 -1
  252. package/dist/src/slide-components/simple-text.d.ts +4 -4
  253. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  254. package/dist/src/slide-components/simple-text.js +4 -4
  255. package/dist/src/slide-components/simple-text.js.map +1 -1
  256. package/dist/src/slide-components/slide-component.d.ts +5 -5
  257. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  258. package/dist/src/slide-components/slide-component.js +4 -4
  259. package/dist/src/slide-components/slide-component.js.map +1 -1
  260. package/dist/src/slide-components/slide-left.d.ts +3 -3
  261. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  262. package/dist/src/slide-components/slide-left.js +3 -3
  263. package/dist/src/slide-components/slide-left.js.map +1 -1
  264. package/dist/src/slide-components/split-video-clip.d.ts +2 -2
  265. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  266. package/dist/src/slide-components/split-video-clip.js +3 -3
  267. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  268. package/dist/src/slide-components/text-effect.d.ts +2 -2
  269. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  270. package/dist/src/slide-components/traditional-text.d.ts +4 -4
  271. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  272. package/dist/src/slide-components/traditional-text.js +3 -3
  273. package/dist/src/slide-components/traditional-text.js.map +1 -1
  274. package/dist/src/slide-components/video-clip.d.ts +17 -5
  275. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  276. package/dist/src/slide-components/video-clip.js +52 -11
  277. package/dist/src/slide-components/video-clip.js.map +1 -1
  278. package/dist/src/slide-components/video-info.d.ts +11 -11
  279. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  280. package/dist/src/slide-components/video-info.js +32 -21
  281. package/dist/src/slide-components/video-info.js.map +1 -1
  282. package/dist/src/slow-image-sources.d.ts +7 -1
  283. package/dist/src/slow-image-sources.d.ts.map +1 -1
  284. package/dist/src/slow-image-sources.js +36 -5
  285. package/dist/src/slow-image-sources.js.map +1 -1
  286. package/dist/src/snapshot.d.ts +2 -2
  287. package/dist/src/snapshot.d.ts.map +1 -1
  288. package/dist/src/snapshot.js +31 -15
  289. package/dist/src/snapshot.js.map +1 -1
  290. package/dist/src/stroke-colors.d.ts +1 -1
  291. package/dist/src/stroke-colors.d.ts.map +1 -1
  292. package/dist/src/stroke-colors.js +4 -4
  293. package/dist/src/stroke-colors.js.map +1 -1
  294. package/dist/src/utility.d.ts +3 -4
  295. package/dist/src/utility.d.ts.map +1 -1
  296. package/dist/src/utility.js +4 -4
  297. package/dist/src/utility.js.map +1 -1
  298. package/lib/index.ts +3 -0
  299. package/lib/main-control.ts +119 -12
  300. package/package.json +7 -5
  301. package/src/binary-search.ts +2 -2
  302. package/src/corner-rounder.ts +128 -0
  303. package/src/cross-fade.ts +3 -3
  304. package/src/fancy-text.ts +255 -0
  305. package/src/glib/letters-base.ts +4 -3
  306. package/src/glib/line-font.ts +2 -2
  307. package/src/glib/paragraph-layout.ts +2 -2
  308. package/src/glib/path-shape-splitter.ts +1 -1
  309. package/src/glib/path-shape.ts +2 -2
  310. package/src/interpolate.ts +3 -3
  311. package/src/lattice.ts +1 -1
  312. package/src/local-files.ts +389 -0
  313. package/src/morph-animation.ts +2 -2
  314. package/src/peano-fourier/fourier-shared.ts +17 -4
  315. package/src/schedule-helper.ts +4 -4
  316. package/src/showable.ts +63 -4
  317. package/src/slide-components/arrow.ts +4 -4
  318. package/src/slide-components/cross-fade-transition.ts +4 -4
  319. package/src/slide-components/duration-agnostic.ts +3 -3
  320. package/src/slide-components/fixed-duration.ts +1 -1
  321. package/src/slide-components/fourier.ts +9 -9
  322. package/src/slide-components/frame-counter.ts +2 -2
  323. package/src/slide-components/function-graph.ts +4 -4
  324. package/src/slide-components/halftone-shadow.ts +4 -4
  325. package/src/slide-components/handwriting-effect.ts +7 -7
  326. package/src/slide-components/hold.ts +4 -4
  327. package/src/slide-components/image.ts +5 -5
  328. package/src/slide-components/in-parallel.ts +4 -4
  329. package/src/slide-components/in-series.ts +7 -4
  330. package/src/slide-components/live-duration.ts +1 -1
  331. package/src/slide-components/multi-text.ts +195 -30
  332. package/src/slide-components/rectangle.ts +3 -3
  333. package/src/slide-components/registry.ts +19 -19
  334. package/src/slide-components/serialize.ts +2 -2
  335. package/src/slide-components/show-error.ts +2 -2
  336. package/src/slide-components/simple-text.ts +7 -7
  337. package/src/slide-components/slide-component.ts +7 -7
  338. package/src/slide-components/slide-left.ts +4 -4
  339. package/src/slide-components/split-video-clip.ts +4 -4
  340. package/src/slide-components/text-effect.ts +2 -2
  341. package/src/slide-components/traditional-text.ts +5 -5
  342. package/src/slide-components/video-clip.ts +64 -13
  343. package/src/slide-components/video-info.ts +33 -21
  344. package/src/slow-image-sources.ts +38 -6
  345. package/src/snapshot.ts +34 -19
  346. package/src/stroke-colors.ts +4 -4
  347. package/src/utility.ts +5 -5
@@ -1,4 +1,4 @@
1
- // Generated by scripts/import-from-canvas-recorder.mjs from canvas-recorder.html. Do not edit.
1
+ // Originally generated from canvas-recorder's canvas-recorder.html. This is the master copy now.
2
2
 
3
3
  /** The contents of the player's `<body>`. {@link canvasRecorder.start} puts this in the page. */
4
4
  export const playerBodyHtml = `
@@ -16,6 +16,29 @@ export const playerBodyHtml = `
16
16
  <option value="2.00">200%</option>
17
17
  </select>
18
18
  </label>
19
+ <span
20
+ id="videoSizeControls"
21
+ style="white-space: nowrap"
22
+ title="The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video."
23
+ >Size:
24
+ <input type="number" id="videoPixelWidth" min="2" step="2" style="width: 4.5em" />
25
+ ×
26
+ <input type="number" id="videoPixelHeight" min="2" step="2" style="width: 4.5em" />
27
+ px,
28
+ <input type="number" id="videoUnitWidth" min="0" step="any" style="width: 3.5em" />
29
+ ×
30
+ <input type="number" id="videoUnitHeight" min="0" step="any" style="width: 3.5em" />
31
+ units
32
+ <span id="videoSizeWarning" style="color: #a06000"></span>
33
+ </span>
34
+ <button
35
+ type="button"
36
+ id="localFilesBtn"
37
+ hidden
38
+ title="Some of this video's files are on your computer, and the browser needs your OK before it reads them again."
39
+ >
40
+ 🔓 Allow local files
41
+ </button>
19
42
  <button type="button" id="loadJsonTestBtn">📂 Import</button>
20
43
  <!-- Each status is outside its label: clicking inside a label
21
44
  toggles the checkbox, and a status can hold buttons. -->
@@ -100,7 +123,12 @@ export const playerBodyHtml = `
100
123
  />Repeat</label
101
124
  >)&nbsp;</span
102
125
  >
103
- <input type="number" id="playPositionSeconds" value="0" />
126
+ <input
127
+ type="number"
128
+ id="playPositionSeconds"
129
+ value="0"
130
+ title="The play position, in seconds. Option-← and Option-→ step one frame."
131
+ />
104
132
  <input type="range" id="playPositionRange" value="0" step="any" />
105
133
  </div>
106
134
  </fieldset>
@@ -163,8 +191,16 @@ export const playerBodyHtml = `
163
191
  <option value="2">2×</option>
164
192
  </select>
165
193
  </label>
194
+ <button
195
+ type="button"
196
+ id="recordModeBtn"
197
+ title="Show or hide the voice recorder. It turns the mic on while it's showing."
198
+ >
199
+ 🎙 Record mode
200
+ </button>
166
201
  </div>
167
202
  </fieldset>
203
+ <div id="voicePanelHolder"></div>
168
204
  <div
169
205
  style="
170
206
  border: 0.3em inset rgb(178, 178, 178);
@@ -177,10 +213,16 @@ export const playerBodyHtml = `
177
213
  <button id="recordJustSound">Record Just Sound</button>
178
214
  <div id="info"><i>status goes here</i>...</div>
179
215
  </div>
180
- <p>
181
- Hot keys: ⌥Space to play/pause. ⌥B to go back 5 seconds and play. ⌥0
182
- to jump to the start of the current section. Alt instead of ⌥ on a PC.
183
- </p>
216
+ <div style="margin: 1em 0">
217
+ Hot keys:
218
+ <ul style="margin: 0">
219
+ <li>⌥Space to play or pause.</li>
220
+ <li>⌥B to go back 5 seconds and play.</li>
221
+ <li>⌥0 to jump to the start of the current section.</li>
222
+ <li>⌥← and ⌥→ to step one frame back or forward.</li>
223
+ </ul>
224
+ Alt instead of ⌥ on a PC.
225
+ </div>
184
226
  <br />
185
227
  <h1>Debug Log</h1>
186
228
  <button id="debugLogClearBtn" type="button">Clear</button>
@@ -343,6 +385,44 @@ export const playerBodyHtml = `
343
385
  />
344
386
  </label>
345
387
  </div>
388
+ <div style="margin-bottom: 0.6em">
389
+ <label
390
+ >Size:
391
+ <input
392
+ type="number"
393
+ id="saveWidth"
394
+ min="2"
395
+ step="2"
396
+ style="width: 6em"
397
+ />
398
+ </label>
399
+ ×
400
+ <label
401
+ ><input
402
+ type="number"
403
+ id="saveHeight"
404
+ min="2"
405
+ step="2"
406
+ style="width: 6em"
407
+ />
408
+ px</label
409
+ >
410
+ &nbsp;
411
+ <label
412
+ title="Change the other number to match, keeping the video's shape. Uncheck to stretch or squish the picture."
413
+ ><input type="checkbox" id="saveKeepAspect" checked /> Keep aspect
414
+ ratio</label
415
+ >
416
+ &nbsp;
417
+ <button
418
+ type="button"
419
+ id="saveVideoSizeBtn"
420
+ title="Use the video's own size."
421
+ >
422
+ Video size
423
+ </button>
424
+ <div id="saveSizeNote" style="font-size: 0.85em; min-height: 1.2em"></div>
425
+ </div>
346
426
  <table style="margin-bottom: 0.75em; border-collapse: collapse">
347
427
  <tr>
348
428
  <td>Start:</td>
@@ -373,6 +453,14 @@ export const playerBodyHtml = `
373
453
  ></td>
374
454
  </tr>
375
455
  </table>
456
+ <div
457
+ id="saveLocalFilesRow"
458
+ hidden
459
+ style="margin-bottom: 0.6em; color: #a06000"
460
+ >
461
+ <span id="saveLocalFilesNote"></span>
462
+ <button type="button" id="saveLocalFilesBtn">🔓 Allow</button>
463
+ </div>
376
464
  <div>
377
465
  <button type="button" id="saveOkBtn">OK — Choose File</button>
378
466
  &nbsp;
package/dev/rect-snap.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ReadOnlyRect } from "phil-lib/misc";
2
2
  import {
3
- CANVAS_HEIGHT_UNITS,
4
- CANVAS_WIDTH_UNITS,
3
+ canvasHeightUnits,
4
+ canvasWidthUnits,
5
5
  } from "../src/slide-components/video-info.ts";
6
6
 
7
7
  /**
8
8
  * One button that moves or stretches a rectangle to the canvas.
9
9
  *
10
- * The canvas is taken to be the 16×9 the component draws into, which is true
10
+ * The canvas is taken to be the whole drawing area (see canvasRecorder.width), which is true
11
11
  * unless it sits inside a transformed parent like a Slide.
12
12
  */
13
13
  export type RectSnap = {
@@ -28,12 +28,12 @@ export const ALIGN_HORIZONTALLY: readonly RectSnap[] = [
28
28
  {
29
29
  text: "⇆",
30
30
  title: "Center horizontally on the canvas",
31
- place: (r) => ({ ...r, x: (CANVAS_WIDTH_UNITS - r.width) / 2 }),
31
+ place: (r) => ({ ...r, x: (canvasWidthUnits() - r.width) / 2 }),
32
32
  },
33
33
  {
34
34
  text: "⇥",
35
35
  title: "Move the right edge to the right of the canvas",
36
- place: (r) => ({ ...r, x: CANVAS_WIDTH_UNITS - r.width }),
36
+ place: (r) => ({ ...r, x: canvasWidthUnits() - r.width }),
37
37
  },
38
38
  ];
39
39
 
@@ -47,12 +47,12 @@ export const ALIGN_VERTICALLY: readonly RectSnap[] = [
47
47
  {
48
48
  text: "⇵",
49
49
  title: "Center vertically on the canvas",
50
- place: (r) => ({ ...r, y: (CANVAS_HEIGHT_UNITS - r.height) / 2 }),
50
+ place: (r) => ({ ...r, y: (canvasHeightUnits() - r.height) / 2 }),
51
51
  },
52
52
  {
53
53
  text: "⤓",
54
54
  title: "Move the bottom edge to the bottom of the canvas",
55
- place: (r) => ({ ...r, y: CANVAS_HEIGHT_UNITS - r.height }),
55
+ place: (r) => ({ ...r, y: canvasHeightUnits() - r.height }),
56
56
  },
57
57
  ];
58
58
 
@@ -61,12 +61,12 @@ export const STRETCH_TO_CANVAS: readonly RectSnap[] = [
61
61
  {
62
62
  text: "↔",
63
63
  title: "Stretch across the full width of the canvas",
64
- place: (r) => ({ ...r, x: 0, width: CANVAS_WIDTH_UNITS }),
64
+ place: (r) => ({ ...r, x: 0, width: canvasWidthUnits() }),
65
65
  },
66
66
  {
67
67
  text: "↕",
68
68
  title: "Stretch across the full height of the canvas",
69
- place: (r) => ({ ...r, y: 0, height: CANVAS_HEIGHT_UNITS }),
69
+ place: (r) => ({ ...r, y: 0, height: canvasHeightUnits() }),
70
70
  },
71
71
  ];
72
72
 
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SlideComponent,
3
3
  TRANSFORM_PLACEHOLDERS,
4
- } from "../src/slide-components/slide-component";
4
+ } from "../src/slide-components/slide-component.ts";
5
5
 
6
6
  /**
7
7
  * Build the Transform Info panel shown at the top of the schedule editor
@@ -26,8 +26,9 @@ function displayName(showable: Showable): string {
26
26
 
27
27
  /**
28
28
  * Every Showable under `root` (including `root`) whose `soundClips` is
29
- * defined, in tree order. That's what makes a Showable a place a sound can
30
- * live, even when its list is empty.
29
+ * defined, in tree order. Any Showable can hold sounds, but these are the
30
+ * ones that have a list, usually because they have, or had, a clip.
31
+ * That keeps the Owner menus short.
31
32
  *
32
33
  * This is the same walk the audio builder does, so the start times agree with
33
34
  * what you hear. A Showable that appears more than once in the tree is listed
@@ -0,0 +1,434 @@
1
+ /**
2
+ * The video's sound, live: every sound clip in the tree, each played by its own
3
+ * `AudioBufferSourceNode`, mixed by the browser.
4
+ *
5
+ * - **Decoded files are kept** for the life of the page, mixed down to mono.
6
+ * An edit never fetches or decodes a file again.
7
+ * - **An edit only touches the clips it changed.** {@link Soundtrack.request} is
8
+ * cheap enough to call on every mouse move: when no clip moved, it does nothing,
9
+ * and otherwise it replaces only the nodes whose clips changed. Everything else
10
+ * keeps playing, sample for sample.
11
+ * - **A file that isn't decoded yet doesn't hold anything up.** Its clips join in
12
+ * when it's ready.
13
+ * - **The saved video gets one mixed buffer,** from {@link Soundtrack.mix}, after
14
+ * {@link Soundtrack.ready}.
15
+ *
16
+ * The clock belongs to the player. It says where the video is with an
17
+ * {@link Anchor}, and this follows.
18
+ *
19
+ * See development-plans/live-sound-mixing.md.
20
+ * @module
21
+ */
22
+
23
+ import { debugLog } from "../src/debug-log.ts";
24
+ import { fetchMedia } from "../src/local-files.ts";
25
+ import { Showable } from "../src/showable.ts";
26
+ import { AudioBuilder } from "./audio-builder.ts";
27
+
28
+ /**
29
+ * Every file is decoded at this rate, and the saved video's sound uses it too.
30
+ * So do the player's AudioContext and the voice recorder.
31
+ */
32
+ export const SAMPLE_RATE = 48000;
33
+
34
+ /**
35
+ * How far ahead a change while playing takes effect, in seconds.
36
+ * The old node stops and the new one starts at the same moment, so both requests
37
+ * must reach the audio thread before that moment comes.
38
+ */
39
+ const SWAP_AHEAD_S = 0.03;
40
+
41
+ /** One sound clip, in the video's time. */
42
+ export type PlacedSoundClip = {
43
+ readonly source: string;
44
+ /** When the clip starts, in ms from the start of the video. Can be negative. */
45
+ readonly startMs: number;
46
+ /** Where in the file to start, in ms. Negative means silence first. */
47
+ readonly trimMs: number;
48
+ /** How much to play. Infinity plays to the end of the file. */
49
+ readonly lengthMs: number;
50
+ };
51
+
52
+ /**
53
+ * Every sound clip in the tree, in the video's time. Read only.
54
+ *
55
+ * A clip with no source yet is left out: a brand new clip, or a URL that's still
56
+ * being typed.
57
+ */
58
+ export function collectSoundClips(root: Showable): PlacedSoundClip[] {
59
+ const result: PlacedSoundClip[] = [];
60
+ function walk(item: Showable, offset: number) {
61
+ for (const clip of item.soundClips ?? []) {
62
+ if (clip.source === "") continue;
63
+ result.push({
64
+ source: clip.source,
65
+ startMs: offset + clip.startMsIntoScene,
66
+ trimMs: clip.startMsIntoClip ?? 0,
67
+ lengthMs: clip.lengthMs ?? Infinity,
68
+ });
69
+ }
70
+ for (const { child, start } of item.children ?? []) {
71
+ walk(child, offset + start);
72
+ }
73
+ }
74
+ walk(root, 0);
75
+ return result;
76
+ }
77
+
78
+ /**
79
+ * Where the video is: at `contextTime`, in the audio context's clock, the video
80
+ * is at `mediaMs`, moving at `rate`.
81
+ */
82
+ export type Anchor = {
83
+ readonly contextTime: number;
84
+ readonly mediaMs: number;
85
+ readonly rate: number;
86
+ };
87
+
88
+ type PlayingNode = {
89
+ readonly node: AudioBufferSourceNode;
90
+ /** Which clip this plays. See {@link Soundtrack.#keyOf}. */
91
+ readonly key: string;
92
+ /** The {@link Soundtrack.#anchorVersion} it was scheduled for. */
93
+ readonly anchorVersion: number;
94
+ };
95
+
96
+ export type SoundtrackOptions = {
97
+ /** Where the clips play. An `OfflineAudioContext` works too, for testing. */
98
+ readonly context: BaseAudioContext;
99
+ /** Usually a gain node, for the volume and mute controls. */
100
+ readonly destination: AudioNode;
101
+ /** The whole video. Read on every {@link Soundtrack.request}. */
102
+ readonly root: () => Showable;
103
+ /** A file finished decoding: its waveform and length are known now. */
104
+ readonly onDecoded?: () => void;
105
+ /** A clip names a file that wasn't in the list before. */
106
+ readonly onNewSource?: () => void;
107
+ };
108
+
109
+ export class Soundtrack {
110
+ readonly #options: SoundtrackOptions;
111
+
112
+ constructor(options: SoundtrackOptions) {
113
+ this.#options = options;
114
+ }
115
+
116
+ // MARK: Decoded files
117
+
118
+ /** Decodes, and resamples to {@link SAMPLE_RATE}. It never renders anything. */
119
+ readonly #decoder = new OfflineAudioContext({
120
+ length: 1,
121
+ sampleRate: SAMPLE_RATE,
122
+ });
123
+ readonly #decoding = new Map<string, Promise<AudioBuffer>>();
124
+ readonly #decoded = new Map<string, AudioBuffer>();
125
+ /** Files that couldn't be read. Not tried again until {@link forgetFailures}. */
126
+ readonly #failed = new Set<string>();
127
+
128
+ /**
129
+ * The decoded file, mono, or null if it hasn't been decoded yet (or can't be).
130
+ * Its length is the file's length.
131
+ */
132
+ getDecodedBuffer(url: string): AudioBuffer | null {
133
+ return this.#decoded.get(url) ?? null;
134
+ }
135
+
136
+ /** Read and decode every file again, e.g. one re-recorded under the same name. */
137
+ forget(): void {
138
+ this.#decoding.clear();
139
+ this.#decoded.clear();
140
+ this.#failed.clear();
141
+ this.#knownSources.clear();
142
+ this.request();
143
+ }
144
+
145
+ /**
146
+ * Use `buffer` as the decoded file for `url`, instead of reading the file.
147
+ * For a file this page just wrote, like a voice recording, whose samples are
148
+ * already in memory. It must be mono, at {@link SAMPLE_RATE}, and exactly as
149
+ * long as the file.
150
+ */
151
+ provide(url: string, buffer: AudioBuffer): void {
152
+ this.#decoding.set(url, Promise.resolve(buffer));
153
+ this.#decoded.set(url, buffer);
154
+ this.#failed.delete(url);
155
+ this.#options.onDecoded?.();
156
+ if (this.#anchor) this.#resync();
157
+ }
158
+
159
+ /** Try the files that couldn't be read again, e.g. after 🔓 Allow local files. */
160
+ forgetFailures(): void {
161
+ for (const url of this.#failed) this.#decoding.delete(url);
162
+ this.#failed.clear();
163
+ this.request();
164
+ }
165
+
166
+ #load(url: string): Promise<AudioBuffer> {
167
+ return this.#decoding.getOrInsertComputed(url, () => {
168
+ const promise = this.#decode(url).then(
169
+ (buffer) => {
170
+ // forget() may have come in the meantime.
171
+ if (this.#decoding.get(url) === promise) {
172
+ this.#decoded.set(url, buffer);
173
+ this.#options.onDecoded?.();
174
+ if (this.#anchor) this.#resync();
175
+ }
176
+ return buffer;
177
+ },
178
+ (reason) => {
179
+ if (this.#decoding.get(url) === promise) this.#failed.add(url);
180
+ debugLog("audio", `Skipped "${url}": ${reason}`);
181
+ throw reason;
182
+ },
183
+ );
184
+ // ready() looks at failures with allSettled(). This is for everyone else.
185
+ promise.catch(() => {});
186
+ return promise;
187
+ });
188
+ }
189
+
190
+ async #decode(url: string): Promise<AudioBuffer> {
191
+ const time1 = performance.now();
192
+ const response = await fetchMedia(url);
193
+ const encoded = await response.arrayBuffer();
194
+ const time2 = performance.now();
195
+ // decodeAudioData() takes about ⅜ - ¾ of a second to decode 4 minutes and 18 seconds of audio.
196
+ const decoded = await this.#decoder.decodeAudioData(encoded);
197
+ const time3 = performance.now();
198
+ debugLog(
199
+ "audio",
200
+ `Decoded "${url}": ${(encoded.byteLength / 1024).toFixed(0)} KB, ` +
201
+ `read ${(time2 - time1).toFixed(0)} ms, decode ${(time3 - time2).toFixed(0)} ms`,
202
+ );
203
+ if (decoded.numberOfChannels === 1) return decoded;
204
+ // Average the channels, don't sum them: identical channels (the usual
205
+ // "stereo") come out exactly as they went in, where a sum would double
206
+ // the level and clip.
207
+ const mono = new AudioBuffer({
208
+ numberOfChannels: 1,
209
+ length: decoded.length,
210
+ sampleRate: decoded.sampleRate,
211
+ });
212
+ const out = mono.getChannelData(0);
213
+ for (let channel = 0; channel < decoded.numberOfChannels; channel++) {
214
+ const data = decoded.getChannelData(channel);
215
+ for (let i = 0; i < out.length; i++) out[i] += data[i];
216
+ }
217
+ const scale = 1 / decoded.numberOfChannels;
218
+ for (let i = 0; i < out.length; i++) out[i] *= scale;
219
+ return mono;
220
+ }
221
+
222
+ // MARK: The clip list
223
+
224
+ #clips: readonly PlacedSoundClip[] = [];
225
+ /** {@link #clips} and the video's length, as JSON: how a request knows nothing changed. */
226
+ #clipsJson = "";
227
+ #requested = false;
228
+ /** Every source a clip has named, so {@link SoundtrackOptions.onNewSource} only fires for new ones. */
229
+ readonly #knownSources = new Set<string>();
230
+
231
+ /**
232
+ * Something may have changed: a clip, a component's timing, the tree.
233
+ *
234
+ * Call it as often as you like, even several times per mouse move. Calls in the
235
+ * same task are combined into one, and that one does almost nothing unless a clip
236
+ * moved. Nothing here allocates anything the size of the video.
237
+ */
238
+ request(): void {
239
+ if (this.#requested) return;
240
+ this.#requested = true;
241
+ queueMicrotask(() => this.#update());
242
+ }
243
+
244
+ #update(): void {
245
+ this.#requested = false;
246
+ const root = this.#options.root();
247
+ const clips = collectSoundClips(root);
248
+ const json = JSON.stringify([root.duration, clips]);
249
+ if (json === this.#clipsJson) return;
250
+ this.#clipsJson = json;
251
+ this.#clips = clips;
252
+ let newSource = false;
253
+ for (const { source } of clips) {
254
+ if (!this.#knownSources.has(source)) {
255
+ this.#knownSources.add(source);
256
+ newSource = true;
257
+ }
258
+ void this.#load(source).catch(() => {});
259
+ }
260
+ if (newSource) this.#options.onNewSource?.();
261
+ if (this.#anchor) this.#resync();
262
+ }
263
+
264
+ /**
265
+ * Resolves when every file the newest clip list names has been decoded, or has
266
+ * failed. The newest: if the list changes while this waits, it waits for that
267
+ * one too.
268
+ */
269
+ async ready(): Promise<void> {
270
+ for (;;) {
271
+ if (this.#requested) this.#update();
272
+ const json = this.#clipsJson;
273
+ await Promise.allSettled(this.#clips.map(({ source }) => this.#load(source)));
274
+ if (!this.#requested && json === this.#clipsJson) return;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * The soundtrack from `fromMs` to `toMs`, mixed into one mono buffer, for saving.
280
+ * Call {@link ready} first, or clips whose file isn't decoded yet are left out.
281
+ */
282
+ mix(fromMs: number, toMs: number): AudioBuilder {
283
+ if (this.#requested) this.#update();
284
+ const builder = new AudioBuilder(
285
+ Math.max(0, toMs - fromMs),
286
+ SAMPLE_RATE,
287
+ );
288
+ for (const clip of this.#clips) {
289
+ const buffer = this.#decoded.get(clip.source);
290
+ if (buffer) {
291
+ builder.add(buffer, clip.startMs - fromMs, clip.trimMs, clip.lengthMs);
292
+ }
293
+ }
294
+ return builder;
295
+ }
296
+
297
+ // MARK: Playing
298
+
299
+ /** Undefined when stopped. */
300
+ #anchor: Anchor | undefined;
301
+ /**
302
+ * Changes whenever the anchor moves (a seek, a new speed). A node scheduled for an
303
+ * older anchor plays at the wrong times, so it has to be replaced.
304
+ */
305
+ #anchorVersion = 0;
306
+ #nodes: PlayingNode[] = [];
307
+
308
+ /** Start playing at `anchor`, from scratch. */
309
+ play(anchor: Anchor): void {
310
+ this.stop();
311
+ this.#anchor = anchor;
312
+ this.#anchorVersion++;
313
+ for (const clip of this.#clips) {
314
+ this.#schedule(clip, anchor.mediaMs);
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Keep playing, at a new speed. `anchor` must agree with the old one about where
320
+ * the video is now, so nothing jumps.
321
+ */
322
+ changeRate(anchor: Anchor): void {
323
+ if (!this.#anchor) return;
324
+ // The nodes already playing are right again at once. The ones waiting to start
325
+ // were timed for the old speed, so all of them are replaced, a moment from now.
326
+ for (const { node } of this.#nodes) node.playbackRate.value = anchor.rate;
327
+ this.#anchor = anchor;
328
+ this.#anchorVersion++;
329
+ this.#resync();
330
+ }
331
+
332
+ /** Stop at once. */
333
+ stop(): void {
334
+ for (const { node } of this.#nodes) {
335
+ try {
336
+ node.stop();
337
+ } catch {
338
+ // Already stopped.
339
+ }
340
+ node.disconnect();
341
+ }
342
+ this.#nodes = [];
343
+ this.#anchor = undefined;
344
+ }
345
+
346
+ /** The video's time at `contextTime`, by the current anchor. */
347
+ #mediaMsAt(contextTime: number): number {
348
+ const anchor = this.#anchor!;
349
+ return anchor.mediaMs + (contextTime - anchor.contextTime) * anchor.rate * 1000;
350
+ }
351
+
352
+ /**
353
+ * Identifies one clip at one place: equal keys play exactly the same sound at the
354
+ * same time, so a node can be kept.
355
+ */
356
+ #keyOf(clip: PlacedSoundClip): string {
357
+ return JSON.stringify([clip.source, clip.startMs, clip.trimMs, clip.lengthMs]);
358
+ }
359
+
360
+ /**
361
+ * Bring the nodes up to date with {@link #clips}, while playing.
362
+ * A node whose clip is unchanged keeps playing. Every other node stops, and its
363
+ * replacement starts, at the same moment, {@link SWAP_AHEAD_S} from now.
364
+ */
365
+ #resync(): void {
366
+ const swapTime = this.#options.context.currentTime + SWAP_AHEAD_S;
367
+ const fromMs = this.#mediaMsAt(swapTime);
368
+ /** Clips with no node yet, by key. An array, in case two clips are identical. */
369
+ const unplayed = new Map<string, PlacedSoundClip[]>();
370
+ for (const clip of this.#clips) {
371
+ unplayed.getOrInsertComputed(this.#keyOf(clip), () => []).push(clip);
372
+ }
373
+ const kept: PlayingNode[] = [];
374
+ for (const playing of this.#nodes) {
375
+ const waiting = unplayed.get(playing.key);
376
+ if (playing.anchorVersion === this.#anchorVersion && waiting?.length) {
377
+ waiting.pop();
378
+ kept.push(playing);
379
+ } else {
380
+ try {
381
+ playing.node.stop(swapTime);
382
+ } catch {
383
+ // Already stopped.
384
+ }
385
+ playing.node.onended = () => playing.node.disconnect();
386
+ }
387
+ }
388
+ this.#nodes = kept;
389
+ for (const clips of unplayed.values()) {
390
+ for (const clip of clips) this.#schedule(clip, fromMs);
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Start a node for the part of `clip` from `fromMs` on, in the video's time, if
396
+ * its file is decoded and there's anything left to play.
397
+ */
398
+ #schedule(clip: PlacedSoundClip, fromMs: number): void {
399
+ const buffer = this.#decoded.get(clip.source);
400
+ const anchor = this.#anchor;
401
+ if (!buffer || !anchor) return;
402
+ let { startMs, trimMs, lengthMs } = clip;
403
+ if (trimMs < 0) {
404
+ // Nothing to play before the file starts: start later instead.
405
+ startMs -= trimMs;
406
+ lengthMs += trimMs;
407
+ trimMs = 0;
408
+ }
409
+ const endMs = Math.min(
410
+ startMs + lengthMs,
411
+ startMs + buffer.duration * 1000 - trimMs,
412
+ this.#options.root().duration,
413
+ );
414
+ // Nothing before the video starts, either, and nothing already played.
415
+ const beginMs = Math.max(startMs, fromMs, 0);
416
+ if (endMs - beginMs < 0.001) return;
417
+ const node = this.#options.context.createBufferSource();
418
+ node.buffer = buffer; // Shared, not copied.
419
+ node.playbackRate.value = anchor.rate;
420
+ node.connect(this.#options.destination);
421
+ // Only `when` depends on the speed. The offset and the duration are in the
422
+ // file's own time.
423
+ node.start(
424
+ anchor.contextTime + (beginMs - anchor.mediaMs) / 1000 / anchor.rate,
425
+ (trimMs + beginMs - startMs) / 1000,
426
+ (endMs - beginMs) / 1000,
427
+ );
428
+ this.#nodes.push({
429
+ node,
430
+ key: this.#keyOf(clip),
431
+ anchorVersion: this.#anchorVersion,
432
+ });
433
+ }
434
+ }
@@ -395,9 +395,17 @@ export function askHowToSplitSound(options: {
395
395
  // MARK: Behavior
396
396
  const inside = (atMs: number) => atMs > 0 && atMs < lengthMs;
397
397
 
398
- /** The quiet moment between words nearest `atMs`, inside the clip, or `atMs` itself. */
398
+ /**
399
+ * `atMs`, moved to the nearest quiet moment between words if it's in the middle of one.
400
+ *
401
+ * Anywhere between one word's `cutAfterMs` and the next word's `cutBeforeMs` is already quiet,
402
+ * so a split there stays where it is. Snapping out of a long pause moved a split a whole second.
403
+ */
399
404
  function snapped(atMs: number): number {
400
405
  if (!snapInput.checked || !words?.length) return atMs;
406
+ const fileMs = startMsIntoClip + atMs;
407
+ const inWord = words.some((w) => w.cutBeforeMs < fileMs && fileMs < w.cutAfterMs);
408
+ if (!inWord) return atMs;
401
409
  let best = atMs;
402
410
  let bestDistance = Infinity;
403
411
  for (const word of words) {
@@ -448,8 +456,11 @@ export function askHowToSplitSound(options: {
448
456
  return;
449
457
  }
450
458
  const moved = Math.abs(atMs - typed) > 0.05;
459
+ const direction = atMs < typed ? "earlier" : "later";
451
460
  whereNote.textContent =
452
- (moved ? `Snapped to ${Math.round(atMs)} ms.` : "") + aroundWords(atMs);
461
+ (moved
462
+ ? `Snapped to ${Math.round(atMs)} ms, ${Math.round(Math.abs(atMs - typed))} ms ${direction}.`
463
+ : "") + aroundWords(atMs);
453
464
  whereNote.style.color = whereNote.textContent.includes("⚠") ? "#a06000" : "#555";
454
465
 
455
466
  const kept = keep();