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
59 changes: 59 additions & 0 deletions integration/ApprovedNativeControlIntent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include "ApprovedNativeV8Projection.h"
#include "../engine/core/DynamicChannelRoster.h"
#include <charconv>
#include <system_error>
#include <juce_core/juce_core.h>
#include <cmath>
#include <cstdint>
Expand Down Expand Up @@ -169,4 +172,60 @@ inline ApprovedNativeControlIntent translateApprovedNativeControl(
converted->setProperty("payload",juce::var(translatedPayload.release()));
return {juce::var(converted.release()),{}};
}

inline bool approvedNativeId(const juce::var& value,std::uint64_t& result) {
if(!value.isString()||!nativeV8Decimal(value))return false;
const auto bytes=value.toString().toStdString();
std::uint64_t decoded=0;
const auto parsed=std::from_chars(bytes.data(),bytes.data()+bytes.size(),decoded);
if(parsed.ec!=std::errc{} ||
parsed.ptr!=bytes.data()+bytes.size() || decoded==0)
return false;
result=decoded;
return true;
}

// The only PCM mutation route for the approved Pages WebView controller.
// This does NOT own a callback, plugin instance, graph or UI state.
// The installed ENGINE source must accept the exact epoch/revision/ChannelId.
// No fallback to ordinal-only M4 or synthetic JS/DSP is permitted.
template<class Engine>
inline bool executeApprovedNativeControl(Engine& engine,
const juce::var& translated) {
if(!translated.isObject())return false;
std::uint64_t epoch=0,revision=0,roster=0,id=0;
if(!approvedNativeId(translated.getProperty("deviceEpoch",{}),epoch) ||
!approvedNativeId(translated.getProperty("baseGraphRevision",{}),revision) ||
!approvedNativeId(translated.getProperty("baseRosterRevision",{}),roster) ||
!approvedNativeId(translated.getProperty("targetChannelId",{}),id))
return false;
const auto payload=translated.getProperty("payload",{});
if(!payload.isObject())return false;
const auto operation=translated.getProperty("operation","").toString();
const auto channel=armix::mixer::ChannelId{id};
if(operation=="NATIVE_SET_CHANNEL_MIX" ||
operation=="NATIVE_SET_BUS_MIX") {
const auto rawGain=payload.getProperty("gain",{});
const auto rawPan=payload.getProperty("pan",{});
double gain=0.,pan=0.;
if(!nativeV8Number(rawGain,gain) ||
!nativeV8Number(rawPan,pan) ||
gain<0. || gain>4. || pan< -1. || pan>1.)
return false;
if(operation=="NATIVE_SET_CHANNEL_MIX")
return engine.setNativeInputMix(epoch,revision,channel,
static_cast<float>(gain),static_cast<float>(pan));
return engine.setNativeBusMix(epoch,revision,channel,
static_cast<float>(gain),static_cast<float>(pan));
}
if(operation=="NATIVE_SET_CHANNEL_MUTE_SOLO") {
const auto mute=payload.getProperty("mute",{});
const auto solo=payload.getProperty("solo",{});
if(!mute.isBool()||!solo.isBool())return false;
return engine.setNativeInputMuteSolo(epoch,revision,channel,
static_cast<bool>(mute),
static_cast<bool>(solo));
}
return false;
}
} // namespace armix::console
28 changes: 21 additions & 7 deletions integration/ApprovedNativeRuntimeSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,30 @@ inline bool projectInstalledNativeChannelIdGraph(
// comes from the verified installed ENGINE status above, not the caller.
if (!projectApprovedNativeV8(snapshot,bus,true))
return false;
// Reading a PCM graph is not a mutating operation: Main.cpp still has a
// G0 reject handler. Until ENGINE/INTEGRATOR jointly install a real
// dispatcher and matching readback, advertise ZERO supported controls.
// In particular, projectApprovedNativeV8's generic WIRE structure alone
// must not enable WIRE intent before native transaction dispatch exists.
// Advertise only controls provided by the currently installed and
// positively admitted native callback (never inferred from a JSON shape
// or the browser). Both the native and public capability are required by
// the stateless control translator. WIRE remains explicitly disabled
// until the native structural dispatcher is independently admitted.
juce::Array<juce::var> available;
const auto nativeOps=bus.getProperty("supportedOps",{});
const auto* actual=nativeOps.getArray();
const auto has=[&](const char* op) {
return actual && actual->contains(juce::String(op));
};
if(has("NATIVE_SET_CHANNEL_MIX")) {
available.add(juce::String("SET_FADER"));
available.add(juce::String("SET_PAN"));
}
if(has("NATIVE_SET_CHANNEL_MUTE_SOLO")) {
available.add(juce::String("SET_MUTE"));
available.add(juce::String("SET_SOLO"));
}
const auto graph=snapshot.getProperty("graph",{});
const auto caps=graph.getProperty("capabilities",{});
if (auto* props=caps.getDynamicObject())
props->setProperty("supportedOps",juce::var(juce::Array<juce::var>{}));
// Full vendor/Show/physical FAT not done. Never promote product LIVE.
props->setProperty("supportedOps",juce::var(available));
// Product LIVE stays false until independent vendor/Show/hardware FAT.
return true;
}
} // namespace armix::console
73 changes: 62 additions & 11 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ApprovedGuiResources.h"
#include "ApprovedConsoleNativeTransportV6.h"
#include "../integration/ApprovedNativeRuntimeSnapshot.h"
#include "../integration/ApprovedNativeControlIntent.h"
#include "LiveAudioEngine.h"
#include "ArSonMixStartupSplash.h"
#include "VstOrbitController.h"
Expand All @@ -32,6 +33,7 @@
#include <chrono>
#include <cmath>
#include <functional>
#include <juce_core/juce_core.h>

