Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions engine/core/DynamicChannelFxLeaseBank.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,33 @@ class DynamicChannelFxLeaseBank final {
return reusePreparedOwners(epoch,revision,prior,destination);
}

// Removing a channel must release only that channel's VST3 owners on the
// NEW accepted graph. The retired PCM snapshot still holds its leases
// until its callback readers are gone. Never inherit orphaned FX across
// repeated Add/Delete Track cycles.
static Fault reuseWithoutChannel(
std::uint64_t epoch,std::uint64_t revision,
const DynamicChannelFxLeaseBank& prior,ChannelId removed,
DynamicChannelFxLeaseBank& destination) {
if(!removed.value||!epoch||epoch!=prior.epoch_||
revision<=prior.revision_)return Fault::invalidEpoch;
std::vector<Assignment> retained;
retained.reserve(prior.rows_.size());
for(const auto& row:prior.rows_){
if(row.id==removed)continue;
Assignment item;
item.id=row.id;item.format=row.format;
item.rackBypassed=row.rackBypassed;
item.inserts.reserve(row.count);
for(std::size_t slot=0;slot<row.count;++slot)
item.inserts.push_back(row.owners[slot]);
retained.push_back(std::move(item));
}
auto external=prior.external_;
if(external.id==removed)external={};
return prepare(epoch,revision,retained,destination,std::move(external));
}

// Caller has independently verified identical negotiated audio format.
static Fault rebindSameFormat(std::uint64_t epoch,std::uint64_t revision,
const DynamicChannelFxLeaseBank& prior,
Expand Down
45 changes: 45 additions & 0 deletions engine/core/DynamicChannelRoster.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,51 @@ class DynamicChannelRoster final {
result.revision=++revision_;return result;
}

// Delete one INPUT in a single CONTROL-only roster edit. Remove every
// incoming WIRE including primary OUTs rather than silently redirecting
// other sources to MAIN. The removed channel's outgoing edges disappear
// with its descriptor. Unrelated channel/edge IDs never change.
ChannelEditResult removeInputAndDisconnect(
std::uint64_t expectedRevision,ChannelId id) {
ChannelEditResult result;result.revision=revision_;
if(expectedRevision!=revision_){
result.fault=ChannelEditFault::staleRevision;return result;
}
if(!id.value||revision_==std::numeric_limits<std::uint64_t>::max()){
result.fault=ChannelEditFault::invalidAction;return result;
}
auto candidate=channels_;
const auto target=std::find_if(candidate.begin(),candidate.end(),
[id](const auto& row){return row.id==id;});
if(target==candidate.end()){
result.fault=ChannelEditFault::missingChannel;return result;
}
if(target->role!=ChannelRole::input){
result.fault=ChannelEditFault::invalidValue;return result;
}
for(auto& row:candidate){
if(row.id==id)continue;
auto& sends=row.sends;
sends.erase(std::remove_if(sends.begin(),sends.end(),
[id](const auto& edge){return edge.destination==id;}),
sends.end());
}
candidate.erase(std::find_if(candidate.begin(),candidate.end(),
[id](const auto& row){return row.id==id;}));
if(!withinBudget(candidate)){
result.fault=ChannelEditFault::budgetExceeded;return result;
}
std::uint64_t stagedNextEdge=nextEdgeId_;
if(!assignMissingEdgeIds(candidate,stagedNextEdge)){
result.fault=ChannelEditFault::idExhausted;return result;
}
auto stagedIndex=buildIndex(candidate);
channels_.swap(candidate);
nextEdgeId_=stagedNextEdge;
index_.swap(stagedIndex);
result.revision=++revision_;return result;
}

// One Studio Console transaction: new independent BUS + multi-source
// primary output reroute, or FX return + parallel sends. CONTROL THREAD.
// Caller must compile one native graph and publish with device epoch/ACK.
Expand Down
2 changes: 2 additions & 0 deletions integration/ApprovedNativeRuntimeSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ inline bool projectInstalledNativeChannelIdGraph(
available.add(juce::String("LOAD_INSERT"));
if(has("NATIVE_CREATE_CHANNEL"))
available.add(juce::String("CREATE_CHANNEL"));
if(has("NATIVE_DELETE_CHANNEL"))
available.add(juce::String("DELETE_CHANNEL"));
if(has("NATIVE_CREATE_GROUP_SELECTED"))
available.add(juce::String("CREATE_GROUP"));
const auto graph=snapshot.getProperty("graph",{});
Expand Down
5 changes: 4 additions & 1 deletion scripts/build_approved_native_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
CANONICAL = ROOT / "site" / "preview-v2"
NATIVE_ADAPTER = ROOT / "web" / "approved-native-bridge.js"
ADAPTER_MARKER = ('<script defer src="assets/approved-native-contract.js"></script>\n'
'<script defer src="assets/approved-native-bridge.js"></script>')
'<script defer src="assets/approved-native-bridge.js"></script>\n'
'<script defer src="assets/approved-native-context-menu.js"></script>')
SCHEMA = "arsonmix.approved-native-pages-bundle.v2"


Expand Down Expand Up @@ -327,6 +328,8 @@ def stage(out: Path) -> dict:
out.mkdir(parents=True)
shutil.copytree(pages / "assets", out / "assets")
shutil.copy2(NATIVE_ADAPTER, out / "assets" / "approved-native-bridge.js")
shutil.copy2(ROOT / "web" / "approved-native-context-menu.js",
out / "assets" / "approved-native-context-menu.js")
shutil.copy2(ROOT / "web" / "approved-native-contract.js",
out / "assets" / "approved-native-contract.js")
native = native_html(approved.decode("utf-8")).encode("utf-8")
Expand Down
9 changes: 9 additions & 0 deletions src/LiveAudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,15 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
epoch,pcmRevision,rosterRevision,name,format,true,beforePublish);
});
}
LiveDryRoutingLab::NativeBusResult removeNativeInputChannel(
std::uint64_t epoch,std::uint64_t pcmRevision,
std::uint64_t rosterRevision,armix::mixer::ChannelId id) {
return editNativeInputTopology(epoch,"NATIVE_TRACK_DEVICE_UNAVAILABLE",
"NATIVE_TRACK_DELETE_PUBLICATION_EXCEPTION",[&](const auto& beforePublish){
return dryRoutingLab_.removeNativeInputChannel(
epoch,pcmRevision,rosterRevision,id,true,beforePublish);
});
}
LiveDryRoutingLab::NativeBusResult patchNativeInputSource(
std::uint64_t epoch,std::uint64_t pcmRevision,
std::uint64_t rosterRevision,armix::mixer::ChannelId channel,
Expand Down
77 changes: 76 additions & 1 deletion src/LiveDryRoutingLab.h
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,81 @@ class LiveDryRoutingLab final {
}
}

