diff --git a/.github/workflows/p1-windows.yml b/.github/workflows/p1-windows.yml index 38099bd00..75d5e4fa2 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 ARMixTenChannelLiveControlTests 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 ARMixLiveChannelFxTests ARMixTenChannelLiveControlTests ARMixWorkspaceTests ARMixVaultTests ARMixBackupTests ARMixOrbitPhaseTests ARMixOrbitControlTests ARMixOrbitMotionTests ARMixOrbitDistanceTests ARMixFxBypassEnvelopeTests ARMixDearVrPolarPolicyTests ARMixRTTests ARMixPresetTests ARMixShowSchemaTests 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 a21f3c2d0..b2d019f1c 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/LiveChannelFxGraph.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_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/LiveChannelFxGraph.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/NativeShowSchema.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 @@ -214,4 +214,10 @@ if(BUILD_TESTING) juce::juce_recommended_config_flags) target_compile_features(ARMixPresetTests PRIVATE cxx_std_20) add_test(NAME NativePresetZipRoundTrip COMMAND ARMixPresetTests) + juce_add_console_app(ARMixShowSchemaTests PRODUCT_NAME "ArSonMix Show V2 Wire Schema Tests") + target_sources(ARMixShowSchemaTests PRIVATE tests/native_show_schema_test.cpp src/NativeShowSchema.h) + 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) + endif() diff --git a/docs/P4_NATIVE_SHOW_V2_SCHEMA_STAGE1_20261029.md b/docs/P4_NATIVE_SHOW_V2_SCHEMA_STAGE1_20261029.md new file mode 100644 index 000000000..a95121593 --- /dev/null +++ b/docs/P4_NATIVE_SHOW_V2_SCHEMA_STAGE1_20261029.md @@ -0,0 +1,24 @@ +# P4 stage 1 — Native ShowV2 / SnapshotV2 schema contract (2026-10-29) + +## Why this is a separate PR +P1J in main now preserves actual running channel VST3 instances across safe route edits, but its accepted route/session is volatile. The left rail's localStorage snapshots are **UI-only** and cannot restore a real 10-channel performance. The first production-safe step is a strict native serialized data contract which cannot accidentally open a different sound device or touch the realtime callback. + +## Delivered by this stage +- `src/NativeShowSchema.h`: two native JSON document kinds, `arsonmix.native.show` and `arsonmix.native.snapshot`, with explicit `schemaVersion=2`, stable UUIDs, bounded names and monotonic positive millisecond timestamps. +- Show metadata stores an ordered bounded list of snapshot UUIDs, current snapshot ID and exactly ten **stable indexed** channel recall-safe flags. Actual snapshots are separate documents, not unbounded nested arrays. +- Snapshot stores **exactly ten** source/physical-port mappings (disconnected/mono/stereo), linear fader and PAN, MUTE/SOLO and to-MASTER, PRE/POST sends (32 total max), ordered per-channel FX references (eight max each), catalog ID, VST UID, SHA256 blob digest and bypass, plus MASTER gain/PAN/MUTE/MONO. +- A plugin state *digest/reference* is not a vendor VST3 state capture. It must point to a verified immutable binary blob created by a later storage stage. This stage does not serialize Orbit automation, HPF, channel trim, full multi-FX bus layouts, external sample libraries or output device driver settings. Those capabilities must be versioned and implemented before a full-scene claim. +- `Codec::decode` rejects malformed, oversized, unsafe or out-of-range documents, duplicate UUIDs, invalid references and unsafe topology basics without changing an already accepted output object. Physical port indexes are data **only**: they are never automatically activated on another PC. Cycle detection and device/plugin compatibility remain mandatory native routing preflight before eventual recall. + +## Runtime and testing boundary +- Serialization is control-only. The production mixer callback, FX graph, Orbit, GUI CSS, master meter, portable vault, dialog and WebView2 code are **unchanged**. +- `tests/native_show_schema_test.cpp` exercises round-trip JSON, ten real indexed source records, sparse stereo pins, PRE sends, FX digest references, channel safes, unknown schema, duplicate snapshot UUIDs, invalid names, invalid plugin/port/pan/send and failure atomicity. The existing canonical Windows MSVC + CTest workflow builds this new test; it does not spawn another CI pipeline. +- There is no save-to-disk/backup integration and **no native recall** in stage 1. Neither green CI nor a Windows artifact means physical audio was tested or that issue #15 is closed. + +## Next PRs (separate gates) +1. **P4 stage 2**: portable Studio/Shows transactional storage + immutable blob checksum verification + recovery journal, budgeted file/entry limits, and verified backup inclusion. Capture actual accepted P1J route and real vendor getState on compliant control/affinity thread; identify unsupported capabilities, never fabricate them. +2. **P4 stage 3**: read-only native show/snapshot metadata via WebView2 ACK, migrate UI-only localStorage as explicitly *legacy UI* (no fake plugin states). +3. **P4 stage 4**: full prepare/validate/ACK-gated recall, device-epoch/port remap fence, per-channel safes/undo, controlled output mute/de-click and transaction rollback. Avoid disk, JSON and plugin vendor lifecycle in RT. +4. Windows 100/125/150/175% first-open Audio Setup DPI and actual ASIO/WASAPI #15 physical FAT remain independent release gates. + +Do not merge historical PR #128 wholesale; keep the P0 #129 gray/green toolbar, lightweight pointer skin and approved 10CH+MASTER layout. diff --git a/src/NativeShowSchema.h b/src/NativeShowSchema.h new file mode 100644 index 000000000..2cad38272 --- /dev/null +++ b/src/NativeShowSchema.h @@ -0,0 +1,291 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include +#include +#include +#include + +// P4 stage 1: inert, CONTROL-thread-only wire schema. No file I/O, device +// activation, WebView bridge or audio callback reads. An encoded record is NOT +// evidence that a VST was captured or that native recall is implemented. +namespace armix::shows { + +constexpr int channels = 10; +constexpr int maxFxPerStrip = 8; +constexpr int maxSendsPerSnapshot = 32; +constexpr int maxSnapshotsPerShow = 256; +constexpr int maxJsonBytes = 512 * 1024; + +struct FxRef final { + juce::String catalogId; // trusted catalog identity, resolved at preflight + int uid = 0; + juce::String stateSha256; // external, separately verified immutable blob + bool bypass = false; +}; +struct Send final { + int destination = 0; // stable zero-based strip index; never GUI row order + bool preFader = false; + double gain = 0.0, pan = 0.0; +}; +struct Strip final { + int source = 0; // armix::mixer::SourceMode: disconnected/mono/stereo + 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; + std::vector fx; + std::vector sends; +}; +struct SnapshotV2 final { + juce::String id, name, sourceBuild; + juce::int64 createdMs = 0, modifiedMs = 0; + std::array strips{}; + double masterGain = 1.0, masterPan = 0.0; + bool masterMute = false, masterMono = false; +}; +struct ShowV2 final { + juce::String id, name, currentSnapshotId; + juce::int64 createdMs = 0, modifiedMs = 0; + std::array channelSafes{}; + std::vector snapshotOrder; // metadata only; snapshots in separate files +}; + +namespace detail { +inline juce::var object() { return juce::var (new juce::DynamicObject()); } +inline void put(juce::var& obj, const char* key, juce::var v) { + obj.getDynamicObject()->setProperty(juce::Identifier(key), std::move(v)); +} +inline juce::var get(const juce::var& obj, const char* key) { + return obj.getProperty(juce::Identifier(key), {}); +} +inline bool integer(const juce::var& v, int& out, int lo, int hi) { + if (!v.isInt()) return false; + const auto n = static_cast(v); + if(n < lo || n > hi) return false; + out=n; return true; +} +inline bool timestamp(const juce::var& v, juce::int64& out) { + if (!v.isInt() && !v.isInt64()) return false; + const auto n = static_cast(v); + if(n <= 0 || n > 9000000000000000LL) return false; + out=n; return true; +} +inline bool real(const juce::var& v, double& out, double lo, double hi) { + if (!v.isDouble() && !v.isInt() && !v.isInt64()) return false; + const auto n=static_cast(v); + if(!std::isfinite(n) || nhi) return false; + out=n; return true; +} +inline bool flag(const juce::var& v, bool& out) { + if(!v.isBool()) return false; + out=static_cast(v); return true; +} +inline bool str(const juce::var& v, juce::String& out, int limit, bool required=true) { + if(!v.isString()) return false; + auto s=v.toString(); + if(s.length()>limit || (required && s.isEmpty())) return false; + out=std::move(s); return true; +} +inline bool uuid(const juce::String& s) { + if(s.length()!=36) return false; + for(int i=0;i<36;++i) { + const auto ch=s[i]; + if(i==8||i==13||i==18||i==23) { if(ch!='-') return false; } + else if(!((ch>='0'&&ch<='9')||(ch>='a'&&ch<='f')||(ch>='A'&&ch<='F'))) return false; + } + return true; +} +inline bool name(const juce::String& n) { + if(n.isEmpty() || n.length()>64 || n.trim()!=n) return false; + for(auto p=n.getCharPointer(); !p.isEmpty(); ++p) { + const auto c=*p; + if(!((c>='A'&&c<='Z')||(c>='a'&&c<='z')|| + (c>='0'&&c<='9')||c==' '||c=='_'||c=='-')) return false; + } + return true; +} +inline bool common(const juce::var& v, juce::String& id, juce::String& label, + juce::int64& created, juce::int64& modified) { + return v.isObject() && str(get(v,"id"),id,36) && uuid(id) && + str(get(v,"name"),label,64) && name(label) && + timestamp(get(v,"createdMs"),created) && + timestamp(get(v,"modifiedMs"),modified) && modified>=created; +} +inline void commonWrite(juce::var& v, const juce::String& id, + const juce::String& name,juce::int64 created,juce::int64 modified) { + put(v,"schemaVersion",2); + put(v,"id",id);put(v,"name",name); + put(v,"createdMs",created);put(v,"modifiedMs",modified); +} +inline juce::String encode(const juce::var& v) { + return juce::JSON::toString(v, true); +} +inline bool header(const juce::var& v,const char* format) { + int schema=0; juce::String kind; + return v.isObject() && integer(get(v,"schemaVersion"),schema,2,2) && + str(get(v,"format"),kind,64) && kind==format; +} +} // namespace detail + +class Codec final { +public: + static juce::String encode(const ShowV2& s) { + auto v=detail::object(); + detail::commonWrite(v,s.id,s.name,s.createdMs,s.modifiedMs); + detail::put(v,"format","arsonmix.native.show"); + detail::put(v,"currentSnapshotId",s.currentSnapshotId); + juce::Array safes,order; + for(bool safe:s.channelSafes) safes.add(safe); + for(const auto& id:s.snapshotOrder) order.add(id); + detail::put(v,"channelSafes",juce::var(safes)); + detail::put(v,"snapshotOrder",juce::var(order)); + return detail::encode(v); + } + static juce::String encode(const SnapshotV2& s) { + auto v=detail::object(); + detail::commonWrite(v,s.id,s.name,s.createdMs,s.modifiedMs); + detail::put(v,"format","arsonmix.native.snapshot"); + detail::put(v,"sourceBuild",s.sourceBuild); + auto master=detail::object(); + detail::put(master,"gain",s.masterGain);detail::put(master,"pan",s.masterPan); + detail::put(master,"mute",s.masterMute);detail::put(master,"mono",s.masterMono); + detail::put(v,"master",master); + juce::Array strips; + for(int i=0;i(i)]; + auto c=detail::object(); + detail::put(c,"id","ch-"+juce::String(i+1).paddedLeft('0',3)); + detail::put(c,"source",ch.source); + detail::put(c,"inputA",ch.inputA);detail::put(c,"inputB",ch.inputB); + 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); + juce::Array fx, sends; + for(const auto& f:ch.fx) { + auto p=detail::object(); + detail::put(p,"catalogId",f.catalogId);detail::put(p,"uid",f.uid); + detail::put(p,"stateSha256",f.stateSha256);detail::put(p,"bypass",f.bypass); + fx.add(p); + } + for(const auto& se:ch.sends) { + auto p=detail::object(); + detail::put(p,"destination",se.destination); + detail::put(p,"preFader",se.preFader); + detail::put(p,"gain",se.gain);detail::put(p,"pan",se.pan); + sends.add(p); + } + detail::put(c,"fx",juce::var(fx));detail::put(c,"sends",juce::var(sends)); + strips.add(c); + } + detail::put(v,"strips",juce::var(strips)); + return detail::encode(v); + } + // Decode is transactional: an invalid record never mutates the caller's + // previously accepted record. Capability/plugin/device preflight is later. + static bool decode(const juce::String& json,ShowV2& out) { + if(json.getNumBytesAsUTF8()>maxJsonBytes) return false; + const auto v=juce::JSON::parse(json); + if(!detail::header(v,"arsonmix.native.show")) return false; + ShowV2 next; + if(!detail::common(v,next.id,next.name,next.createdMs,next.modifiedMs) || + !detail::str(detail::get(v,"currentSnapshotId"),next.currentSnapshotId,36,false) || + (!next.currentSnapshotId.isEmpty() && !detail::uuid(next.currentSnapshotId))) + return false; + return decodeShowArrays(v,next,out); + } + static bool decode(const juce::String& json,SnapshotV2& out) { + if(json.getNumBytesAsUTF8()>maxJsonBytes) return false; + const auto v=juce::JSON::parse(json); + if(!detail::header(v,"arsonmix.native.snapshot")) return false; + SnapshotV2 next; + if(!detail::common(v,next.id,next.name,next.createdMs,next.modifiedMs) || + !detail::str(detail::get(v,"sourceBuild"),next.sourceBuild,80,false)) + return false; + const auto master=detail::get(v,"master"); + if(!master.isObject() || + !detail::real(detail::get(master,"gain"),next.masterGain,0.0,4.0) || + !detail::real(detail::get(master,"pan"),next.masterPan,-1.0,1.0) || + !detail::flag(detail::get(master,"mute"),next.masterMute) || + !detail::flag(detail::get(master,"mono"),next.masterMono)) return false; + const auto list=detail::get(v,"strips"); + const auto* channelsArray=list.getArray(); + if(!channelsArray || channelsArray->size()!=channels) return false; + int totalSends=0; + for(int i=0;i(i)]; + const auto& rec=channelsArray->getReference(i); + juce::String id; + if(!rec.isObject() || + !detail::str(detail::get(rec,"id"),id,6) || + id!="ch-"+juce::String(i+1).paddedLeft('0',3) || + !detail::integer(detail::get(rec,"source"),ch.source,0,2) || + !detail::integer(detail::get(rec,"inputA"),ch.inputA,-1,255) || + !detail::integer(detail::get(rec,"inputB"),ch.inputB,-1,255) || + !detail::real(detail::get(rec,"fader"),ch.fader,0.0,4.0) || + !detail::real(detail::get(rec,"pan"),ch.pan,-1.0,1.0) || + !detail::flag(detail::get(rec,"mute"),ch.mute) || + !detail::flag(detail::get(rec,"solo"),ch.solo) || + !detail::flag(detail::get(rec,"toMaster"),ch.toMaster)) + 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))) + return false; + const auto fxv=detail::get(rec,"fx"), sv=detail::get(rec,"sends"); + const auto* fx=fxv.getArray(); + const auto* sends=sv.getArray(); + if(!fx||!sends||fx->size()>maxFxPerStrip || + (totalSends+=sends->size())>maxSendsPerSnapshot) return false; + for(const auto& p:*fx) { + FxRef f; + if(!p.isObject() || + !detail::str(detail::get(p,"catalogId"),f.catalogId,512) || + !detail::integer(detail::get(p,"uid"),f.uid,-2147483647,2147483647) || + !detail::str(detail::get(p,"stateSha256"),f.stateSha256,64) || + !detail::flag(detail::get(p,"bypass"),f.bypass) || + f.stateSha256.length()!=64) return false; + for(auto chHex:f.stateSha256.toStdString()) + if(!((chHex>='a'&&chHex<='f')||(chHex>='A'&&chHex<='F')|| + (chHex>='0'&&chHex<='9'))) return false; + ch.fx.push_back(std::move(f)); + } + for(const auto& p:*sends) { + Send send; + if(!p.isObject() || + !detail::integer(detail::get(p,"destination"),send.destination,0,channels-1) || + send.destination==i || + !detail::flag(detail::get(p,"preFader"),send.preFader) || + !detail::real(detail::get(p,"gain"),send.gain,0.0,4.0) || + !detail::real(detail::get(p,"pan"),send.pan,-1.0,1.0)) + return false; + ch.sends.push_back(send); + } + } + out=std::move(next); return true; + } +private: + static bool decodeShowArrays(const juce::var& v,ShowV2& next,ShowV2& out) { + const auto orderV=detail::get(v,"snapshotOrder"); + const auto safesV=detail::get(v,"channelSafes"); + const auto* order=orderV.getArray(), *safes=safesV.getArray(); + if(!order||!safes||safes->size()!=channels|| + order->size()>maxSnapshotsPerShow) return false; + for(int i=0;igetReference(i),next.channelSafes[static_cast(i)])) + return false; + for(const auto& item:*order) { + juce::String id; + if(!detail::str(item,id,36)||!detail::uuid(id)) return false; + for(const auto& previous:next.snapshotOrder) + if(previous.equalsIgnoreCase(id)) return false; + next.snapshotOrder.push_back(id); + } + if(!next.currentSnapshotId.isEmpty()) { + bool found=false; + for(const auto& id:next.snapshotOrder) + if(id.equalsIgnoreCase(next.currentSnapshotId)) {found=true;break;} + if(!found) return false; + } + out=std::move(next); return true; + } +}; +} // namespace armix::shows diff --git a/tests/native_show_schema_test.cpp b/tests/native_show_schema_test.cpp new file mode 100644 index 000000000..e4d77b0b6 --- /dev/null +++ b/tests/native_show_schema_test.cpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#ifdef NDEBUG + #undef NDEBUG +#endif +#include +#include +#include "../src/NativeShowSchema.h" + +int main() { + using namespace armix::shows; + const juce::String a="11111111-2222-4333-8444-555555555555"; + const juce::String b="aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee"; + const juce::String c="12345678-1234-4234-9234-123456789abc"; + ShowV2 show; + show.id=a; show.name="Live Set 1"; + show.createdMs=1761700000000LL;show.modifiedMs=show.createdMs+100; + show.currentSnapshotId=b;show.snapshotOrder={b,c}; + show.channelSafes[3]=true; + const auto encodedShow=Codec::encode(show); + ShowV2 restoredShow; + assert(Codec::decode(encodedShow,restoredShow)); + assert(restoredShow.snapshotOrder.size()==2); + assert(restoredShow.currentSnapshotId==b); + assert(restoredShow.channelSafes[3]&&!restoredShow.channelSafes[4]); + assert(Codec::encode(restoredShow)==encodedShow); + + ShowV2 invalid=show; + invalid.snapshotOrder={b,b}; + assert(!Codec::decode(Codec::encode(invalid),restoredShow)); + assert(restoredShow.snapshotOrder.size()==2); // failure atomicity + invalid=show;invalid.currentSnapshotId=a; + assert(!Codec::decode(Codec::encode(invalid),restoredShow)); + invalid=show;invalid.name="../unsafe"; + assert(!Codec::decode(Codec::encode(invalid),restoredShow)); + invalid=show;invalid.channelSafes[0]=true; + auto mutated=juce::JSON::parse(Codec::encode(invalid)); + mutated.getDynamicObject()->setProperty("schemaVersion",3); + assert(!Codec::decode(juce::JSON::toString(mutated),restoredShow)); + + SnapshotV2 snap; + snap.id=b;snap.name="Soundcheck 01";snap.sourceBuild="p1j"; + snap.createdMs=show.createdMs;snap.modifiedMs=show.modifiedMs; + snap.strips[0].source=2; + snap.strips[0].inputA=3;snap.strips[0].inputB=5; // sparse physical pins + snap.strips[0].pan=-0.32;snap.strips[0].fader=0.75; + snap.strips[0].mute=true; + snap.strips[0].fx.push_back({ + "vault:test|987",987,juce::String::repeatedString("a",64),true + }); + snap.strips[0].sends.push_back({5,true,0.4,-0.1}); + snap.strips[6].solo=true;snap.strips[6].toMaster=false; + snap.masterGain=0.65;snap.masterMono=true; + const auto encoded=Codec::encode(snap); + SnapshotV2 loaded; + assert(Codec::decode(encoded,loaded)); + assert(Codec::encode(loaded)==encoded); + assert(loaded.strips[0].inputA==3&&loaded.strips[0].inputB==5); + assert(loaded.strips[0].fx[0].stateSha256==juce::String::repeatedString("a",64)); + assert(loaded.strips[0].sends[0].preFader); + assert(loaded.strips[6].solo&&!loaded.strips[6].toMaster); + assert(loaded.masterMono); + + auto broken=snap; + broken.strips[0].fx[0].stateSha256="not-a-digest"; + assert(!Codec::decode(Codec::encode(broken),loaded)); + assert(loaded.strips[0].inputB==5); // failure leaves last good record + broken=snap;broken.strips[0].inputB=3; + assert(!Codec::decode(Codec::encode(broken),loaded)); + broken=snap;broken.strips[0].pan=1.01; + assert(!Codec::decode(Codec::encode(broken),loaded)); + broken=snap;broken.strips[0].sends[0].destination=0; + assert(!Codec::decode(Codec::encode(broken),loaded)); + broken=snap;broken.strips[0].fx.resize(9); + assert(!Codec::decode(Codec::encode(broken),loaded)); + broken=snap;broken.strips[0].source=0; + assert(!Codec::decode(Codec::encode(broken),loaded)); + assert(!Codec::decode(juce::String::repeatedString("x",maxJsonBytes+1),loaded)); + assert(loaded.name=="Soundcheck 01"); + + std::cout << "PASS: bounded ShowV2/SnapshotV2 JSON round-trips, 10CH references, safes, corrupted records, rollback\n"; + return 0; +}