diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 3b838b34a..06002b11e 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 ARMixNativeDrySendTests ARMixLiveChannelFxTests ARMixDedicatedAuxBusTests ARMixTenChannelLiveControlTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixShowSchemaTests ARMixShowStoreTests 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 ARMixLiveChannelFxTests ARMixDedicatedAuxBusTests ARMixTenChannelLiveControlTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixShowSchemaTests ARMixShowStoreTests ARMixLiveShowCaptureTests 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index cbf68550d..d7b30c85f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,6 +222,11 @@ if(BUILD_TESTING) target_link_libraries(ARMixShowSchemaTests PRIVATE juce::juce_core juce::juce_recommended_config_flags) target_compile_features(ARMixShowSchemaTests PRIVATE cxx_std_20) add_test(NAME P4NativeShowSnapshotV2WireRoundTrip COMMAND ARMixShowSchemaTests) + juce_add_console_app(ARMixLiveShowCaptureTests PRODUCT_NAME "ArSonMix Live Native Dry Show Capture Tests") + target_sources(ARMixLiveShowCaptureTests PRIVATE tests/native_live_show_capture_test.cpp src/NativeLiveShowCapture.h src/NativeShowStore.h) + target_link_libraries(ARMixLiveShowCaptureTests PRIVATE juce::juce_core juce::juce_cryptography juce::juce_recommended_config_flags) + target_compile_features(ARMixLiveShowCaptureTests PRIVATE cxx_std_20) + add_test(NAME P4NativeAcknowledgedDryShowCaptureAndStorage COMMAND ARMixLiveShowCaptureTests) juce_add_console_app(ARMixShowStoreTests PRODUCT_NAME "ArSonMix Native Studio Shows Generation Tests") target_sources(ARMixShowStoreTests PRIVATE tests/native_show_store_test.cpp src/NativeShowStore.h src/NativeShowSchema.h) diff --git a/docs/P4_NATIVE_DRY_SHOW_CAPTURE_STAGE3_20261029.md b/docs/P4_NATIVE_DRY_SHOW_CAPTURE_STAGE3_20261029.md new file mode 100644 index 000000000..6e8d5e523 --- /dev/null +++ b/docs/P4_NATIVE_DRY_SHOW_CAPTURE_STAGE3_20261029.md @@ -0,0 +1,26 @@ +# P4 stage 3 — Save an acknowledged native DRY Routing Show + +**Scope:** A user-triggered, usable native SAVE path for an actual ACK-verified 10 INPUT + 4 AUX route with **zero** VST3; no simulated/localStorage state. Not native live recall. + +## Runtime path +1. Enable a real verified DIRECT full-duplex device and APPLY Routing LAB. The audio engine publishes a prepared graph only after native device-mask, epoch and route revision checks. +2. In Routing LAB, adjust live CH faders/PAN/MUTE/SOLO as needed, then MUTE OUTPUT before selecting **SAVE DRY SHOW**. +3. `NativeLiveShowCapture::captureDry` runs on the JUCE message thread, reading `LiveAudioEngine::status()` and only its `dryRoutingLab.acceptedRoute` and `channelControls` native ACK. No JS draft, browser localStorage, remote path or guessed VST3 state is read. +4. Capture verifies `ready/active`, current device epoch, revision, actual physical enabled input mask, zero FX, exact 10CH controls and 4 AUX. The name and timestamp are generated natively. It preserves source NONE vs BUS distinction, sparse physical indices, exact linear faders (including 0 / -infinity), PRE/POST CH and AUX sends, AUX levels/switches, master level/mute/mono. On any error the previously accepted snapshot is unchanged. +5. `NativeShowSaveWorker` receives a **private copy** of the validated snapshot and commits one new Show generation under the portable `Studio/Shows` workspace. Staging + verification + atomic HEAD policy are reused from P4 stage 2; it reads back and compares the entire saved snapshot before showing success. IO/hashing never runs on callback or WebView paint thread. Saving and USB backup are mutually excluded. +6. The GUI only reports success from the native worker ACK. It does not arm audio, auto-apply physical I/O, auto-unmute or restore a Show. A stale/unsupported request is rejected. + +## Non-negotiable guardrails +- **DRY-only**. Running VST3 state capture is explicitly refused. Muted output alone is not yet proof every vendor processor is quiescent: vendor-specific `getStateInformation` affinity, safe callback handoff, state blobs, Orbit state, hardware remap, and atomic live restore/undo remain future gates. +- This save is not full production scene recall and does not qualify #15 zero-FX hardware crackle. No arbitrary physical ports or VST3 binaries are activated from a loaded Show on a different PC. +- One existing JUCE device/engine and immutable published route. No filesystem scan, device call, plugin lifecycle operation, lock, heap allocation or JSON conversion on the audio callback. +- STOP LAB remains mute-first and restores the original CH1 path. All four AUX returns stay independent from the ten INPUT strips. +- Schema V3 carries an optional `busReturn` boolean per strip, allowing new recordings to distinguish a channel-to-channel BUS return from an unassigned NONE. Older V2/V3 snapshots without the field remain safely disconnected by default. + +## Automated verification +- Native `P4NativeAcknowledgedDryShowCaptureAndStorage` CTest constructs a representative acknowledged routing session with sparse hardware mask, MONO/STEREO/BUS input types, 2 concurrent AUX, live gain 0, fader/PAN/MUTE/SOLO, PRE/POST, master and subsequent on-disk readback. Reject stale revision, output not muted, VST3, and disappeared physical input without changing last-good snapshot. +- Existing 47 native CTests + new test; Windows MSVC full app, native contract tests and packaged artifact; Chromium UI smoke (new Routing LAB button/event must not regress GUI). +- Hardware FAT still required at 48 kHz with physical 1/2/10 inputs, 128/256/480 frames, sparse ASIO/WASAPI masks, save/stop/restart/disconnect/USB backup, and #15 crackle isolation. PASS in synthetic CI is not a hardware claim. + +## Next engineering milestone +True vendor VST3 state capture requires a deliberate callback quiescence/epoch handshake and correct message/vendor-thread affinity without destroying FX tails. Then integrate verified states into Show commit, preflight plugin availability, prepare off RT, and do an explicit muted atomic restore with rollback and native ACK. This stage deliberately does NOT enable old UI simulated scenes as native recalls. diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index f237d0e08..cffdec53d 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -910,6 +910,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback channelGain_.load (std::memory_order_relaxed), -60.f)); o->setProperty ("masterDb", juce::Decibels::gainToDecibels ( masterGain_.load (std::memory_order_relaxed), -60.f)); + o->setProperty ("masterLinear", masterGain_.load (std::memory_order_relaxed)); o->setProperty ("dryTest", dryTest_.load()); const auto route = diagnosticRoute(); o->setProperty ("diagnosticRoute", armix::diagnostics::routeName (route)); diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 838077cd4..778eef173 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -445,6 +445,7 @@ class LiveDryRoutingLab final { const auto& st=channelEdits_[i]; auto obj=std::make_unique(); obj->setProperty("db",st.linear>0.f?20.f*std::log10(st.linear):-60.f); + obj->setProperty("linear",st.linear); // exact, including hard -infinity mute obj->setProperty("pan",st.pan*100.f); obj->setProperty("mute",st.mute); obj->setProperty("solo",st.solo); diff --git a/src/Main.cpp b/src/Main.cpp index b8483f31f..11f24c6d1 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -18,6 +18,8 @@ #include "PluginCatalog.h" #include "PortableWorkspace.h" #include "StudioBackup.h" +#include "NativeLiveShowCapture.h" +#include "NativeShowSaveWorker.h" #include #include #include @@ -230,6 +232,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr armix::storage::NativePresetArchive presets_; Browser browser_; armix::storage::StudioBackup::Worker studioBackupWorker_; + armix::shows::NativeShowSaveWorker nativeShowWorker_; + bool nativeShowBusy_ = false; bool studioBackupBusy_ = false; std::unique_ptr chooser_; std::unique_ptr editorWindow_; @@ -758,7 +762,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // portable folder. IO/hashing stay on StudioBackup's worker thread. void chooseStudioBackup() { - if (studioBackupBusy_ || catalog_.busy() || engine_.isGraphSwitchPending()) + if (studioBackupBusy_ || nativeShowBusy_ || catalog_.busy() || engine_.isGraphSwitchPending()) return emitNotice ("Finish VST import or FX recall before backing up Studio.", true); // Large USB copies cause disk contention even on an IO worker. Avoid // starting a backup during a live performance. @@ -775,7 +779,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr if (safe == nullptr) return; const auto destination = picker.getResult(); if (destination == juce::File()) return; - if (safe->studioBackupBusy_ || safe->catalog_.busy() || + if (safe->studioBackupBusy_ || safe->nativeShowBusy_ || safe->catalog_.busy() || safe->engine_.isGraphSwitchPending() || !safe->engine_.isOutputMuted()) return safe->emitNotice ("Plugin import/FX recall is active; backup was not started.", true); const auto app = juce::File::getSpecialLocation (juce::File::currentExecutableFile); @@ -934,7 +938,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const int slot = static_cast (args.getProperty ("slot", -1)); // User may adjust live levels, but cannot alter the persisted VST // library/preset while a background snapshot is being copied. - if (studioBackupBusy_ && (action.startsWith ("preset") || + if ((studioBackupBusy_ || nativeShowBusy_) && (action.startsWith ("preset") || action.startsWith ("import") || action.startsWith ("fx") || action == "addCatalog" || action == "addScanFolder" || action == "scanVst3" || action == "routingDryApply")) @@ -1026,6 +1030,60 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr " independent VST3 inserts, real PRE/POST sends. " "Use low headphone volume; STOP LAB before normal CH1 VST3."); } + if (action == "routingDryShowSave") + { + const auto reject=[this](const juce::String& reason) { + if(browser_.loaded) { + auto ack=std::make_unique(); + ack->setProperty("ok",false); + ack->setProperty("error",reason); + browser_.emitEventIfBrowserIsVisible("arMixNativeShowSaveAck", + juce::var(ack.release())); + } + emitNotice("Show not saved: "+reason,true); + }; + if (nativeShowBusy_ || studioBackupBusy_ || catalog_.busy() || + engine_.isGraphSwitchPending() || engine_.hasTemporaryDiagnosticDevice()) + return reject("Finish the current Studio task before capturing a native Show."); + // Never save the unacknowledged JS draft. Message-thread capture + // reads the accepted LIVE graph, updated faders and exact device epoch. + // VST3 is fail-closed until a quiescent vendor state capture gate exists. + armix::shows::SnapshotV2 captured; + const auto name=juce::String("Dry Routing ")+juce::Time::getCurrentTime().formatted("%Y%m%d %H%M%S"); + const auto error=armix::shows::NativeLiveShowCapture::captureDry( + engine_.status(),name,captured); + if(error.isNotEmpty()) { + diagnostics_.record("NATIVE_SHOW_REJECTED",error); + return reject(error); + } + auto safe=juce::Component::SafePointer(this); + const bool started=nativeShowWorker_.launch(settingsDirectory(), + std::move(captured),[safe](armix::shows::NativeShowSaveWorker::Result result) { + if(safe==nullptr)return; + safe->nativeShowBusy_=false; + if(!result.ok()) { + safe->diagnostics_.record("NATIVE_SHOW_SAVE_FAIL",result.error); + safe->emitNotice("Native Show not saved: "+result.error,true); + }else{ + safe->diagnostics_.record("NATIVE_DRY_SHOW_SAVED", + result.showId+" | "+result.snapshotId); + safe->emitNotice("Native DRY Show saved and verified in Studio/Shows: "+ + result.name+". FX-equipped Show capture/recall is not available yet."); + } + if(safe->browser_.loaded) { + auto ack=std::make_unique(); + ack->setProperty("ok",result.ok()); + ack->setProperty("error",result.error); + ack->setProperty("showId",result.ok()?result.showId:juce::String()); + ack->setProperty("snapshotId",result.ok()?result.snapshotId:juce::String()); + safe->browser_.emitEventIfBrowserIsVisible("arMixNativeShowSaveAck", + juce::var(ack.release())); + } + }); + if(!started)return reject("Native Show worker is busy. No session was modified."); + nativeShowBusy_=true; + return emitNotice("Saving ACK-verified dry routing to Studio/Shows on the IO worker."); + } if (action == "routingDryStop") { engine_.disableDryRoutingLab(); diff --git a/src/NativeLiveShowCapture.h b/src/NativeLiveShowCapture.h new file mode 100644 index 000000000..3d64b136d --- /dev/null +++ b/src/NativeLiveShowCapture.h @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "NativeShowSchema.h" +#include "../engine/core/NativeDryRouteCommand.h" +#include +#include + +// P4 stage 3: message-thread native SSOT -> SHOW snapshot. This is deliberately +// a DRY (zero vendor FX) capture: vendor getStateInformation() requires a +// separately qualified processor-quiescence and thread-affinity protocol. +// No UI draft or browser localStorage can become the saved audio truth. +namespace armix::shows { +class NativeLiveShowCapture final { + static bool numeric(const juce::var& v,double& n,double lo,double hi) { + if(!(v.isInt()||v.isInt64()||v.isDouble()))return false; + n=static_cast(v); + return std::isfinite(n)&&n>=lo&&n<=hi; + } + static bool flag(const juce::var& v,bool& b) { + if(!v.isBool())return false; + b=static_cast(v); + return true; + } + static bool integer(const juce::var& v,juce::int64& n) { + if(!(v.isInt()||v.isInt64()))return false; + n=static_cast(v); + return true; + } +public: + // Return empty String on success, otherwise reason. On any failure, + // preserve the caller's prior accepted snapshot in its entirety. + static juce::String captureDry(const juce::var& nativeStatus, + const juce::String& cleanName, + SnapshotV2& out) { + if(!detail::name(cleanName))return "Invalid Show snapshot name"; + if(!nativeStatus.isObject())return "Native audio status unavailable"; + bool outputArmed=true,independent=false; + if(!flag(nativeStatus.getProperty("monitor",{}),outputArmed) || + !flag(nativeStatus.getProperty("adaptiveClockActive",{}),independent) || + outputArmed || independent) + return "Mute native output and use a single DIRECT device before SAVE"; + if(nativeStatus.getProperty("diagnosticRoute",{}).toString()!="NORMAL") + return "Return diagnostic audio to NORMAL before SAVE"; + const auto lab=nativeStatus.getProperty("dryRoutingLab",{}); + if(!lab.isObject())return "Native Routing LAB has no published session"; + bool active=false,ready=false; + if(!flag(lab.getProperty("active",{}),active) || + !flag(lab.getProperty("ready",{}),ready) || !active || !ready) + return "Routing LAB is not active and acknowledged"; + juce::int64 epoch=0,rev=0; + if(!integer(lab.getProperty("epoch",{}),epoch) || + !integer(lab.getProperty("revision",{}),rev) || + epoch<=0 || rev<=0) + return "Native route device epoch/revision missing"; + const auto fxCount=lab.getProperty("fxCount",{}); + if(!fxCount.isInt()||static_cast(fxCount)!=0) + return "Live VST3 requires safe vendor state quiescence; DRY-only SAVE"; + const auto route=lab.getProperty("acceptedRoute",{}); + juce::int64 routeEpoch=0,routeRev=0; + if(!route.isObject() || + !integer(route.getProperty("deviceEpoch",{}),routeEpoch) || + !integer(route.getProperty("revision",{}),routeRev) || + routeEpoch!=epoch || routeRev+1!=rev) + return "Native route changed after acceptance; refresh before SAVE"; + + armix::mixer::NativeDryRouteCommand parsed; + juce::String error; + if(!armix::mixer::NativeDryRouteCommand::decode(route,parsed,error)) + return "Accepted native routing record invalid: "+error; + const auto rows=route.getProperty("channels",{}); + const auto* channels=rows.getArray(); + const auto controlsValue=lab.getProperty("channelControls",{}); + const auto* controls=controlsValue.getArray(); + const auto busesValue=route.getProperty("auxes",{}); + const auto* buses=busesValue.getArray(); + if(!channels||channels->size()!=armix::mixer::stripCount || + !controls||controls->size()!=armix::mixer::stripCount || + !buses||buses->size()!=armix::mixer::auxBusCount) + return "Native controls or four AUX definitions are incomplete"; + // Confirm every physical port still appears in the native enabled + // mask; never accept arbitrary WebView port numbers as restored IO. + const auto portsValue=lab.getProperty("ports",{}); + const auto* ports=portsValue.getArray(); + if(!ports)return "Current hardware input mask unavailable"; + auto portEnabled=[ports](int physical) { + for(const auto& port:*ports) { + const auto raw=port.getProperty("port",{}); + if(raw.isInt()&&static_cast(raw)==physical)return true; + } + return false; + }; + SnapshotV2 next; + next.id=juce::Uuid().toDashedString().toLowerCase(); + next.name=cleanName; + next.sourceBuild="P4_NATIVE_DRY_ACK_10CH_4AUX"; + next.createdMs=next.modifiedMs=juce::Time::currentTimeMillis(); + for(int i=0;isize();++i) { + const auto& row=channels->getReference(i); + const auto& ctrl=controls->getReference(i); + if(!row.isObject()||!ctrl.isObject() || + row.getProperty("fxId",{}).toString().isNotEmpty()) + return "Uncaptured VST3 or incomplete channel state"; + auto& strip=next.strips[static_cast(i)]; + const auto& parsedStrip=parsed.channels.stripsAndMaster.strips[i]; + const auto mode=row.getProperty("mode",{}).toString(); + strip.busReturn=(mode=="BUS"); + strip.source=mode=="MONO"?1:mode=="STEREO"?2:0; + strip.inputA=strip.source!=0?parsedStrip.inputA:-1; + strip.inputB=strip.source==2?parsedStrip.inputB:-1; + if(strip.source!=0 && + (!portEnabled(strip.inputA) || + (strip.source==2&&!portEnabled(strip.inputB)))) + return "Enabled hardware port changed during Show capture"; + double gain=0,pan=0; + if(!numeric(ctrl.getProperty("linear",{}),gain,0,4) || + !numeric(ctrl.getProperty("pan",{}),pan,-100,100) || + !flag(ctrl.getProperty("mute",{}),strip.mute) || + !flag(ctrl.getProperty("solo",{}),strip.solo)) + return "Acknowledged native channel control is invalid"; + strip.fader=gain; + strip.pan=pan/100.0; + strip.toMaster=parsed.sends.toMaster[i]; + } + for(int i=0;igetReference(i); + if(!row.isObject()||row.getProperty("fxId",{}).toString().isNotEmpty()) + return "Uncaptured AUX VST3 cannot be saved as DRY"; + auto& bus=next.aux[static_cast(i)]; + const auto& input=parsed.aux.buses[i]; + bus.enabled=input.enabled; + bus.toMaster=input.toMaster; + bus.mute=input.mute; + bus.gain=input.gain; + } + for(int i=0;i(e.source)].sends.push_back({ + e.destination,e.tap==armix::mixer::SendTap::preFader,e.gain,e.pan + }); + } + for(int i=0;i +#include +#include +#include +#include +#include + +// One opt-in DRY Show per commit, bounded by the existing transactional store. +// All disk I/O and SHA verification run outside the JUCE message/audio threads. +// The worker's native copy cannot observe subsequent live routing mutations. +namespace armix::shows { +class NativeShowSaveWorker final : private juce::Thread { +public: + struct Result { + juce::String showId, snapshotId, name, error; + bool ok() const noexcept {return error.isEmpty();} + }; + using Completion=std::function; + NativeShowSaveWorker() : juce::Thread("ArSonMix Native Show Save") {} + ~NativeShowSaveWorker() override { + alive_->store(false,std::memory_order_release); + signalThreadShouldExit(); + stopThread(-1); + } + bool launch(juce::File studio,SnapshotV2 snapshot,Completion completion) { + if(isThreadRunning() || !completion || !detail::uuid(snapshot.id)) + return false; + studio_=std::move(studio); + snapshot_=std::move(snapshot); + finished_=std::move(completion); + return startThread(); + } +private: + void run() override { + Result result; + result.snapshotId=snapshot_.id; + result.name=snapshot_.name; + ShowV2 show; + show.id=juce::Uuid().toDashedString().toLowerCase(); + show.name=snapshot_.name; + show.createdMs=snapshot_.createdMs; + show.modifiedMs=snapshot_.modifiedMs; + show.currentSnapshotId=snapshot_.id; + show.snapshotOrder.push_back(snapshot_.id); + result.showId=show.id; + try { + NativeShowStore store(studio_); + result.error=store.commit(show,{snapshot_},{}); + if(result.error.isEmpty()) { + ShowV2 reread; + std::vector snapshots; + result.error=store.load(show.id,reread,snapshots); + if(result.error.isEmpty() && + (reread.currentSnapshotId!=snapshot_.id || + snapshots.size()!=1 || + Codec::encode(snapshots[0])!=Codec::encode(snapshot_))) + result.error="Saved DRY Show verification mismatch"; + } + } catch(const std::exception& e) { + result.error="Native Show IO exception: "+juce::String(e.what()); + } catch(...) { + result.error="Unknown native Show IO exception; existing Shows untouched"; + } + auto alive=alive_; + auto done=finished_; + juce::MessageManager::callAsync( + [alive,done=std::move(done),result=std::move(result)]() mutable { + if(alive->load(std::memory_order_acquire)&&done) + done(std::move(result)); + }); + } + juce::File studio_; + SnapshotV2 snapshot_; + Completion finished_; + std::shared_ptr> alive_= + std::make_shared>(true); +}; +} // namespace armix::shows diff --git a/src/NativeShowSchema.h b/src/NativeShowSchema.h index df4a70d3b..d8b553f15 100644 --- a/src/NativeShowSchema.h +++ b/src/NativeShowSchema.h @@ -34,6 +34,7 @@ struct Strip final { int inputA = -1, inputB = -1; // DEVICE-LOCAL physical indexes; never auto-applied double fader = 1.0, pan = 0.0; // DSP linear gain, not GUI dB bool mute = false, solo = false, toMaster = true; + bool busReturn = false; // disconnected BUS return distinct from NONE std::vector fx; std::vector sends; }; @@ -179,6 +180,7 @@ class Codec final { detail::put(c,"fader",ch.fader);detail::put(c,"pan",ch.pan); detail::put(c,"mute",ch.mute);detail::put(c,"solo",ch.solo); detail::put(c,"toMaster",ch.toMaster); + detail::put(c,"busReturn",ch.busReturn); const auto fx=encodeFx(ch.fx); juce::Array sends; for(const auto& se:ch.sends) { @@ -264,6 +266,12 @@ class Codec final { !detail::flag(detail::get(rec,"solo"),ch.solo) || !detail::flag(detail::get(rec,"toMaster"),ch.toMaster)) return false; + // Old V2/V3 records did not distinguish BUS from NONE. Preserve + // their safe disconnected interpretation; new captures are exact. + const auto busField=detail::get(rec,"busReturn"); + if(!busField.isVoid() && !detail::flag(busField,ch.busReturn)) + return false; + if(ch.busReturn && ch.source!=0) return false; if((ch.source==0 && (ch.inputA!=-1||ch.inputB!=-1)) || (ch.source==1 && (ch.inputA<0||ch.inputB!=-1)) || (ch.source==2 && (ch.inputA<0||ch.inputB<0||ch.inputA==ch.inputB))) diff --git a/tests/native_live_show_capture_test.cpp b/tests/native_live_show_capture_test.cpp new file mode 100644 index 000000000..5bfcb112e --- /dev/null +++ b/tests/native_live_show_capture_test.cpp @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#ifdef NDEBUG + #undef NDEBUG +#endif +#include +#include +#include "../src/NativeLiveShowCapture.h" +#include "../src/NativeShowStore.h" + +namespace { +juce::var obj(){return juce::var(new juce::DynamicObject());} +void set(juce::var& x,const char* k,juce::var v){ + x.getDynamicObject()->setProperty(juce::Identifier(k),std::move(v)); +} +juce::var routeRow(const juce::String& mode,int a=-1,int b=-1){ + auto x=obj(); + set(x,"mode",mode);set(x,"left",a);set(x,"right",b); + set(x,"gain",0.5);set(x,"pan",0.0); + set(x,"main",true);set(x,"mute",false);set(x,"solo",false); + set(x,"fxId",""); + return x; +} +juce::var send(int from,int to,const char* tap){ + auto x=obj(); + set(x,"from",from);set(x,"to",to);set(x,"tap",tap); + set(x,"gain",0.35);set(x,"pan",-0.2); + return x; +} +juce::var setup(){ + juce::Array channelRows,liveControls,auxes,sends,ports; + for(int i=0;i<10;++i) { + channelRows.add(i==0?routeRow("MONO",3): + i==1?routeRow("STEREO",6,8): + i==2?routeRow("BUS"):routeRow("NONE")); + auto control=obj(); + set(control,"linear",i==0?0.0:i==1?0.75:0.25); + set(control,"pan",i==1?22.0:0.0); + set(control,"mute",i==0);set(control,"solo",i==1); + liveControls.add(control); + } + for(int i=0;i<4;++i) { + auto a=obj();set(a,"enabled",i<2);set(a,"gain",i==0?0.7:1.0); + set(a,"main",true);set(a,"mute",false);set(a,"fxId",""); + auxes.add(a); + } + sends.add(send(0,2,"POST")); + sends.add(send(1,10,"PRE")); + sends.add(send(0,11,"POST")); + for(int n:{3,6,8}) { + auto p=obj();set(p,"port",n);ports.add(p); + } + auto route=obj();set(route,"deviceEpoch",static_cast(9)); + set(route,"revision",static_cast(4)); + set(route,"channels",juce::var(channelRows)); + set(route,"auxes",juce::var(auxes)); + set(route,"sends",juce::var(sends)); + auto lab=obj(); + set(lab,"active",true);set(lab,"ready",true); + set(lab,"epoch",static_cast(9)); + set(lab,"revision",static_cast(5)); + set(lab,"fxCount",0); + set(lab,"acceptedRoute",route); + set(lab,"channelControls",juce::var(liveControls)); + set(lab,"ports",juce::var(ports)); + auto root=obj(); + set(root,"monitor",false);set(root,"adaptiveClockActive",false); + set(root,"diagnosticRoute","NORMAL"); + set(root,"masterLinear",0.55); + set(root,"masterMute",false);set(root,"masterMono",true); + set(root,"dryRoutingLab",lab); + return root; +} +} +int main() { + using namespace armix::shows; + auto status=setup(); + SnapshotV2 captured; + const auto success=NativeLiveShowCapture::captureDry(status,"Dry Routing Test",captured); + if(success.isNotEmpty())std::cerr<<"Capture failure: "<0.69); + assert(captured.auxSends.size()==2&&captured.auxSends[0].preFader); + assert(captured.auxSends[0].source==1&&captured.auxSends[0].destination==0); + assert(!captured.auxSends[1].preFader); + assert(captured.masterGain==0.55&&captured.masterMono); + const auto stable=Codec::encode(captured); + SnapshotV2 decoded; + assert(Codec::decode(stable,decoded)); + assert(decoded.strips[2].busReturn&&decoded.strips[0].fader==0.0); + + // Never let untrusted or stale UI state replace an accepted capture. + const auto prior=Codec::encode(captured); + auto armed=setup();set(armed,"monitor",true); + assert(NativeLiveShowCapture::captureDry(armed,"Dry Routing Test",captured).isNotEmpty()); + assert(Codec::encode(captured)==prior); + auto mutated=setup(); + auto lab=mutated.getProperty("dryRoutingLab",{}); + set(lab,"revision",static_cast(6)); + assert(NativeLiveShowCapture::captureDry(mutated,"Dry Routing Test",captured).isNotEmpty()); + auto plugin=setup(); + lab=plugin.getProperty("dryRoutingLab",{}); + set(lab,"fxCount",1); + assert(NativeLiveShowCapture::captureDry(plugin,"Dry Routing Test",captured).isNotEmpty()); + auto portsLost=setup();lab=portsLost.getProperty("dryRoutingLab",{}); + juce::Array ports;auto p=obj();set(p,"port",3);ports.add(p); + set(lab,"ports",juce::var(ports)); + assert(NativeLiveShowCapture::captureDry(portsLost,"Dry Routing Test",captured).isNotEmpty()); + assert(Codec::encode(captured)==prior); + + const auto home=juce::File::getSpecialLocation(juce::File::tempDirectory) + .getNonexistentChildFile("ArSonMixNativeDryCaptureV3","",false); + assert(home.createDirectory().wasOk()); + NativeShowStore store(home); + ShowV2 show; + show.id=juce::Uuid().toDashedString().toLowerCase(); + show.name=captured.name; + show.createdMs=captured.createdMs;show.modifiedMs=captured.modifiedMs; + show.currentSnapshotId=captured.id;show.snapshotOrder={captured.id}; + assert(store.commit(show,{captured},{}).isEmpty()); + ShowV2 reread;std::vector snaps; + assert(store.load(show.id,reread,snaps).isEmpty()); + assert(snaps.size()==1&&Codec::encode(snaps[0])==prior); + assert(home.deleteRecursively()); + std::cout<<"PASS: actual ACK dry routing capture, 10 INPUT / 4 AUX, bus identity, live linear, master, PRE/POST, stale epoch/plugin/ports rejection, transactional persistence\n"; +} diff --git a/web/monitor.js b/web/monitor.js index ba1cf8ece..2512d2d7c 100644 --- a/web/monitor.js +++ b/web/monitor.js @@ -74,7 +74,7 @@ 'The normal CH1 VST3 host resumes after STOP. Every port shown is from the device active input mask.