// One atomic prepared PCM publication for Delete Audio Track. The
// accepted native source patch, inbound/outbound wires, and VST3 owner
// references are removed together only after a successful graph commit.
NativeBusResult removeNativeInputChannel(std::uint64_t expectedEpoch,
std::uint64_t expectedPcmRevision,std::uint64_t expectedRosterRevision,
armix::mixer::ChannelId id,bool outputsDisarmed=false,
const std::function<void()>& beforePublish={}) {
using namespace armix::mixer;
NativeBusResult reply{};
reply.pcmRevision=nativeAccepted_.pcmRevision;
reply.rosterRevision=nativeAccepted_.graph.roster.revision();
if(!outputsDisarmed){reply.error="OUTPUT_MUST_BE_DISARMED";return reply;}
if(!channelIdPhysicalPcmActive()||!ready()||
expectedEpoch!=epoch()||nativeAccepted_.deviceEpoch!=expectedEpoch||
!nativeAccepted_.fxOwners||
expectedPcmRevision!=nativeAccepted_.pcmRevision||
expectedRosterRevision!=nativeAccepted_.graph.roster.revision()){
reply.error="STALE_NATIVE_TRACK_DELETE";return reply;
}
const auto* target=nativeAccepted_.graph.roster.find(id);
if(!target||target->role!=ChannelRole::input){
reply.error="NATIVE_INPUT_ID_UNAVAILABLE";return reply;
}
try {
auto roster=nativeAccepted_.graph.roster;
const auto edited=roster.removeInputAndDisconnect(expectedRosterRevision,id);
if(!edited.ok()){
reply.error="NATIVE_TRACK_DELETE_EDIT_REJECTED";return reply;
}
auto request=nativeAccepted_.graph.request;
auto& inputs=request.sources;
inputs.erase(std::remove_if(inputs.begin(),inputs.end(),
[id](const auto& source){return source.id==id;}),
inputs.end());
DynamicChannelFxLeaseBank bank;
if(DynamicChannelFxLeaseBank::reuseWithoutChannel(
expectedEpoch,expectedPcmRevision+1,
*nativeAccepted_.fxOwners,id,bank)!=
DynamicChannelFxLeaseBank::Fault::none){
reply.error="NATIVE_TRACK_FX_RELEASE_REJECTED";return reply;
}
auto owner=std::make_shared<DynamicChannelFxLeaseBank>(std::move(bank));
DynamicNativeSessionPublisher::FxPlan fx;
fx.owner=std::static_pointer_cast<void>(owner);
fx.context=owner.get();
fx.render=+[](void* ctx,ChannelId channel,float* l,float* r,int n) noexcept {
(*static_cast<DynamicChannelFxLeaseBank*>(ctx))(channel,l,r,n);
};
fx.latency=+[](void* ctx,ChannelId channel) noexcept {
return static_cast<DynamicChannelFxLeaseBank*>(ctx)->latencySamples(channel);
};
fx.deviceEpoch=expectedEpoch;
fx.graphRevision=expectedPcmRevision+1;
if(beforePublish)beforePublish();
const auto published=nativePublisher_.commit(
roster,request,expectedPcmRevision,
expectedEpoch,epoch(),true,std::move(fx));
if(!published.ok()){
reply.error="NATIVE_TRACK_PCM_COMMIT_REJECTED";return reply;
}
nativeAccepted_.graph.roster=std::move(roster);
nativeAccepted_.graph.request=std::move(request);
nativeAccepted_.fxOwners=std::move(owner);
nativeAccepted_.pcmRevision=published.revision;
Comment on lines +1742 to +1745

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep mixer sessions serializable after deleting an original input

Deleting any of the original ten input channels removes it from the roster but leaves its ID in nativeAccepted_.graph.ids.inputs. captureNativeMixerSession() copies that unchanged mapping into draft.legacyIds, while NativeMixerSessionDocument.h:424 requires every legacy input ID to resolve to an existing input. Consequently, NativeMixerSessionStore::commit() rejects the edited mixer with “Mixer session graph cannot be serialized safely,” breaking subsequent saves and autosaves. Reconcile the legacy-ID mapping and persistence validation when removing an original input, or reject that deletion until persistence supports it.

Useful? React with 👍 / 👎.

nativeStructureLive_=true;
nativeMeterEpoch_.store(0,std::memory_order_release);
reply.accepted=true;reply.error="";
reply.pcmRevision=published.revision;
reply.rosterRevision=nativeAccepted_.graph.roster.revision();
return reply;
}catch(...){
reply.error="NATIVE_TRACK_DELETE_PREPARE_FAILED";return reply;
}
}

// Wire a verified physical capture pin to a dynamically CREATED input.
// M4-owned CH1–10 keep the original device/VST continuity contract.
// Prepared topology + lease revision is published once; never patch an
Expand Down Expand Up @@ -2200,7 +2275,7 @@ class LiveDryRoutingLab final {
if(!retained)
for(const char* op: {"NATIVE_CREATE_GROUP_SELECTED",
"NATIVE_REMOVE_BUS","NATIVE_SET_BUS_MIX",
"NATIVE_CREATE_CHANNEL","NATIVE_PATCH_CHANNEL",
"NATIVE_CREATE_CHANNEL","NATIVE_DELETE_CHANNEL","NATIVE_PATCH_CHANNEL",
"NATIVE_SET_PRIMARY_OUT",
"NATIVE_APPLY_WIRE_TRANSACTION",
"NATIVE_SET_WIRE_GAIN",
Expand Down
Loading
Loading