Skip to content
Merged
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ if(BUILD_TESTING)
add_test(NAME ConsoleV6NativeAcceptedSnapshotAndGoldenPCM COMMAND ARMixConsoleBridgeV6Tests)
# Existing Windows build target pulls in this test without a second workflow.
add_dependencies(ARMixMixerRoutingTests ARMixConsoleBridgeV6Tests)
# M3-B INTEGRATOR-only readback serialization of real ChannelId PCM.
# Never installs a second callback, renderer or fake live source.
juce_add_console_app(ARMixNativeV8ProjectionTests PRODUCT_NAME "ArSonMix Native V8 Readback Projection Tests")
target_sources(ARMixNativeV8ProjectionTests PRIVATE tests/approved_native_v8_projection_test.cpp integration/ApprovedNativeV8Projection.h integration/ApprovedNativeControlIntent.h integration/ApprovedNativeRuntimeSnapshot.h)
target_link_libraries(ARMixNativeV8ProjectionTests PRIVATE juce::juce_core juce::juce_recommended_config_flags)
target_compile_features(ARMixNativeV8ProjectionTests PRIVATE cxx_std_20)
add_test(NAME M3BNativeV8StableIdReadbackAndFailClosedProjection COMMAND ARMixNativeV8ProjectionTests)
add_dependencies(ARMixMixerRoutingTests ARMixNativeV8ProjectionTests)
add_executable(ARMixChannelRoutingContractTests tests/channel_routing_contract_test.cpp)
target_compile_features(ARMixChannelRoutingContractTests PRIVATE cxx_std_20)
add_test(NAME MonoStereoSparsePhysicalPortRouting COMMAND ARMixChannelRoutingContractTests)
Expand Down
172 changes: 172 additions & 0 deletions integration/ApprovedNativeControlIntent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include "ApprovedNativeV8Projection.h"
#include <juce_core/juce_core.h>
#include <cmath>
#include <cstdint>
#include <memory>
#include <string>