' + '

4 DEDICATED AUX / FX RETURNS · INPUT CH1–10 REMAIN AVAILABLE

Each AUX has a separate stereo return, VST3, level and MASTER routing. PRE/POST sends may target AUX1–4 without consuming CH strips.

INTERNAL SENDS · PRE / POST FADER (MAX 32)

' + '
Select channels, BUS returns and sends; APPLY is a native graph transaction.
' + - '
'; + '
'; document.body.appendChild(routeOverlay); const draftRoutes=Array.from({length:10},()=>({mode:"NONE",left:-1,right:-1,gain:0.25,pan:0,main:true,mute:false,solo:false,fxId:""})); const draftAux=Array.from({length:4},()=>({enabled:false,gain:1,main:true,mute:false,fxId:""})); @@ -289,6 +289,23 @@ }}); }); document.getElementById("arRouteStop").addEventListener("click",()=>api.emitEvent("arMixAction",{action:"routingDryStop"})); + document.getElementById("arRouteSaveDry").addEventListener("click",()=>{ + const d=state.dryRoutingLab||{}; + if(!d.ready || !d.active || !d.acceptedRoute || state.monitor || + Number(d.fxCount)!==0){ + document.getElementById("arRouteFeedback").textContent= + "SAVE DRY SHOW requires an ACKnowledged native route, MUTED OUTPUT and zero VST3; no changes saved."; + return; + } + document.getElementById("arRouteFeedback").textContent= + "Saving acknowledged 10 INPUT + 4 AUX DRY state to Studio/Shows (not a live recall)..."; + api.emitEvent("arMixAction",{action:"routingDryShowSave"}); + }); + api.addEventListener("arMixNativeShowSaveAck",ack=>{ + document.getElementById("arRouteFeedback").textContent=ack?.ok + ? "NATIVE SHOW VERIFIED · "+String(ack.showId||"")+" · Studio/Shows · live recall not yet supported" + : "SHOW NOT SAVED · "+String(ack?.error||"Unknown storage failure"); + }); api.addEventListener("arMixRoutingLabAck",reply=>{ const result=reply?.state||reply||{}; if(result && typeof result==="object" && "epoch" in result)state.dryRoutingLab=result;