From 1667746a2c8a3de2120597666b37deb9f6a40d80 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:45:24 +0700 Subject: [PATCH 1/5] refactor(fx): validate canonical native FX descriptors and share extension lookup --- src/NativeBuiltInFx.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/NativeBuiltInFx.h b/src/NativeBuiltInFx.h index 2509816a4..f2c5ecbed 100644 --- a/src/NativeBuiltInFx.h +++ b/src/NativeBuiltInFx.h @@ -7,6 +7,8 @@ #include "../engine/builtin_fx/VocalThrowProcessor.h" #include #include +#include +#include namespace armix::builtin_fx { // Control-side registration shared by live insert, offline edit and restore. @@ -61,9 +63,40 @@ inline constexpr std::array nativeBuiltInFx{ prepareNativeBuiltInFx} }; -inline const NativeBuiltInFx* findNativeBuiltInFx(const juce::String& id) { - for(const auto& fx:nativeBuiltInFx) - if(id==fx.id)return &fx; +// Compile-time registration contract: one stable catalog identity per FX, +// with one prepare function and a bounded device-rate policy. The same +// validator is usable by a fixture registry without adding a product host +// branch or touching the realtime callback. +constexpr bool validNativeBuiltInFxCatalog(std::span registry) { + if(registry.empty())return false; + for(std::size_t i=0;i=8000.) || + !(fx.maximumLiveRate>=fx.minimumLiveRate) || + !(fx.maximumLiveRate<=384000.)) + return false; + for(std::size_t j=i+1;j registry,const juce::String& id) { + if(id.isEmpty())return nullptr; + for(const auto& fx:registry) + if(fx.id && id==fx.id)return &fx; return nullptr; } +inline const NativeBuiltInFx* findNativeBuiltInFx(const juce::String& id) { + return findNativeBuiltInFxIn(nativeBuiltInFx,id); +} } // namespace armix::builtin_fx From 021383d20c0c7938c32ea5e8481c2f715d5940f8 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:45:52 +0700 Subject: [PATCH 2/5] test(fx): exercise injected host FX descriptor through real registry prepare and PCM --- tests/native_fx_registry_extension_test.cpp | 105 ++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/native_fx_registry_extension_test.cpp diff --git a/tests/native_fx_registry_extension_test.cpp b/tests/native_fx_registry_extension_test.cpp new file mode 100644 index 000000000..16223373a --- /dev/null +++ b/tests/native_fx_registry_extension_test.cpp @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../src/NativeBuiltInFx.h" +#include +#include +#include +#include +#include + +// M4: a future native FX must extend the real host registry, not require +// new branches in Main, the route graph, WebView or the JUCE callback. +class FixtureGainFx final : public juce::AudioProcessor { +public: + FixtureGainFx():juce::AudioProcessor(BusesProperties() + .withInput("Main",juce::AudioChannelSet::stereo(),true) + .withOutput("Main",juce::AudioChannelSet::stereo(),true)){} + const juce::String getName() const override {return "Fixture Gain";} + void prepareToPlay(double rate,int frames) override { + ready_=(rate>=8000. && frames>=32); + } + void releaseResources() override {ready_=false;} + bool isReady() const noexcept {return ready_;} + bool restoreUnpublishedState(const void* data,int bytes) noexcept { + if(!data || bytes!=static_cast(sizeof(float)))return false; + float candidate=0.f; + std::memcpy(&candidate,data,sizeof(candidate)); + if(!std::isfinite(candidate)||candidate<0.f||candidate>4.f)return false; + gain_=candidate; + return true; + } + void processBlock(juce::AudioBuffer& pcm,juce::MidiBuffer&) override { + pcm.applyGain(gain_); + } + double getTailLengthSeconds() const override {return 0.;} + bool acceptsMidi() const override {return false;} + bool producesMidi() const override {return false;} + juce::AudioProcessorEditor* createEditor() override {return nullptr;} + bool hasEditor() const override {return false;} + int getNumPrograms() override {return 1;} + int getCurrentProgram() override {return 0;} + void setCurrentProgram(int) override {} + const juce::String getProgramName(int) override {return {};} + void changeProgramName(int,const juce::String&) override {} + void getStateInformation(juce::MemoryBlock& dest) override { + dest.append(&gain_,sizeof(gain_)); + } + void setStateInformation(const void* data,int bytes) override { + restoreUnpublishedState(data,bytes); + } +private: + float gain_=1.f; + bool ready_=false; +}; + +using Entry=armix::builtin_fx::NativeBuiltInFx; +using armix::builtin_fx::prepareNativeBuiltInFx; +using armix::builtin_fx::validNativeBuiltInFxCatalog; +using armix::builtin_fx::findNativeBuiltInFxIn; + +constexpr Entry fixture{ + "armix.test.fixture-gain.v1","Fixture Gain","Test",false, + 8000.,192000., + "UNAVAILABLE","DEVICE_CHANGED","FORMAT_REJECTED", + "PREPARE_REJECTED","PREPARE_EXCEPTION","RESTORE_REJECTED", + prepareNativeBuiltInFx +}; +constexpr std::array injected{fixture}; +constexpr std::array duplicate{fixture,fixture}; +static_assert(validNativeBuiltInFxCatalog(injected)); +static_assert(!validNativeBuiltInFxCatalog(duplicate)); +static_assert(validNativeBuiltInFxCatalog(armix::builtin_fx::nativeBuiltInFx)); +static_assert(std::is_same_v); + +int main() { + const auto* found=findNativeBuiltInFxIn(injected,"armix.test.fixture-gain.v1"); + assert(found==&injected[0]); + assert(!findNativeBuiltInFxIn(injected,"")); + assert(!findNativeBuiltInFxIn(injected,"armix.test.fixture-gain.v2")); + // Production IDs still resolve through the exact SAME lookup implementation. + for(const auto& production:armix::builtin_fx::nativeBuiltInFx) + assert(armix::builtin_fx::findNativeBuiltInFx(production.id)==&production); + + constexpr float gain=1.5f; + auto prepared=found->prepare(48000.,128,&gain,sizeof(gain)); + assert(prepared!=nullptr); + assert(prepared->getLatencySamples()==0); + juce::AudioBuffer stereo(2,32); + stereo.clear(); + stereo.setSample(0,0,0.6f); + stereo.setSample(1,0,-0.4f); + juce::MidiBuffer midi; + prepared->processBlock(stereo,midi); + assert(std::abs(stereo.getSample(0,0)-0.9f)<0.00001f); + assert(std::abs(stereo.getSample(1,0)+0.6f)<0.00001f); + + const float bad=std::numeric_limits::quiet_NaN(); + assert(!found->prepare(48000.,128,&bad,sizeof(bad))); + assert(!found->prepare(48000.,128,&gain,0)); + assert(!found->prepare(48000.,128,nullptr,sizeof(gain))); + // A new type is registered by adding a descriptor only: the production + // graph's FX lease, bypass and VST3 editor lifetime remain untouched. + return 0; +} From 21042f7334081af2a3e14c3334cda15cf8fa86ab Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:46:31 +0700 Subject: [PATCH 3/5] fix(fx): reject inconsistent native state pointers before processor prepare --- src/NativeBuiltInFx.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/NativeBuiltInFx.h b/src/NativeBuiltInFx.h index f2c5ecbed..11cf3d1c5 100644 --- a/src/NativeBuiltInFx.h +++ b/src/NativeBuiltInFx.h @@ -33,6 +33,11 @@ struct NativeBuiltInFx { template std::unique_ptr prepareNativeBuiltInFx( double rate,int frames,const void* state,int bytes) { + // State bytes are CONTROL-only. A missing pointer with a positive size + // must never be mistaken for a valid default, especially during restore. + if(bytes<0 || bytes>8*1024*1024 || + (state==nullptr && bytes!=0) || (state!=nullptr && bytes==0)) + return {}; auto processor=std::make_unique(); processor->prepareToPlay(rate,frames); if(!processor->isReady() || (state && !processor->restoreUnpublishedState(state,bytes))) From 7bd22974cc0b58f9524262274e0042e76cc96ad4 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:46:34 +0700 Subject: [PATCH 4/5] test(fx): cover malformed state and fixed descriptor function pointer --- tests/native_fx_registry_extension_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/native_fx_registry_extension_test.cpp b/tests/native_fx_registry_extension_test.cpp index 16223373a..30e099d1e 100644 --- a/tests/native_fx_registry_extension_test.cpp +++ b/tests/native_fx_registry_extension_test.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include // M4: a future native FX must extend the real host registry, not require @@ -71,7 +72,7 @@ constexpr std::array duplicate{fixture,fixture}; static_assert(validNativeBuiltInFxCatalog(injected)); static_assert(!validNativeBuiltInFxCatalog(duplicate)); static_assert(validNativeBuiltInFxCatalog(armix::builtin_fx::nativeBuiltInFx)); -static_assert(std::is_same_v); +static_assert(std::is_same_v>); int main() { const auto* found=findNativeBuiltInFxIn(injected,"armix.test.fixture-gain.v1"); From 773edab3f21698d7ae9ef30335218673b32dba86 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:46:48 +0700 Subject: [PATCH 5/5] build(fx): register M4 extension PCM CTest under existing Windows mixer target --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35fef2ded..b93486c0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,16 @@ if(BUILD_TESTING) target_link_libraries(ARMixFactoryFxRegistryTests PRIVATE juce::juce_core juce::juce_cryptography juce::juce_recommended_config_flags) target_compile_features(ARMixFactoryFxRegistryTests PRIVATE cxx_std_20) add_test(NAME FactoryFxVerifiedManifestAndNegativePathGate COMMAND ARMixFactoryFxRegistryTests) + # M4: a native FX fixture goes through the SAME descriptor/prepare path + # as all built-ins, without registration branches in Main or RT graph. + juce_add_console_app(ARMixNativeFxExtensionTests PRODUCT_NAME "ArSonMix Native FX Host Extension Tests") + target_sources(ARMixNativeFxExtensionTests PRIVATE + tests/native_fx_registry_extension_test.cpp src/NativeBuiltInFx.h) + target_link_libraries(ARMixNativeFxExtensionTests PRIVATE + juce::juce_audio_processors juce::juce_recommended_config_flags) + target_compile_features(ARMixNativeFxExtensionTests PRIVATE cxx_std_20) + add_test(NAME M4NativeFxCatalogExtensionAndStatePreparation + COMMAND ARMixNativeFxExtensionTests) add_executable(ARMixFxStructuralHandoffTests tests/live_fx_structural_handoff_test.cpp) target_compile_features(ARMixFxStructuralHandoffTests PRIVATE cxx_std_20) add_test(NAME R0BStructuralFxAckAndControlThreadRetirement COMMAND ARMixFxStructuralHandoffTests) @@ -214,6 +224,7 @@ if(BUILD_TESTING) target_compile_features(ARMixNativeV8ProjectionTests PRIVATE cxx_std_20) add_test(NAME M3BNativeV8StableIdReadbackAndFailClosedProjection COMMAND ARMixNativeV8ProjectionTests) add_dependencies(ARMixMixerRoutingTests ARMixNativeV8ProjectionTests) + add_dependencies(ARMixMixerRoutingTests ARMixNativeFxExtensionTests) juce_add_console_app(ARMixApprovedRoutingPcmTests PRODUCT_NAME "ArSonMix Approved WIRE PCM Tests") target_sources(ARMixApprovedRoutingPcmTests PRIVATE tests/approved_native_routing_pcm_test.cpp) target_link_libraries(ARMixApprovedRoutingPcmTests PRIVATE juce::juce_core juce::juce_recommended_config_flags)