// INTEGRATOR M3-B: bridge the approved /preview/ control ABI to the ONE
// native ChannelId PCM owner from ENGINE #266. Translation is CONTROL-thread
// only and has NO side effects. It does not install, drive or claim audio.
// Real JUCE nativeBus/callback admission and genuine mutating operation
// support must be independently established by the producer before use.
//
// The public UI submits SET_FADER/PAN/MUTE/SOLO; native PCM currently uses
// NATIVE_SET_CHANNEL_MIX / NATIVE_SET_CHANNEL_MUTE_SOLO / NATIVE_SET_BUS_MIX.
// This translator NEVER fabricates capability support or stable ChannelIds.
namespace armix::console {
struct ApprovedNativeControlIntent {
juce::var translated;
juce::String error;
bool ok() const noexcept { return translated.isObject() && error.isEmpty(); }
};

inline bool approvedHasOperation(const juce::var& list,const char* name) {
const auto* values=list.getArray();
return values && values->contains(juce::var(juce::String(name)));
}

inline ApprovedNativeControlIntent translateApprovedNativeControl(
const juce::var& publicIntent,
const juce::var& acceptedSnapshot,
const juce::var& installedBus) {
const auto reject=[](const char* code)->ApprovedNativeControlIntent {
return {{},juce::String(code)};
};
if(!publicIntent.isObject() || !acceptedSnapshot.isObject() ||
!installedBus.isObject())return reject("NATIVE_READBACK_UNAVAILABLE");
const auto device=acceptedSnapshot.getProperty("device",{});
const auto graph=acceptedSnapshot.getProperty("graph",{});
const auto caps=graph.getProperty("capabilities",{});
const auto rows=graph.getProperty("channels",{});
const auto nativeRows=installedBus.getProperty("channels",{});
const auto& ids=publicIntent.getProperty("targetChannelId",{});
const auto& request=publicIntent.getProperty("requestId",{});
const auto op=publicIntent.getProperty("operation",{}).toString();
const auto epoch=device.getProperty("epoch",{});
const auto revision=graph.getProperty("revision",{});
const auto roster=graph.getProperty("rosterRevision",{});
if(!device.isObject() || !graph.isObject() || !caps.isObject() ||
!rows.isArray() || !nativeRows.isArray() ||
!static_cast<bool>(caps.getProperty("callbackOwnsChannelIds",false)) ||
!nativeV8Decimal(epoch) || epoch.toString()=="0" ||
!nativeV8Decimal(revision) || revision.toString()=="0" ||
!nativeV8Decimal(roster) || roster.toString()=="0" ||
!nativeV8Decimal(ids) || ids.toString()=="0")
return reject("CHANNELID_CALLBACK_NOT_ADMITTED");
// Reject cross-device / cross-graph commands BEFORE any conversion.
if(publicIntent.getProperty("deviceEpoch",{}).toString()!=epoch.toString() ||
publicIntent.getProperty("baseGraphRevision",{}).toString()!=revision.toString() ||
publicIntent.getProperty("baseRosterRevision",{}).toString()!=roster.toString() ||
installedBus.getProperty("graphRevision",{}).toString()!=revision.toString() ||
installedBus.getProperty("rosterRevision",{}).toString()!=roster.toString())
return reject("STALE_NATIVE_CONTROL_REVISION");
if(!request.isString() || request.toString().isEmpty() ||
request.toString().length()>128)return reject("INVALID_REQUEST_ID");
if(op!="SET_FADER" && op!="SET_PAN" && op!="SET_MUTE" &&
op!="SET_SOLO")return reject("UNSUPPORTED_APPROVED_CONTROL");
// Both native *and* GUI-side capabilities must be explicitly advertised
// from real installed PCM. Native ops alone do not prove that legacy M4
// ChannelIds (especially original CH1-10) support these controls.
if(!approvedHasOperation(caps.getProperty("supportedOps",{}),
op.toRawUTF8()))
return reject("PUBLIC_CONTROL_NOT_ADMITTED");
juce::var channel,producer;
for(const auto& item:*rows.getArray())
if(item.getProperty("id","").toString()==ids.toString()) {
if(channel.isObject())return reject("DUPLICATE_APPROVED_CHANNEL");
channel=item;
}
for(const auto& item:*nativeRows.getArray())
if(item.getProperty("id","").toString()==ids.toString()) {
if(producer.isObject())return reject("DUPLICATE_NATIVE_CHANNEL");
producer=item;
}
if(!channel.isObject() || !producer.isObject())
return reject("UNKNOWN_OR_STALE_CHANNELID");
const auto role=channel.getProperty("role","").toString();
if(role!=producer.getProperty("role","").toString())
return reject("NATIVE_ROLE_MISMATCH");
const bool input=role=="INPUT";
const bool bus=role=="GROUP" || role=="FX_RETURN";
if(!input && !bus)return reject("CHANNEL_ROLE_NOT_MUTABLE");
if(bus && (op=="SET_MUTE" || op=="SET_SOLO"))
return reject("BUS_MUTE_SOLO_NOT_ADMITTED");
const auto controls=channel.getProperty("controls",{});
if(!controls.isObject())return reject("INVALID_NATIVE_CONTROLS");
const auto fader=controls.getProperty("faderDb",{});
const auto pan=controls.getProperty("pan",{});
const auto mute=controls.getProperty("mute",{});
const auto solo=controls.getProperty("solo",{});
double acceptedDb=0.,acceptedPan=0.,nativeGain=0.,nativePan=0.;
if(!nativeV8Number(fader,acceptedDb) ||
!nativeV8Number(pan,acceptedPan) ||
!nativeV8Number(producer.getProperty("fader",{}),nativeGain) ||
!nativeV8Number(producer.getProperty("pan",{}),nativePan) ||
!mute.isBool() || !solo.isBool() ||
!producer.getProperty("mute",{}).isBool() ||
!producer.getProperty("solo",{}).isBool() ||
nativeGain<0. || nativeGain>4. ||
std::abs(nativePan-acceptedPan)>0.015 ||
static_cast<bool>(mute)!=static_cast<bool>(
producer.getProperty("mute",{})) ||
static_cast<bool>(solo)!=static_cast<bool>(
producer.getProperty("solo",{})))
return reject("NATIVE_CONTROL_READBACK_MISMATCH");
const double nativeDb=nativeGain>0.?20.*std::log10(nativeGain):-60.;
if(std::abs(nativeDb-acceptedDb)>0.11)
return reject("STALE_NATIVE_CONTROL_READBACK");
const auto payload=publicIntent.getProperty("payload",{});
if(!payload.isObject())return reject("INVALID_CONTROL_PAYLOAD");
const auto value=payload.getProperty(
op=="SET_FADER"?"valueDb":"value",{});
const char* nativeOperation=nullptr;
auto translatedPayload=std::make_unique<juce::DynamicObject>();
if(op=="SET_FADER" || op=="SET_PAN") {
if(op=="SET_FADER") {
double requested=0.;
if(!nativeV8Number(value,requested) ||
requested< -60. || requested>(bus?12.:10.))
return reject("INVALID_FADER_VALUE");
acceptedDb=requested;
} else {
double requested=0.;
if(!nativeV8Number(value,requested) ||
requested< -1. || requested>1.)
return reject("INVALID_PAN_VALUE");
acceptedPan=requested;
}
// PAN must not round-trip the companion fader through a clipped dB
// projection: an accepted -60 dB can represent 0.001 linear, not
// silence, and an upper-clamped +12 dB can represent gain 4.0.
// Keep the verified native linear gain byte-for-byte on PAN edits.
// Only an explicit SET_FADER request converts dB into new gain.
const double gain=op=="SET_PAN"?nativeGain:
(acceptedDb<= -60.?0.:std::pow(10.,acceptedDb/20.));
if(!std::isfinite(gain) || gain>4.)
return reject("UNREPRESENTABLE_GAIN");
nativeOperation=bus?"NATIVE_SET_BUS_MIX":"NATIVE_SET_CHANNEL_MIX";
translatedPayload->setProperty("gain",gain);
translatedPayload->setProperty("pan",acceptedPan);
} else {
if(!value.isBool())return reject("INVALID_MUTE_SOLO_VALUE");
nativeOperation="NATIVE_SET_CHANNEL_MUTE_SOLO";
translatedPayload->setProperty("mute",op=="SET_MUTE"?value:mute);
translatedPayload->setProperty("solo",op=="SET_SOLO"?value:solo);
}
if(!approvedHasOperation(installedBus.getProperty("supportedOps",{}),
nativeOperation))
return reject("NATIVE_PCM_OPERATION_NOT_ADMITTED");
auto converted=std::make_unique<juce::DynamicObject>();
converted->setProperty("requestId",request);
converted->setProperty("deviceEpoch",epoch);
converted->setProperty("baseGraphRevision",revision);
converted->setProperty("baseRosterRevision",roster);
converted->setProperty("targetChannelId",ids);
converted->setProperty("operation",nativeOperation);
converted->setProperty("payload",juce::var(translatedPayload.release()));
return {juce::var(converted.release()),{}};
}
} // namespace armix::console
99 changes: 99 additions & 0 deletions integration/ApprovedNativeRuntimeSnapshot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include "ApprovedNativeV8Projection.h"
#include <juce_core/juce_core.h>
#include <cstdint>

