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
17 changes: 17 additions & 0 deletions docs/R0B_CH1_FX_MOVE_NATIVE_ROUTING_20261029.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# R0B B1 — CH1 FX MOVE while 10CH/4AUX native routing is active

## Scope
One small native vertical slice toward issue #149. Builds on merged R0A CH1 external rack lease and P1K dedicated AUX. Not a new session owner or second mixer.

- Previously `moveSlot()` rejected `dryRoutingLab_.active()`, despite the same legacy CH1 physical FX processors already being borrowed into one routed pass.
- It now publishes the requested logical order via existing lock-free atomic `FxOrderPlan` and uses existing `FxMoveRamp` inside the routed callback: fade OUT in one buffer; publish order at zero; fade IN next buffer. CH1 vendor identity, editor, POLAR Orbit, bypass envelopes, and tails retain their existing instances.
- Native MASTER PCM is measured after routed MOVE de-click, with output peak using the actual ramped samples. No new timer, callback, allocations, locks, VST scanning, state read/write or callback detach on the routed RT path.
- Effects on AUX/other lanes are unchanged. ADD/REMOVE/PRESET still carry the old offline restrictions; this is **not** yet unified native startup/full FX lifecycle. The physical #15 crackle FAT remains open.

## Acceptance
- `tests/live_graph_contract_test.mjs` enforces no detach, phase publication, ramp-before-meter, stable CH1 instances.
- Existing `fx_order_atomic_test.cpp` provides deterministic 2-buffer de-click; existing `live_channel_fx_graph_test.cpp` validates CH1 external insert processing.
- Require exact-head Windows MSVC+CTest and Chromium as applicable, and separate ASIO/WASAPI live MOVE/Orbit FAT before any clean-audio claim.

