diff --git a/engine/core/DynamicAcceptedSession.h b/engine/core/DynamicAcceptedSession.h index 64d9667d9..32a03b941 100644 --- a/engine/core/DynamicAcceptedSession.h +++ b/engine/core/DynamicAcceptedSession.h @@ -65,6 +65,50 @@ class DynamicAcceptedSession final { std::move(result),std::move(fx)); } + // WIRE transaction is validated against accepted roster+graph revisions, + // then compiled/published by the SAME native PCM publisher as other edits. + // No GUI state or separate audio graph becomes authoritative on rejection. + Result wireTransaction(std::uint64_t expectedRosterRevision, + std::uint64_t expectedGraphRevision, + std::span changes, + const DynamicGraphRequest& route, + std::uint64_t expectedDeviceEpoch, + std::uint64_t activeDeviceEpoch, + bool allOutputsDisarmed, + DynamicNativeSessionPublisher::FxPlan fx={}) { + Result result=preflight(expectedRosterRevision,expectedGraphRevision); + if(!result.ok())return result; + auto candidate=accepted_; + result.edit=candidate.wireTransaction(expectedRosterRevision,changes); + if(!result.edit.ok()) { + result.fault=Fault::editRejected;return result; + } + // WIRE-only publication may remain armed ONLY when every accepted + // physical patch and device admission parameter remains unchanged. + // Reject stale/changed physical drafts rather than silently rebasing. + const bool samePhysical= + route.physicalInputs==acceptedRequest_.physicalInputs && + route.maxFrames==acceptedRequest_.maxFrames && + route.maxScratchBytes==acceptedRequest_.maxScratchBytes && + route.mainMonoAfterFx==acceptedRequest_.mainMonoAfterFx && + route.sources.size()==acceptedRequest_.sources.size() && + std::equal(route.sources.begin(),route.sources.end(), + acceptedRequest_.sources.begin(), + [](const DynamicSourcePatch& a,const DynamicSourcePatch& b) { + return a.id==b.id && a.inputL==b.inputL && + a.inputR==b.inputR && a.stereo==b.stereo; + }); + if(!allOutputsDisarmed && !samePhysical) { + result.fault=Fault::graphRejected; + result.native.fault=DynamicNativeSessionPublisher::Fault::outputArmed; + result.native.revision=publisher_.acceptedRevision(); + return result; + } + return publish(std::move(candidate),route,expectedGraphRevision, + expectedDeviceEpoch,activeDeviceEpoch,allOutputsDisarmed, + std::move(result),std::move(fx),samePhysical); + } + // Studio Pro: one independent Bus ChannelId and automatic assignment of // selected primary OUTs; FX Return leaves those OUTs intact and adds sends. Result createBusForSelected(std::uint64_t expectedRosterRevision, @@ -221,7 +265,8 @@ class DynamicAcceptedSession final { std::uint64_t previousGraphRevision, std::uint64_t requestedEpoch,std::uint64_t currentEpoch, bool outputsDisarmed,Result&& result, - DynamicNativeSessionPublisher::FxPlan fx) { + DynamicNativeSessionPublisher::FxPlan fx, + bool verifiedWireOnly=false) { // Existing SOURCE targets belong to the accepted native session. // For already-patched ChannelIds with the same input format, ignore // stale physical pin ordinals supplied by an old GUI draft during @@ -267,7 +312,7 @@ class DynamicAcceptedSession final { const bool nextHasFx=static_cast(fx.owner); result.native=publisher_.commit(candidate,effective,previousGraphRevision, requestedEpoch,currentEpoch,outputsDisarmed, - std::move(fx)); + std::move(fx),verifiedWireOnly); if(!result.native.ok()) { result.fault=Fault::graphRejected; result.edit.createdIds.clear(); // NEVER advertise phantom Bus diff --git a/engine/core/DynamicChannelRoster.h b/engine/core/DynamicChannelRoster.h index f05736a35..c537d82d4 100644 --- a/engine/core/DynamicChannelRoster.h +++ b/engine/core/DynamicChannelRoster.h @@ -29,6 +29,7 @@ struct ChannelSendRef final { bool preFader=false; float pan=0.f; // send-only balance: PRE mono uses equal-power coefficients bool primaryOutput=false; // OUT selector edge, not a parallel SEND + std::uint64_t edgeId=0; // control-owned stable identity, never a PCM buffer }; struct ChannelStripDefinition final { ChannelId id{}; @@ -78,6 +79,15 @@ struct ChannelEditResult final { bool ok() const noexcept {return fault==ChannelEditFault::none;} }; +struct WireChange final { + enum class Kind : std::uint8_t { connect, remove, retarget, routeOnly }; + Kind kind=Kind::connect; + std::uint64_t edgeId=0; // REMOVE/RETARGET must address exact accepted edge + ChannelId source{},destination{}; + float gain=1.f; + bool preFader=false; +}; + class DynamicChannelRoster final { public: explicit DynamicChannelRoster(ChannelRosterBudget budget={}) : budget_(budget) {} @@ -276,6 +286,10 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + if(!assignMissingEdges(candidate,nextEdgeId_)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); index_.swap(stagedIndex); @@ -284,6 +298,122 @@ class DynamicChannelRoster final { return result; } + // CONTROL only: one atomic WIRE batch against the canonical roster. + // Native PCM compile/publish is performed by DynamicAcceptedSession. + // Edge identity survives RETARGET and unrelated graph edits. + ChannelEditResult wireTransaction(std::uint64_t expectedRevision, + std::span changes) { + ChannelEditResult result;result.revision=revision_; + if(expectedRevision!=revision_) { + result.fault=ChannelEditFault::staleRevision;return result; + } + if(changes.empty() || revision_==std::numeric_limits::max()) { + result.fault=ChannelEditFault::invalidAction;return result; + } + auto candidate=channels_; + auto edgeCounter=nextEdgeId_; + if(!assignMissingEdges(candidate,edgeCounter)) { + result.fault=ChannelEditFault::idExhausted;return result; + } + const auto findRow=[&](ChannelId id) { + return std::find_if(candidate.begin(),candidate.end(), + [id](const auto& row){return row.id==id;}); + }; + const auto findEdge=[&](std::uint64_t id) { + for(auto& row:candidate) + for(auto it=row.sends.begin();it!=row.sends.end();++it) + if(it->edgeId==id) + return std::pair{&row,it}; + return std::pair::iterator>{nullptr,{}}; + }; + const auto legal=[&](ChannelId from,ChannelId to,float gain) { + const auto a=findRow(from),b=findRow(to); + return from.value && to.value && from!=to && + a!=candidate.end() && b!=candidate.end() && + a->role!=ChannelRole::main && a->role!=ChannelRole::monitor && + b->role!=ChannelRole::monitor && + std::isfinite(gain) && gain>=0.f && gain<=4.f; + }; + const auto duplicate=[&](ChannelId from,ChannelId to) { + const auto row=findRow(from); + return row!=candidate.end() && + std::any_of(row->sends.begin(),row->sends.end(), + [to](const auto& e){return e.destination==to;}); + }; + const auto connect=[&](ChannelId from,ChannelId to,float gain, + bool pre) { + auto row=findRow(from); + if(!legal(from,to,gain) || duplicate(from,to) || + row->sends.size()>=budget_.maximumSendsPerChannel || + edgeCounter==0 || edgeCounter==std::numeric_limits::max()) + return false; + row->sends.push_back({to,gain,pre,0.f,false,edgeCounter++}); + return true; + }; + for(std::size_t i=0;isends.erase(it);ok=true;} + break; + } + case WireChange::Kind::retarget: { + if(!change.edgeId)break; + auto [row,it]=findEdge(change.edgeId); + if(!row || !legal(row->id,change.destination,it->gain))break; + if(it->destination!=change.destination && + duplicate(row->id,change.destination))break; + it->destination=change.destination; + ok=true;break; + } + case WireChange::Kind::routeOnly: { + const auto src=findRow(change.source); + if(src==candidate.end())break; + const auto master=std::find_if(candidate.begin(),candidate.end(), + [](const auto& row){return row.role==ChannelRole::main;}); + if(master==candidate.end() || + !legal(change.source,change.destination,change.gain) || + change.destination==master->id)break; + const auto mainId=master->id; + // Normal SEND retained its MAIN route. ROUTE_ONLY removes + // precisely MAIN and reuses an existing target edge instead + // of double summing or rejecting an already-connected target. + const bool alreadyConnected=duplicate(change.source, + change.destination); + auto& sends=src->sends; + sends.erase(std::remove_if(sends.begin(),sends.end(), + [mainId](const auto& e){return e.destination==mainId;}), + sends.end()); + ok=alreadyConnected || + connect(change.source,change.destination,change.gain, + change.preFader); + break; + } + } + if(!ok) {result.fault=ChannelEditFault::invalidValue;return result;} + } + if(!withinBudget(candidate)) { + result.fault=ChannelEditFault::budgetExceeded;return result; + } + if(!assignMissingEdges(candidate,nextEdgeId_)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } + auto stagedIndex=buildIndex(candidate); + channels_.swap(candidate);index_.swap(stagedIndex); + nextEdgeId_=edgeCounter; + result.revision=++revision_;return result; + } + // Studio Console Add Bus / Add FX Channel: allocate a fresh independent // stereo ChannelId, OUT -> MAIN, without borrowing an input or requiring // a selection. CONTROL only; native graph publication is separate. @@ -322,6 +452,10 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + if(!assignMissingEdges(candidate,nextEdgeId_)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); index_.swap(stagedIndex);result.createdIds.push_back({nextId_++}); @@ -377,6 +511,10 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + if(!assignMissingEdges(candidate,nextEdgeId_)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); index_.swap(stagedIndex); @@ -457,6 +595,10 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + if(!assignMissingEdges(candidate,nextEdgeId_)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); index_.swap(stagedIndex); @@ -466,6 +608,17 @@ class DynamicChannelRoster final { } private: + static bool assignMissingEdges(std::vector& rows, + std::uint64_t& next) noexcept { + for(auto& row:rows) + for(auto& edge:row.sends) + if(!edge.edgeId) { + if(!next || next==std::numeric_limits::max()) + return false; + edge.edgeId=next++; + } + return true; + } static std::unordered_map buildIndex( const std::vector& rows) { std::unordered_map index; @@ -506,6 +659,6 @@ class DynamicChannelRoster final { ChannelRosterBudget budget_; std::vector channels_; std::unordered_map index_; // CONTROL ONLY - std::uint64_t revision_=0, nextId_=1; + std::uint64_t revision_=0, nextId_=1, nextEdgeId_=1; }; } // namespace armix::mixer diff --git a/engine/core/DynamicConsoleRoutingView.h b/engine/core/DynamicConsoleRoutingView.h index a610abbe3..ec7775823 100644 --- a/engine/core/DynamicConsoleRoutingView.h +++ b/engine/core/DynamicConsoleRoutingView.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,12 @@ struct ConsoleSendView final { float gain=1.f,pan=0.f; bool preFader=false; }; +struct ConsoleWireView final { + std::uint64_t edgeId=0; + ChannelId source{},destination{}; + float gain=1.f; + bool preFader=false,primaryOutput=false; +}; struct ConsoleChannelView final { ChannelId id{}; ChannelRole role=ChannelRole::input; @@ -40,6 +47,7 @@ class DynamicConsoleRoutingView final { public: std::uint64_t rosterRevision=0; std::vector channels; + std::vector edges; // same accepted graph, not GUI-owned routes ChannelId main{},monitor{}; const ConsoleChannelView* find(ChannelId id) const noexcept { const auto it=std::find_if(channels.begin(),channels.end(), @@ -55,6 +63,7 @@ class DynamicConsoleRoutingView final { const auto& rows=roster.channels(); next.channels.reserve(rows.size()); std::unordered_map index; + std::unordered_set edgeIds; index.reserve(rows.size()); for(const auto& row:rows) { if(!row.id.value || !index.emplace(row.id.value,next.channels.size()).second) @@ -76,6 +85,10 @@ class DynamicConsoleRoutingView final { for(std::size_t i=0;isecond]; diff --git a/engine/core/DynamicNativeSessionPublisher.h b/engine/core/DynamicNativeSessionPublisher.h index 0574f9753..a9201c9a0 100644 --- a/engine/core/DynamicNativeSessionPublisher.h +++ b/engine/core/DynamicNativeSessionPublisher.h @@ -68,7 +68,7 @@ class DynamicNativeSessionPublisher final { std::uint64_t proposedDeviceEpoch, std::uint64_t activeDeviceEpoch, bool allOutputsDisarmed, - FxPlan fx={}) { + FxPlan fx={},bool verifiedWireOnly=false) { CommitResult report;report.revision=publisher_.lastRevision(); if(!fx.valid() || (fx.owner && (fx.deviceEpoch!=proposedDeviceEpoch || @@ -83,7 +83,10 @@ class DynamicNativeSessionPublisher final { expectedRevision==std::numeric_limits::max()) { report.fault=Fault::staleRevision;return report; } - if(!allOutputsDisarmed) { + // Only DynamicAcceptedSession may authorize a WIRE-only change + // while armed after checking the physical device patch is unchanged. + // All source/device/roster edits still require output disarm. + if(!allOutputsDisarmed && !verifiedWireOnly) { report.fault=Fault::outputArmed;return report; } auto next=std::make_unique(); diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index f3cfc002a..46cadc80c 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1387,6 +1387,25 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return dryRoutingLab_.setNativePrimaryOutput( ep,pcmRev,rosterRev,src,dst,true); } + // Native WIRE mutation on the already installed single ChannelId PCM + // path. No device restart, audio-thread heap work or output disarm; + // fail closed for legacy M4 sources until they are migrated. + LiveDryRoutingLab::NativeBusResult applyNativeWireTransaction( + std::uint64_t ep,std::uint64_t pcmRevision, + std::uint64_t rosterRevision, + std::span changes) { + LiveDryRoutingLab::NativeBusResult fail; + fail.error="NATIVE_WIRE_DEVICE_NOT_READY"; + if(independent_.active()||!attached_||!directFence_.permitted()|| + routeReconfiguring_.load(std::memory_order_acquire)|| + diagnosticRoute_.load(std::memory_order_acquire)!= + armix::diagnostics::Route::normal|| + handoff_.busy()|| + fxMovePhase_.load(std::memory_order_acquire)!=0) + return fail; + return dryRoutingLab_.applyNativeWireTransaction( + ep,pcmRevision,rosterRevision,changes); + } bool setNativeInputMix(std::uint64_t epoch,std::uint64_t rev, armix::mixer::ChannelId id,float gain,float pan) noexcept { if(independent_.active()||!directFence_.permitted()|| diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 5eb0ad4ad..97fdb6fa3 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1528,6 +1528,94 @@ class LiveDryRoutingLab final { } } + // Native WIRE-first control transaction. Uses the EXISTING installed + // ChannelId publisher and VST3 lease bank, never a second callback or + // an independently accepted JS graph. CONTROL thread only. + NativeBusResult applyNativeWireTransaction( + std::uint64_t ep,std::uint64_t expectedPcmRev, + std::uint64_t expectedRosterRev, + std::span changes) { + using namespace armix::mixer; + NativeBusResult result{}; + result.pcmRevision=nativeAccepted_.pcmRevision; + result.rosterRevision=nativeAccepted_.graph.roster.revision(); + if(!nativeStructureLive_||!channelIdPhysicalPcmActive()||!ready()|| + ep!=epoch()||nativeAccepted_.deviceEpoch!=ep|| + !nativeAccepted_.fxOwners|| + expectedPcmRev!=nativeAccepted_.pcmRevision|| + expectedRosterRev!=nativeAccepted_.graph.roster.revision()) { + result.error="NATIVE_WIRE_STALE_OR_UNAVAILABLE";return result; + } + // M4's occupied input/aux FX path must never be moved by this + // universal WIRE transaction until its lease has been fully cut over. + // Reject the ENTIRE batch rather than partly moving a vendor source. + if(changes.empty()) { + result.error="NATIVE_WIRE_EMPTY";return result; + } + for(const auto& change:changes) { + ChannelId source=change.source; + if(change.kind==WireChange::Kind::remove || + change.kind==WireChange::Kind::retarget) { + source={}; + for(const auto& row:nativeAccepted_.graph.roster.channels()) + for(const auto& edge:row.sends) + if(edge.edgeId==change.edgeId)source=row.id; + } + if(!source.value) { + result.error="NATIVE_WIRE_UNKNOWN_EDGE";return result; + } + for(const auto id:nativeAccepted_.graph.ids.inputs) + if(id==source) { + result.error="M4_INPUT_ROUTE_NOT_DYNAMIC";return result; + } + if(originalM4Aux(source)) { + result.error="M4_AUX_ROUTE_NOT_DYNAMIC";return result; + } + } + try { + auto roster=nativeAccepted_.graph.roster; + const auto edited=roster.wireTransaction(expectedRosterRev,changes); + if(!edited.ok()) { + result.error="NATIVE_WIRE_GUARDIAN_REJECTED";return result; + } + DynamicChannelFxLeaseBank bank; + if(DynamicChannelFxLeaseBank::reuseRevision( + ep,expectedPcmRev+1,*nativeAccepted_.fxOwners,bank)!= + DynamicChannelFxLeaseBank::Fault::none) { + result.error="NATIVE_WIRE_FX_LEASE_REJECTED";return result; + } + auto owner=std::make_shared( + std::move(bank)); + DynamicNativeSessionPublisher::FxPlan fx; + fx.owner=std::static_pointer_cast(owner); + fx.context=owner.get(); + fx.render=+[](void* ctx,ChannelId id,float* l,float* rr, + int n) noexcept { + (*static_cast(ctx))(id,l,rr,n); + }; + fx.deviceEpoch=ep;fx.graphRevision=expectedPcmRev+1; + // Only internal wires changed: same admitted physical patch, + // same device epoch and same plugin instances. Routine WIRE + // gestures do not need to detach or mute the audio callback. + const auto accepted=nativePublisher_.commit( + roster,nativeAccepted_.graph.request,expectedPcmRev, + ep,epoch(),false,std::move(fx),true); + if(!accepted.ok()) { + result.error="NATIVE_WIRE_PCM_COMMIT_REJECTED";return result; + } + nativeAccepted_.graph.roster=std::move(roster); + nativeAccepted_.fxOwners=std::move(owner); + nativeAccepted_.pcmRevision=accepted.revision; + nativeMeterEpoch_.store(0,std::memory_order_release); + result.accepted=true;result.error=""; + result.pcmRevision=accepted.revision; + result.rosterRevision=nativeAccepted_.graph.roster.revision(); + return result; + } catch(...) { + result.error="NATIVE_WIRE_PREPARE_FAILED";return result; + } + } + // Live dynamic-input controls: one canonical ChannelId PCM callback, // no M4 ordinal alias, vendor reload or RT thread allocation. bool setNativeInputMix(std::uint64_t epochValue,std::uint64_t revision, @@ -1695,6 +1783,24 @@ class LiveDryRoutingLab final { rows.add(juce::var(row.release())); } state->setProperty("channels",juce::var(rows)); + // Accepted edge inventory from the SAME native PCM publisher as + // channel meters and VST leases. Identity is decimal uint64, not + // a JS recomputation from OUT/send labels or a display index. + juce::Array wires; + for(const auto& edge:routing->edges) { + auto item=std::make_unique(); + item->setProperty("edgeId",juce::String( + std::to_string(edge.edgeId))); + item->setProperty("from",juce::String( + std::to_string(edge.source.value))); + item->setProperty("to",juce::String( + std::to_string(edge.destination.value))); + item->setProperty("tap",edge.preFader?"PRE_FADER":"POST_FADER"); + item->setProperty("gainLinear",static_cast(edge.gain)); + item->setProperty("primaryOutput",edge.primaryOutput); + wires.add(juce::var(item.release())); + } + state->setProperty("edges",juce::var(wires)); return juce::var(state.release()); } diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index f9699bb46..e32fde6fc 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -229,6 +229,143 @@ int main() { assert(block.channelCount()==2); // previous prepared PCM untouched } + // WIRE B2: one atomic native graph publication, stable edge identity, + // direct/indirect same-block PCM, invalid-cycle and stale rollback. + { + DynamicAcceptedSession wire; + constexpr std::uint64_t wireEpoch=4201; + DynamicGraphRequest req;req.physicalInputs=1;req.maxFrames=64; + const std::array creates{ + add(0,ChannelRole::input,"SOURCE"), + add(1,ChannelRole::input,"SUBMIX",ProcessingFormat::stereo), + add(2,ChannelRole::main,"MAIN",ProcessingFormat::stereo) + }; + auto result=wire.edit(0,0,creates,req,wireEpoch,wireEpoch,true); + assert(result.ok()); + const auto source=result.edit.createdIds[0]; + const auto submix=result.edit.createdIds[1]; + const auto main=result.edit.createdIds[2]; + const std::array primary{output(source,main)}; + req.sources={{source,0,-1,false}}; + result=wire.edit(1,1,primary,req,wireEpoch,wireEpoch,true); + assert(result.ok()); + const auto edgeId=wire.acceptedRoster().find(source)->sends.front().edgeId; + assert(edgeId!=0); + const auto* initialView=wire.acceptedRouting(wireEpoch,2); + assert(initialView && initialView->edges.size()==1); + assert(initialView->edges.front().edgeId==edgeId && + initialView->edges.front().source==source && + initialView->edges.front().destination==main); + std::array impulse{},left{},right{}; + impulse[7]=.5f; + const float* pins[]{impulse.data()}; + const auto noFx=+[](ChannelId,float*,float*,int) noexcept {}; + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx)); + const float direct=left[7]; + assert(direct>.1f); + assert(left[6]==0.f && left[8]==0.f); + std::array parallel{}; + parallel[0].kind=WireChange::Kind::connect; + parallel[0].source=source;parallel[0].destination=submix; + parallel[1].kind=WireChange::Kind::connect; + parallel[1].source=submix;parallel[1].destination=main; + result=wire.wireTransaction(2,2,parallel,req,wireEpoch,wireEpoch,false); // real WIRE edit while output armed + assert(result.ok() && wire.acceptedGraphRevision()==3); + assert(wire.acceptedRoster().find(source)->sends.front().edgeId==edgeId); + // A second path to the same ordered pair is not an extra send. + WireChange duplicate;duplicate.kind=WireChange::Kind::connect; + duplicate.source=source;duplicate.destination=submix; + const std::array duplicatePair{duplicate}; + const auto duplicateResult=wire.wireTransaction( + 3,3,duplicatePair,req,wireEpoch,wireEpoch,false); + assert(duplicateResult.fault==DynamicAcceptedSession::Fault::editRejected); + assert(wire.acceptedGraphRevision()==3); + DynamicGraphRequest changedHardware=req; + changedHardware.maxFrames=128; + WireChange newDraft;newDraft.kind=WireChange::Kind::remove; + newDraft.edgeId=edgeId; + const std::array wrongHardware{newDraft}; + const auto rejectedArmed=wire.wireTransaction( + 3,3,wrongHardware,changedHardware,wireEpoch,wireEpoch,false); + assert(!rejectedArmed.ok() && + rejectedArmed.native.fault== + DynamicNativeSessionPublisher::Fault::outputArmed && + wire.acceptedGraphRevision()==3); + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx)); + assert(near(left[7],direct*2.f)); + assert(left[6]==0.f && left[8]==0.f); + // Disconnect only the exact original direct MAIN edge. + WireChange remove;remove.kind=WireChange::Kind::remove; + remove.edgeId=edgeId; + const std::array removeOne{remove}; + result=wire.wireTransaction(3,3,removeOne,req,wireEpoch,wireEpoch,true); + assert(result.ok()); + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx)); + assert(near(left[7],direct)); // same index, no extra routing sample + const auto beforeCycle=wire.acceptedGraphRevision(); + WireChange cycle;cycle.kind=WireChange::Kind::connect; + cycle.source=submix;cycle.destination=source; + const std::array invalid{cycle}; + result=wire.wireTransaction(4,4,invalid,req,wireEpoch,wireEpoch,true); + assert(!result.ok() && wire.acceptedGraphRevision()==beforeCycle); + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx) && near(left[7],direct)); + // Stale graph epoch/revision must leave the accepted PCM unchanged. + result=wire.wireTransaction(4,3,removeOne,req,wireEpoch,wireEpoch,true); + assert(result.fault==DynamicAcceptedSession::Fault::staleGraph); + assert(wire.acceptedGraphRevision()==beforeCycle); + // ROUTE_ONLY against an already-existing CH->CH edge removes MAIN + // exactly once without duplicating the intermediate signal. + WireChange reconnect;reconnect.kind=WireChange::Kind::connect; + reconnect.source=source;reconnect.destination=main; + const std::array replug{reconnect}; + result=wire.wireTransaction(4,4,replug,req,wireEpoch,wireEpoch,true); + assert(result.ok() && wire.acceptedGraphRevision()==5); + const auto* beforeOnly=wire.acceptedRoster().find(source); + assert(beforeOnly && beforeOnly->sends.size()==2); + const auto submixEdge=std::find_if(beforeOnly->sends.begin(), + beforeOnly->sends.end(),[submix](const ChannelSendRef& edge) { + return edge.destination==submix; + })->edgeId; + WireChange only;only.kind=WireChange::Kind::routeOnly; + only.source=source;only.destination=submix; + const std::array routeOnly{only}; + result=wire.wireTransaction(5,5,routeOnly,req,wireEpoch,wireEpoch,true); + assert(result.ok() && wire.acceptedGraphRevision()==6); + const auto* onlyRow=wire.acceptedRoster().find(source); + assert(onlyRow && onlyRow->sends.size()==1); + assert(onlyRow->sends.front().edgeId==submixEdge); + assert(onlyRow->sends.front().destination==submix); + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx) && near(left[7],direct)); + // Exact edge retarget preserves ID; source now goes directly MAIN, + // with no extra DSP hop or duplicate path. + WireChange retarget;retarget.kind=WireChange::Kind::retarget; + retarget.edgeId=submixEdge;retarget.destination=main; + const std::array moveOne{retarget}; + result=wire.wireTransaction(6,6,moveOne,req,wireEpoch,wireEpoch,true); + assert(result.ok() && wire.acceptedGraphRevision()==7); + const auto* retargeted=wire.acceptedRoster().find(source); + assert(retargeted && retargeted->sends.size()==1); + assert(retargeted->sends.front().edgeId==submixEdge && + retargeted->sends.front().destination==main); + const auto* acceptedWires=wire.acceptedRouting(wireEpoch,7); + assert(acceptedWires && acceptedWires->edges.size()==2); + const auto projected=std::find_if(acceptedWires->edges.begin(), + acceptedWires->edges.end(), + [submixEdge](const ConsoleWireView& edge) { + return edge.edgeId==submixEdge; + }); + assert(projected!=acceptedWires->edges.end() && + projected->destination==main); + assert(wire.render(wireEpoch,pins,1,left.data(),right.data(), + 64,false,noFx) && near(left[7],direct)); + wire.unpublish();wire.pollRetirement(); + } + verifyConsoleWirePrimaryOutputPcm(); verifyRealtimeSlewAndNativeChannelIdContinuousControls(); constexpr std::uint64_t epoch=77;