diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e2eac7bb..b866ca05b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,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: fixture processor goes through the SAME native FX descriptor path. + # Remains part of the existing Windows native mixer qualification build. + 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) # One user-owned, effect-scoped library; not .smix or FX-chain .armix. # File IO is forbidden in the realtime PCM callback. juce_add_console_app(ARMixBuiltInFxPresetStoreTests PRODUCT_NAME "ArSonMix Native Built-in FX User Preset Store") @@ -234,6 +244,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) diff --git a/src/NativeBuiltInFx.h b/src/NativeBuiltInFx.h index 2509816a4..11cf3d1c5 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. @@ -31,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))) @@ -61,9 +68,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 diff --git a/tests/native_fx_registry_extension_test.cpp b/tests/native_fx_registry_extension_test.cpp new file mode 100644 index 000000000..30e099d1e --- /dev/null +++ b/tests/native_fx_registry_extension_test.cpp @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include "../src/NativeBuiltInFx.h" +#include +#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; +}