namespace
{
Expand Down Expand Up @@ -201,16 +203,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
emitApprovedNativeSnapshot();
})
.withEventListener ("arMixConsoleIntent", [this] (juce::var args) {
// Until ENGINE #266 owns production ChannelId graph, ALL v6
// control intents are native-rejected, never silently emulated
// via the old ordinal-only M4 engine.
const auto accepted = approvedNativeSnapshot();
if (browser_.loaded)
{
browser_.emitEventIfBrowserIsVisible ("arMixConsoleAck",
armix::native_console_m2::reject (args, accepted));
browser_.emitEventIfBrowserIsVisible ("arMixConsoleSnapshot", accepted);
}
// The native control thread owns ONLY accepted mutations.
// No GUI-side PCM, no legacy ordinal fallback and no fake ACK.
handleApprovedNativeControl(args);
})
.withEventListener ("arMixParameter", [this] (juce::var args) { onParameter (args); })
.withEventListener ("arMixAction", [this] (juce::var args) { onAction (args); })
Expand Down Expand Up @@ -278,7 +273,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
std::unique_ptr<AudioSetupWindow> audioSetupWindow_;
juce::String startupError_, lastAudioXml_;
bool initialStateSent_ = false;
bool consoleSubscribed_ = false; // WebView v6 G0 subscription, not PCM admission
bool consoleSubscribed_ = false; // Real snapshot subscription; not FAT certification
juce::StringArray acceptedControlRequests_; // bounded request replay fence
bool webViewPeerWarmed_ = false;
bool webViewStartupNoticeSent_ = false;
juce::uint32 webViewStartupTick_ = 0;
Expand Down Expand Up @@ -722,6 +718,58 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
"arMixConsoleSnapshot", approvedNativeSnapshot());
}