// Sole JUCE MESSAGE-thread production readback for approved /preview/.
// Never creates a ChannelId bus, audio callback, synthetic device, or
// browser-owned PCM. ENGINE #266 reports nativeChannelIdPcmActive ONLY after
// its installed realtime callback owns the accepted publisher/epoch.
// G0/M4 and any forged nativeBus without that predicate MUST stay unadmitted.
namespace armix::console {
// Legacy M2 counted only device START callbacks; the actual routing epoch
// also advances on STOP. After ASIO/WASAPI re-open they can differ (e.g.,
// G0 start=2 while accepted routing epoch=3). Always use the installed
// LiveDryRoutingLab epoch for both G0 and native accepted snapshots so a
// disconnected physical device cannot leave a stale accepted GUI LIVE.
// This remains a CONTROL-only metadata correction; never creates a graph.
inline bool synchronizeApprovedRouteDeviceEpoch(
juce::var& snapshot,const juce::var& live)
{
if (!snapshot.isObject() || !live.isObject()) return false;
const auto device=snapshot.getProperty("device",{});
const auto route=live.getProperty("dryRoutingLab",{});
if (!device.isObject() || !route.isObject()) return false;
const auto generation=device.getProperty("epoch",{});
const auto epoch=route.getProperty("epoch",{});
if (!generation.isString() ||
!(generation.toString()=="0" || nativeV8Decimal(generation)) ||
!(epoch.isInt() || epoch.isInt64())) return false;
const auto actual=static_cast<juce::int64>(epoch);
if(actual<0 || actual<generation.toString().getLargeIntValue())
return false;
if(auto* d=device.getDynamicObject())
d->setProperty("epoch",juce::String(actual));
return true;
}

inline bool projectInstalledNativeChannelIdGraph(
juce::var& snapshot, const juce::var& live)
{
if (!snapshot.isObject() || !live.isObject()) return false;
const auto route=live.getProperty("dryRoutingLab",{});
const auto device=snapshot.getProperty("device",{});
if (!route.isObject() || !device.isObject()) return false;
const auto actualFlag=[&](const juce::var& source,const char* key) {
const auto value=source.getProperty(key,{});
return value.isBool() && static_cast<bool>(value);
};
const auto actualFalse=[&](const juce::var& source,const char* key) {
const auto value=source.getProperty(key,{});
return value.isBool() && !static_cast<bool>(value);
};
if (!actualFlag(live,"connected") ||
!actualFlag(live,"directRouteAuthorized") ||
!actualFalse(live,"adaptiveClockActive") ||
!actualFlag(route,"ready") ||
!actualFlag(route,"hasAcceptedRoute") ||
!actualFlag(route,"nativeChannelIdPcmActive") ||
!actualFalse(route,"topologyFault"))
return false;
const auto epoch=device.getProperty("epoch",{});
const auto nativeEpoch=route.getProperty("epoch",{});
if (!nativeV8Decimal(epoch) || epoch.toString()=="0" ||
!(nativeEpoch.isInt() || nativeEpoch.isInt64()) ||
static_cast<juce::int64>(nativeEpoch)<=0 ||
juce::String(static_cast<juce::int64>(nativeEpoch))!=epoch.toString())
return false;
const auto outputMask=device.getProperty("enabledOutputs",{});
const auto inputMask=device.getProperty("enabledInputs",{});
const auto rate=device.getProperty("sampleRate",{});
const auto frames=device.getProperty("bufferFrames",{});
double actualRate=0.,actualFrames=0.;
if (!outputMask.isArray() || !inputMask.isArray() ||
outputMask.getArray()->size()<2 || inputMask.getArray()->isEmpty() ||
!nativeV8Number(rate,actualRate) ||
!nativeV8Number(frames,actualFrames) ||
actualRate<8000. || actualRate>384000. ||
actualFrames<16. || actualFrames>32768.)
return false;
const auto bus=route.getProperty("nativeBus",{});
if (!bus.isObject()) return false;
// This function has no independent "true" argument. Callback admission
// 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.
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.
return true;
}
} // namespace armix::console
Loading
Loading