@motionscript/browser 0.0.0-stage → 0.1.0-alpha.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/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/README.md +68 -3
- package/dist/asset-bytes.d.ts +50 -0
- package/dist/asset-bytes.d.ts.map +1 -0
- package/dist/asset-bytes.js +60 -0
- package/dist/asset-bytes.js.map +1 -0
- package/dist/audio/bus-graph.d.ts +43 -0
- package/dist/audio/bus-graph.d.ts.map +1 -0
- package/dist/audio/bus-graph.js +104 -0
- package/dist/audio/bus-graph.js.map +1 -0
- package/dist/audio/filter-graph.d.ts +58 -0
- package/dist/audio/filter-graph.d.ts.map +1 -0
- package/dist/audio/filter-graph.js +235 -0
- package/dist/audio/filter-graph.js.map +1 -0
- package/dist/audio/index.d.ts +5 -0
- package/dist/audio/index.d.ts.map +1 -0
- package/dist/audio/index.js +12 -0
- package/dist/audio/index.js.map +1 -0
- package/dist/audio/mixer.d.ts +59 -0
- package/dist/audio/mixer.d.ts.map +1 -0
- package/dist/audio/mixer.js +193 -0
- package/dist/audio/mixer.js.map +1 -0
- package/dist/audio/player.d.ts +49 -0
- package/dist/audio/player.d.ts.map +1 -0
- package/dist/audio/player.js +226 -0
- package/dist/audio/player.js.map +1 -0
- package/dist/browser/audio.js +2 -0
- package/dist/browser/audio.js.map +7 -0
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js +2 -0
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js.map +7 -0
- package/dist/browser/chunks/SkeletonUtils-XYDMTGTM.js +2 -0
- package/dist/browser/chunks/SkeletonUtils-XYDMTGTM.js.map +7 -0
- package/dist/browser/chunks/chunk-CTLBXZSU.js +4119 -0
- package/dist/browser/chunks/chunk-CTLBXZSU.js.map +7 -0
- package/dist/browser/chunks/chunk-FQ32PDIU.js +2 -0
- package/dist/browser/chunks/chunk-FQ32PDIU.js.map +7 -0
- package/dist/browser/chunks/chunk-FY3BTKY4.js +2 -0
- package/dist/browser/chunks/chunk-FY3BTKY4.js.map +7 -0
- package/dist/browser/chunks/chunk-NSFLRI4P.js +2 -0
- package/dist/browser/chunks/chunk-NSFLRI4P.js.map +7 -0
- package/dist/browser/chunks/three.module-Z4EOVUWF.js +2 -0
- package/dist/browser/chunks/three.module-Z4EOVUWF.js.map +7 -0
- package/dist/browser/esbuild.wasm +0 -0
- package/dist/browser/index.js +2172 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/manifest.json +15 -0
- package/dist/concat.d.ts +95 -0
- package/dist/concat.d.ts.map +1 -0
- package/dist/concat.js +174 -0
- package/dist/concat.js.map +1 -0
- package/dist/decode/image-levels.d.ts +137 -0
- package/dist/decode/image-levels.d.ts.map +1 -0
- package/dist/decode/image-levels.js +477 -0
- package/dist/decode/image-levels.js.map +1 -0
- package/dist/decode/levels.d.ts +37 -0
- package/dist/decode/levels.d.ts.map +1 -0
- package/dist/decode/levels.js +68 -0
- package/dist/decode/levels.js.map +1 -0
- package/dist/decode/video-levels.d.ts +37 -0
- package/dist/decode/video-levels.d.ts.map +1 -0
- package/dist/decode/video-levels.js +95 -0
- package/dist/decode/video-levels.js.map +1 -0
- package/dist/dynamic-nodes.d.ts +9 -0
- package/dist/dynamic-nodes.d.ts.map +1 -0
- package/dist/dynamic-nodes.js +56 -0
- package/dist/dynamic-nodes.js.map +1 -0
- package/dist/engine.d.ts +59 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +171 -0
- package/dist/engine.js.map +1 -0
- package/dist/exporter.d.ts +163 -0
- package/dist/exporter.d.ts.map +1 -0
- package/dist/exporter.js +263 -0
- package/dist/exporter.js.map +1 -0
- package/dist/getter.d.ts +10 -0
- package/dist/getter.d.ts.map +1 -0
- package/dist/getter.js +38 -0
- package/dist/getter.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/measure-context.d.ts +12 -0
- package/dist/measure-context.d.ts.map +1 -0
- package/dist/measure-context.js +12 -0
- package/dist/measure-context.js.map +1 -0
- package/dist/mix-timeline-audio.d.ts +42 -0
- package/dist/mix-timeline-audio.d.ts.map +1 -0
- package/dist/mix-timeline-audio.js +63 -0
- package/dist/mix-timeline-audio.js.map +1 -0
- package/dist/output.d.ts +7 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +6 -0
- package/dist/output.js.map +1 -0
- package/dist/render-context.d.ts +30 -0
- package/dist/render-context.d.ts.map +1 -0
- package/dist/render-context.js +55 -0
- package/dist/render-context.js.map +1 -0
- package/dist/screenshot.d.ts +45 -0
- package/dist/screenshot.d.ts.map +1 -0
- package/dist/screenshot.js +32 -0
- package/dist/screenshot.js.map +1 -0
- package/dist/still.d.ts +151 -0
- package/dist/still.d.ts.map +1 -0
- package/dist/still.js +222 -0
- package/dist/still.js.map +1 -0
- package/dist/storage-adapter.d.ts +367 -0
- package/dist/storage-adapter.d.ts.map +1 -0
- package/dist/storage-adapter.js +1278 -0
- package/dist/storage-adapter.js.map +1 -0
- package/dist/three/renderer.d.ts +48 -0
- package/dist/three/renderer.d.ts.map +1 -0
- package/dist/three/renderer.js +177 -0
- package/dist/three/renderer.js.map +1 -0
- package/dist/ticker.d.ts +42 -0
- package/dist/ticker.d.ts.map +1 -0
- package/dist/ticker.js +143 -0
- package/dist/ticker.js.map +1 -0
- package/package.json +74 -3
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,4 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @motionscript/browser
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
The browser rendering backend for [Motion Script](https://motionscript.dev),
|
|
4
|
+
built on Skia via [`@motionscript/canvaskit`](../canvaskit). It implements the
|
|
5
|
+
`platform`/`render` abstractions from [`@motionscript/core`](../core) so
|
|
6
|
+
documents can be drawn to a canvas, played back with synchronized audio, and
|
|
7
|
+
exported to video all in the browser.
|
|
8
|
+
|
|
9
|
+
## What's in here
|
|
10
|
+
|
|
11
|
+
- **Engine**: `createBrowserEngine` wires every platform seam below into a
|
|
12
|
+
`@motionscript/core` `Engine`. Await it once at app start and share it.
|
|
13
|
+
- **Render context**: `WebRenderContext` draws the `@motionscript/core` scene
|
|
14
|
+
graph (shapes, fills, strokes, effects, text, video, masks) onto a CanvasKit
|
|
15
|
+
surface.
|
|
16
|
+
- **Exporter**: `exportVideo` renders a document offline and muxes video and
|
|
17
|
+
audio into an MP4 using [mediabunny](https://github.com/Vanilagy/mediabunny).
|
|
18
|
+
- **Stills**: `StillRenderer` (from `createStillRenderer`) is a long-lived
|
|
19
|
+
renderer that repaints single frames into a canvas the host owns, for
|
|
20
|
+
thumbnails and previews; `exportScreenshot` is the one-shot wrapper over it.
|
|
21
|
+
- **Concat**: `concatVideoSegments` joins separately encoded MP4 segments
|
|
22
|
+
without re-encoding, so an export can be split across workers.
|
|
23
|
+
`mixTimelineAudio` mixes the whole timeline's audio once for the joined file.
|
|
24
|
+
Every segment must share one encoder configuration; a mismatch throws
|
|
25
|
+
`ConcatMismatchError`.
|
|
26
|
+
- **3D**: importing this package registers the WebGL renderer that makes
|
|
27
|
+
`Canvas3D` draw (three.js, loaded lazily). Import from the package root,
|
|
28
|
+
not a deep path, or 3D renders empty.
|
|
29
|
+
- **Audio**: `WebAudioPlayer` drives playback through the Web Audio API;
|
|
30
|
+
`mixAudio` and `encodeWav` (also on the `@motionscript/browser/audio`
|
|
31
|
+
subpath, which skips CanvasKit) mix down offline.
|
|
32
|
+
- **Storage / assets**: `WebStorageAdapter` and `WebMeasureContext` implement the
|
|
33
|
+
asset-loading and text-measurement abstractions `@motionscript/core` needs.
|
|
34
|
+
- **Clock**: `WebTicker` synchronizes scene playback to `requestAnimationFrame` while calculating dt from audio context to ensure audio and animation line up.
|
|
35
|
+
- **CanvasKit access**: `getCanvasKit` loads and caches the CanvasKit/Skia
|
|
36
|
+
WebAssembly module used for rendering.
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @motionscript/browser @motionscript/core @motionscript/canvaskit
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { createBrowserEngine } from '@motionscript/browser';
|
|
46
|
+
|
|
47
|
+
const engine = await createBrowserEngine({ wasmUrl: '/canvaskit.wasm', nodes: [MyNode] });
|
|
48
|
+
const session = engine.open({ document, target: canvasEl });
|
|
49
|
+
session.playback!.play();
|
|
50
|
+
|
|
51
|
+
const mp4 = await session.export();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Serve `canvaskit.wasm` from `@motionscript/canvaskit` as a static asset and pass
|
|
55
|
+
its URL as `wasmUrl`.
|
|
56
|
+
|
|
57
|
+
See the [docs](https://motionscript.dev/docs) for the full feature set and API
|
|
58
|
+
reference.
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
From the monorepo root:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm --filter @motionscript/browser build
|
|
66
|
+
pnpm --filter @motionscript/browser test
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for the architecture overview.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a source URL's bytes may come from, other than the network.
|
|
3
|
+
*
|
|
4
|
+
* ## Why the web adapter needs this at all
|
|
5
|
+
*
|
|
6
|
+
* `WebStorageAdapter` addresses every asset by URL and fetches it. That is
|
|
7
|
+
* right for an asset that lives somewhere, and wrong for one whose bytes the
|
|
8
|
+
* host already has in hand — a file the user has just chosen, a render a local
|
|
9
|
+
* model has just produced, a picture whose upload has not finished or cannot
|
|
10
|
+
* start because there is no network. In all three the adapter downloads bytes
|
|
11
|
+
* that never needed to travel.
|
|
12
|
+
*
|
|
13
|
+
* `NodeStorageAdapter` has had the answer since it was written: an injected
|
|
14
|
+
* `AssetLoader`, with an `inline` map consulted ahead of the disk. This is the
|
|
15
|
+
* same seam for the browser.
|
|
16
|
+
*
|
|
17
|
+
* ## Why it is module-level
|
|
18
|
+
*
|
|
19
|
+
* `WebStorageAdapter` is constructed at five sites *inside* these packages —
|
|
20
|
+
* the React player backend, the exporter, the audio mixer, and both still
|
|
21
|
+
* renderers — none of which a host can reach. A constructor argument would
|
|
22
|
+
* therefore cover the preview and leave export and stills on the network,
|
|
23
|
+
* which is the worst of both: the picture a user sees would come from local
|
|
24
|
+
* bytes and the one they render would not.
|
|
25
|
+
*
|
|
26
|
+
* So this is an *injection point*, not a cache. The adapter still owns every
|
|
27
|
+
* decode, every cache, every size ceiling and every eviction rule; all this
|
|
28
|
+
* changes is where the compressed bytes came from. A source that answers `null`
|
|
29
|
+
* — which is what an unregistered URL, an evicted entry or a host with no local
|
|
30
|
+
* store does — leaves the adapter exactly as it was.
|
|
31
|
+
*/
|
|
32
|
+
/** Local bytes for a source URL, or `null` to go to the network. */
|
|
33
|
+
export type AssetByteSource = (src: string) => Promise<Blob | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Installs the byte source for this browsing context, or clears it with `null`.
|
|
36
|
+
*
|
|
37
|
+
* Called once per window that renders. Later calls replace the previous source
|
|
38
|
+
* rather than stacking, because two sources disagreeing about one URL has no
|
|
39
|
+
* sensible answer.
|
|
40
|
+
*/
|
|
41
|
+
export declare function setAssetByteSource(next: AssetByteSource | null): void;
|
|
42
|
+
/**
|
|
43
|
+
* The bytes for `src`, or `null`.
|
|
44
|
+
*
|
|
45
|
+
* Swallows a throwing source on purpose. A host's local store failing is a
|
|
46
|
+
* cache miss, not a render failure — the caller falls through to `fetch`, which
|
|
47
|
+
* is what it would have done had the source never been installed.
|
|
48
|
+
*/
|
|
49
|
+
export declare function localAssetBytes(src: string): Promise<Blob | null>;
|
|
50
|
+
//# sourceMappingURL=asset-bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-bytes.d.ts","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,oEAAoE;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AAIpE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAErE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAOvE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a source URL's bytes may come from, other than the network.
|
|
3
|
+
*
|
|
4
|
+
* ## Why the web adapter needs this at all
|
|
5
|
+
*
|
|
6
|
+
* `WebStorageAdapter` addresses every asset by URL and fetches it. That is
|
|
7
|
+
* right for an asset that lives somewhere, and wrong for one whose bytes the
|
|
8
|
+
* host already has in hand — a file the user has just chosen, a render a local
|
|
9
|
+
* model has just produced, a picture whose upload has not finished or cannot
|
|
10
|
+
* start because there is no network. In all three the adapter downloads bytes
|
|
11
|
+
* that never needed to travel.
|
|
12
|
+
*
|
|
13
|
+
* `NodeStorageAdapter` has had the answer since it was written: an injected
|
|
14
|
+
* `AssetLoader`, with an `inline` map consulted ahead of the disk. This is the
|
|
15
|
+
* same seam for the browser.
|
|
16
|
+
*
|
|
17
|
+
* ## Why it is module-level
|
|
18
|
+
*
|
|
19
|
+
* `WebStorageAdapter` is constructed at five sites *inside* these packages —
|
|
20
|
+
* the React player backend, the exporter, the audio mixer, and both still
|
|
21
|
+
* renderers — none of which a host can reach. A constructor argument would
|
|
22
|
+
* therefore cover the preview and leave export and stills on the network,
|
|
23
|
+
* which is the worst of both: the picture a user sees would come from local
|
|
24
|
+
* bytes and the one they render would not.
|
|
25
|
+
*
|
|
26
|
+
* So this is an *injection point*, not a cache. The adapter still owns every
|
|
27
|
+
* decode, every cache, every size ceiling and every eviction rule; all this
|
|
28
|
+
* changes is where the compressed bytes came from. A source that answers `null`
|
|
29
|
+
* — which is what an unregistered URL, an evicted entry or a host with no local
|
|
30
|
+
* store does — leaves the adapter exactly as it was.
|
|
31
|
+
*/
|
|
32
|
+
let source = null;
|
|
33
|
+
/**
|
|
34
|
+
* Installs the byte source for this browsing context, or clears it with `null`.
|
|
35
|
+
*
|
|
36
|
+
* Called once per window that renders. Later calls replace the previous source
|
|
37
|
+
* rather than stacking, because two sources disagreeing about one URL has no
|
|
38
|
+
* sensible answer.
|
|
39
|
+
*/
|
|
40
|
+
export function setAssetByteSource(next) {
|
|
41
|
+
source = next;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The bytes for `src`, or `null`.
|
|
45
|
+
*
|
|
46
|
+
* Swallows a throwing source on purpose. A host's local store failing is a
|
|
47
|
+
* cache miss, not a render failure — the caller falls through to `fetch`, which
|
|
48
|
+
* is what it would have done had the source never been installed.
|
|
49
|
+
*/
|
|
50
|
+
export async function localAssetBytes(src) {
|
|
51
|
+
if (!source)
|
|
52
|
+
return null;
|
|
53
|
+
try {
|
|
54
|
+
return await source(src);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=asset-bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-bytes.js","sourceRoot":"","sources":["../src/asset-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAKH,IAAI,MAAM,GAA2B,IAAI,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAA4B;IAC3D,MAAM,GAAG,IAAI,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC","sourcesContent":["/**\n * Where a source URL's bytes may come from, other than the network.\n *\n * ## Why the web adapter needs this at all\n *\n * `WebStorageAdapter` addresses every asset by URL and fetches it. That is\n * right for an asset that lives somewhere, and wrong for one whose bytes the\n * host already has in hand — a file the user has just chosen, a render a local\n * model has just produced, a picture whose upload has not finished or cannot\n * start because there is no network. In all three the adapter downloads bytes\n * that never needed to travel.\n *\n * `NodeStorageAdapter` has had the answer since it was written: an injected\n * `AssetLoader`, with an `inline` map consulted ahead of the disk. This is the\n * same seam for the browser.\n *\n * ## Why it is module-level\n *\n * `WebStorageAdapter` is constructed at five sites *inside* these packages —\n * the React player backend, the exporter, the audio mixer, and both still\n * renderers — none of which a host can reach. A constructor argument would\n * therefore cover the preview and leave export and stills on the network,\n * which is the worst of both: the picture a user sees would come from local\n * bytes and the one they render would not.\n *\n * So this is an *injection point*, not a cache. The adapter still owns every\n * decode, every cache, every size ceiling and every eviction rule; all this\n * changes is where the compressed bytes came from. A source that answers `null`\n * — which is what an unregistered URL, an evicted entry or a host with no local\n * store does — leaves the adapter exactly as it was.\n */\n\n/** Local bytes for a source URL, or `null` to go to the network. */\nexport type AssetByteSource = (src: string) => Promise<Blob | null>;\n\nlet source: AssetByteSource | null = null;\n\n/**\n * Installs the byte source for this browsing context, or clears it with `null`.\n *\n * Called once per window that renders. Later calls replace the previous source\n * rather than stacking, because two sources disagreeing about one URL has no\n * sensible answer.\n */\nexport function setAssetByteSource(next: AssetByteSource | null): void {\n source = next;\n}\n\n/**\n * The bytes for `src`, or `null`.\n *\n * Swallows a throwing source on purpose. A host's local store failing is a\n * cache miss, not a render failure — the caller falls through to `fetch`, which\n * is what it would have done had the source never been installed.\n */\nexport async function localAssetBytes(src: string): Promise<Blob | null> {\n if (!source) return null;\n try {\n return await source(src);\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AudioBusStop } from "@motionscript/core";
|
|
2
|
+
/**
|
|
3
|
+
* The live chains for one audio context's buses.
|
|
4
|
+
*
|
|
5
|
+
* Held per context rather than per clip, because that is the whole difference
|
|
6
|
+
* between a bus and per-clip processing: every clip naming a bus connects into
|
|
7
|
+
* the *same* nodes, so a reverb on a bus is one tail the group shares rather
|
|
8
|
+
* than one tail each. Flattening the levels into per-clip gain would sound
|
|
9
|
+
* right; flattening the effects would not.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AudioBusGraph {
|
|
12
|
+
private readonly ctx;
|
|
13
|
+
/** Where the last bus in a chain connects — the master, or the destination. */
|
|
14
|
+
private readonly destination;
|
|
15
|
+
constructor(ctx: BaseAudioContext,
|
|
16
|
+
/** Where the last bus in a chain connects — the master, or the destination. */
|
|
17
|
+
destination: AudioNode);
|
|
18
|
+
/**
|
|
19
|
+
* The input node a clip on `bus` should connect to, building the chain the
|
|
20
|
+
* first time it is asked for.
|
|
21
|
+
*
|
|
22
|
+
* `bus` is source-adjacent first, so `bus[0]` is the one the clip feeds and
|
|
23
|
+
* each stop after it is that bus's own parent. An empty or absent chain
|
|
24
|
+
* returns the destination, which is what every clip did before buses
|
|
25
|
+
* existed.
|
|
26
|
+
*/
|
|
27
|
+
inputFor(bus: readonly AudioBusStop[] | undefined, startTime: number): AudioNode;
|
|
28
|
+
/** Disconnect every live bus node. Safe to call more than once. */
|
|
29
|
+
dispose(): void;
|
|
30
|
+
private readonly inputs;
|
|
31
|
+
private readonly nodes;
|
|
32
|
+
private readonly oscillators;
|
|
33
|
+
/**
|
|
34
|
+
* Build (or reuse) the chain for `bus[index]`, connected to whatever
|
|
35
|
+
* `bus[index + 1]` resolves to.
|
|
36
|
+
*
|
|
37
|
+
* Recursive rather than iterative because a bus's *output* has to exist
|
|
38
|
+
* before its own nodes can connect to it, and the outermost bus is the last
|
|
39
|
+
* entry.
|
|
40
|
+
*/
|
|
41
|
+
private chainFrom;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=bus-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus-graph.d.ts","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD;;;;;;;;GAQG;AACH,qBAAa,aAAa;IAElB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAFX,GAAG,EAAE,gBAAgB;IACtC,+EAA+E;IAC9D,WAAW,EAAE,SAAS;IAG3C;;;;;;;;OAQG;IACH,QAAQ,CAAC,GAAG,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS;IAKhF,mEAAmE;IACnE,OAAO,IAAI,IAAI;IAYf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;IAEpD;;;;;;;OAOG;IACH,OAAO,CAAC,SAAS;CA+BpB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { buildAudioFilterGraph } from "./filter-graph";
|
|
2
|
+
/**
|
|
3
|
+
* The live chains for one audio context's buses.
|
|
4
|
+
*
|
|
5
|
+
* Held per context rather than per clip, because that is the whole difference
|
|
6
|
+
* between a bus and per-clip processing: every clip naming a bus connects into
|
|
7
|
+
* the *same* nodes, so a reverb on a bus is one tail the group shares rather
|
|
8
|
+
* than one tail each. Flattening the levels into per-clip gain would sound
|
|
9
|
+
* right; flattening the effects would not.
|
|
10
|
+
*/
|
|
11
|
+
export class AudioBusGraph {
|
|
12
|
+
ctx;
|
|
13
|
+
destination;
|
|
14
|
+
constructor(ctx,
|
|
15
|
+
/** Where the last bus in a chain connects — the master, or the destination. */
|
|
16
|
+
destination) {
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
this.destination = destination;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The input node a clip on `bus` should connect to, building the chain the
|
|
22
|
+
* first time it is asked for.
|
|
23
|
+
*
|
|
24
|
+
* `bus` is source-adjacent first, so `bus[0]` is the one the clip feeds and
|
|
25
|
+
* each stop after it is that bus's own parent. An empty or absent chain
|
|
26
|
+
* returns the destination, which is what every clip did before buses
|
|
27
|
+
* existed.
|
|
28
|
+
*/
|
|
29
|
+
inputFor(bus, startTime) {
|
|
30
|
+
if (!bus || bus.length === 0)
|
|
31
|
+
return this.destination;
|
|
32
|
+
return this.chainFrom(bus, 0, startTime);
|
|
33
|
+
}
|
|
34
|
+
/** Disconnect every live bus node. Safe to call more than once. */
|
|
35
|
+
dispose() {
|
|
36
|
+
for (const node of this.nodes) {
|
|
37
|
+
try {
|
|
38
|
+
node.disconnect();
|
|
39
|
+
}
|
|
40
|
+
catch { /* already torn down */ }
|
|
41
|
+
}
|
|
42
|
+
for (const osc of this.oscillators) {
|
|
43
|
+
try {
|
|
44
|
+
osc.stop();
|
|
45
|
+
}
|
|
46
|
+
catch { /* never started, or already stopped */ }
|
|
47
|
+
}
|
|
48
|
+
this.nodes.length = 0;
|
|
49
|
+
this.oscillators.length = 0;
|
|
50
|
+
this.inputs.clear();
|
|
51
|
+
}
|
|
52
|
+
inputs = new Map();
|
|
53
|
+
nodes = [];
|
|
54
|
+
oscillators = [];
|
|
55
|
+
/**
|
|
56
|
+
* Build (or reuse) the chain for `bus[index]`, connected to whatever
|
|
57
|
+
* `bus[index + 1]` resolves to.
|
|
58
|
+
*
|
|
59
|
+
* Recursive rather than iterative because a bus's *output* has to exist
|
|
60
|
+
* before its own nodes can connect to it, and the outermost bus is the last
|
|
61
|
+
* entry.
|
|
62
|
+
*/
|
|
63
|
+
chainFrom(bus, index, startTime) {
|
|
64
|
+
if (index >= bus.length)
|
|
65
|
+
return this.destination;
|
|
66
|
+
const stop = bus[index];
|
|
67
|
+
const existing = this.inputs.get(stop.id);
|
|
68
|
+
if (existing)
|
|
69
|
+
return existing;
|
|
70
|
+
const output = this.chainFrom(bus, index + 1, startTime);
|
|
71
|
+
// A pass-through head every clip connects to, so the bus has one input
|
|
72
|
+
// whatever its filters turn out to be.
|
|
73
|
+
const input = this.ctx.createGain();
|
|
74
|
+
input.gain.value = 1;
|
|
75
|
+
const level = this.ctx.createGain();
|
|
76
|
+
level.gain.value = stop.mute ? 0 : levelOf(stop);
|
|
77
|
+
// `clipDuration` is 0 and `elapsed` 0: a bus is not a clip, so a curve on
|
|
78
|
+
// one is authored against the timeline rather than against a source's
|
|
79
|
+
// length. `applyParam` resolves a curve of its own duration from that.
|
|
80
|
+
const graph = buildAudioFilterGraph(this.ctx, input, stop.filters ?? [], startTime, 0, 0);
|
|
81
|
+
graph.output.connect(level);
|
|
82
|
+
level.connect(output);
|
|
83
|
+
this.nodes.push(input, level, ...graph.nodes);
|
|
84
|
+
this.oscillators.push(...graph.oscillators);
|
|
85
|
+
for (const osc of graph.oscillators)
|
|
86
|
+
osc.start(startTime);
|
|
87
|
+
this.inputs.set(stop.id, input);
|
|
88
|
+
return input;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A bus's gain as a plain number.
|
|
93
|
+
*
|
|
94
|
+
* A curve-valued bus level is scheduled by the filter chain a bus carries, not
|
|
95
|
+
* here: this node is created once for the whole bus and shared by every clip on
|
|
96
|
+
* it, so there is no single clip start to resolve a curve against. Authoring a
|
|
97
|
+
* bus fade as `filters: AudioFilters.gain(fadeOut(1))` puts it on the chain,
|
|
98
|
+
* where it is scheduled against the context clock like any other.
|
|
99
|
+
*/
|
|
100
|
+
function levelOf(stop) {
|
|
101
|
+
const value = typeof stop.volume === "number" ? stop.volume : 1;
|
|
102
|
+
return Number.isFinite(value) ? value : 1;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=bus-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus-graph.js","sourceRoot":"","sources":["../../src/audio/bus-graph.ts"],"names":[],"mappings":"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","sourcesContent":["import type { AudioBusStop } from \"@motionscript/core\";\nimport { buildAudioFilterGraph } from \"./filter-graph\";\n\n/**\n * The live chains for one audio context's buses.\n *\n * Held per context rather than per clip, because that is the whole difference\n * between a bus and per-clip processing: every clip naming a bus connects into\n * the *same* nodes, so a reverb on a bus is one tail the group shares rather\n * than one tail each. Flattening the levels into per-clip gain would sound\n * right; flattening the effects would not.\n */\nexport class AudioBusGraph {\n constructor(\n private readonly ctx: BaseAudioContext,\n /** Where the last bus in a chain connects — the master, or the destination. */\n private readonly destination: AudioNode,\n ) { }\n\n /**\n * The input node a clip on `bus` should connect to, building the chain the\n * first time it is asked for.\n *\n * `bus` is source-adjacent first, so `bus[0]` is the one the clip feeds and\n * each stop after it is that bus's own parent. An empty or absent chain\n * returns the destination, which is what every clip did before buses\n * existed.\n */\n inputFor(bus: readonly AudioBusStop[] | undefined, startTime: number): AudioNode {\n if (!bus || bus.length === 0) return this.destination;\n return this.chainFrom(bus, 0, startTime);\n }\n\n /** Disconnect every live bus node. Safe to call more than once. */\n dispose(): void {\n for (const node of this.nodes) {\n try { node.disconnect(); } catch { /* already torn down */ }\n }\n for (const osc of this.oscillators) {\n try { osc.stop(); } catch { /* never started, or already stopped */ }\n }\n this.nodes.length = 0;\n this.oscillators.length = 0;\n this.inputs.clear();\n }\n\n private readonly inputs = new Map<string, AudioNode>();\n private readonly nodes: AudioNode[] = [];\n private readonly oscillators: OscillatorNode[] = [];\n\n /**\n * Build (or reuse) the chain for `bus[index]`, connected to whatever\n * `bus[index + 1]` resolves to.\n *\n * Recursive rather than iterative because a bus's *output* has to exist\n * before its own nodes can connect to it, and the outermost bus is the last\n * entry.\n */\n private chainFrom(bus: readonly AudioBusStop[], index: number, startTime: number): AudioNode {\n if (index >= bus.length) return this.destination;\n\n const stop = bus[index];\n const existing = this.inputs.get(stop.id);\n if (existing) return existing;\n\n const output = this.chainFrom(bus, index + 1, startTime);\n\n // A pass-through head every clip connects to, so the bus has one input\n // whatever its filters turn out to be.\n const input = this.ctx.createGain();\n input.gain.value = 1;\n\n const level = this.ctx.createGain();\n level.gain.value = stop.mute ? 0 : levelOf(stop);\n\n // `clipDuration` is 0 and `elapsed` 0: a bus is not a clip, so a curve on\n // one is authored against the timeline rather than against a source's\n // length. `applyParam` resolves a curve of its own duration from that.\n const graph = buildAudioFilterGraph(this.ctx, input, stop.filters ?? [], startTime, 0, 0);\n graph.output.connect(level);\n level.connect(output);\n\n this.nodes.push(input, level, ...graph.nodes);\n this.oscillators.push(...graph.oscillators);\n for (const osc of graph.oscillators) osc.start(startTime);\n\n this.inputs.set(stop.id, input);\n return input;\n }\n}\n\n/**\n * A bus's gain as a plain number.\n *\n * A curve-valued bus level is scheduled by the filter chain a bus carries, not\n * here: this node is created once for the whole bus and shared by every clip on\n * it, so there is no single clip start to resolve a curve against. Authoring a\n * bus fade as `filters: AudioFilters.gain(fadeOut(1))` puts it on the chain,\n * where it is scheduled against the context clock like any other.\n */\nfunction levelOf(stop: AudioBusStop): number {\n const value = typeof stop.volume === \"number\" ? stop.volume : 1;\n return Number.isFinite(value) ? value : 1;\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AudioFilterItem } from "@motionscript/core";
|
|
2
|
+
/**
|
|
3
|
+
* Result of building an audio-filter graph for one source.
|
|
4
|
+
*
|
|
5
|
+
* - `output` is the last node in the chain; connect it downstream (e.g. to the
|
|
6
|
+
* per-request gain node).
|
|
7
|
+
* - `nodes` are every intermediate node, so callers can `disconnect()` them on
|
|
8
|
+
* teardown.
|
|
9
|
+
* - `oscillators` are LFOs (from `tremolo`) the caller must `start()` — and may
|
|
10
|
+
* `stop()` — alongside the source, since oscillators need an explicit start.
|
|
11
|
+
*/
|
|
12
|
+
export interface AudioFilterGraph {
|
|
13
|
+
output: AudioNode;
|
|
14
|
+
nodes: AudioNode[];
|
|
15
|
+
oscillators: OscillatorNode[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds the Web Audio graph for a clip's filter chain, returning the node to
|
|
19
|
+
* connect downstream. Shared by live playback ({@link WebAudioSink}) and
|
|
20
|
+
* offline export (`mixAudio`) so both paths sound identical.
|
|
21
|
+
*
|
|
22
|
+
* Filters apply in array order (index 0 closest to the source). `speed` filters
|
|
23
|
+
* are intentionally ignored here — they're realized via `source.playbackRate`
|
|
24
|
+
* by the caller (and affect timeline scheduling), not as a graph node.
|
|
25
|
+
*
|
|
26
|
+
* `startTime` is the AudioContext time the source starts; `clipDuration` is the
|
|
27
|
+
* clip's scene-time length; `elapsed` is scene-seconds already played at a mid-clip
|
|
28
|
+
* seek (0 for a clean start). These let curve-valued params schedule and align.
|
|
29
|
+
*
|
|
30
|
+
* Pass the already-created `source` so its `playbackRate` can be set by the
|
|
31
|
+
* caller; this function only wires nodes *after* the source.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildAudioFilterGraph(ctx: BaseAudioContext, source: AudioNode, filters: readonly AudioFilterItem[], startTime?: number, clipDuration?: number, elapsed?: number): AudioFilterGraph;
|
|
34
|
+
/**
|
|
35
|
+
* Net *constant* playback-rate multiplier from any scalar `speed` filters in the
|
|
36
|
+
* chain (product of all), defaulting to 1. Curve-valued speeds contribute 1 here
|
|
37
|
+
* and are scheduled separately by {@link applySpeedToPlaybackRate}. Mirrors
|
|
38
|
+
* `Sound.effectiveSpeed()` so the renderer applies the same rate the core timeline
|
|
39
|
+
* reserved time for.
|
|
40
|
+
*/
|
|
41
|
+
export declare function effectiveSpeed(filters: readonly AudioFilterItem[] | undefined): number;
|
|
42
|
+
/** The first curve-valued `speed` filter in the chain, if any. */
|
|
43
|
+
export declare function speedCurveOf(filters: readonly AudioFilterItem[] | undefined): import("@motionscript/core").Curve | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Schedule a time-varying speed curve onto an `AudioBufferSourceNode.playbackRate`.
|
|
46
|
+
*
|
|
47
|
+
* The curve is authored over **source time** (rate as a function of how far through
|
|
48
|
+
* the source we've played). `setValueAtTime`/`linearRampToValueAtTime` schedule in
|
|
49
|
+
* **context time**, so we walk scene-time forward in small steps, convert each to a
|
|
50
|
+
* source-time offset via the integral inverse, read the curve there, and lay down a
|
|
51
|
+
* value point at the matching context time. `scalar` folds in any constant speed
|
|
52
|
+
* filters (they scale the whole rate uniformly).
|
|
53
|
+
*
|
|
54
|
+
* `elapsed` is scene-seconds already played at a mid-clip seek, so the schedule
|
|
55
|
+
* starts at the seek point and aligns the playbackRate to the clip's true position.
|
|
56
|
+
*/
|
|
57
|
+
export declare function applySpeedToPlaybackRate(rate: AudioParam, curve: ReturnType<typeof speedCurveOf>, sourceLength: number, sceneDuration: number, scalar: number, startTime: number, elapsed: number): void;
|
|
58
|
+
//# sourceMappingURL=filter-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-graph.d.ts","sourceRoot":"","sources":["../../src/audio/filter-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA4C,MAAM,oBAAoB,CAAC;AAE/F;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,WAAW,EAAE,cAAc,EAAE,CAAC;CACjC;AAyFD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACjC,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,SAAS,GAAE,MAAwB,EACnC,YAAY,GAAE,MAAU,EACxB,OAAO,GAAE,MAAU,GACpB,gBAAgB,CAwFlB;AAYD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,GAAG,MAAM,CAOtF;AAED,kEAAkE;AAClE,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,kDAM3E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACpC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EACtC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GAChB,IAAI,CAgBN"}
|