// One native dispatcher; the source of truth is the already installed
// ENGINE callback. This code executes on the JUCE message thread, not RT.
void handleApprovedNativeControl(const juce::var& request)
{
const auto beforeLive=engine_.status();
const auto before=approvedNativeSnapshot(beforeLive);
const auto route=beforeLive.getProperty("dryRoutingLab",{});
const auto installedBus=route.getProperty("nativeBus",{});
const auto idValue=request.getProperty("requestId",{});
const auto id=idValue.isString()?idValue.toString():juce::String{};
const bool replay=id.isNotEmpty()&&acceptedControlRequests_.contains(id);
// All well-formed IDs are consumed once, including failed mutations.
// Bounded storage avoids unbounded memory growth in a long session.
if(id.isNotEmpty()&&id.length()<=128&&!replay) {
acceptedControlRequests_.add(id);
if(acceptedControlRequests_.size()>512)
acceptedControlRequests_.remove(0);
}
const auto translated=armix::console::translateApprovedNativeControl(
request,before,installedBus);
const bool applied=!replay&&translated.ok()&&
armix::console::executeApprovedNativeControl(engine_,translated.translated);
Comment on lines +741 to +742

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 Show capture synchronized with accepted native controls

For the original CH1–10 topology, an accepted fader/PAN/mute/solo edit now calls the native setters directly, which update the PCM target and native roster but not LiveDryRoutingLab::channelEdits_. However, LiveDryRoutingLab::status() still builds channelControls from channelEdits_, and NativeLiveShowCapture::captureDry() saves those values rather than the native roster. Because a nonstructural control edit does not set nativeBusStructural, the existing routingDryShowSave handler permits the save and silently records the pre-edit controls; recalling that Show can therefore restore an old gain or unmute a channel the user saved muted. Synchronize the original-channel save baseline after successful mutations, or make Show capture read the accepted native controls.

AGENTS.md reference: AGENTS.md:L30-L30

Useful? React with 👍 / 👎.

// An engine setter ACK is not independent PCM evidence. Re-read the
// same physical callback authority after mutation before claiming it
// was accepted; browser then explicitly requests LATER readback.
const auto after=applied?approvedNativeSnapshot():before;
const auto device=after.getProperty("device",{});
const auto graph=after.getProperty("graph",{});
const auto caps=graph.getProperty("capabilities",{});
const bool nativeStillAdmitted=applied&&caps.isObject()&&
static_cast<bool>(caps.getProperty("callbackOwnsChannelIds",false))&&
device.getProperty("epoch","0").toString()==
request.getProperty("deviceEpoch","").toString();
auto ack=std::make_unique<juce::DynamicObject>();
ack->setProperty("requestId",id);
ack->setProperty("status",nativeStillAdmitted?"ACCEPTED":"REJECTED");
ack->setProperty("errorCode",nativeStillAdmitted?"NONE":
replay?"DUPLICATE_REQUEST_ID":
translated.error.isNotEmpty()?translated.error:
applied?"NATIVE_CALLBACK_LOST":"NATIVE_PCM_MUTATION_REJECTED");
ack->setProperty("deviceEpoch",device.getProperty("epoch","0"));
ack->setProperty("graphRevision",graph.getProperty("revision","0"));
ack->setProperty("rosterRevision",graph.getProperty("rosterRevision","0"));
ack->setProperty("productionCallbackLive",false);
if(browser_.loaded)
browser_.emitEventIfBrowserIsVisible("arMixConsoleAck",
juce::var(ack.release()));
// NEVER emit a same-handler optimistic snapshot. The approved browser
// sends arMixConsoleSubscribe AFTER ACK and verifies a later producer
// readback before moving fader/route UI from its accepted state.
}

void onParameter (const juce::var& args)
{
const auto name = args.getProperty ("parameter", {}).toString();
Expand Down Expand Up @@ -1070,6 +1118,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
safe->startupError_.clear();
safe->diagnostics_.record ("DIRECT_ROUTE_APPROVED",
"User confirmed selected ASIO/WASAPI backend in AUDIO SETUP");
// Refresh native physical port inventory after the user
// finishes device selection; never require a restart.
safe->emitApprovedNativeSnapshot();
}
else
{
Expand Down
26 changes: 26 additions & 0 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,29 @@ test("M3 Windows bundle owns pointerup fader gesture and fences native FX keyboa
assert.ok(bridge.includes("scope?.findTrack?.(el)"));
assert.ok(!bridge.includes('window.addEventListener("pointerup"'));
});

