xbintsc 0.7.0 → 0.7.7
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/dist/src/ast/common.d.ts +10 -0
- package/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +4 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +10 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- package/dist/src/codegen/generator/state.js +4 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/parser/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +13 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- package/dist/tests/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
- package/dist/tests/e2e/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +66 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- package/dist/tests/e2e/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +6 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — the Web Audio node kinds beyond the classic set, part 2:
|
|
3
|
+
* Analyser and Panner.
|
|
4
|
+
*
|
|
5
|
+
* The Analyser's getters pull a spectrum or a time window out of the mixer
|
|
6
|
+
* (which keeps the samples the render thread produced) and convert it to the
|
|
7
|
+
* decibel/byte ranges the Web Audio API specifies. The Panner exposes position
|
|
8
|
+
* and orientation as AudioParams (indices 0…5) so automation works, and keeps
|
|
9
|
+
* everything else — distance model, cone — as plain values that are pushed into
|
|
10
|
+
* the mixer whenever they change.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#include <cmath>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <vector>
|
|
16
|
+
|
|
17
|
+
#include "audio_nodes_internal.h"
|
|
18
|
+
|
|
19
|
+
namespace xtgui {
|
|
20
|
+
namespace {
|
|
21
|
+
|
|
22
|
+
using xtgui::audio_clamp_number;
|
|
23
|
+
using xtgui::audio_define_accessor;
|
|
24
|
+
using xtgui::audio_node_set_prop;
|
|
25
|
+
using xtgui::audio_text_prop;
|
|
26
|
+
using xtgui::audio_write_numeric_array;
|
|
27
|
+
using xtgui::audio_typed_length;
|
|
28
|
+
|
|
29
|
+
/** Round down to a power of two inside the AnalyserNode range. */
|
|
30
|
+
int analyser_fft_size(double requested) {
|
|
31
|
+
int size = 32;
|
|
32
|
+
while (size < 32768 && size * 2 <= static_cast<int>(requested)) size *= 2;
|
|
33
|
+
return size;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
xt_value analyser_fft_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
37
|
+
(void)env;
|
|
38
|
+
(void)argc;
|
|
39
|
+
(void)argv;
|
|
40
|
+
return xt_number(audio_number_prop(self, "__xt_analyser_fft"));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
xt_value analyser_fft_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
44
|
+
(void)env;
|
|
45
|
+
int size = analyser_fft_size(xt_to_number(xt_arg(argc, argv, 0)));
|
|
46
|
+
audio_node_set_prop(self, "__xt_analyser_fft", xt_number(static_cast<double>(size)));
|
|
47
|
+
uint64_t context = 0;
|
|
48
|
+
uint64_t id = 0;
|
|
49
|
+
if (audio_node_ref(self, &context, &id)) audio_mixer_of(self)->set_analyser_fft(id, size);
|
|
50
|
+
return xt_number(static_cast<double>(size));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
xt_value analyser_bin_count_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
54
|
+
(void)env;
|
|
55
|
+
(void)argc;
|
|
56
|
+
(void)argv;
|
|
57
|
+
return xt_number(audio_number_prop(self, "__xt_analyser_fft") / 2.0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
xt_value analyser_smoothing_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
61
|
+
(void)env;
|
|
62
|
+
(void)argc;
|
|
63
|
+
(void)argv;
|
|
64
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_analyser_smoothing");
|
|
65
|
+
return XT_IS_NUMBER(stored) ? stored : xt_number(0.8);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
xt_value analyser_smoothing_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
69
|
+
(void)env;
|
|
70
|
+
double value = audio_clamp_number(xt_to_number(xt_arg(argc, argv, 0)), 0.0, 1.0);
|
|
71
|
+
audio_node_set_prop(self, "__xt_analyser_smoothing", xt_number(value));
|
|
72
|
+
uint64_t context = 0;
|
|
73
|
+
uint64_t id = 0;
|
|
74
|
+
if (audio_node_ref(self, &context, &id)) {
|
|
75
|
+
audio_mixer_of(self)->set_analyser_smoothing(id, static_cast<float>(value));
|
|
76
|
+
}
|
|
77
|
+
return xt_number(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
xt_value analyser_min_db_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
81
|
+
(void)env;
|
|
82
|
+
(void)argc;
|
|
83
|
+
(void)argv;
|
|
84
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_analyser_min_db");
|
|
85
|
+
return XT_IS_NUMBER(stored) ? stored : xt_number(-100);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
xt_value analyser_min_db_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
89
|
+
(void)env;
|
|
90
|
+
double value = xt_to_number(xt_arg(argc, argv, 0));
|
|
91
|
+
double maximum = audio_number_prop(self, "__xt_analyser_max_db");
|
|
92
|
+
if (maximum <= value) value = maximum - 1.0;
|
|
93
|
+
audio_node_set_prop(self, "__xt_analyser_min_db", xt_number(value));
|
|
94
|
+
return xt_number(value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
xt_value analyser_max_db_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
98
|
+
(void)env;
|
|
99
|
+
(void)argc;
|
|
100
|
+
(void)argv;
|
|
101
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_analyser_max_db");
|
|
102
|
+
return XT_IS_NUMBER(stored) ? stored : xt_number(-30);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
xt_value analyser_max_db_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
106
|
+
(void)env;
|
|
107
|
+
double value = xt_to_number(xt_arg(argc, argv, 0));
|
|
108
|
+
double minimum = audio_number_prop(self, "__xt_analyser_min_db");
|
|
109
|
+
if (value <= minimum) value = minimum + 1.0;
|
|
110
|
+
audio_node_set_prop(self, "__xt_analyser_max_db", xt_number(value));
|
|
111
|
+
return xt_number(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** `getByteFrequencyData(array)`: decibels mapped onto 0…255. */
|
|
115
|
+
xt_value analyser_byte_frequency(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
116
|
+
(void)env;
|
|
117
|
+
uint64_t context = 0;
|
|
118
|
+
uint64_t id = 0;
|
|
119
|
+
xt_value array = xt_arg(argc, argv, 0);
|
|
120
|
+
if (!audio_node_ref(self, &context, &id) || audio_typed_length(array) == 0) return XT_UNDEFINED;
|
|
121
|
+
std::vector<float> spectrum;
|
|
122
|
+
if (!audio_mixer_of(self)->analyser_spectrum(id, &spectrum)) return XT_UNDEFINED;
|
|
123
|
+
double minimum = audio_number_prop(self, "__xt_analyser_min_db");
|
|
124
|
+
double maximum = audio_number_prop(self, "__xt_analyser_max_db");
|
|
125
|
+
double span = maximum - minimum > 0 ? maximum - minimum : 1.0;
|
|
126
|
+
uint32_t count = audio_typed_length(array);
|
|
127
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
128
|
+
double decibels = i < spectrum.size() ? spectrum[i] : minimum;
|
|
129
|
+
double scaled = (decibels - minimum) / span * 255.0;
|
|
130
|
+
audio_write_numeric_array(array, i, audio_clamp_number(scaled, 0.0, 255.0));
|
|
131
|
+
}
|
|
132
|
+
return XT_UNDEFINED;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** `getFloatFrequencyData(array)`: decibels, one per bin. */
|
|
136
|
+
xt_value analyser_float_frequency(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
137
|
+
(void)env;
|
|
138
|
+
uint64_t context = 0;
|
|
139
|
+
uint64_t id = 0;
|
|
140
|
+
xt_value array = xt_arg(argc, argv, 0);
|
|
141
|
+
if (!audio_node_ref(self, &context, &id) || audio_typed_length(array) == 0) return XT_UNDEFINED;
|
|
142
|
+
std::vector<float> spectrum;
|
|
143
|
+
if (!audio_mixer_of(self)->analyser_spectrum(id, &spectrum)) return XT_UNDEFINED;
|
|
144
|
+
uint32_t count = audio_typed_length(array);
|
|
145
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
146
|
+
audio_write_numeric_array(array, i, i < spectrum.size() ? spectrum[i] : -100.0);
|
|
147
|
+
}
|
|
148
|
+
return XT_UNDEFINED;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** `getByteTimeDomainData(array)`: samples as unsigned bytes around 128. */
|
|
152
|
+
xt_value analyser_byte_time(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
153
|
+
(void)env;
|
|
154
|
+
uint64_t context = 0;
|
|
155
|
+
uint64_t id = 0;
|
|
156
|
+
xt_value array = xt_arg(argc, argv, 0);
|
|
157
|
+
if (!audio_node_ref(self, &context, &id) || audio_typed_length(array) == 0) return XT_UNDEFINED;
|
|
158
|
+
std::vector<float> samples;
|
|
159
|
+
int count = static_cast<int>(audio_typed_length(array));
|
|
160
|
+
if (!audio_mixer_of(self)->analyser_time_domain(id, count, &samples)) return XT_UNDEFINED;
|
|
161
|
+
for (uint32_t i = 0; i < static_cast<uint32_t>(count) && i < samples.size(); i++) {
|
|
162
|
+
double value = samples[i] * 128.0 + 128.0;
|
|
163
|
+
audio_write_numeric_array(array, i, audio_clamp_number(value, 0.0, 255.0));
|
|
164
|
+
}
|
|
165
|
+
return XT_UNDEFINED;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `getFloatTimeDomainData(array)`: the same window as floats. */
|
|
169
|
+
xt_value analyser_float_time(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
170
|
+
(void)env;
|
|
171
|
+
uint64_t context = 0;
|
|
172
|
+
uint64_t id = 0;
|
|
173
|
+
xt_value array = xt_arg(argc, argv, 0);
|
|
174
|
+
if (!audio_node_ref(self, &context, &id) || audio_typed_length(array) == 0) return XT_UNDEFINED;
|
|
175
|
+
std::vector<float> samples;
|
|
176
|
+
int count = static_cast<int>(audio_typed_length(array));
|
|
177
|
+
if (!audio_mixer_of(self)->analyser_time_domain(id, count, &samples)) return XT_UNDEFINED;
|
|
178
|
+
for (uint32_t i = 0; i < static_cast<uint32_t>(count) && i < samples.size(); i++) {
|
|
179
|
+
audio_write_numeric_array(array, i, samples[i]);
|
|
180
|
+
}
|
|
181
|
+
return XT_UNDEFINED;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* -- Panner ---------------------------------------------------------------- */
|
|
185
|
+
|
|
186
|
+
void panner_apply(xt_value self) {
|
|
187
|
+
uint64_t context = 0;
|
|
188
|
+
uint64_t id = 0;
|
|
189
|
+
if (!audio_node_ref(self, &context, &id)) return;
|
|
190
|
+
std::string distance_model = audio_text_prop(self, "__xt_panner_distance_model");
|
|
191
|
+
int model = 1; /* inverse */
|
|
192
|
+
if (distance_model == "linear") model = 0;
|
|
193
|
+
else if (distance_model == "exponential") model = 2;
|
|
194
|
+
int panning = audio_text_prop(self, "__xt_panner_panning_model") == "HRTF" ? 1 : 0;
|
|
195
|
+
double ref_distance = audio_number_prop(self, "__xt_panner_ref_distance");
|
|
196
|
+
if (xt_object_get_cstr(self, "__xt_panner_ref_distance") == XT_UNDEFINED) ref_distance = 1.0;
|
|
197
|
+
double max_distance = audio_number_prop(self, "__xt_panner_max_distance");
|
|
198
|
+
if (xt_object_get_cstr(self, "__xt_panner_max_distance") == XT_UNDEFINED) max_distance = 10000.0;
|
|
199
|
+
double rolloff = audio_number_prop(self, "__xt_panner_rolloff");
|
|
200
|
+
if (xt_object_get_cstr(self, "__xt_panner_rolloff") == XT_UNDEFINED) rolloff = 1.0;
|
|
201
|
+
double cone_inner = audio_number_prop(self, "__xt_panner_cone_inner");
|
|
202
|
+
if (xt_object_get_cstr(self, "__xt_panner_cone_inner") == XT_UNDEFINED) cone_inner = 360.0;
|
|
203
|
+
double cone_outer = audio_number_prop(self, "__xt_panner_cone_outer");
|
|
204
|
+
if (xt_object_get_cstr(self, "__xt_panner_cone_outer") == XT_UNDEFINED) cone_outer = 360.0;
|
|
205
|
+
double cone_gain = audio_number_prop(self, "__xt_panner_cone_gain");
|
|
206
|
+
audio_mixer_of(self)->set_panner(id, model, ref_distance, max_distance, rolloff, cone_inner,
|
|
207
|
+
cone_outer, cone_gain, panning);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** `panningModel`/`distanceModel` and the numeric distance/cone settings share
|
|
211
|
+
* the same shape: store the value under `key`, then re-apply the node. */
|
|
212
|
+
xt_value panner_text_set(xt_value self, const char *key, const char *const *allowed,
|
|
213
|
+
int allowed_count, xt_value value) {
|
|
214
|
+
xt_value text = xt_to_string(value);
|
|
215
|
+
const char *name = XT_IS_STRING(text) ? xt_string_data(text) : nullptr;
|
|
216
|
+
bool ok = name == nullptr;
|
|
217
|
+
for (int i = 0; !ok && i < allowed_count; i++) {
|
|
218
|
+
if (std::string(allowed[i]) == name) ok = true;
|
|
219
|
+
}
|
|
220
|
+
if (ok) {
|
|
221
|
+
audio_node_set_prop(self, key, text);
|
|
222
|
+
panner_apply(self);
|
|
223
|
+
}
|
|
224
|
+
return text;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
xt_value panner_panning_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
228
|
+
(void)env;
|
|
229
|
+
(void)argc;
|
|
230
|
+
(void)argv;
|
|
231
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_panner_panning_model");
|
|
232
|
+
return XT_IS_STRING(stored) ? stored : xt_string_from_cstr("equalpower");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
xt_value panner_panning_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
236
|
+
(void)env;
|
|
237
|
+
static const char *const allowed[] = {"equalpower", "HRTF"};
|
|
238
|
+
return panner_text_set(self, "__xt_panner_panning_model", allowed, 2, xt_arg(argc, argv, 0));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
xt_value panner_distance_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
242
|
+
(void)env;
|
|
243
|
+
(void)argc;
|
|
244
|
+
(void)argv;
|
|
245
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_panner_distance_model");
|
|
246
|
+
return XT_IS_STRING(stored) ? stored : xt_string_from_cstr("inverse");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
xt_value panner_distance_set(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
250
|
+
(void)env;
|
|
251
|
+
static const char *const allowed[] = {"linear", "inverse", "exponential"};
|
|
252
|
+
return panner_text_set(self, "__xt_panner_distance_model", allowed, 3, xt_arg(argc, argv, 0));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
} // namespace
|
|
256
|
+
|
|
257
|
+
xt_value ctx_create_analyser(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
258
|
+
(void)env;
|
|
259
|
+
(void)argc;
|
|
260
|
+
(void)argv;
|
|
261
|
+
xt_value node = audio_build_node(audio_context_id(self), kAudioAnalyser, nullptr, nullptr, 0);
|
|
262
|
+
audio_node_set_prop(node, "__xt_analyser_fft", xt_number(2048));
|
|
263
|
+
audio_node_set_prop(node, "__xt_analyser_smoothing", xt_number(0.8));
|
|
264
|
+
audio_node_set_prop(node, "__xt_analyser_min_db", xt_number(-100));
|
|
265
|
+
audio_node_set_prop(node, "__xt_analyser_max_db", xt_number(-30));
|
|
266
|
+
uint64_t context = 0;
|
|
267
|
+
uint64_t id = 0;
|
|
268
|
+
if (audio_node_ref(node, &context, &id)) {
|
|
269
|
+
audio_mixer_of(node)->set_analyser_fft(id, 2048);
|
|
270
|
+
audio_mixer_of(node)->set_analyser_smoothing(id, 0.8f);
|
|
271
|
+
}
|
|
272
|
+
audio_define_accessor(node, "fftSize", (void *)analyser_fft_get, (void *)analyser_fft_set);
|
|
273
|
+
audio_define_accessor(node, "frequencyBinCount", (void *)analyser_bin_count_get, nullptr);
|
|
274
|
+
audio_define_accessor(node, "smoothingTimeConstant", (void *)analyser_smoothing_get,
|
|
275
|
+
(void *)analyser_smoothing_set);
|
|
276
|
+
audio_define_accessor(node, "minDecibels", (void *)analyser_min_db_get,
|
|
277
|
+
(void *)analyser_min_db_set);
|
|
278
|
+
audio_define_accessor(node, "maxDecibels", (void *)analyser_max_db_get,
|
|
279
|
+
(void *)analyser_max_db_set);
|
|
280
|
+
audio_set_method(node, "getByteFrequencyData", (void *)analyser_byte_frequency);
|
|
281
|
+
audio_set_method(node, "getFloatFrequencyData", (void *)analyser_float_frequency);
|
|
282
|
+
audio_set_method(node, "getByteTimeDomainData", (void *)analyser_byte_time);
|
|
283
|
+
audio_set_method(node, "getFloatTimeDomainData", (void *)analyser_float_time);
|
|
284
|
+
return node;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
namespace {
|
|
288
|
+
|
|
289
|
+
xt_value panner_set_position(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
290
|
+
(void)env;
|
|
291
|
+
uint64_t context = 0;
|
|
292
|
+
uint64_t id = 0;
|
|
293
|
+
if (!audio_node_ref(self, &context, &id)) return XT_UNDEFINED;
|
|
294
|
+
std::shared_ptr<AudioMixer> mixer = audio_mixer_of(self);
|
|
295
|
+
for (int index = 0; index < 3 && index < argc; index++) {
|
|
296
|
+
mixer->param_set(id, index, xt_to_number(argv[index]));
|
|
297
|
+
}
|
|
298
|
+
return XT_UNDEFINED;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
xt_value panner_set_orientation(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
302
|
+
(void)env;
|
|
303
|
+
uint64_t context = 0;
|
|
304
|
+
uint64_t id = 0;
|
|
305
|
+
if (!audio_node_ref(self, &context, &id)) return XT_UNDEFINED;
|
|
306
|
+
std::shared_ptr<AudioMixer> mixer = audio_mixer_of(self);
|
|
307
|
+
for (int index = 0; index < 3 && index < argc; index++) {
|
|
308
|
+
mixer->param_set(id, 3 + index, xt_to_number(argv[index]));
|
|
309
|
+
}
|
|
310
|
+
return XT_UNDEFINED;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** The numeric distance/cone properties are all the same accessor pair with a
|
|
314
|
+
* fixed key and default. */
|
|
315
|
+
#define XT_PANNER_NUMBER(key, default_value) \
|
|
316
|
+
xt_value panner_##key##_get(xt_value self, xt_value env, int32_t argc, \
|
|
317
|
+
xt_value *argv) { \
|
|
318
|
+
(void)env; \
|
|
319
|
+
(void)argc; \
|
|
320
|
+
(void)argv; \
|
|
321
|
+
xt_value stored = xt_object_get_cstr(self, "__xt_panner_" #key); \
|
|
322
|
+
return XT_IS_NUMBER(stored) ? stored : xt_number(default_value); \
|
|
323
|
+
} \
|
|
324
|
+
xt_value panner_##key##_set(xt_value self, xt_value env, int32_t argc, \
|
|
325
|
+
xt_value *argv) { \
|
|
326
|
+
(void)env; \
|
|
327
|
+
double value = xt_to_number(xt_arg(argc, argv, 0)); \
|
|
328
|
+
audio_node_set_prop(self, "__xt_panner_" #key, xt_number(value)); \
|
|
329
|
+
panner_apply(self); \
|
|
330
|
+
return xt_number(value); \
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
XT_PANNER_NUMBER(ref_distance, 1.0)
|
|
334
|
+
XT_PANNER_NUMBER(max_distance, 10000.0)
|
|
335
|
+
XT_PANNER_NUMBER(rolloff, 1.0)
|
|
336
|
+
XT_PANNER_NUMBER(cone_inner, 360.0)
|
|
337
|
+
XT_PANNER_NUMBER(cone_outer, 360.0)
|
|
338
|
+
XT_PANNER_NUMBER(cone_gain, 0.0)
|
|
339
|
+
|
|
340
|
+
#undef XT_PANNER_NUMBER
|
|
341
|
+
|
|
342
|
+
} // namespace
|
|
343
|
+
|
|
344
|
+
xt_value ctx_create_panner(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
345
|
+
(void)env;
|
|
346
|
+
(void)argc;
|
|
347
|
+
(void)argv;
|
|
348
|
+
static const char *const params[] = {"positionX", "positionY", "positionZ",
|
|
349
|
+
"orientationX", "orientationY", "orientationZ"};
|
|
350
|
+
xt_value node = audio_build_node(audio_context_id(self), kAudioPanner, nullptr, params, 6);
|
|
351
|
+
audio_node_set_prop(node, "__xt_panner_panning_model", xt_string_from_cstr("equalpower"));
|
|
352
|
+
audio_node_set_prop(node, "__xt_panner_distance_model", xt_string_from_cstr("inverse"));
|
|
353
|
+
audio_set_method(node, "setPosition", (void *)panner_set_position);
|
|
354
|
+
audio_set_method(node, "setOrientation", (void *)panner_set_orientation);
|
|
355
|
+
audio_define_accessor(node, "panningModel", (void *)panner_panning_get,
|
|
356
|
+
(void *)panner_panning_set);
|
|
357
|
+
audio_define_accessor(node, "distanceModel", (void *)panner_distance_get,
|
|
358
|
+
(void *)panner_distance_set);
|
|
359
|
+
audio_define_accessor(node, "refDistance", (void *)panner_ref_distance_get,
|
|
360
|
+
(void *)panner_ref_distance_set);
|
|
361
|
+
audio_define_accessor(node, "maxDistance", (void *)panner_max_distance_get,
|
|
362
|
+
(void *)panner_max_distance_set);
|
|
363
|
+
audio_define_accessor(node, "rolloffFactor", (void *)panner_rolloff_get,
|
|
364
|
+
(void *)panner_rolloff_set);
|
|
365
|
+
audio_define_accessor(node, "coneInnerAngle", (void *)panner_cone_inner_get,
|
|
366
|
+
(void *)panner_cone_inner_set);
|
|
367
|
+
audio_define_accessor(node, "coneOuterAngle", (void *)panner_cone_outer_get,
|
|
368
|
+
(void *)panner_cone_outer_set);
|
|
369
|
+
audio_define_accessor(node, "coneOuterGain", (void *)panner_cone_gain_get,
|
|
370
|
+
(void *)panner_cone_gain_set);
|
|
371
|
+
panner_apply(node);
|
|
372
|
+
return node;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
} // namespace xtgui
|
|
@@ -156,6 +156,14 @@ xt_value win_location_get(xt_value self, xt_value env, int32_t argc, xt_value *a
|
|
|
156
156
|
return g_location;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
/** `screen`: the display the window is on (built in `browser_screen.cpp`). */
|
|
160
|
+
xt_value win_screen_get(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
161
|
+
(void)env;
|
|
162
|
+
(void)argc;
|
|
163
|
+
(void)argv;
|
|
164
|
+
return xt_gui_screen_object(self);
|
|
165
|
+
}
|
|
166
|
+
|
|
159
167
|
/** `matchMedia(query)` -> a live `MediaQueryList` evaluated against the current
|
|
160
168
|
* viewport with the same evaluator as `@media` rules. The list is cached per
|
|
161
169
|
* window and query, and `change` listeners fire when a resize flips it. */
|
|
@@ -320,6 +328,7 @@ xt_value host_type_construct(xt_value self, xt_value env, int32_t argc, xt_value
|
|
|
320
328
|
xt_value type_proto(const std::string &name) {
|
|
321
329
|
if (name == "AbortController") return domapi::abort_controller_proto();
|
|
322
330
|
if (name == "AbortSignal") return domapi::abort_signal_proto();
|
|
331
|
+
if (name == "MutationObserver") return domapi::mutation_observer_proto();
|
|
323
332
|
if (name == "Event" || name == "CustomEvent" || name == "ProgressEvent" ||
|
|
324
333
|
name == "UIEvent" || name == "MouseEvent" || name == "PointerEvent" ||
|
|
325
334
|
name == "WheelEvent" || name == "KeyboardEvent" || name == "FocusEvent" ||
|
|
@@ -418,6 +427,7 @@ void install_window_globals(xt_value win) {
|
|
|
418
427
|
set_prop(win, "Audio", type_value("Audio"));
|
|
419
428
|
set_prop(win, "Event", type_value("Event"));
|
|
420
429
|
set_prop(win, "CustomEvent", type_value("CustomEvent"));
|
|
430
|
+
set_prop(win, "MutationObserver", type_value("MutationObserver"));
|
|
421
431
|
set_prop(win, "WebGLRenderingContext", type_value("WebGLRenderingContext"));
|
|
422
432
|
set_prop(win, "WebGL2RenderingContext", type_value("WebGL2RenderingContext"));
|
|
423
433
|
set_prop(win, "isSecureContext", XT_TRUE);
|
|
@@ -460,6 +470,7 @@ void xt_browser_install_window(xt_value proto) {
|
|
|
460
470
|
xt_object_define_getter(proto, xt_string_from_cstr("localStorage"),
|
|
461
471
|
fn_of((void *)win_local_storage_get));
|
|
462
472
|
xt_object_define_getter(proto, xt_string_from_cstr("location"), fn_of((void *)win_location_get));
|
|
473
|
+
xt_object_define_getter(proto, xt_string_from_cstr("screen"), fn_of((void *)win_screen_get));
|
|
463
474
|
set_method(proto, "setTimeout", (void *)win_set_timeout);
|
|
464
475
|
set_method(proto, "clearTimeout", (void *)win_clear_timeout);
|
|
465
476
|
set_method(proto, "setInterval", (void *)win_set_interval);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — the `screen` global.
|
|
3
|
+
*
|
|
4
|
+
* A browser page reads `screen.width` / `screen.height` to size a layout or pick
|
|
5
|
+
* a quality tier, so the object describes the *display* (desktop mode and usable
|
|
6
|
+
* bounds) rather than the window, which is what `innerWidth` is for. It is built
|
|
7
|
+
* once and rooted, because `screen` is a stable singletons in a browser too.
|
|
8
|
+
*
|
|
9
|
+
* The window prototype getter is installed by `browser.cpp`; the member also
|
|
10
|
+
* shows up as a bare `screen` global through the extension's window-member table
|
|
11
|
+
* (`src/extensions/gui/index.ts`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#include "gui_engine.h"
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
xt_value g_screen = XT_UNDEFINED;
|
|
19
|
+
|
|
20
|
+
void set_prop(xt_value target, const char *name, xt_value value) {
|
|
21
|
+
xt_object_set(target, xt_string_from_cstr(name), value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void set_number(xt_value target, const char *name, double value) {
|
|
25
|
+
set_prop(target, name, xt_number(value));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
} // namespace
|
|
29
|
+
|
|
30
|
+
/** `screen`: the desktop display the window is on.
|
|
31
|
+
*
|
|
32
|
+
* The engine falls back to the window size when SDL cannot name a display (a
|
|
33
|
+
* headless host), so a page never sees a zero-sized screen. */
|
|
34
|
+
xt_value xt_gui_screen_object(xt_value self) {
|
|
35
|
+
if (XT_IS_OBJECT(g_screen)) return g_screen;
|
|
36
|
+
SDL_DisplayID display = SDL_GetPrimaryDisplay();
|
|
37
|
+
const SDL_DisplayMode *mode = display != 0 ? SDL_GetDesktopDisplayMode(display) : NULL;
|
|
38
|
+
int width = mode != NULL ? mode->w : 0;
|
|
39
|
+
int height = mode != NULL ? mode->h : 0;
|
|
40
|
+
if (width <= 0 || height <= 0) {
|
|
41
|
+
XtGuiWindow *win = xt_gui_window_from_this(self);
|
|
42
|
+
float viewportWidth = 0.0f;
|
|
43
|
+
float viewportHeight = 0.0f;
|
|
44
|
+
if (win != NULL) xt_gui_window_viewport(win, &viewportWidth, &viewportHeight);
|
|
45
|
+
width = viewportWidth > 0.0f ? (int)viewportWidth : 1920;
|
|
46
|
+
height = viewportHeight > 0.0f ? (int)viewportHeight : 1080;
|
|
47
|
+
}
|
|
48
|
+
int availWidth = width;
|
|
49
|
+
int availHeight = height;
|
|
50
|
+
SDL_Rect usable;
|
|
51
|
+
if (display != 0 && SDL_GetDisplayUsableBounds(display, &usable)) {
|
|
52
|
+
if (usable.w > 0 && usable.h > 0) {
|
|
53
|
+
availWidth = usable.w;
|
|
54
|
+
availHeight = usable.h;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
xt_value screen = xt_object_new();
|
|
58
|
+
set_number(screen, "width", (double)width);
|
|
59
|
+
set_number(screen, "height", (double)height);
|
|
60
|
+
set_number(screen, "availWidth", (double)availWidth);
|
|
61
|
+
set_number(screen, "availHeight", (double)availHeight);
|
|
62
|
+
set_number(screen, "colorDepth", 24);
|
|
63
|
+
set_number(screen, "pixelDepth", 24);
|
|
64
|
+
/* `screen.orientation` is part of the Screen Orientation API; a desktop
|
|
65
|
+
* display is always landscape-primary. */
|
|
66
|
+
xt_value orientation = xt_object_new();
|
|
67
|
+
set_prop(orientation, "type", xt_string_from_cstr(width >= height ? "landscape-primary" : "portrait-primary"));
|
|
68
|
+
set_number(orientation, "angle", 0);
|
|
69
|
+
set_prop(screen, "orientation", orientation);
|
|
70
|
+
g_screen = screen;
|
|
71
|
+
xt_gc_add_root(&g_screen);
|
|
72
|
+
return screen;
|
|
73
|
+
}
|
|
@@ -198,6 +198,10 @@ xt_value xt_gui_node_handle(XtGuiWindow *win, const xtgui::Node *node) {
|
|
|
198
198
|
|
|
199
199
|
void xt_gui_node_handle_forget(XtGuiWindow *win, const xtgui::Node *node) {
|
|
200
200
|
if (win == nullptr || node == nullptr) return;
|
|
201
|
+
/* Removing the locked element ends the Pointer Lock, as in the DOM. Release
|
|
202
|
+
* silently here: the removal is mid-mutation, so running page code for a
|
|
203
|
+
* `pointerlockchange` now could re-enter the tree being torn down. */
|
|
204
|
+
if (win->pointer_lock_node == node) xt_gui_pointer_lock_release(win);
|
|
201
205
|
/* The node is about to be destroyed (a removal, or `innerHTML = …` dropping
|
|
202
206
|
* the old children). Drop its slot as well as its handle: the slot is what
|
|
203
207
|
* `resolve_node` reads, and leaving a freed pointer there is a
|
|
@@ -119,7 +119,15 @@ METHOD(node_get_context) {
|
|
|
119
119
|
const bool cached_webgl2 = value_truthy(xt_object_get_cstr(cached, "__xt_gl_webgl2"));
|
|
120
120
|
return cached_webgl2 == webgl2 ? cached : XT_NULL;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
/* WebGL's `antialias` creation attribute defaults to true; the engine only
|
|
123
|
+
* applies it when the context is created. */
|
|
124
|
+
bool webgl_antialias = true;
|
|
125
|
+
xt_value attributes = xt_arg(argc, argv, 1);
|
|
126
|
+
if (XT_IS_OBJECT(attributes)) {
|
|
127
|
+
xt_value value = xt_object_get_cstr(attributes, "antialias");
|
|
128
|
+
if (XT_IS_BOOL(value)) webgl_antialias = value_truthy(value);
|
|
129
|
+
}
|
|
130
|
+
void *context = webgl->get(win, node, webgl2, webgl_antialias);
|
|
123
131
|
return webgl->handle(self, context);
|
|
124
132
|
}
|
|
125
133
|
if (mode != "2d") return XT_NULL;
|
|
@@ -26,7 +26,8 @@ static xt_value make_dom_event(XtGuiWindow *win, const char *type, const xtgui::
|
|
|
26
26
|
xt_object_set(event, xt_string_from_cstr("timeStamp"), xt_number((double)SDL_GetTicks()));
|
|
27
27
|
if (XT_IS_OBJECT(legacy)) {
|
|
28
28
|
static const char *const fields[] = {
|
|
29
|
-
"x", "y", "clientX", "clientY", "
|
|
29
|
+
"x", "y", "clientX", "clientY", "movementX", "movementY",
|
|
30
|
+
"button", "clicks",
|
|
30
31
|
"deltaX", "deltaY", "key", "code", "repeat", "ctrl",
|
|
31
32
|
"shift", "alt", "meta", "ctrlKey", "shiftKey", "altKey",
|
|
32
33
|
"metaKey", "data", "inputType", "isComposing", "value", "charCode",
|
|
@@ -78,6 +78,10 @@ xt_value abort_controller_proto();
|
|
|
78
78
|
xt_value abort_signal_proto();
|
|
79
79
|
xt_value abort_controller_new();
|
|
80
80
|
xt_value abort_signal_new(bool aborted);
|
|
81
|
+
/** `MutationObserver.prototype`: an inert observer (`observe` / `disconnect` /
|
|
82
|
+
* `takeRecords` exist, no callback ever fires). The constructor itself is the
|
|
83
|
+
* generic host type, so `new MutationObserver(…)` needs no runtime entry. */
|
|
84
|
+
xt_value mutation_observer_proto();
|
|
81
85
|
/** The prototype a WebGL object of `kind` inherits (`buffer`, `texture`, …),
|
|
82
86
|
* so `buffer instanceof WebGLBuffer` holds. */
|
|
83
87
|
xt_value webgl_object_proto(const std::string &kind);
|
|
@@ -165,6 +169,9 @@ METHOD(doc_body_get);
|
|
|
165
169
|
METHOD(doc_head_get);
|
|
166
170
|
METHOD(doc_document_element_get);
|
|
167
171
|
METHOD(doc_active_element_get);
|
|
172
|
+
/* Pointer Lock (`pointer_lock.cpp`). */
|
|
173
|
+
METHOD(doc_exit_pointer_lock);
|
|
174
|
+
METHOD(doc_pointer_lock_element_get);
|
|
168
175
|
|
|
169
176
|
/* node getters */
|
|
170
177
|
METHOD(node_tag_name_get);
|
|
@@ -174,6 +181,8 @@ METHOD(node_local_name_get);
|
|
|
174
181
|
METHOD(node_prefix_get);
|
|
175
182
|
METHOD(node_id_get);
|
|
176
183
|
METHOD(node_id_set);
|
|
184
|
+
METHOD(node_hidden_get);
|
|
185
|
+
METHOD(node_hidden_set);
|
|
177
186
|
METHOD(node_class_name_get);
|
|
178
187
|
METHOD(node_class_name_set);
|
|
179
188
|
METHOD(node_html_for_get);
|
|
@@ -246,6 +255,7 @@ METHOD(node_has_attribute);
|
|
|
246
255
|
METHOD(node_query_selector);
|
|
247
256
|
METHOD(node_query_selector_all);
|
|
248
257
|
METHOD(node_matches);
|
|
258
|
+
METHOD(node_closest);
|
|
249
259
|
METHOD(node_append_child);
|
|
250
260
|
METHOD(node_append);
|
|
251
261
|
METHOD(node_prepend);
|
|
@@ -266,6 +276,7 @@ METHOD(node_click);
|
|
|
266
276
|
METHOD(node_add_event_listener);
|
|
267
277
|
METHOD(node_remove_event_listener);
|
|
268
278
|
METHOD(node_dispatch_event);
|
|
279
|
+
METHOD(node_request_pointer_lock);
|
|
269
280
|
|
|
270
281
|
/* event construction (a detached `Event`/`CustomEvent` handle) */
|
|
271
282
|
xt_value event_construct(xt_value type, xt_value init);
|
|
@@ -154,6 +154,55 @@ METHOD(node_insert_adjacent_html) {
|
|
|
154
154
|
return XT_UNDEFINED;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/* -- MutationObserver ----------------------------------------------------- */
|
|
158
|
+
|
|
159
|
+
/* The engine keeps no mutation queue to report on, so an observer is *inert*:
|
|
160
|
+
* `observe` records nothing and the callback never fires (see
|
|
161
|
+
* doc/gui/known-issues.md). It exists as a real constructor because pages and
|
|
162
|
+
* bundlers build one unconditionally — Vite's `modulepreload` polyfill does
|
|
163
|
+
* `new MutationObserver(…).observe(document, …)` before the page runs — and a
|
|
164
|
+
* `TypeError` there aborts the whole script. Code that only *installs* an
|
|
165
|
+
* observer therefore runs unchanged; code that waits for records has nothing
|
|
166
|
+
* to receive yet. */
|
|
167
|
+
|
|
168
|
+
METHOD(observer_observe) {
|
|
169
|
+
(void)self;
|
|
170
|
+
(void)env;
|
|
171
|
+
(void)argc;
|
|
172
|
+
(void)argv;
|
|
173
|
+
return XT_UNDEFINED;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
METHOD(observer_disconnect) {
|
|
177
|
+
(void)self;
|
|
178
|
+
(void)env;
|
|
179
|
+
(void)argc;
|
|
180
|
+
(void)argv;
|
|
181
|
+
return XT_UNDEFINED;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** `takeRecords()`: an inert observer has no queued records. */
|
|
185
|
+
METHOD(observer_take_records) {
|
|
186
|
+
(void)argc;
|
|
187
|
+
(void)argv;
|
|
188
|
+
(void)env;
|
|
189
|
+
return xt_array_new(0, nullptr);
|
|
190
|
+
}
|
|
191
|
+
|
|
157
192
|
#undef METHOD
|
|
158
193
|
|
|
194
|
+
xt_value mutation_observer_proto() {
|
|
195
|
+
static xt_value proto = XT_UNDEFINED;
|
|
196
|
+
if (XT_IS_OBJECT(proto)) return proto;
|
|
197
|
+
proto = xt_object_new();
|
|
198
|
+
xt_gc_add_root(&proto);
|
|
199
|
+
xt_object_set(proto, xt_string_from_cstr("observe"),
|
|
200
|
+
xt_closure_new((void *)observer_observe, 0, nullptr));
|
|
201
|
+
xt_object_set(proto, xt_string_from_cstr("disconnect"),
|
|
202
|
+
xt_closure_new((void *)observer_disconnect, 0, nullptr));
|
|
203
|
+
xt_object_set(proto, xt_string_from_cstr("takeRecords"),
|
|
204
|
+
xt_closure_new((void *)observer_take_records, 0, nullptr));
|
|
205
|
+
return proto;
|
|
206
|
+
}
|
|
207
|
+
|
|
159
208
|
} // namespace domapi
|
|
@@ -139,6 +139,27 @@ METHOD(node_matches) {
|
|
|
139
139
|
return XT_FALSE;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
/** `element.closest(selector)`: the element itself or its nearest ancestor that
|
|
143
|
+
* matches. A page's delegated click handler is usually
|
|
144
|
+
* `event.target.closest("button")`, so this is the one selector API a page uses
|
|
145
|
+
* without querying. */
|
|
146
|
+
METHOD(node_closest) {
|
|
147
|
+
(void)env;
|
|
148
|
+
XtGuiWindow *win = nullptr;
|
|
149
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
150
|
+
if (node == nullptr || win == nullptr || argc < 1) return XT_NULL;
|
|
151
|
+
std::vector<xtgui::ComplexSelector> selectors =
|
|
152
|
+
xtgui::xt_css_parse_selector_list(to_string_value(xt_arg(argc, argv, 0)));
|
|
153
|
+
if (selectors.empty()) return XT_NULL;
|
|
154
|
+
for (const xtgui::Node *cursor = node; cursor != nullptr; cursor = cursor->parent) {
|
|
155
|
+
if (!cursor->isElement()) continue;
|
|
156
|
+
for (const xtgui::ComplexSelector &selector : selectors) {
|
|
157
|
+
if (xtgui::xt_css_match(cursor, selector)) return xt_gui_node_handle(win, cursor);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return XT_NULL;
|
|
161
|
+
}
|
|
162
|
+
|
|
142
163
|
METHOD(node_append_child) {
|
|
143
164
|
(void)env;
|
|
144
165
|
XtGuiWindow *win = nullptr;
|