From f763dc2551798a9e8438b6992d847faadcc90532 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:02:11 +0700 Subject: [PATCH 01/20] feat(device): attest actual JUCE active channel masks and sparse port-to-callback mapping --- engine/device/JuceActivePortSnapshot.h | 98 ++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 engine/device/JuceActivePortSnapshot.h diff --git a/engine/device/JuceActivePortSnapshot.h b/engine/device/JuceActivePortSnapshot.h new file mode 100644 index 000000000..3858d1b23 --- /dev/null +++ b/engine/device/JuceActivePortSnapshot.h @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "LiveInputPortRegistry.h" +#include +#include +#include + +// P1F: control-thread hardware topology attestation. The JUCE callback's +// input pointers are PACKED in ascending order of the actual active input +// mask. Never use the physical channel number as a callback pointer ordinal. +// This component DOES NOT reopen devices, nor enable disabled pins. +namespace armix::device { +struct JuceActivePortSnapshot final { + enum class Fault : std::uint8_t { + none, nullDevice, uninitialisedDevice, emptyInput, emptyOutput, + tooManyInputs, tooManyOutputs, inputRegistryRejected, + deviceChangedDuringRead + }; + static constexpr int limit=LiveInputPortRegistry::limit; + LiveInputPortRegistry inputs {}; + std::array outputByCallback {}; + int outputCount=0; + std::uint64_t epoch=0; + juce::String deviceName, typeName; + + // Accept a frozen copy of masks so unit tests can exercise sparse + // numbering without requiring an ASIO device. This executes off RT. + static bool fromMasks(std::uint64_t epoch, + const juce::BigInteger& inputMask, + const juce::BigInteger& outputMask, + JuceActivePortSnapshot& destination, + Fault& error) noexcept { + error=Fault::none; + std::array inputIndices{}, outputIndices{}; + int in=0,out=0; + for(int p=inputMask.findNextSetBit(0);p>=0; + p=inputMask.findNextSetBit(p+1)) { + if(p>=limit || in>=limit){error=Fault::tooManyInputs;return false;} + inputIndices[in++]=p; + } + for(int p=outputMask.findNextSetBit(0);p>=0; + p=outputMask.findNextSetBit(p+1)) { + if(p>=limit || out>=limit){error=Fault::tooManyOutputs;return false;} + outputIndices[out++]=p; + } + if(in==0){error=Fault::emptyInput;return false;} + if(out==0){error=Fault::emptyOutput;return false;} + JuceActivePortSnapshot candidate; + LiveInputPortRegistry::Fault inputFault{}; + if(!LiveInputPortRegistry::prepare( + epoch,std::span(inputIndices.data(),static_cast(in)), + candidate.inputs,inputFault)) { + error=Fault::inputRegistryRejected;return false; + } + std::copy_n(outputIndices.begin(),out,candidate.outputByCallback.begin()); + candidate.outputCount=out; + candidate.epoch=epoch; + destination=std::move(candidate); + return true; + } + + // Call only from device lifecycle/configuration control thread after + // the selected DEVICESETUP is verified. Name/type alone are not the + // security identity: backend ASIO registration/endpoint fence remains + // authoritative outside this helper. + static bool capture(juce::AudioIODevice* device,std::uint64_t epoch, + JuceActivePortSnapshot& destination, + Fault& error) { + error=Fault::none; + if(!device){error=Fault::nullDevice;return false;} + if(!device->isOpen()){error=Fault::uninitialisedDevice;return false;} + const auto in=device->getActiveInputChannels(); + const auto out=device->getActiveOutputChannels(); + JuceActivePortSnapshot candidate; + if(!fromMasks(epoch,in,out,candidate,error))return false; + // A driver may be reconfigured asynchronously. Reject if masks + // changed across the control-thread snapshot read. + if(in!=device->getActiveInputChannels() || + out!=device->getActiveOutputChannels()) { + error=Fault::deviceChangedDuringRead;return false; + } + candidate.deviceName=device->getName(); + candidate.typeName=device->getTypeName(); + destination=std::move(candidate); + return true; + } + int outputPhysicalPort(int callbackIndex) const noexcept { + return callbackIndex>=0 && callbackIndex Date: Wed, 28 Oct 2026 11:02:20 +0700 Subject: [PATCH 02/20] build(device): include explicit standard dependencies for channel snapshot --- engine/device/JuceActivePortSnapshot.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/device/JuceActivePortSnapshot.h b/engine/device/JuceActivePortSnapshot.h index 3858d1b23..359ea9d96 100644 --- a/engine/device/JuceActivePortSnapshot.h +++ b/engine/device/JuceActivePortSnapshot.h @@ -2,7 +2,10 @@ #pragma once #include "LiveInputPortRegistry.h" #include +#include #include +#include +#include #include // P1F: control-thread hardware topology attestation. The JUCE callback's From f5c6dad73d444ce7f300a9db8e3e61a1a33bc693 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:02:34 +0700 Subject: [PATCH 03/20] test(device): verify sparse physical channels, output mask, epochs and no partial publication --- tests/juce_active_port_snapshot_test.cpp | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/juce_active_port_snapshot_test.cpp diff --git a/tests/juce_active_port_snapshot_test.cpp b/tests/juce_active_port_snapshot_test.cpp new file mode 100644 index 000000000..b4e76b976 --- /dev/null +++ b/tests/juce_active_port_snapshot_test.cpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/device/JuceActivePortSnapshot.h" +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include +#include +using namespace armix::device; +int main(){ + JuceActivePortSnapshot snap; + JuceActivePortSnapshot::Fault fault; + juce::BigInteger in,out; + in.setBit(5);in.setBit(2);in.setBit(9); + out.setBit(1);out.setBit(7); + assert(JuceActivePortSnapshot::fromMasks(11,in,out,snap,fault)); + assert(snap.inputs.enabledCount==3); + assert(snap.inputs.callbackIndex(2)==0); + assert(snap.inputs.callbackIndex(5)==1); + assert(snap.inputs.callbackIndex(9)==2); + assert(snap.inputs.callbackIndex(3)==-1); + assert(snap.outputPhysicalPort(0)==1); + assert(snap.outputPhysicalPort(1)==7); + assert(snap.outputPhysicalPort(2)==-1); + assert(snap.matchesCallback(11,3,2)); + assert(!snap.matchesCallback(11,2,2)); + assert(!snap.matchesCallback(12,3,2)); + assert(!snap.matchesCallback(11,3,1)); + const auto previous=snap; + assert(!JuceActivePortSnapshot::fromMasks(0,in,out,snap,fault)); + assert(snap.matchesCallback(11,3,2)); // rollback + in.setBit(256); + assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::tooManyInputs); + assert(snap.matchesCallback(11,3,2)); + in.clearBit(256); + out.setBit(256); + assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::tooManyOutputs); + out.clearBit(256); + out.clear(); + assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::emptyOutput); + in.clear(); + assert(!JuceActivePortSnapshot::fromMasks(12,in,out,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::emptyInput); + assert(snap.inputs.callbackIndex(9)==previous.inputs.callbackIndex(9)); + assert(!JuceActivePortSnapshot::capture(nullptr,12,snap,fault)); + assert(fault==JuceActivePortSnapshot::Fault::nullDevice); +} From f55224b22d7ac7cf6ae0fcfb34e48172e5a10b5e Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:02:47 +0700 Subject: [PATCH 04/20] build: register native JUCE physical channel topology verification --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 734e93ad7..f68fd139b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ juce_add_gui_app(ARMixConsole juce_add_binary_data(ARMixAssets SOURCES web/index.html web/styles.css web/app.js web/bridge.js web/monitor.js) -target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) +target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) target_compile_definitions(ARMixConsole PRIVATE JUCE_WEB_BROWSER=1 JUCE_USE_WIN_WEBVIEW2=1 @@ -59,6 +59,11 @@ if(BUILD_TESTING) add_executable(ARMixPreparedMixerBlockTests tests/prepared_mixer_block_test.cpp) target_compile_features(ARMixPreparedMixerBlockTests PRIVATE cxx_std_20) add_test(NAME TenChannelEndToEndPreparedAudioRender COMMAND ARMixPreparedMixerBlockTests) + juce_add_console_app(ARMixJucePortMaskTests PRODUCT_NAME "ArSonMix JUCE Port Mask Snapshot Tests") + target_sources(ARMixJucePortMaskTests PRIVATE tests/juce_active_port_snapshot_test.cpp engine/device/JuceActivePortSnapshot.h) + target_link_libraries(ARMixJucePortMaskTests PRIVATE juce::juce_audio_devices juce::juce_recommended_config_flags) + target_compile_features(ARMixJucePortMaskTests PRIVATE cxx_std_20) + add_test(NAME JuceSparseActiveChannelMaskAndEpoch COMMAND ARMixJucePortMaskTests) add_executable(ARMixLiveRoutingEpochTests tests/live_port_epoch_publisher_test.cpp) target_compile_features(ARMixLiveRoutingEpochTests PRIVATE cxx_std_20) add_test(NAME P1ELivePortGenerationRevisionAndRealtimeRetirement COMMAND ARMixLiveRoutingEpochTests) From 3fcedd17c718a97b8c3f9ce596501b7b4aaed29d Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:02:50 +0700 Subject: [PATCH 05/20] ci: test actual JUCE active-mask translation on Windows CI --- .github/workflows/p1-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 11c5aeadb..025f5c640 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -92,7 +92,7 @@ jobs: -DBUILD_TESTING=ON -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" - name: Build executable and native RT tests - run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 + run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixJucePortMaskTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 - name: Test realtime control primitives run: ctest --test-dir build -C Release --output-on-failure - name: Package verified JUCE GUI for hardware FAT From 54f276a9d10fdef9f41cf930bac9f76f72badadf Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:03:15 +0700 Subject: [PATCH 06/20] feat(mixer): bind JUCE device masks to 10-channel DSP and realtime graph publication --- engine/core/PreparedNativeMixerSession.h | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 engine/core/PreparedNativeMixerSession.h diff --git a/engine/core/PreparedNativeMixerSession.h b/engine/core/PreparedNativeMixerSession.h new file mode 100644 index 000000000..6956c79ce --- /dev/null +++ b/engine/core/PreparedNativeMixerSession.h @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "../device/JuceActivePortSnapshot.h" +#include "PreparedMixerBlock.h" +#include "RealtimeRoutePublisher.h" +#include +#include +#include + +// P1F: complete, device-epoch-bound prepared DSP render session. +// Configures actual opened JUCE input masks on the CONTROL thread; does not +// silently enable physical pins, restart devices or allocate during rendering. +// No VST lifecycle coupling: FX callback is supplied by the host after it has +// independently negotiated compatible plugin buses and proven instance ownership. +namespace armix::mixer { +class PreparedNativeMixerSession final { +public: + struct BoundGraph final { + armix::device::JuceActivePortSnapshot ports; + std::unique_ptr mixer; + }; + using Publisher=armix::rt::RealtimeRoutePublisher; + using PublishResult=Publisher::Result; + + struct PrepareResult { + enum class Fault : unsigned char { + none, invalidTopology, graphRejected, invalidBufferCapacity + } fault=Fault::none; + armix::device::JuceActivePortSnapshot::Fault portFault{}; + RenderError graphError{}; + }; + + static std::unique_ptr prepare( + const ChannelRoutingConfig& channels, + const SendRequest& sends, + const juce::BigInteger& activeInputMask, + const juce::BigInteger& activeOutputMask, + std::uint64_t deviceEpoch, + std::uint64_t revision, + int maxFrames, + PrepareResult& result) { + result={}; + if(maxFrames<=0 || maxFrames>PreparedMixerBlock::hardFrameLimit) { + result.fault=PrepareResult::Fault::invalidBufferCapacity; + return {}; + } + armix::device::JuceActivePortSnapshot ports; + if(!armix::device::JuceActivePortSnapshot::fromMasks( + deviceEpoch,activeInputMask,activeOutputMask, + ports,result.portFault)) { + result.fault=PrepareResult::Fault::invalidTopology; + return {}; + } + std::array ordered{}; + for(int i=0;i(ordered.data(), + static_cast(ports.inputs.enabledCount)), + sends,candidate,result.graphError)) { + result.fault=PrepareResult::Fault::graphRejected; + return {}; + } + auto snapshot=std::make_unique(); + snapshot->deviceEpoch=deviceEpoch; + snapshot->graphRevision=revision; + snapshot->prepared=std::make_unique(); + snapshot->prepared->ports=ports; + snapshot->prepared->mixer=std::make_unique( + candidate,maxFrames); + return snapshot; + } + + // CONTROL thread: publication must be serialized with device lifecycle, + // and caller must provide last-ACK revision + current device generation. + PublishResult publish(std::unique_ptr candidate, + std::uint64_t expectedRevision, + std::uint64_t currentDeviceEpoch) noexcept { + return publisher_.publish(std::move(candidate),expectedRevision, + currentDeviceEpoch); + } + void unpublish() noexcept { publisher_.unpublish(); } + bool pollRetirement() noexcept { return publisher_.pollRetirement(); } + std::uint64_t lastRevision() const noexcept {return publisher_.lastRevision();} + + // RT: acquire a lease bound to the device generation; refuse changed + // callback I/O counts. No spin, locks, allocations or temporary buffers. + // A rejected callback is silent. Caller guarantees output buffers hold + // at least frames values. + template + bool render(const float* const* inputs,int inputChannels, + float* outputL,float* outputR,int outputChannels, + int frames,std::uint64_t deviceEpoch, + Fx&& fx,RenderLevels* observed=nullptr) noexcept { + if(!outputL || !outputR || frames<=0)return false; + auto lease=publisher_.acquire(); + const auto* snap=lease.get(deviceEpoch); + if(!snap || !snap->prepared || !snap->prepared->mixer || + !snap->prepared->ports.matchesCallback( + deviceEpoch,inputChannels,outputChannels)) { + std::fill_n(outputL,frames,0.f); + std::fill_n(outputR,frames,0.f); + if(observed)*observed={}; + return false; + } + return snap->prepared->mixer->process(inputs,inputChannels, + outputL,outputR,frames,std::forward(fx),observed); + } +private: + Publisher publisher_{}; +}; +} // namespace armix::mixer From 660a37963cbe1244ca9232996596d05cfe0e7533 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:03:29 +0700 Subject: [PATCH 07/20] test(mixer): JUCE sparse physical hardware pins through native-epoch mixer graph to actual samples --- tests/prepared_native_mixer_session_test.cpp | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/prepared_native_mixer_session_test.cpp diff --git a/tests/prepared_native_mixer_session_test.cpp b/tests/prepared_native_mixer_session_test.cpp new file mode 100644 index 000000000..ea8251b8e --- /dev/null +++ b/tests/prepared_native_mixer_session_test.cpp @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/core/PreparedNativeMixerSession.h" +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include +#include +#include +using namespace armix::mixer; +static bool near(float a,float b){return std::abs(a-b)<1.e-5f;} +int main(){ + PreparedNativeMixerSession session; + ChannelRoutingConfig cfg; SendRequest sends; + juce::BigInteger in,out; + // callback[0]=physical2, callback[1]=physical5, callback[2]=physical9 + in.setBit(2);in.setBit(5);in.setBit(9); + out.setBit(0);out.setBit(1); + cfg.stripsAndMaster.strips[0]={ + SourceMode::mono,9,-1,1.f,-1.f,false,false}; + cfg.stripsAndMaster.strips[1]={ + SourceMode::stereo,2,5,1.f,0.f,false,false}; + cfg.stripsAndMaster.strips[2]={ + SourceMode::disconnected,-1,-1,1.f,0.f,false,false}; + cfg.formats[2]=ChannelFormat::stereo; + sends.count=1; + sends.sends[0]={0,2,SendTap::postFader,0.5f,0.f,true}; + PreparedNativeMixerSession::PrepareResult result; + auto candidate=PreparedNativeMixerSession::prepare( + cfg,sends,in,out,41,1,64,result); + assert(candidate && result.fault==decltype(result.fault)::none); + assert(session.publish(std::move(candidate),0,41)== + PreparedNativeMixerSession::PublishResult::applied); + const std::array a{.2f,.2f,.2f}; + const std::array b{.4f,.4f,.4f}; + const std::array c{.8f,.8f,.8f}; + const float* inputs[]{a.data(),b.data(),c.data()}; + std::array l{},r{}; + auto noop=[](int,float*,float*,int) noexcept {}; + RenderLevels meters; + assert(session.render(inputs,3,l.data(),r.data(),2,3,41,noop,&meters)); + // CH1 hard L .8; CH2 L .2, R .4; CH3 return L .4 + assert(near(l[0],1.4f) && near(r[0],.4f)); + assert(near(meters.channelPeak[0],.8f)); + // Device mismatches: silence, do not reuse stale hardware pointers. + l.fill(8);r.fill(8); + assert(!session.render(inputs,3,l.data(),r.data(),2,3,42,noop)); + assert(l[0]==0&&r[0]==0); + l.fill(8);r.fill(8); + assert(!session.render(inputs,2,l.data(),r.data(),2,3,41,noop)); + assert(l[0]==0&&r[0]==0); + l.fill(8);r.fill(8); + assert(!session.render(inputs,3,l.data(),r.data(),1,3,41,noop)); + assert(l[0]==0&&r[0]==0); + + // Invalid physical source and mutated device topology do not publish. + cfg.stripsAndMaster.strips[0].inputA=8; + auto bad=PreparedNativeMixerSession::prepare( + cfg,sends,in,out,41,2,64,result); + assert(!bad && result.fault==decltype(result.fault)::graphRejected); + assert(session.lastRevision()==1); + cfg.stripsAndMaster.strips[0].inputA=9; + auto wrongEpoch=PreparedNativeMixerSession::prepare( + cfg,sends,in,out,42,2,64,result); + assert(wrongEpoch); + assert(session.publish(std::move(wrongEpoch),1,41)== + PreparedNativeMixerSession::PublishResult::staleDevice); + assert(session.lastRevision()==1); + auto second=PreparedNativeMixerSession::prepare( + cfg,sends,in,out,41,2,64,result); + assert(session.publish(std::move(second),1,41)== + PreparedNativeMixerSession::PublishResult::applied); + assert(session.lastRevision()==2); + assert(session.render(inputs,3,l.data(),r.data(),2,3,41,noop)); + assert(near(l[0],1.4f)); + session.unpublish(); + l.fill(8);r.fill(8); + assert(!session.render(inputs,3,l.data(),r.data(),2,3,41,noop)); + assert(l[0]==0&&r[0]==0); + assert(session.pollRetirement()); +} From c4d5190a02eeda2c6806ded3dbf5cf46cc2eafe3 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:03:40 +0700 Subject: [PATCH 08/20] build: wire prepared JUCE-to-DSP session end-to-end acceptance test --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f68fd139b..d562ab8d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ juce_add_gui_app(ARMixConsole juce_add_binary_data(ARMixAssets SOURCES web/index.html web/styles.css web/app.js web/bridge.js web/monitor.js) -target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) +target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/PreparedNativeMixerSession.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) target_compile_definitions(ARMixConsole PRIVATE JUCE_WEB_BROWSER=1 JUCE_USE_WIN_WEBVIEW2=1 @@ -64,6 +64,11 @@ if(BUILD_TESTING) target_link_libraries(ARMixJucePortMaskTests PRIVATE juce::juce_audio_devices juce::juce_recommended_config_flags) target_compile_features(ARMixJucePortMaskTests PRIVATE cxx_std_20) add_test(NAME JuceSparseActiveChannelMaskAndEpoch COMMAND ARMixJucePortMaskTests) + juce_add_console_app(ARMixNativeMixerSessionTests PRODUCT_NAME "ArSonMix Bound Native Routing Tests") + target_sources(ARMixNativeMixerSessionTests PRIVATE tests/prepared_native_mixer_session_test.cpp engine/core/PreparedNativeMixerSession.h) + target_link_libraries(ARMixNativeMixerSessionTests PRIVATE juce::juce_audio_devices juce::juce_recommended_config_flags) + target_compile_features(ARMixNativeMixerSessionTests PRIVATE cxx_std_20) + add_test(NAME P1FPhysicalPortToNativeMasterAndEpochGuard COMMAND ARMixNativeMixerSessionTests) add_executable(ARMixLiveRoutingEpochTests tests/live_port_epoch_publisher_test.cpp) target_compile_features(ARMixLiveRoutingEpochTests PRIVATE cxx_std_20) add_test(NAME P1ELivePortGenerationRevisionAndRealtimeRetirement COMMAND ARMixLiveRoutingEpochTests) From 99624845b26ee51ef3d319de45f72bfc2db2123b Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:03:45 +0700 Subject: [PATCH 09/20] ci: include P1F device-epoch native render test in existing optimized Windows workflow --- .github/workflows/p1-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 025f5c640..006392021 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -92,7 +92,7 @@ jobs: -DBUILD_TESTING=ON -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" - name: Build executable and native RT tests - run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixJucePortMaskTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 + run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixJucePortMaskTests ARMixNativeMixerSessionTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 - name: Test realtime control primitives run: ctest --test-dir build -C Release --output-on-failure - name: Package verified JUCE GUI for hardware FAT From 6a17a515a36333f581c4a9c9231fc06a7557096b Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 11:04:10 +0700 Subject: [PATCH 10/20] docs: retain P1F hardware session guard, cross-thread baseline, and native release gates --- docs/P1F_JUCE_DEVICE_BOUND_DSP_20261028.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docs/P1F_JUCE_DEVICE_BOUND_DSP_20261028.md diff --git a/docs/P1F_JUCE_DEVICE_BOUND_DSP_20261028.md b/docs/P1F_JUCE_DEVICE_BOUND_DSP_20261028.md new file mode 100644 index 000000000..412698586 --- /dev/null +++ b/docs/P1F_JUCE_DEVICE_BOUND_DSP_20261028.md @@ -0,0 +1,21 @@ +# P1F — JUCE hardware port binding to prepared native 10-channel graph + +Source: main `15450e64d6fbb683150a624859a6351ca5ad2c34` (FX drag atomic reorder, Orbit/POLAR, meter, bypass and lean CI already reconciled). No edits to production `LiveAudioEngine.h`, `src/Main.cpp`, `web/*`, vendor VST or hardware settings. + +## Implemented in code + +- `engine/device/JuceActivePortSnapshot.h` reads the *real opened device's* `getActiveInputChannels()` and `getActiveOutputChannels()` masks on the control/device lifecycle thread. Sparse enabled physical inputs are sorted and mapped to JUCE callback pointer ordinals. Output physical indices are retained. Rejects missing device, unopened device, empty inputs/outputs, masks >256 physical channels, a changing mask while read, invalid epochs. No fallback to `input[0]` or invention of physical pins. Driver/ASIO registration identity remains protected by the existing direct-route fence. +- `engine/core/PreparedNativeMixerSession.h` composes `JuceActivePortSnapshot` + `PreparedRenderGraph` + `PreparedMixerBlock` + existing P1E `RealtimeRoutePublisher`. The **same** physical port mapping is validated into the DSP source and bound to immutable graph/device epoch/revision. Rejects invalid buffer limits and invalid routing without partial publication. Audio-reader render lease rejects changed device epoch or callback input/output counts and clears master output. Realtime render has no port discovery, allocations, device restart, file calls or locks. Snapshots and FX ownership are retired on control thread. +- Two executable native JUCE CTests, `JuceSparseActiveChannelMaskAndEpoch` and `P1FPhysicalPortToNativeMasterAndEpochGuard`, are built into existing Windows workflow. Test: active input bits 2/5/9, actual callback pointer order, channel physical mono IN9 + stereo IN2/5, CH1→CH3 return without physical input, exact stereo master audio values, stale epoch/input count/output count fail-closed, invalid routing rollback, and epoch/revision publication validation. + +## Strict gate to full live DAW routing + +This is **an executable control-to-DSP integration artifact**, not yet enabled as the native live JUCE host path. The existing host still starts `deviceManager_.initialise(1,2,...)`; enabling any other hardware input may require user-controlled device reopen. A verified requested physical ASIO mask and deliberate device profile must precede live activation. + +The native callback currently owns one CH1-only VST chain; replacing it blindly would erase proven Orbit, FabFilter processing, FX reorder, anti-crackle bypass and the user's physical audio results. The next milestone must first provide independent VST3 instance ownership and real mono/stereo plugin bus negotiation, then wire a callback-boundary route change with ACK, preallocated FX scratch, actual VU per strip, and preserve DIRECT / Independent Clock diagnostics. Do not mark CH2–10 GUI buttons active without all of that. + +Issue #15 zero-FX crackle remains open. Unit tests do not qualify hardware sound quality. Approved GUI remains unchanged; #115/#117 are overlapping offline graphs and must be reconciled by function rather than merged as duplicate engines. + +## Acceptance and follow-up + +Windows MSVC native CTest and UI must pass at exact PR head; no main merge without that. Audio interface ASIO tests with ports not starting at 1 and sparse enabled masks are required before declaring physical I/O mapping trustworthy. Device disconnect/reopen increments epoch and cannot inherit old live snapshots, with port identity remapping explicit for portable performances. If a route requests a currently inactive physical pin, the control plane must ask for Audio Setup and cannot silently reopen during live performance. From ee1f9558888752912daa15e60e24b7ad53725889 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:37:55 +0700 Subject: [PATCH 11/20] feat(routing): decode validated 10-channel bus/send/mute/solo configuration before RT --- engine/core/NativeDryRouteCommand.h | 120 ++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 engine/core/NativeDryRouteCommand.h diff --git a/engine/core/NativeDryRouteCommand.h b/engine/core/NativeDryRouteCommand.h new file mode 100644 index 000000000..af07e7785 --- /dev/null +++ b/engine/core/NativeDryRouteCommand.h @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "ChannelSendPlan.h" +#include +#include +#include +#include + +// P1G control thread: decode the entire Routing LAB transaction exactly once. +// GUI selections are untrusted drafts. Audio RT never parses JSON or allocates. +namespace armix::mixer { +struct NativeDryRouteCommand final { + ChannelRoutingConfig channels {}; + SendRequest sends {}; + + static bool decode(const juce::var& request, + NativeDryRouteCommand& destination, + juce::String& problem) { + problem.clear(); + if(!request.isObject()) {problem="Invalid routing command";return false;} + auto* rows=request.getProperty("channels",{}).getArray(); + if(!rows || rows->size()!=stripCount) { + problem="Exactly 10 channel assignments are required";return false; + } + NativeDryRouteCommand candidate; + std::array modeNames {}; + for(int i=0;igetReference(i); + if(!row.isObject()){problem="Invalid channel assignment";return false;} + const auto mode=row.getProperty("mode",{}).toString(); + modeNames[i]=mode; + const auto left=row.getProperty("left",-1); + const auto right=row.getProperty("right",-1); + const auto gain=row.getProperty("gain",.25); + const auto pan=row.getProperty("pan",0.0); + const auto muted=row.getProperty("mute",false); + const auto soloed=row.getProperty("solo",false); + const auto main=row.getProperty("main",true); + if(!left.isInt()||!right.isInt()|| + !(gain.isDouble()||gain.isInt())|| + !(pan.isDouble()||pan.isInt())|| + !muted.isBool()||!soloed.isBool()||!main.isBool()) { + problem="Invalid channel port, level, pan or switch type";return false; + } + const float level=static_cast(static_cast(gain)); + const float balance=static_cast(static_cast(pan)); + if(!std::isfinite(level)||level<0.f||level>1.f|| + !std::isfinite(balance)||balance< -1.f||balance>1.f) { + problem="Channel level must be 0..1 and pan -1..1";return false; + } + auto& c=candidate.channels.stripsAndMaster.strips[i]; + c.faderLinear=level;c.pan=balance; + c.mute=bool(muted);c.solo=bool(soloed); + candidate.sends.toMaster[i]=bool(main); + if(mode=="NONE" || mode=="BUS") { + c.source=SourceMode::disconnected; + candidate.channels.formats[i]=mode=="BUS" + ? ChannelFormat::stereo:ChannelFormat::followSource; + } else if(mode=="MONO"){ + c.source=SourceMode::mono;c.inputA=static_cast(left); + candidate.channels.formats[i]=ChannelFormat::mono; + } else if(mode=="STEREO"){ + c.source=SourceMode::stereo; + c.inputA=static_cast(left);c.inputB=static_cast(right); + candidate.channels.formats[i]=ChannelFormat::stereo; + } else { + problem="Channel must be NONE, MONO, STEREO or BUS";return false; + } + } + const auto rawSends=request.getProperty("sends",juce::var()); + if(!rawSends.isVoid() && !rawSends.isArray()){ + problem="Sends must be an array";return false; + } + auto* sendArray=rawSends.getArray(); + if(sendArray) { + if(sendArray->size()>maxChannelSends){ + problem="Maximum 32 internal sends";return false; + } + for(int i=0;isize();++i) { + const auto& raw=sendArray->getReference(i); + if(!raw.isObject()){problem="Invalid send row";return false;} + const auto source=raw.getProperty("from",-1); + const auto dest=raw.getProperty("to",-1); + const auto tap=raw.getProperty("tap",{}).toString(); + const auto gain=raw.getProperty("gain",.25); + const auto pan=raw.getProperty("pan",0.0); + if(!source.isInt()||!dest.isInt()|| + !(gain.isInt()||gain.isDouble())|| + !(pan.isInt()||pan.isDouble())) { + problem="Invalid send source, destination or gain";return false; + } + if(tap!="PRE" && tap!="POST"){ + problem="Send tap must be PRE or POST";return false; + } + const int from=static_cast(source),to=static_cast(dest); + if(from<0||from>=stripCount||to<0||to>=stripCount){ + problem="Send channel outside 1..10";return false; + } + if(modeNames[from]=="NONE"||modeNames[to]=="NONE"){ + problem="Enable a sender and set the recipient to BUS or an assigned channel";return false; + } + const float sendGain=static_cast(static_cast(gain)); + const float sendPan=static_cast(static_cast(pan)); + if(!std::isfinite(sendGain)||sendGain<0.f||sendGain>1.f|| + !std::isfinite(sendPan)||sendPan< -1.f||sendPan>1.f){ + problem="Send level 0..1, pan -1..1";return false; + } + auto& s=candidate.sends.sends[candidate.sends.count++]; + s.source=from;s.destination=to; + s.tap=tap=="PRE"?SendTap::preFader:SendTap::postFader; + s.gain=sendGain;s.pan=sendPan;s.enabled=true; + } + } + // Rejection never mutates the destination. Explicit DAG validation + // below occurs via PreparedRenderGraph::compile during apply(). + destination=candidate; + return true; + } +}; +} // namespace armix::mixer From d8bada6af8c88e9cb90032fdf9ce063739fcf8fb Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:38:17 +0700 Subject: [PATCH 12/20] fix(routing): keep decoded JUCE array lifetime stable while validating command --- engine/core/NativeDryRouteCommand.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/core/NativeDryRouteCommand.h b/engine/core/NativeDryRouteCommand.h index af07e7785..8f50cdf16 100644 --- a/engine/core/NativeDryRouteCommand.h +++ b/engine/core/NativeDryRouteCommand.h @@ -18,7 +18,8 @@ struct NativeDryRouteCommand final { juce::String& problem) { problem.clear(); if(!request.isObject()) {problem="Invalid routing command";return false;} - auto* rows=request.getProperty("channels",{}).getArray(); + const auto rawRows=request.getProperty("channels",juce::var()); + auto* rows=rawRows.getArray(); if(!rows || rows->size()!=stripCount) { problem="Exactly 10 channel assignments are required";return false; } From 2d23311cd35ca4102bfd8c9a9a5d401cfaf5bc0f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:38:44 +0700 Subject: [PATCH 13/20] feat(live): extend existing JUCE dry routing LAB with real cycle-safe sends, BUS return, per-channel meters and port mask attestation --- src/LiveDryRoutingLab.h | 114 +++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 652b1cecf..6ae9a7a7d 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1,6 +1,8 @@ // SPDX-License-Identifier: AGPL-3.0-only #pragma once #include "../engine/core/PreparedMixerBlock.h" +#include "../engine/core/NativeDryRouteCommand.h" +#include "../engine/device/JuceActivePortSnapshot.h" #include "../engine/core/RealtimeRoutePublisher.h" #include "../engine/device/LiveInputPortRegistry.h" #include @@ -27,32 +29,30 @@ class LiveDryRoutingLab final { // JUCE calls aboutToStart after configuring the input/output device. // One device session gets a new epoch; stored route cannot survive it. void prepareDevice (juce::AudioIODevice* device) noexcept { - // The new epoch invalidates old DSP immediately. Publish the new - // active mask using ATOMIC port slots: JUCE can restart the driver - // while its message thread is generating a routing/status snapshot. const auto generation=deviceEpoch_.fetch_add(1,std::memory_order_acq_rel)+1; registryValid_.store(false,std::memory_order_release); portCount_.store(0,std::memory_order_release); callbackInputCount_.store(-1,std::memory_order_release); - if(!device)return; - std::array candidate{}; - int count=0; - const auto mask=device->getActiveInputChannels(); - for(int bit=mask.findNextSetBit(0);bit>=0; - bit=mask.findNextSetBit(bit+1)) { - if(count>=armix::device::LiveInputPortRegistry::limit) - return; // never truncate/alias active device ports - candidate[count++]=bit; - } - armix::device::LiveInputPortRegistry prepared; - armix::device::LiveInputPortRegistry::Fault fault; - if(!armix::device::LiveInputPortRegistry::prepare( - generation,{candidate.data(),static_cast(count)}, - prepared,fault))return; - for(int i=0;i(command.getProperty("revision",juce::var(0)))); if(currentEpoch==0 || expectedEpoch!=currentEpoch) return "Audio device changed: reopen ROUTING to remap physical ports"; - const auto values=command.getProperty("channels",{}); - auto* assignments=values.getArray(); - if(!assignments || assignments->size()!=count) - return "Supply exactly 10 explicit channel assignments"; - armix::mixer::ChannelRoutingConfig cfg; - for(int i=0;igetReference(i); - if(!item.isObject())return "Invalid channel assignment"; - const auto mode=item.getProperty("mode",{}).toString(); - const auto left=item.getProperty("left",-1); - const auto right=item.getProperty("right",-1); - const auto gain=item.getProperty("gain",0.25); - if(!left.isInt()||!right.isInt()||!(gain.isDouble()||gain.isInt())) - return "Invalid input port number or channel level"; - const float level=static_cast(static_cast(gain)); - if(!std::isfinite(level)||level<0.f||level>1.f) - return "Channel level must be 0..1"; - auto& c=cfg.stripsAndMaster.strips[i]; - c.faderLinear=level; - c.pan=0.f; - if(mode=="NONE") { - c.source=armix::mixer::SourceMode::disconnected; - continue; - } - if(mode=="MONO") { - c.source=armix::mixer::SourceMode::mono; - c.inputA=static_cast(left); - cfg.formats[i]=armix::mixer::ChannelFormat::mono; - } else if(mode=="STEREO") { - c.source=armix::mixer::SourceMode::stereo; - c.inputA=static_cast(left); - c.inputB=static_cast(right); - cfg.formats[i]=armix::mixer::ChannelFormat::stereo; - } else return "Channel format must be NONE, MONO or STEREO"; - } - armix::mixer::SendRequest sends; // hardware dry FAT, no FX/send fabric yet + armix::mixer::NativeDryRouteCommand decoded; + juce::String validationError; + if(!armix::mixer::NativeDryRouteCommand::decode( + command,decoded,validationError))return validationError; + const auto& cfg=decoded.channels; + const auto& sends=decoded.sends; Plan plan; armix::mixer::RenderError error; if(!Plan::compile(cfg, @@ -150,6 +121,7 @@ class LiveDryRoutingLab final { case Publisher::Result::applied: publishedEpoch_.store(currentEpoch,std::memory_order_release); enabled_.store(true,std::memory_order_release); + sendCount_.store(sends.count,std::memory_order_relaxed); return {}; case Publisher::Result::staleDevice: return "Device epoch changed during preparation"; @@ -168,6 +140,8 @@ class LiveDryRoutingLab final { publisher_.unpublish(); // control thread only peakL_.store(0.f,std::memory_order_relaxed); peakR_.store(0.f,std::memory_order_relaxed); + sendCount_.store(0,std::memory_order_relaxed); + for(auto& p:channelPeaks_)p.store(0.f,std::memory_order_relaxed); } void poll() noexcept {publisher_.pollRetirement();} // message thread bool active() const noexcept {return enabled_.load(std::memory_order_acquire);} @@ -188,6 +162,7 @@ class LiveDryRoutingLab final { float* const* outputs,int outputCount,int frames, float masterGain,bool masterMuted) noexcept { if(!active())return false; + for(auto& p:channelPeaks_)p.store(0.f,std::memory_order_relaxed); // Stale meters must never survive a failed device/epoch mapping. peakL_.store(0.f,std::memory_order_relaxed); peakR_.store(0.f,std::memory_order_relaxed); @@ -196,6 +171,7 @@ class LiveDryRoutingLab final { if(outputs && outputs[c]) juce::FloatVectorOperations::clear(outputs[c],frames); if(!outputs||outputCount<2||!outputs[0]||!outputs[1] || + outputCount!=callbackOutputCount_.load(std::memory_order_acquire) || inputCount<0 || inputCount>armix::device::LiveInputPortRegistry::limit) return true; const auto generation=epoch(); @@ -230,6 +206,7 @@ class LiveDryRoutingLab final { constexpr int max=Block::hardFrameLimit; const auto noFx=[](int,float*,float*,int) noexcept {}; float peakL=0.f,peakR=0.f; + std::array perChannelPeaks{}; for(int offset=0;offsetprepared->process(shifted.data(),inputCount, outputs[0]+offset,outputs[1]+offset,n,noFx,&level)) return true; + for(int ch=0;chsetProperty("revision",static_cast(revision())); out->setProperty("peakL",peakL_.load(std::memory_order_relaxed)); out->setProperty("peakR",peakR_.load(std::memory_order_relaxed)); + out->setProperty("sendCount",sendCount_.load(std::memory_order_relaxed)); + juce::Array levels; + for(const auto& p:channelPeaks_)levels.add(p.load(std::memory_order_relaxed)); + out->setProperty("channelPeaks",juce::var(levels)); juce::Array ports; if(device && registryValid_.load(std::memory_order_acquire)) { const auto generation=epoch(); @@ -291,7 +276,14 @@ class LiveDryRoutingLab final { ports.clear(); } out->setProperty("ports",juce::var(ports)); - out->setProperty("note","EXPLICIT DRY HARDWARE FAT ONLY: no channel VST3, no sends, no portable route persistence"); + juce::Array outputPorts; + if(registryValid_.load(std::memory_order_acquire)) { + const int outputs=callbackOutputCount_.load(std::memory_order_acquire); + for(int i=0;isetProperty("outputPorts",juce::var(outputPorts)); + out->setProperty("note","EXPLICIT DRY HARDWARE FAT: real pre/post sends, no VST3 or portable route persistence"); return juce::var(out.release()); } private: @@ -299,13 +291,17 @@ class LiveDryRoutingLab final { // All data shared between JUCE device lifecycle and GUI/control reads // are atomic; the callback never enumerates masks or channel names. std::array,armix::device::LiveInputPortRegistry::limit> enabledPorts_{}; + std::array,armix::device::LiveInputPortRegistry::limit> enabledOutputPorts_{}; std::atomic portCount_{0}; std::atomic registryValid_{false}; std::atomic deviceEpoch_{0}; std::atomic publishedEpoch_{0}; std::atomic callbackInputCount_{-1}; + std::atomic callbackOutputCount_{-1}; std::atomic enabled_{false}; std::atomic peakL_{0.f},peakR_{0.f}; + std::atomic sendCount_{0}; + std::array,count> channelPeaks_{}; // Exclusive render-producer state. Bounded fade starts from the exact // previously output sample, preventing a topology switch discontinuity. static constexpr int rampFrames=256; From 84ef06316ade7ebc0fd3eeddf8b76889287ceea8 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:39:35 +0700 Subject: [PATCH 14/20] feat(gui): operator-friendly live routing BUS, PRE/POST send matrix, mute/solo/main and truthful channel peaks --- web/monitor.js | 73 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/web/monitor.js b/web/monitor.js index 4e91a531f..c24163d59 100644 --- a/web/monitor.js +++ b/web/monitor.js @@ -27,8 +27,10 @@ "#arRoutingLabOverlay{display:none;position:fixed;inset:0;z-index:995;background:#08121be8;align-items:center;justify-content:center}" + "#arRoutingLabOverlay.open{display:flex}#arRoutingLabPanel{width:min(760px,94vw);max-height:86vh;overflow:auto;box-sizing:border-box;padding:16px;background:#172834;border:1px solid #637e8a;border-radius:8px;color:#dcecf3}" + "#arRoutingLabPanel h2{font-size:17px;font-weight:600;margin:0 0 6px}#arRoutingLabPanel p{font-size:11px;line-height:1.6;color:#9cc5d4;margin:6px 0 13px}" + - ".arRouteRow{display:grid;grid-template-columns:60px 105px 1fr 1fr 110px;gap:6px;align-items:center;padding:5px 0;border-bottom:1px solid #2d4653}" + + ".arRouteRow{display:grid;grid-template-columns:54px 82px minmax(65px,1fr) minmax(65px,1fr) 88px 148px;gap:6px;align-items:center;padding:5px 0;border-bottom:1px solid #2d4653}" + ".arRouteRow label{font-size:11px;font-weight:600}.arRouteRow select{width:100%;min-width:0;padding:6px;background:#0d202b;border:1px solid #4d6879;border-radius:4px;color:#e1eef5;font-size:11px}" + + ".arRouteFlags{display:flex;gap:5px;align-items:center;font-size:10px}.arRouteFlags label{display:flex;gap:1px;align-items:center;font-size:10px;white-space:nowrap}.arRouteFlags input{width:12px;height:12px;margin:0}.arRoutePeak{display:block;color:#91dcd0;font-size:9px;font-variant-numeric:tabular-nums}" + + "#arRouteRows{overflow-x:auto}.arRouteRow{min-width:590px}#arRouteSends{margin-top:12px}#arRouteSends h3{font-size:12px;margin:8px 0;color:#b1d4dd}.arSendRow{display:grid;grid-template-columns:1fr 1fr 76px 83px 32px;gap:6px;margin-bottom:5px}.arSendRow select{width:100%;min-width:0;padding:6px;color:#e1eef5;background:#0d202b;border:1px solid #4d6879;border-radius:4px}.arSendRow button{border:1px solid #9a6060;background:#442930;color:#f3dadd;border-radius:4px}#arAddSend{font-size:10px;padding:6px 8px}" + ".arRouteFoot{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end;margin-top:12px}.arRouteFoot button,.arRouteClose{color:#f0f7fa;background:#24475a;border:1px solid #587f91;border-radius:4px;padding:8px 12px;cursor:pointer}" + "#arRouteApply{background:#237566;border-color:#4ba48d}#arRouteStop{background:#50343c;border-color:#a8717c}" + "#arRouteFeedback{font-size:11px;min-height:18px;color:#8bdec1;margin-top:10px}"; @@ -65,19 +67,23 @@ routeOverlay.id="arRoutingLabOverlay"; routeOverlay.innerHTML=''; document.body.appendChild(routeOverlay); - const draftRoutes=Array.from({length:10},()=>({mode:"NONE",left:-1,right:-1,gain:0.25})); + const draftRoutes=Array.from({length:10},()=>({mode:"NONE",left:-1,right:-1,gain:0.25,main:true,mute:false,solo:false})); + const draftSends=[]; let draftEpoch=0; // identity of the hardware used to draw these selectors function invalidateDraftForNewDevice(nextEpoch){ if(draftEpoch===nextEpoch)return false; draftEpoch=nextEpoch; for(const route of draftRoutes) { route.mode="NONE";route.left=-1;route.right=-1;route.gain=0.25; + route.main=true;route.mute=false;route.solo=false; } + draftSends.length=0; return true; } const safeRouteText=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); @@ -92,14 +98,19 @@ const rows=document.getElementById("arRouteRows"); rows.innerHTML=Array.from({length:10},(_,i)=>{ const v=draftRoutes[i]; - return '
'+ + return '
'+ ''+ + ['NONE','MONO','STEREO','BUS'].map(m=>'').join('')+''+ ''+ ''+ '
'; + '').join('')+''+ + '
'+ + ''+ + ''+ + ''+ + '
'; }).join(''); rows.querySelectorAll('[data-route-row]').forEach(row=>{ const model=draftRoutes[Number(row.dataset.routeRow)]; @@ -107,22 +118,54 @@ row.querySelector('[data-route-left]').addEventListener('change',e=>{model.left=Number(e.target.value);}); row.querySelector('[data-route-right]').addEventListener('change',e=>{model.right=Number(e.target.value);}); row.querySelector('[data-route-gain]').addEventListener('change',e=>{model.gain=Number(e.target.value);}); + row.querySelector('[data-route-main]').addEventListener('change',e=>{model.main=e.target.checked;}); + row.querySelector('[data-route-mute]').addEventListener('change',e=>{model.mute=e.target.checked;}); + row.querySelector('[data-route-solo]').addEventListener('change',e=>{model.solo=e.target.checked;}); refreshMode(row); }); + drawSends(); updateRouteLabIdentity(); } function refreshMode(row){ const type=row.querySelector('[data-route-mode]').value; - row.querySelector('[data-route-left]').disabled=type==="NONE"; + row.querySelector('[data-route-left]').disabled=type==="NONE"||type==="BUS"; row.querySelector('[data-route-right]').disabled=type!=="STEREO"; } + function drawSends(){ + const el=document.getElementById("arSendRows"); + const channels=Array.from({length:10},(_,i)=>''); + const channelSelect=(value)=>channels.map((option,i)=>option.replace(' + '
'+ + ''+ + ''+ + ''+ + ''+ + '
').join(''); + el.querySelectorAll('[data-send-row]').forEach(row=>{ + const i=Number(row.dataset.sendRow),m=draftSends[i]; + row.querySelector('[data-send-from]').addEventListener('change',e=>{m.from=Number(e.target.value);}); + row.querySelector('[data-send-to]').addEventListener('change',e=>{m.to=Number(e.target.value);}); + row.querySelector('[data-send-tap]').addEventListener('change',e=>{m.tap=e.target.value;}); + row.querySelector('[data-send-gain]').addEventListener('change',e=>{m.gain=Number(e.target.value);}); + row.querySelector('[data-send-remove]').addEventListener('click',()=>{draftSends.splice(i,1);drawSends();}); + }); + document.getElementById("arAddSend").disabled=draftSends.length>=32; + } + document.getElementById("arAddSend").addEventListener('click',()=>{ + if(draftSends.length>=32)return; + // Draft only; no sound changes until native acknowledgement. + draftSends.push({from:0,to:1,tap:"POST",gain:.25}); + drawSends(); + }); function updateRouteLabIdentity(){ const d=state.dryRoutingLab||{}; const label=document.getElementById("arRouteIdentity"); if(!label)return; setTextIfChanged(label,(d.active ? (d.ready?"DRY LAB ACTIVE":"DRY LAB STALE — SILENT, REAPPLY"):"DRY LAB OFF")+ " · device epoch "+(d.epoch||0)+" · rev "+(d.revision||0)+ - " · "+(d.ports?.length||0)+" enabled physical inputs"); + " · "+(d.ports?.length||0)+" enabled inputs · "+(d.outputPorts?.length||0)+" outputs · "+(d.sendCount||0)+" live sends"); } document.getElementById("arOpenRoutingLab").addEventListener("click",()=>{ drawRoutes(); @@ -145,7 +188,8 @@ document.getElementById("arRouteFeedback").textContent="Applying native route (output must be MUTED)..."; api.emitEvent("arMixAction",{action:"routingDryApply",value:{ deviceEpoch:draftEpoch,revision:Number(d.revision)||0, - channels:draftRoutes.map(c=>({...c})) + channels:draftRoutes.map(c=>({...c})), + sends:draftSends.map(s=>({...s})) }}); }); document.getElementById("arRouteStop").addEventListener("click",()=>api.emitEvent("arMixAction",{action:"routingDryStop"})); @@ -154,7 +198,7 @@ if(result && typeof result==="object" && "epoch" in result)state.dryRoutingLab=result; document.getElementById("arRouteFeedback").textContent= reply?.ok===false?("REJECTED · "+(reply.error||"Invalid route")): - result.active?"NATIVE ACK: DRY LAB ENABLED · zero VST3 · UNMUTE OUTPUT in SIGNAL CHECK":"NATIVE ACK: STOPPED · output remains MUTED for safety"; + result.active?"NATIVE ACK: "+(result.sendCount||0)+" LIVE SENDS · zero VST3 · UNMUTE OUTPUT in SIGNAL CHECK":"NATIVE ACK: STOPPED · output remains MUTED for safety"; updateRouteLabIdentity(); }); @@ -175,7 +219,7 @@ Number(d?.overBudgetCount)===0; function diagnosis(d) { if(d.dryRoutingLab?.active) return d.dryRoutingLab.ready? - "Live 10-channel DRY ROUTING LAB: actual native inputs → dry master. No VST3, AUX or snapshot routing. Use low headphone volume.": + "Live 10-channel DRY ROUTING LAB: real inputs, PRE/POST sends and BUS returns to master. No VST3 or portable routing. Use low headphone volume.": "Routing LAB device generation changed. Output is SILENT until you remap the real device and APPLY again."; if(d.diagnosticRoute==="OUTPUT_ONLY_TONE") return "Output-only test: capture endpoint is disconnected. Listen for tone at low headphone volume and click MARK CRACKLE when audible."; if(d.diagnosticRoute==="CAPTURE_ONLY") return "Capture-only test: hardware render endpoint is disconnected. Observe capture input and backend discontinuity count; you should hear no audio."; @@ -199,6 +243,11 @@ } function repaint(d) { if(routeOverlay.classList.contains("open")){ + const levels=Array.isArray(d.dryRoutingLab?.channelPeaks)?d.dryRoutingLab.channelPeaks:[]; + routeOverlay.querySelectorAll('[data-route-peak]').forEach(el=>{ + const peak=Number(levels[Number(el.dataset.routePeak)])||0; + setTextIfChanged(el,d.dryRoutingLab?.ready?(Math.round(Math.min(1,peak)*100)+"%"):"—"); + }); if(draftEpoch!==(Number(d.dryRoutingLab?.epoch)||0)) { drawRoutes(); // fresh port names; reset stale user assignments document.getElementById("arRouteFeedback").textContent= From a2b115bba5212a3dad2a4f21f3957bfcb299b950 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:40:17 +0700 Subject: [PATCH 15/20] test(live): verify real PRE vs POST bus audio, cycles, invalid GUI commands and transactional rollback --- tests/native_dry_route_command_test.cpp | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/native_dry_route_command_test.cpp diff --git a/tests/native_dry_route_command_test.cpp b/tests/native_dry_route_command_test.cpp new file mode 100644 index 000000000..f53837bbe --- /dev/null +++ b/tests/native_dry_route_command_test.cpp @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../engine/core/NativeDryRouteCommand.h" +#include "../engine/core/PreparedMixerBlock.h" +#if defined(NDEBUG) +#undef NDEBUG +#endif +#include +#include +#include +using namespace armix::mixer; +static bool near(float a,float b){return std::abs(a-b)<0.00001f;} +int main(){ + juce::String json=R"({"channels":[)"; + for(int i=0;i physical{1.f,.5f}; + const std::array empty{0.f,0.f}; + const float* inputs[]={physical.data(),empty.data(),empty.data()}; + std::array l{},r{}; + const auto noFx=[](int,float*,float*,int) noexcept {}; + assert(block.process(inputs,3,l.data(),r.data(),2,noFx)); + // PRE is independent from source fader=0, POST is silent. + assert(near(l[0],.5f) && near(r[0],.5f)); + assert(graph.sends.receivesInternalAudio(1)); + assert(graph.sends.receivesInternalAudio(2)); + + // A cycle is rejected by the actual graph compiler, not the GUI. + auto cyclic=decoded; + cyclic.sends.sends[cyclic.sends.count++]={1,0,SendTap::postFader,.5f,0.f,true}; + const auto previous=graph; + assert(!PreparedRenderGraph::compile(cyclic.channels,ports,cyclic.sends,graph,fault)); + assert(fault.fault==RenderFault::invalidSendRouting); + assert(fault.sends.fault==SendFault::cycleDetected); + assert(graph.sends.edgeCount==previous.sends.edgeCount); + + // Native decoder does not partially mutate committed configuration. + const auto good=decoded; + auto invalid=juce::JSON::parse(json.replace("PRE","INVALID_TAP")); + assert(!NativeDryRouteCommand::decode(invalid,decoded,error)); + assert(decoded.sends.count==good.sends.count); + assert(decoded.sends.sends[0].tap==SendTap::preFader); + json=json.replace("INVALID_TAP","PRE"); + invalid=juce::JSON::parse(json.replace("\"to\":1","\"to\":9")); + assert(!NativeDryRouteCommand::decode(invalid,decoded,error)); // CH10 NONE + json=json.replace("\"to\":9","\"to\":1"); + invalid=juce::JSON::parse(json.replace("\"gain\":0.5","\"gain\":999")); + assert(!NativeDryRouteCommand::decode(invalid,decoded,error)); + assert(decoded.sends.count==2); + // Legacy command without "sends" remains backwards compatible. + auto legacy=juce::JSON::parse(json.upToFirstOccurrenceOf(",\"sends\"",false,false)+"}"); + assert(NativeDryRouteCommand::decode(legacy,decoded,error)); + assert(decoded.sends.count==0); + assert(decoded.sends.toMaster[0]==false); +} From 1820f4a19af5c8e6b35844b0925cbadecf0751eb Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:40:48 +0700 Subject: [PATCH 16/20] build: native JUCE dry routing bus/send test in existing CTest --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d562ab8d0..9f3cb1a9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ juce_add_gui_app(ARMixConsole juce_add_binary_data(ARMixAssets SOURCES web/index.html web/styles.css web/app.js web/bridge.js web/monitor.js) -target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/PreparedNativeMixerSession.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) +target_sources(ARMixConsole PRIVATE src/Main.cpp src/LiveAudioEngine.h src/VstOrbitController.h engine/core/MixerRoutingPlan.h engine/core/ChannelRoutingContract.h engine/core/ChannelSendPlan.h engine/core/PreparedMixerBlock.h engine/core/PreparedNativeMixerSession.h engine/core/NativeDryRouteCommand.h engine/core/RealtimeRoutePublisher.h engine/device/LiveInputPortRegistry.h src/LiveDryRoutingLab.h engine/core/OrbitPhase.h engine/core/OrbitControlPolicy.h engine/core/OrbitMotion.h engine/core/OrbitDistanceMapping.h engine/core/DearVrPolarPolicy.h src/PluginCatalog.h src/PluginVault.h src/PortableWorkspace.h src/StudioBackup.h src/DiagnosticsRecorder.h src/StereoPan.h src/NativePresetArchive.h src/VstBusLayout.h src/LiveGraphHandoff.h src/DiagnosticTone.h engine/core/RealtimeHealthHistogram.h engine/core/CallbackCadenceEvidence.h engine/diagnostics/CrackleEvidenceWindow.h engine/device/AdaptiveClockBridge.h engine/device/AudioProfilePolicy.h engine/device/PeriodCapabilityEvidence.h engine/device/SessionLifecycle.h engine/device/WasapiCapabilityProbe.h engine/device/JuceIndependentClockDevice.h engine/device/ClockBridgeSizing.h engine/device/IndependentStreamFormatFence.h engine/device/DirectRestoreBackoff.h engine/device/IndependentStreamWatchdog.h engine/device/BridgeContinuityGate.h engine/device/EndpointIdentityPolicy.h engine/device/WasapiEndpointIdentityGuard.h engine/device/AsioStartupPolicy.h engine/device/AsioPriorityDeviceManager.h engine/device/JuceActivePortSnapshot.h engine/device/AsioRegistrationPolicy.h engine/device/AsioRegistryIdentityProbe.h engine/device/DirectRouteFence.h) target_compile_definitions(ARMixConsole PRIVATE JUCE_WEB_BROWSER=1 JUCE_USE_WIN_WEBVIEW2=1 @@ -69,6 +69,11 @@ if(BUILD_TESTING) target_link_libraries(ARMixNativeMixerSessionTests PRIVATE juce::juce_audio_devices juce::juce_recommended_config_flags) target_compile_features(ARMixNativeMixerSessionTests PRIVATE cxx_std_20) add_test(NAME P1FPhysicalPortToNativeMasterAndEpochGuard COMMAND ARMixNativeMixerSessionTests) + juce_add_console_app(ARMixNativeDrySendTests PRODUCT_NAME "ArSonMix Live Dry Send and BUS Tests") + target_sources(ARMixNativeDrySendTests PRIVATE tests/native_dry_route_command_test.cpp engine/core/NativeDryRouteCommand.h) + target_link_libraries(ARMixNativeDrySendTests PRIVATE juce::juce_core juce::juce_recommended_config_flags) + target_compile_features(ARMixNativeDrySendTests PRIVATE cxx_std_20) + add_test(NAME LiveNativePrePostSendAndBusContract COMMAND ARMixNativeDrySendTests) add_executable(ARMixLiveRoutingEpochTests tests/live_port_epoch_publisher_test.cpp) target_compile_features(ARMixLiveRoutingEpochTests PRIVATE cxx_std_20) add_test(NAME P1ELivePortGenerationRevisionAndRealtimeRetirement COMMAND ARMixLiveRoutingEpochTests) From 0ed1428ab2467a6173a3b330af3dacdf8f6485ab Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:40:52 +0700 Subject: [PATCH 17/20] ci: execute hardware mask and real dry BUS/send tests on Windows --- .github/workflows/p1-windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 006392021..5d3c169d3 100644 --- a/.github/workflows/p1-windows.yml +++ b/.github/workflows/p1-windows.yml @@ -92,7 +92,7 @@ jobs: -DBUILD_TESTING=ON -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" - name: Build executable and native RT tests - run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixJucePortMaskTests ARMixNativeMixerSessionTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 + run: cmake --build build --config Release --target ARMixConsole ARMixFxOrderTests ARMixMixerRoutingTests ARMixChannelRoutingContractTests ARMixChannelSendTests ARMixPreparedMixerBlockTests ARMixLiveRoutingEpochTests ARMixJucePortMaskTests ARMixNativeMixerSessionTests ARMixNativeDrySendTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixDiagnosticTests ARMixClockBridgeTests ARMixVirtualClockSoakTests ARMixCadenceTests ARMixCrackleWindowTests ARMixHealthTests ARMixPolicyTests ARMixPeriodEvidenceTests ARMixLifecycleTests ARMixWasapiProbeTests ARMixDualJuceTests ARMixClockSizingTests ARMixIndependentFormatTests ARMixRecoveryTests ARMixStreamWatchdogTests ARMixBridgeContinuityTests ARMixEndpointPolicyTests ARMixEndpointGuardTests ARMixAsioPolicyTests ARMixAsioBackendTests ARMixAsioRegistryIdentityTests ARMixDirectFenceTests --parallel 2 - name: Test realtime control primitives run: ctest --test-dir build -C Release --output-on-failure - name: Package verified JUCE GUI for hardware FAT From cabb17f0e36c075b5dc458386ac0cd93ca1324b0 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:40:55 +0700 Subject: [PATCH 18/20] test(gui): guard truthful native BUS/send controls and ACK --- tests/live_routing_ui_contract_test.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/live_routing_ui_contract_test.mjs b/tests/live_routing_ui_contract_test.mjs index ef797dd96..e87bc1da8 100644 --- a/tests/live_routing_ui_contract_test.mjs +++ b/tests/live_routing_ui_contract_test.mjs @@ -68,3 +68,20 @@ test("MUTE gate precedes processing and suppresses previous audible crossfade",( assert.match(gate,/return true/); assert.ok(!lab.includes("masterMuted?0.f:std::clamp(masterGain"), "don't mute before fade and then reintroduce old samples"); }); + +test("P1G is real native BUS/send, not a cosmetic routing picker",()=>{ + assert.match(lab,/NativeDryRouteCommand::decode/); + assert.match(lab,/const auto& sends=decoded\.sends/); + assert.match(lab,/JuceActivePortSnapshot::capture/); + assert.match(lab,/callbackOutputCount_\.load/); + assert.match(lab,/level\.channelPeak\[ch\]/); + assert.match(ui,/\['NONE','MONO','STEREO','BUS'\]/); + assert.match(ui,/data-route-main/); + assert.match(ui,/data-route-mute/); + assert.match(ui,/data-route-solo/); + assert.match(ui,/arAddSend/); + assert.match(ui,/data-send-tap/); + assert.match(ui,/sends:draftSends\.map/); + assert.match(ui,/result\.sendCount/); + assert.match(ui,/data-route-peak/); +}); From 0ef67576d69b738a593bc2b903654b5b367904b5 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:41:45 +0700 Subject: [PATCH 19/20] docs: P1G real hardware lab send and BUS acceptance with latest GUI baseline --- docs/P1G_NATIVE_DRY_BUS_SENDS_FAT_20261028.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docs/P1G_NATIVE_DRY_BUS_SENDS_FAT_20261028.md diff --git a/docs/P1G_NATIVE_DRY_BUS_SENDS_FAT_20261028.md b/docs/P1G_NATIVE_DRY_BUS_SENDS_FAT_20261028.md new file mode 100644 index 000000000..d80b04412 --- /dev/null +++ b/docs/P1G_NATIVE_DRY_BUS_SENDS_FAT_20261028.md @@ -0,0 +1,32 @@ +# P1F–P1G — Native 10-Channel Routing LAB + PRE/POST Sends (2026-10-28) + +**Starting point:** reconciled latest `main@3b327bd5f9513ad405122258665457eb8ee07e73`. Preserve merged GUI finish, channel/master strip layout, button colors, master mono, CH1 native VST3/Orbit/FX reorder and bypass, backup, lean CI and physical no-FX diagnostic. The native Routing LAB existed already in main: this is an extension of that actual callback path, **not a second mixer engine or GUI mockup**. + +## What actually runs natively now + +- A verified direct JUCE device supplies **actual active hardware input/output masks**, not guessed pin ordinals; physical IN 3 can be callback[0], and a stereo pair can have nonadjacent physical pins. The P1F `JuceActivePortSnapshot` validates hardware topology at device start and records output mask/count. If the callback input **or output** count changes, LAB writes silence and never falls through to the live CH1 host. +- The opt-in `LiveDryRoutingLab` already called `PreparedMixerBlock` in `LiveAudioEngine` without changing the normal VST3 path. P1G now decodes one **transactional** routing command into ten physical/BUS channels and up to **32 internal PRE or POST fader sends**. Edits are validated completely off RT; a graph that contains feedback loops, duplicate edges, invalid port selection, invalid levels, self-send, stale device epoch or stale graph revision is **rejected without changing the active graph**. +- Channels can be `NONE`, physical `MONO`, physical `STEREO`, or virtual `BUS` (a native stereo return with no physical capture port). Each has a fader, MAIN output toggle, mute and solo. A source can go to MAIN, to sends only, or both. BUS returns can send onward to other buses in validated topological order. Native signal path: **real input → optional downmix/dual-mono → PRE send → fader/pan/mute/solo → POST send → BUS return → MAIN master**. +- The audio callback uses the existing preallocated array-backed `PreparedMixerBlock` and `RealtimeRoutePublisher`. Graph publication uses device-epoch and revision fencing. No JSON parsing, heap, I/O, plugin initialization, device restart, JS, mutex or thread spawn in the realtime render. Preserve 256-sample de-click ramp and strict emergency mute behavior. +- Ten true post-fader per-strip peaks are published using atomics (peak values reflect DSP channel output), exposed to the Routing LAB panel only; no fake VU or heavy blur/DOM animation. The GUI has one consolidated panel with physical input selectors, format/BUS, level, MAIN/MUTE/SOLO and an Add/Remove PRE/POST send list; it submits **draft only** and reflects the native ACK. The source list resets on device epoch change. +- One new JUCE C++ test validates command parsing, actual synthetic sample audio through pre-fader bus return with the source fader at zero, silence at post-fader sends, cycle rejection, invalid GUI values and rollback. An expanded Node/UI contract proves the source is connected to native audio and send controls. Existing P1A–P1F and P0 tests still run on the same Windows CI. + +## Actual on-device usage — *controlled FAT, not a show build* + +1. Open SIGNAL CHECK → **MUTE OUTPUT** first. Confirm DIRECT ASIO/WASAPI device is authorized. Remove any CH1 VST3 before using LAB. +2. Click **ROUTING LAB · 10 CH**. Select a real physical `MONO` or `STEREO` input for CH1, select `BUS` for CH2 or another return. Leave unused channels `NONE`. +3. For a dry AUX example: set CH1 `MAIN` off, CH1 fader zero, CH2 `BUS` with `MAIN` on. Press `+ ADD SEND`, choose `CH1 → CH2`, `PRE`, gain `−12 dB`. APPLY TO NATIVE AUDIO while muted; verify ACK. +4. Unmute with **headphones and low external monitoring volume**, observe master and channel peak in LAB. The PRE send should still be audible even if CH1 fader is zero. Change send to `POST`, APPLY while muted; the output should be silent at fader zero. This is actual DSP, not an FX plugin reverb; BUS does not insert a VST. +5. Use `STOP LAB` to exit back to the original CH1 host. Output stays muted for safety. If the device restarts, the LAB route becomes stale; inputs need explicit remapping and fresh native approval. Invalid sends produce a reason and preserve the prior verified state. + +## Explicit uncompleted qualifications + +- **No real VST3 chains on CH2–10.** No AUX hardware outputs or true plug-in FX returns yet. BUS is internal dry mixing, not an FX plugin. CH1 native VST3 remains suspended/excluded during LAB and resumes only after STOP. +- The production JUCE host initialises with 1 input and 2 outputs. Extra active ASIO hardware inputs require the user to enable channels in AUDIO SETUP; the LAB cannot silently reopen or activate absent ports. +- The new status outputPort mask is backend-reported. Hardware port names, device serial identity, actual dual-clock endpoint identity, PDC and portable per-user routing persistence remain follow-on obligations. +- Real hardware click/dropout validation, independent-clocks FAT, VST3 bus negotiation, latency compensation and **Issue #15 zero-FX crackle** are still not qualified. CTest PASS only proves programmatic contracts; never label a build FAT-certified based on CI. +- Bounded 32 sends, ten strips and stereo MAIN are an implementation scope; these do not limit the flexibility of imported VST3 plugins or public/private feature parity. + +## Merge gates and follow-on + +Use exact-head Windows MSVC, CTest and JS+Chromium checks, compare main before merge, and verify GitHub release artifact. GUI finishes currently in main **must not be overwritten**. Next milestone: native CH1–10 independent plugin instance ownership, stereo/mono VST3 bus negotiation and latency/PDC, publish/retire all FX state safely off callback; activate normal GUI SOURCE/FX only after real hardware acceptance. From 3c89596afffa12cfef0b50254d111578780cfd94 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 28 Oct 2026 14:42:16 +0700 Subject: [PATCH 20/20] fix(rt): latch callback I/O topology mismatch to silence until validated device restart --- src/LiveDryRoutingLab.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 6ae9a7a7d..4aed71dc9 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -31,6 +31,7 @@ class LiveDryRoutingLab final { void prepareDevice (juce::AudioIODevice* device) noexcept { const auto generation=deviceEpoch_.fetch_add(1,std::memory_order_acq_rel)+1; registryValid_.store(false,std::memory_order_release); + topologyFault_.store(false,std::memory_order_release); portCount_.store(0,std::memory_order_release); callbackInputCount_.store(-1,std::memory_order_release); callbackOutputCount_.store(-1,std::memory_order_release); @@ -62,6 +63,9 @@ class LiveDryRoutingLab final { portCount_.store(0,std::memory_order_release); callbackInputCount_.store(-1,std::memory_order_release); callbackOutputCount_.store(-1,std::memory_order_release); + topologyFault_.store(false,std::memory_order_release); + sendCount_.store(0,std::memory_order_relaxed); + for(auto& p:channelPeaks_)p.store(0.f,std::memory_order_relaxed); peakL_.store(0.f,std::memory_order_relaxed); peakR_.store(0.f,std::memory_order_relaxed); } @@ -77,6 +81,8 @@ class LiveDryRoutingLab final { const auto currentEpoch=deviceEpoch_.load(std::memory_order_acquire); if(!registryValid_.load(std::memory_order_acquire)) return "Audio device has no validated active capture ports"; + if(topologyFault_.load(std::memory_order_acquire)) + return "Device callback channel layout changed; reopen AUDIO SETUP before applying"; const int countNow=portCount_.load(std::memory_order_acquire); if(countNow<=0 || countNow>armix::device::LiveInputPortRegistry::limit) return "Invalid active device input channel mask"; @@ -148,7 +154,8 @@ class LiveDryRoutingLab final { float peakLeft() const noexcept {return peakL_.load(std::memory_order_relaxed);} float peakRight() const noexcept {return peakR_.load(std::memory_order_relaxed);} bool ready() const noexcept { - return active() && publishedEpoch_.load(std::memory_order_acquire)==epoch(); + return active() && !topologyFault_.load(std::memory_order_acquire) + && publishedEpoch_.load(std::memory_order_acquire)==epoch(); } std::uint64_t epoch() const noexcept { return deviceEpoch_.load(std::memory_order_acquire); @@ -172,13 +179,18 @@ class LiveDryRoutingLab final { juce::FloatVectorOperations::clear(outputs[c],frames); if(!outputs||outputCount<2||!outputs[0]||!outputs[1] || outputCount!=callbackOutputCount_.load(std::memory_order_acquire) || - inputCount<0 || inputCount>armix::device::LiveInputPortRegistry::limit) + inputCount<0 || inputCount>armix::device::LiveInputPortRegistry::limit) { + topologyFault_.store(true,std::memory_order_release); return true; + } + if(topologyFault_.load(std::memory_order_acquire))return true; const auto generation=epoch(); auto lease=publisher_.acquire(); const auto* snapshot=lease.get(generation); if(!snapshot||!snapshot->prepared || inputCount!=callbackInputCount_.load(std::memory_order_acquire)) { + if(inputCount!=callbackInputCount_.load(std::memory_order_acquire)) + topologyFault_.store(true,std::memory_order_release); fadeRemaining_=0; lastOutputL_=lastOutputR_=0.f; return true; @@ -246,6 +258,7 @@ class LiveDryRoutingLab final { juce::var status(juce::AudioIODevice* device) const { auto out=std::make_unique(); out->setProperty("active",active()); + out->setProperty("topologyFault",topologyFault_.load(std::memory_order_acquire)); out->setProperty("ready",ready()); out->setProperty("epoch",static_cast(epoch())); out->setProperty("revision",static_cast(revision())); @@ -294,6 +307,7 @@ class LiveDryRoutingLab final { std::array,armix::device::LiveInputPortRegistry::limit> enabledOutputPorts_{}; std::atomic portCount_{0}; std::atomic registryValid_{false}; + std::atomic topologyFault_{false}; std::atomic deviceEpoch_{0}; std::atomic publishedEpoch_{0}; std::atomic callbackInputCount_{-1};