test("native Windows operator can explicitly patch first physical input, arm and mute",()=>{
const js=read("web/approved-native-bridge.js");
const main=read("src/Main.cpp");
const engine=read("src/LiveAudioEngine.h");
assert.match(js,/REAL AUDIO · FIRST SOUND/);
assert.match(js,/action:"audioSetup"/);
assert.match(js,/d\.inputEndpoints\.filter\(p=>/);
assert.match(js,/d\.enabledInputs\.includes\(p\.port\)/);
assert.match(js,/action:"routingSourceSwitch",requestId:pendingSourceId/);
assert.match(js,/channel:0,mode:"MONO",left:pin,right:-1/);
assert.match(js,/action:"monitor",value:true/);
assert.match(js,/action:"monitor",value:false/);
assert.match(js,/expectedEpoch:epoch,expectedRevision:revision/);
assert.match(js,/arMixSourceSwitchAck/);
assert.match(js,/arMixAudioArmAck/);
assert.match(js,/if\(ack\.ok===true\)/);
assert.match(js,/NATIVE PATCH REJECTED:/);
assert.match(js,/NO VERIFIED AUDIO DEVICE/);
assert.match(js,/REAL NATIVE PCM · FAT PENDING/);
assert.match(main,/action=="routingSourceSwitch"/);
assert.match(main,/engine_\.liveOutputArmFault\(\)/);
assert.match(main,/safe->emitApprovedNativeSnapshot\(\)/);
assert.match(engine,/juce::String switchDryRoutingLabSource\(/);
assert.match(engine,/setOutputMuted\(true\)/);
});
28 changes: 28 additions & 0 deletions tests/approved_native_v8_projection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
#include <limits>
using namespace armix::console;


// Compile-time and runtime proof that accepted v8 native intents route to
// the actual ChannelId setter rather than a fake WebView-only state change.
struct NativeControlProbe {
std::uint64_t lastEpoch=0,lastRevision=0,lastId=0;
float lastGain= -1.f,lastPan= -2.f;
bool lastMute=false,lastSolo=false;
bool setNativeInputMix(std::uint64_t e,std::uint64_t r,
armix::mixer::ChannelId id,float g,float p) {
lastEpoch=e;lastRevision=r;lastId=id.value;lastGain=g;lastPan=p;
return true;
}
bool setNativeBusMix(std::uint64_t e,std::uint64_t r,
armix::mixer::ChannelId id,float g,float p) {
return setNativeInputMix(e,r,id,g,p);
}
bool setNativeInputMuteSolo(std::uint64_t e,std::uint64_t r,
armix::mixer::ChannelId id,bool m,bool s) {
lastEpoch=e;lastRevision=r;lastId=id.value;
lastMute=m;lastSolo=s;return true;
}
};
static juce::var parse(const char* bytes) {
auto json=juce::JSON::parse(juce::String::fromUTF8(bytes));
assert(json.isObject());
Expand Down Expand Up @@ -90,6 +112,12 @@ static void controlIntentTranslationCases(const juce::var& canonical,
const auto fader=makeIntent("SET_FADER",juce::var(-12.0),source);
const auto translated=translateApprovedNativeControl(fader,accepted,bus);
assert(translated.ok());
NativeControlProbe producer;
assert(executeApprovedNativeControl(producer,translated.translated));
assert(producer.lastEpoch==91 && producer.lastRevision==25);
assert(producer.lastId==9007199254740993ULL);
assert(std::abs(producer.lastGain-std::pow(10.,-12./20.))<0.000001);
assert(!executeApprovedNativeControl(producer,juce::var{}));
assert(translated.translated.getProperty("operation","").toString()
=="NATIVE_SET_CHANNEL_MIX");
assert(translated.translated.getProperty("targetChannelId","").toString()
Expand Down
Loading
Loading