## Follow-on
R0B B2: shared prepared instance/graph ownership and add/remove lifecycle without detaching callback. R0B B3: always-on verified/unpatched silent session startup, device-loss rollback and retirement of legacy/LAB split. Do not claim solved from this slice.
46 changes: 40 additions & 6 deletions src/LiveAudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,11 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
// The processor instances remain at stable PHYSICAL addresses.
// A 64-bit release store publishes the complete logical order.
// The callback takes one acquire snapshot per audio buffer.
if (dryRoutingLab_.active() || independent_.active()) return false;
// R0B slice: CH1 rack MOVE is a pure atomic physical-slot reorder,
// including while the native 10CH/4AUX graph borrows this same rack.
// The routed callback below owns the identical two-block de-click
// publication that the legacy callback already uses.
if (independent_.active()) return false;
if (handoff_.busy() || fxMovePhase_.load (std::memory_order_acquire) != 0)
return false;
const int count = graphOwned_->count;
Expand Down Expand Up @@ -1411,6 +1415,34 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
if(outputs && outputs[c])
juce::FloatVectorOperations::clear(outputs[c],samples);
}
// R0B: when routed CH1 borrows the original vendor rack, apply
// the SAME two-buffer FX MOVE de-click as the original callback.
// The physical instance pointers do not change. Publish the new
// logical order only after the old render has faded to zero.
// No heap, plugin lifecycle, callback detach, locks or UI on RT.
const int routedFxMove=fxMovePhase_.load(std::memory_order_acquire);
float movedPeakL=0.f,movedPeakR=0.f;
if(routedFxMove!=0) {
for(int c=0;c<juce::jmin(outputChannels,2);++c) {
auto* const out=outputs?outputs[c]:nullptr;
if(!out)continue;
float peak=0.f;
for(int i=0;i<samples;++i) {
out[i]*=armix::dsp::FxMoveRamp::gain(routedFxMove,i,samples);
peak=juce::jmax(peak,std::abs(out[i]));
}
if(c==0)movedPeakL=peak;
else movedPeakR=peak;
}
if(routedFxMove==1 && cycle.graph) {
cycle.graph->orderPacked.store(
fxMovePendingOrder_.load(std::memory_order_acquire),
std::memory_order_release);
fxMovePhase_.store(2,std::memory_order_release);
} else if(routedFxMove==2) {
fxMovePhase_.store(0,std::memory_order_release);
}
}
// Read actual hardware-bound MASTER PCM, never browser preview.
// A fixed stack view; no VST/JSON/heap/locks in the audio callback.
const float* measured[2] = {
Expand All @@ -1421,13 +1453,15 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
// Only actually routed audio can produce a live output meter.
const float left=routed?dryRoutingLab_.peakLeft():0.f;
const float right=routed?dryRoutingLab_.peakRight():0.f;
const float audibleLeft=routedFxMove!=0?movedPeakL:left;
const float audibleRight=routedFxMove!=0?movedPeakR:right;
inputPeak_.store(0.f,std::memory_order_relaxed);
postFxPeak_.store(juce::jmin(1.f,juce::jmax(left,right)),std::memory_order_relaxed);
outputPeakL_.store(juce::jmin(1.f,left),std::memory_order_relaxed);
outputPeakR_.store(juce::jmin(1.f,right),std::memory_order_relaxed);
outputPeak_.store(juce::jmin(1.f,juce::jmax(left,right)),std::memory_order_relaxed);
// Existing FX graph is excluded at enable time. A structural
// edit during LAB is rejected on the control thread.
outputPeakL_.store(juce::jmin(1.f,audibleLeft),std::memory_order_relaxed);
outputPeakR_.store(juce::jmin(1.f,audibleRight),std::memory_order_relaxed);
outputPeak_.store(juce::jmin(1.f,juce::jmax(audibleLeft,audibleRight)),std::memory_order_relaxed);
// ADD/REMOVE still need the R0B prepared shared-owner lifecycle;
// only CH1 MOVE is now safe inside the routed render callback.
const auto elapsed=clockMicros()-beginUs;
lastCallbackUs_.store(elapsed,std::memory_order_relaxed);
publishMax(worstCallbackUs_,elapsed);
Expand Down
18 changes: 18 additions & 0 deletions tests/live_graph_contract_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ test('bypass is sample-smoothed on audio callback without control-thread CPU wor
assert.match(e,/bypass\.shouldProcessWet\(\)/);
assert.doesNotMatch(e.slice(e.indexOf('bool setBypass'),e.indexOf('bool removeAt')),/detach\(|prepareToPlay|releaseResources/);
});

test('R0B CH1 MOVE inside routed 10CH graph uses the same callback-boundary de-click',()=>{
const move=e.slice(e.indexOf('bool moveSlot'),e.indexOf('juce::String applyDryRoutingLab'));
assert.doesNotMatch(move,/dryRoutingLab_\.active\(\)\s*\|\|/);
assert.match(move,/FxOrderPlan::moved/);
assert.match(move,/fxMovePendingOrder_\.store/);
assert.doesNotMatch(move,/detach\(|attach\(|prepareToPlay|releaseResources/);
const begin=e.indexOf('if (dryRoutingLab_.active())',e.indexOf('callbackCount_.fetch_add'));
const end=e.indexOf('const bool enabled = monitor_',begin);
const routed=e.slice(begin,end);
assert.match(routed,/FxMoveRamp::gain\(routedFxMove,i,samples\)/);
assert.match(routed,/fxMovePhase_\.store\(2,std::memory_order_release\)/);
assert.match(routed,/fxMovePhase_\.store\(0,std::memory_order_release\)/);
assert.match(routed,/cycle\.graph->orderPacked\.store/);
assert.ok(routed.indexOf('FxMoveRamp::gain')<routed.indexOf('masterLoudness_.process'));
assert.match(routed,/audibleLeft=routedFxMove!=0\?movedPeakL:left/);
assert.doesNotMatch(routed,/detach\(|attach\(|prepareToPlay|releaseResources/);
});
4 changes: 3 additions & 1 deletion tests/live_routing_ui_contract_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ test("GUI exposes only truthful dry device routes and acknowledged commit",()=>{

test("STOP-race is fail closed: all outputs are written to silence without CH1 fallback",()=>{
const enter=engine.indexOf("if (dryRoutingLab_.active())",engine.indexOf("callbackCount_.fetch_add"));
const end=engine.indexOf("// Existing FX graph is excluded",enter);
// Bound the entire routed branch by the first statement of the legacy
// fallback, not by an informational comment that can change at each R0B slice.
const end=engine.indexOf("const bool enabled = monitor_",enter);
assert.ok(enter>=0&&end>enter, "live audio callback LAB branch must exist");
const branch=engine.slice(enter,end);
assert.match(branch,/const bool routed=dryRoutingLab_\.process\(/);
Expand Down
Loading