Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
046ff7b
M1 live console: coalesced ACK-backed continuous AUX sends and bus ma…
masarray Oct 31, 2026
b195d5f
M1 named input profiles: strict device pin identity, mono/stereo alia…
masarray Oct 31, 2026
717d65f
M1 GUI regression: device-verified named sparse stereo source and str…
masarray Oct 31, 2026
cc685ca
Fix M1 alias remap assertion: distinguish named identity from raw CUS…
masarray Oct 31, 2026
2027d5d
M1 RT input crossfade: same prepared graph, one packed atomic source …
masarray Oct 31, 2026
c7252d4
M1 native source switch: verified sparse port binding, epoch fencing …
masarray Oct 31, 2026
57fa6e6
M1 native-ACKed same-format SOURCE quick handoff in single monitor.js…
masarray Oct 31, 2026
95f1259
Wire M1 same-format native crossfade into selected SOURCE and strip i…
masarray Oct 31, 2026
aa7e428
Verify M1 source PCM sample crossfade, strict format/pin rejection an…
masarray Oct 31, 2026
e5ad3e5
M1 functional GUI: armed same-format SOURCE 64-sample switch ACK, sta…
masarray Oct 31, 2026
0f59244
Reconcile SOURCE1 safety contract with M1 same-format live input swit…
masarray Oct 31, 2026
f38256b
Pin the selected input channel in armed SOURCE crossfade UI test
masarray Oct 31, 2026
eeccc5c
Diagnose M1 selected SOURCE live switch test rejection using native/U…
masarray Oct 31, 2026
ca28eb0
Isolate M1 SOURCE picker event vs native routing preflight rejection …
masarray Oct 31, 2026
2593314
Fix M1 live SOURCE JS undefined backup gate and preserve pending ACK …
masarray Oct 31, 2026
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
202 changes: 181 additions & 21 deletions AR-MIX-Live-FX-Host-Standalone-v0.3.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions engine/core/LiveChannelFxGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class LiveChannelFxGraph final {
int monitorOutputLeft() const noexcept{return monitorLeft_;}
int monitorOutputRight() const noexcept{return monitorRight_;}
const std::array<float,fxSlots>& monitorGains() const noexcept{return monitorGains_;}
bool switchPhysicalSource(int strip,SourceMode mode,int left,int right) noexcept {
return block_&&block_->setPhysicalSource(strip,mode,left,right);
}
// M1: native realtime send fader on an EXISTING validated AUX POST edge.
// Same prepared graph, no VST instance change or global mute.
bool setAuxBusGain(int bus,float gain) noexcept {
Expand Down
83 changes: 73 additions & 10 deletions engine/core/PreparedMixerBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <array>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -174,6 +175,13 @@ class PreparedMixerBlock final {
: 0u, 0.f) {
if (!validCapacity(maxFrames))
capacity_=0;
for(int i=0;i<stripCount;++i){
const auto& s=plan_.channels.base.strips[i];
const auto pair=s.mode==SourceMode::disconnected
?invalidSourcePair:packSourcePair(s.inputA,s.inputB);
physicalTarget_[i].store(pair,std::memory_order_relaxed);
physicalBlend_[i]={pair,pair,0};
}
// All gain targets exist before ANY audio thread sees the candidate.
for(int e=0;e<plan_.aux.edgeCount;++e){
const float v=plan_.aux.edges[e].initialGain;
Expand Down Expand Up @@ -208,6 +216,21 @@ class PreparedMixerBlock final {
int capacity() const noexcept { return capacity_; }
const PreparedRenderGraph& plan() const noexcept {return plan_;}

// M1: CONTROL writes one atomic verified callback source pair; audio thread
// performs a 64-sample input crossfade BEFORE processing the same FX rack.
// Only an existing same-format physical channel may switch without mute.
bool setPhysicalSource(int strip,SourceMode mode,int left,int right) noexcept {
if(strip<0||strip>=stripCount||mode==SourceMode::disconnected||
plan_.channels.base.strips[strip].mode!=mode)return false;
const int n=plan_.channels.inputPorts.enabledCount;
if(left<0||left>=n||right<0||right>=n||
(mode==SourceMode::mono&&left!=right)||
(mode==SourceMode::stereo&&left==right))return false;
physicalTarget_[strip].store(packSourcePair(left,right),
std::memory_order_release);
return true;
}

// Message-thread-only target update; immutable edge topology/pan/FX ownership.
// Only an ALREADY EXISTING POST edge may be adjusted while output is live.
// This index lookup is on CONTROL, never inside the audio callback.
Expand Down Expand Up @@ -296,16 +319,45 @@ class PreparedMixerBlock final {
const auto& source=graph.channels.base.strips[strip];
// Incoming sends are already in l/r. Add actual hardware only
// when that port is valid; never overwrite internal bus returns.
if (source.mode!=SourceMode::disconnected &&
physical && source.inputA>=0 &&
source.inputA<callbackInputCount &&
source.inputB>=0 && source.inputB<callbackInputCount &&
physical[source.inputA] && physical[source.inputB]) {
const auto* const a=physical[source.inputA];
const auto* const b=physical[source.inputB];
for(int f=0;f<frames;++f) {
l[f]+=a[f];
r[f]+=b[f];
if(source.mode!=SourceMode::disconnected&&physical){
auto& fade=physicalBlend_[strip]; // audio-producer owned
const auto request=physicalTarget_[strip].load(std::memory_order_acquire);
// Mid-fade requests coalesce to the latest target, but never
// interrupt a currently audible ramp with a discontinuity.
if(fade.remaining==0&&request!=fade.target){
fade.previous=fade.target;
fade.target=request;
fade.remaining=64;
}
const auto valid=[&](std::uint32_t pair) noexcept {
const int a=static_cast<int>(pair&0xffffu);
const int b=static_cast<int>((pair>>16)&0xffffu);
return pair!=invalidSourcePair&&a<callbackInputCount&&
b<callbackInputCount&&physical[a]&&physical[b];
};
const int a=static_cast<int>(fade.target&0xffffu);
const int b=static_cast<int>((fade.target>>16)&0xffffu);
if(fade.remaining==0){
if(valid(fade.target))for(int f=0;f<frames;++f){
l[f]+=physical[a][f];r[f]+=physical[b][f];
}
}else{
const int oldA=static_cast<int>(fade.previous&0xffffu);
const int oldB=static_cast<int>((fade.previous>>16)&0xffffu);
const bool oldGood=valid(fade.previous),newGood=valid(fade.target);
for(int f=0;f<frames;++f){
const float t=1.f-static_cast<float>(--fade.remaining)/64.f;
if(oldGood){l[f]+=physical[oldA][f]*(1.f-t);
r[f]+=physical[oldB][f]*(1.f-t);}
if(newGood){l[f]+=physical[a][f]*t;
r[f]+=physical[b][f]*t;}
if(fade.remaining==0){
if(newGood)for(int j=f+1;j<frames;++j){
l[j]+=physical[a][j];r[j]+=physical[b][j];
}
break;
}
}
}
}
// Channel MONO includes internally received stereo sends.
Expand Down Expand Up @@ -450,6 +502,15 @@ class PreparedMixerBlock final {
return true;
}
private:
static constexpr std::uint32_t invalidSourcePair=0xffffffffu;
static constexpr std::uint32_t packSourcePair(int left,int right) noexcept {
return static_cast<std::uint32_t>(left)|
(static_cast<std::uint32_t>(right)<<16);
}
struct PhysicalSourceFade final {
std::uint32_t previous=invalidSourcePair,target=invalidSourcePair;
int remaining=0; // callback-thread-only, never shared with GUI
};
// Audio-thread exclusive smoothing state plus atomically published gain
// targets. No lock, heap, plugin recreation or per-block graph compile.
// POST/PRE edge identity and normalized PAN are immutable per revision.
Expand Down Expand Up @@ -487,6 +548,8 @@ class PreparedMixerBlock final {
std::array<float*,stripCount> right_{};
std::array<float*,auxBusCount> auxLeft_{},auxRight_{};
std::array<float,stripCount> preGate_{},lastGainL_{},lastGainR_{};
std::array<std::atomic<std::uint32_t>,stripCount> physicalTarget_{};
std::array<PhysicalSourceFade,stripCount> physicalBlend_{};
std::array<std::atomic<float>,maxAuxSends> auxTarget_{};
std::array<float,maxAuxSends> auxApplied_{}; // callback thread exclusive
std::array<std::atomic<float>,auxBusCount> auxBusTarget_{};
Expand Down
11 changes: 11 additions & 0 deletions src/LiveAudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,17 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
setOutputMuted(true); // never expose CH1 unexpectedly on STOP
dryRoutingLab_.disable();
}
juce::String switchDryRoutingLabSource(int strip,std::uint64_t epoch,
std::uint64_t revision,const juce::String& mode,
int left,int right) noexcept {
if(independent_.active()||routeReconfiguring_.load(std::memory_order_acquire)||
handoff_.busy()||!directFence_.permitted()||
diagnosticRoute_.load(std::memory_order_acquire)
!=armix::diagnostics::Route::normal||
savedDirectSetup_||savedLiveSetup_)
return "SOURCE SWITCH: live DIRECT device or graph unavailable";
return dryRoutingLab_.switchPhysicalSource(strip,epoch,revision,mode,left,right);
}
bool setDryRoutingLabParameter(int strip,std::uint64_t epoch,
std::uint64_t revision,const juce::String& parameter,
float value) noexcept {
Expand Down
49 changes: 49 additions & 0 deletions src/LiveDryRoutingLab.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,55 @@ class LiveDryRoutingLab final {
}
}

// M1 direct-source parameter: only same-format physical→physical
// input on an ALREADY scheduled channel. Route DAG, VST3 lease, FX
// identity and hardware output ownership are immutable. Epoch/revision
// and actual enabled sparse port mask are checked on CONTROL thread.
juce::String switchPhysicalSource(int strip,std::uint64_t expectedEpoch,
std::uint64_t expectedRevision,const juce::String& mode,
int physicalLeft,int physicalRight) noexcept {
if(strip<0||strip>=count||!hasExplicitRoute()||
expectedEpoch!=epoch()||expectedRevision!=revision()||
topologyFault_.load(std::memory_order_acquire))
return "SOURCE SWITCH: stale native device, graph or channel";
if(mode!="MONO"&&mode!="STEREO")
return "SOURCE SWITCH: existing MONO/STEREO format required";
auto channels=acceptedRoute_.getProperty("channels",juce::var());
auto* rows=channels.getArray();
if(!rows||rows->size()!=count)
return "SOURCE SWITCH: missing accepted input routing";
auto& row=rows->getReference(strip);
if(row.getProperty("mode",{}).toString()!=mode)
return "SOURCE SWITCH: channel format/topology change requires MUTE + APPLY";
const int n=portCount_.load(std::memory_order_acquire);
int callbackLeft=-1,callbackRight=-1;
for(int i=0;i<n;++i){
const int p=enabledPorts_[i].load(std::memory_order_relaxed);
if(p==physicalLeft)callbackLeft=i;
if(p==physicalRight)callbackRight=i;
}
if(mode=="MONO")callbackRight=callbackLeft;
if(callbackLeft<0||callbackRight<0||
(mode=="STEREO"&&(callbackLeft==callbackRight||physicalLeft==physicalRight)))
return "SOURCE SWITCH: input is not in verified enabled device pins";
if(expectedEpoch!=epoch()||!registryValid_.load(std::memory_order_acquire))
return "SOURCE SWITCH: audio device changed during selection";
const auto format=mode=="MONO"
?armix::mixer::SourceMode::mono:armix::mixer::SourceMode::stereo;
if(!publisher_.updateActiveControl(expectedEpoch,expectedRevision,
[&](FxGraph& fx) noexcept {
return fx.switchPhysicalSource(strip,format,callbackLeft,callbackRight);
}))
return "SOURCE SWITCH: native graph rejected same-format input";
// This is the authoritative native parameter target, not an
// unacknowledged browser draft. The callback fades PCM over 64 samples.
if(auto* object=row.getDynamicObject()){
object->setProperty("left",physicalLeft);
object->setProperty("right",mode=="STEREO"?physicalRight:-1);
}
return {};
}

// Native live control path. Only the JUCE message thread writes. No
// graph recompilation, VST3 instantiation or callback detach.
// Browser carries the exact acknowledged route token to reject stale
Expand Down
29 changes: 29 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,35 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr

// A user-controlled hardware dry routing FAT, not a change to the
// existing 1-channel VST3 production chain. Explicit Apply/Stop.
// M1 RT source switch on an existing physical channel. Unlike
// structural routingDryApply, it does not unpatch outputs, rebuild
// VST3s, or restart the device; input PCM fades inside one graph.
if(action=="routingSourceSwitch"){
const int requestId=static_cast<int>(args.getProperty("requestId",0));
const int channel=static_cast<int>(args.getProperty("channel",-1));
const auto mode=args.getProperty("mode",juce::var()).toString();
const auto ep=args.getProperty("deviceEpoch",juce::var());
const auto rv=args.getProperty("revision",juce::var());
const int left=static_cast<int>(args.getProperty("left",-1));
const int right=static_cast<int>(args.getProperty("right",-1));
const juce::String error=requestId>0&&!ep.isVoid()&&!rv.isVoid()&&
!nativeShowBusy_&&!studioBackupBusy_?
engine_.switchDryRoutingLabSource(channel,
static_cast<std::uint64_t>(static_cast<juce::int64>(ep)),
static_cast<std::uint64_t>(static_cast<juce::int64>(rv)),
mode,left,right):
juce::String("SOURCE SWITCH: stale request or Show/backup busy");
auto ack=std::make_unique<juce::DynamicObject>();
ack->setProperty("requestId",requestId);
ack->setProperty("channel",channel);
ack->setProperty("ok",error.isEmpty());
ack->setProperty("error",error);
ack->setProperty("state",engine_.status().getProperty("dryRoutingLab",{}));
if(browser_.loaded)browser_.emitEventIfBrowserIsVisible(
"arMixSourceSwitchAck",juce::var(ack.release()));
if(error.isNotEmpty())emitNotice(error,true);
return;
}
if (action == "routingDryApply")
{
LiveDryRoutingLab::FxSelections selected{};
Expand Down
56 changes: 53 additions & 3 deletions tests/mixer_io_operator_contract_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ test('SETUP1 honest bus patch has real AUX/MAIN/MONITOR navigation, no fake GROU
});


test('SOURCE1 mute-only instant SOURCE uses one native ACK; armed output is rejected',()=>{
test('SOURCE quick switch is live only for verified same format; structural fallback remains muted',()=>{
const io=read('web/mixer-io.js'),monitor=read('web/monitor.js');
assert.match(io,/__arMixCommitMutedSource\?\.\(channel,mode,left,right\)/);
assert.match(io,/__arMixCommitSelectedSource\?\.\(channel,mode,left,right\)/);
assert.match(io,/quickSourcePending/);
assert.match(io,/PENDING · NATIVE ACK/);
assert.match(monitor,/window\.__arMixCommitMutedSource=/);
Expand Down Expand Up @@ -268,10 +268,60 @@ test('SOURCE2 selected-channel popover selects verified physical ports without a
const js=read('web/mixer-io.js');
assert.match(js,/function refreshFocus\(s\)/);
assert.match(js,/const openSourceChooser=channel=>/);
assert.match(js,/window\.__arMixCommitMutedSource\?\.\(/);
assert.match(js,/window\.__arMixCommitSelectedSource\?\.\(/);
assert.match(js,/sourceNote\.textContent/);
assert.match(js,/sourceChooser\.addEventListener\('click'/);
assert.match(js,/portsFor\(s,r\|\|/);
assert.match(js,/NONADJACENT L\/R/);
assert.doesNotMatch(js,/new AudioContext\(/);
});


test('M1 faders send continuous coalesced ACK-backed params without structural APPLY',()=>{
const gui=read('web/mixer-io.js'),monitor=read('web/monitor.js'),html=read('AR-MIX-Live-FX-Host-Standalone-v0.3.html');
assert.match(gui,/sofControls\.addEventListener\('input',sendAuxMaster\)/);
assert.match(gui,/const now=performance\.now\(\)/);
assert.match(gui,/Math\.abs\(d\.db-d\.lastSentDb\)>=\.25/);
assert.match(gui,/window\.__arMixSetLiveAuxSendGain\?\.\(/);
assert.match(monitor,/const liveSendLatest=new Map\(\)/);
assert.match(monitor,/const auxMasterLatest=new Map\(\)/);
assert.match(monitor,/LIVE SEND COALESCED/);
assert.match(monitor,/AUX MASTER COALESCED/);
assert.match(monitor,/if\(matched&&latest!==undefined/);
assert.match(monitor,/if\(ok&&latest!==undefined/);
assert.match(html,/Math\.abs\(d\.db-d\.lastSentDb\)>=\.25/);
});


test('M1 named input sources are persisted only for native device and enabled pin identity',()=>{
const ui=read('web/mixer-io.js');
const html=read('AR-MIX-Live-FX-Host-Standalone-v0.3.html');
for(const src of [ui,html]){
assert.match(src,/const sourceIdentity=s=>/);
assert.match(src,/d\.backend,d\.captureDevice,pins\.map/);
assert.match(src,/const validAlias=\(a,pins\)=>/);
assert.match(src,/localStorage\.setItem\(key,JSON\.stringify\(items\)\)/);
assert.match(src,/const aliasValue=a=>/);
assert.match(src,/window\.__arMixCommitSelectedSource\?\.\(/);
assert.match(src,/data-source-alias-save/);
assert.match(src,/if\(!sourceIdentity\(route\(\)\)\)deviceRefresh\(\)/);
}
});


test('M1 SOURCE safe unmuted handoff uses native input crossfade with immutable FX graph',()=>{
const ui=read('web/mixer-io.js'),monitor=read('web/monitor.js');
const main=read('src/Main.cpp'),engine=read('src/LiveAudioEngine.h');
const lab=read('src/LiveDryRoutingLab.h'),block=read('engine/core/PreparedMixerBlock.h');
assert.match(ui,/window\.__arMixCommitSelectedSource\?\.\(/);
assert.match(ui,/arMixSourceSwitchResult/);
assert.match(monitor,/window\.__arMixCommitSelectedSource=/);
assert.match(monitor,/action:"routingSourceSwitch"/);
assert.match(monitor,/arMixSourceSwitchAck/);
assert.match(main,/action=="routingSourceSwitch"/);
assert.match(engine,/switchDryRoutingLabSource\(/);
assert.match(lab,/switchPhysicalSource\(/);
assert.match(block,/physicalTarget_\[strip\]\.store/);
assert.match(block,/fade\.remaining=64/);
assert.doesNotMatch(ui,/new AudioContext\(/);
});
Loading
Loading