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
129 changes: 45 additions & 84 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "NativeLogicalMixerControl.h"
#include "NativeHotkeyRegistry.h"
#include "NativeFxParameterHotkey.h"
#include "NativeFxControlRequest.h"
#include "NativeDeviceApplyCoordinator.h"
#include <algorithm>
#include <cstring>
Expand Down Expand Up @@ -3889,20 +3890,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr

// Exact native instance lease; queued != audio-applied.
if(action=="nativeHarmonySnapshot"||action=="nativeHarmonySetSettings") {
const auto rawChannel=args.getProperty("channelId",{});
const auto rawEpoch=args.getProperty("deviceEpoch",{});
const auto rawRevision=args.getProperty("graphRevision",{});
const auto rawInstance=args.getProperty("instanceId",{});
const auto request=args.getProperty("requestId",{}).toString();
const int slot=static_cast<int>(args.getProperty("slot",-1));
std::uint64_t ch=0,ep=0,rev=0;
const bool valid=armix::console::approvedNativeId(rawChannel,ch)&&
armix::console::approvedNativeId(rawEpoch,ep)&&
armix::console::approvedNativeId(rawRevision,rev)&&
rawInstance.isString()&&rawInstance.toString().isNotEmpty()&&
slot>=0&&slot<LiveDryRoutingLab::maxFxPerLane &&
request.isNotEmpty()&&request.length()<=72;
const bool unbound=args.getProperty("workspaceToken","").toString().isNotEmpty();
const auto fxRequest=armix::builtin_fx::NativeFxControlRequest::parse(
args,LiveDryRoutingLab::maxFxPerLane);
const auto& rawChannel=fxRequest.rawChannel;
const auto& rawEpoch=fxRequest.rawEpoch;
const auto& rawRevision=fxRequest.rawRevision;
const auto& rawInstance=fxRequest.rawInstance;
const auto& request=fxRequest.request;
const int slot=fxRequest.slot;
const auto ch=fxRequest.channel,ep=fxRequest.epoch,rev=fxRequest.revision;
const bool valid=fxRequest.valid,unbound=fxRequest.unbound;
armix::session::StoredInsert offlineInsert;
auto offline=unbound?openLogicalBuiltinFx(args,offlineInsert,
armix::builtin_fx::ChannelHarmonyProcessor::catalogIdentity):nullptr;
Expand Down Expand Up @@ -3971,12 +3968,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
if(typed&&guideValid&&processor&&!pendingNativeHarmony_.owner&&!nativeShowBusy_&&
!studioBackupBusy_&&!engine_.independentClockActive()&&
armix::harmony::valid(settings)&&request.startsWith("harm-")) {
const auto digits=request.substring(5).toStdString();
std::uint64_t numeric=0;
if(!digits.empty()&&digits.size()<=19&&
digits.find_first_not_of("0123456789")==std::string::npos) {
try{numeric=std::stoull(digits);}catch(...){numeric=0;}
}
const auto numeric=fxRequest.sequence("harm-");
queued=numeric>0&&processor->queueAccepted(settings,numeric);
if(queued && !unbound) {
pendingNativeHarmony_.owner=owner;
Expand Down Expand Up @@ -4006,20 +3998,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
// Real built-in rack node, not a GUI-only pre-VST channel EQ.
// All identity fields are validated by the accepted native lease.
if(action=="nativeEqSnapshot"||action=="nativeEqSetBand") {
const auto rawChannel=args.getProperty("channelId",{});
const auto rawEpoch=args.getProperty("deviceEpoch",{});
const auto rawRevision=args.getProperty("graphRevision",{});
const auto rawInstance=args.getProperty("instanceId",{});
const auto request=args.getProperty("requestId",{}).toString();
const int eqSlot=static_cast<int>(args.getProperty("slot",-1));
std::uint64_t ch=0,ep=0,rev=0;
const bool valid=armix::console::approvedNativeId(rawChannel,ch)&&
armix::console::approvedNativeId(rawEpoch,ep)&&
armix::console::approvedNativeId(rawRevision,rev)&&
rawInstance.isString()&&rawInstance.toString().isNotEmpty()&&
eqSlot>=0&&eqSlot<LiveDryRoutingLab::maxFxPerLane &&
request.isNotEmpty()&&request.length()<=72;
const bool unbound=args.getProperty("workspaceToken","").toString().isNotEmpty();
const auto fxRequest=armix::builtin_fx::NativeFxControlRequest::parse(
args,LiveDryRoutingLab::maxFxPerLane);
const auto& rawChannel=fxRequest.rawChannel;
const auto& rawEpoch=fxRequest.rawEpoch;
const auto& rawRevision=fxRequest.rawRevision;
const auto& rawInstance=fxRequest.rawInstance;
const auto& request=fxRequest.request;
const int eqSlot=fxRequest.slot;
const auto ch=fxRequest.channel,ep=fxRequest.epoch,rev=fxRequest.revision;
const bool valid=fxRequest.valid,unbound=fxRequest.unbound;
armix::session::StoredInsert offlineInsert;
auto offline=unbound?openLogicalBuiltinFx(args,offlineInsert,
armix::builtin_fx::ChannelEqProcessor::catalogIdentity):nullptr;
Expand Down Expand Up @@ -4061,14 +4049,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
b.q=static_cast<float>(quality);
b.slope=static_cast<int>(slope)==24?
armix::builtin_fx::Slope::db24:armix::builtin_fx::Slope::db12;
// Id strings are decimal after "eq-", unlike canonical
// ChannelIds; never convert 64-bit ChannelId to JS Number.
const auto wire=request.substring(3).toStdString();
std::uint64_t numeric=0;
if(!wire.empty()&&wire.size()<=19&&
wire.find_first_not_of("0123456789")==std::string::npos) {
try{numeric=std::stoull(wire);}catch(...){numeric=0;}
}
const auto numeric=fxRequest.sequence("eq-");
queued=numeric>0&&processor->queueBand(
static_cast<std::size_t>(index),b,numeric);
if(queued && !unbound) {
Expand Down Expand Up @@ -4101,20 +4082,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
// Each accepted compressor edit stays on this ChannelId's ordered
// native insert. No GUI mutation until callback ACK + graph readback.
if(action=="nativeCompSnapshot"||action=="nativeCompSet") {
const auto rawChannel=args.getProperty("channelId",{});
const auto rawEpoch=args.getProperty("deviceEpoch",{});
const auto rawRevision=args.getProperty("graphRevision",{});
const auto rawInstance=args.getProperty("instanceId",{});
const auto request=args.getProperty("requestId",{}).toString();
const int compSlot=static_cast<int>(args.getProperty("slot",-1));
std::uint64_t ch=0,ep=0,rev=0;
const bool valid=armix::console::approvedNativeId(rawChannel,ch)&&
armix::console::approvedNativeId(rawEpoch,ep)&&
armix::console::approvedNativeId(rawRevision,rev)&&
rawInstance.isString()&&rawInstance.toString().isNotEmpty()&&
compSlot>=0&&compSlot<LiveDryRoutingLab::maxFxPerLane &&
request.isNotEmpty()&&request.length()<=72;
const bool unbound=args.getProperty("workspaceToken","").toString().isNotEmpty();
const auto fxRequest=armix::builtin_fx::NativeFxControlRequest::parse(
args,LiveDryRoutingLab::maxFxPerLane);
const auto& rawChannel=fxRequest.rawChannel;
const auto& rawEpoch=fxRequest.rawEpoch;
const auto& rawRevision=fxRequest.rawRevision;
const auto& rawInstance=fxRequest.rawInstance;
const auto& request=fxRequest.request;
const int compSlot=fxRequest.slot;
const auto ch=fxRequest.channel,ep=fxRequest.epoch,rev=fxRequest.revision;
const bool valid=fxRequest.valid,unbound=fxRequest.unbound;
armix::session::StoredInsert offlineInsert;
auto offline=unbound?openLogicalBuiltinFx(args,offlineInsert,
armix::builtin_fx::ChannelCompressorProcessor::catalogIdentity):nullptr;
Expand All @@ -4140,13 +4117,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
out=static_cast<float>(n);
return std::isfinite(out);
};
const auto wire=request.startsWith("comp-")?
request.substring(5).toStdString():std::string();
std::uint64_t numeric=0;
if(!wire.empty()&&wire.size()<=19&&
wire.find_first_not_of("0123456789")==std::string::npos) {
try{numeric=std::stoull(wire);}catch(...){numeric=0;}
}
const auto numeric=fxRequest.sequence("comp-");
const bool parameters=values.isObject()&&
number("thresholdDb",settings.thresholdDb)&&
number("ratio",settings.ratio)&&
Expand Down Expand Up @@ -4187,20 +4158,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
// ChannelId + device epoch + graph revision + insert instance.
if(action=="nativeThrowSnapshot"||action=="nativeThrowSet"||
action=="nativeThrowTrigger"||action=="nativeThrowTempoSource") {
const auto rawChannel=args.getProperty("channelId",{});
const auto rawEpoch=args.getProperty("deviceEpoch",{});
const auto rawRevision=args.getProperty("graphRevision",{});
const auto rawInstance=args.getProperty("instanceId",{});
const auto request=args.getProperty("requestId",{}).toString();
const int throwSlot=static_cast<int>(args.getProperty("slot",-1));
std::uint64_t ch=0,ep=0,rev=0;
const bool valid=armix::console::approvedNativeId(rawChannel,ch)&&
armix::console::approvedNativeId(rawEpoch,ep)&&
armix::console::approvedNativeId(rawRevision,rev)&&
rawInstance.isString()&&rawInstance.toString().isNotEmpty()&&
throwSlot>=0&&throwSlot<LiveDryRoutingLab::maxFxPerLane&&
request.isNotEmpty()&&request.length()<=72;
const bool unbound=args.getProperty("workspaceToken","").toString().isNotEmpty();
const auto fxRequest=armix::builtin_fx::NativeFxControlRequest::parse(
args,LiveDryRoutingLab::maxFxPerLane);
const auto& rawChannel=fxRequest.rawChannel;
const auto& rawEpoch=fxRequest.rawEpoch;
const auto& rawRevision=fxRequest.rawRevision;
const auto& rawInstance=fxRequest.rawInstance;
const auto& request=fxRequest.request;
const int throwSlot=fxRequest.slot;
const auto ch=fxRequest.channel,ep=fxRequest.epoch,rev=fxRequest.revision;
const bool valid=fxRequest.valid,unbound=fxRequest.unbound;
armix::session::StoredInsert offlineInsert;
auto offline=unbound?openLogicalBuiltinFx(args,offlineInsert,
armix::builtin_fx::VocalThrowProcessor::catalogIdentity):nullptr;
Expand Down Expand Up @@ -4239,13 +4206,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
"arMixBuiltinThrowTempoAck",juce::var(reply.release()));
return;
}
const auto wire=request.startsWith("throw-")?
request.substring(6).toStdString():std::string();
std::uint64_t numeric=0;
if(!wire.empty()&&wire.size()<=19&&
wire.find_first_not_of("0123456789")==std::string::npos) {
try{numeric=std::stoull(wire);}catch(...){numeric=0;}
}
const auto numeric=fxRequest.sequence("throw-");
const bool isSettings=action=="nativeThrowSet";
const auto values=args.getProperty("settings",{});
armix::builtin_fx::VocalThrowSettings settings{};
Expand Down
54 changes: 54 additions & 0 deletions src/NativeFxControlRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: AGPL-3.0-only
#pragma once
#include "../integration/ApprovedNativeControlIntent.h"
#include <cstdint>

// Message/CONTROL-thread-only identity policy for built-in FX commands.
// EQ, Compressor, Harmonice and Vocal Throw must all validate the SAME exact
// ChannelId, device epoch, graph revision, insert lease and request envelope.
// No plugin construction, editor, callback, graph or PCM authority lives here.
namespace armix::builtin_fx {
struct NativeFxControlRequest final {
juce::var rawChannel,rawEpoch,rawRevision,rawInstance;
juce::String request;
int slot=-1;
std::uint64_t channel=0,epoch=0,revision=0;
bool valid=false,unbound=false;

static NativeFxControlRequest parse(const juce::var& args,int maximumSlots) {
NativeFxControlRequest result;
result.rawChannel=args.getProperty("channelId",{});
result.rawEpoch=args.getProperty("deviceEpoch",{});
result.rawRevision=args.getProperty("graphRevision",{});
result.rawInstance=args.getProperty("instanceId",{});
result.request=args.getProperty("requestId",{}).toString();
result.slot=static_cast<int>(args.getProperty("slot",-1));
result.unbound=args.getProperty("workspaceToken","").toString().isNotEmpty();
result.valid=armix::console::approvedNativeId(result.rawChannel,result.channel) &&
armix::console::approvedNativeId(result.rawEpoch,result.epoch) &&
armix::console::approvedNativeId(result.rawRevision,result.revision) &&
result.rawInstance.isString() &&
result.rawInstance.toString().isNotEmpty() &&
result.slot>=0 && result.slot<maximumSlots &&
result.request.isNotEmpty() && result.request.length()<=72;
return result;
}

// Parse the host FX mailbox sequence, not a ChannelId. The existing
// protocol admits 1..19 ASCII digits after its exact effect prefix.
// This is exception-free and cannot overflow uint64 at <=19 digits.
std::uint64_t sequence(const char* prefix) const noexcept {
if(!prefix)return 0;
const juce::String marker(prefix);
if(!request.startsWith(marker))return 0;
const auto digits=request.substring(marker.length());
if(digits.isEmpty()||digits.length()>19)return 0;
std::uint64_t value=0;
for(auto c:digits) {
if(c<'0'||c>'9')return 0;
value=value*10u+static_cast<std::uint64_t>(c-'0');
}
return value;
}
};
} // namespace armix::builtin_fx
50 changes: 50 additions & 0 deletions tests/native_fx_registry_extension_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#undef NDEBUG
#endif
#include "../src/NativeBuiltInFx.h"
#include "../src/NativeFxControlRequest.h"
#include <array>
#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -74,7 +75,56 @@ static_assert(!validNativeBuiltInFxCatalog(duplicate));
static_assert(validNativeBuiltInFxCatalog(armix::builtin_fx::nativeBuiltInFx));
static_assert(std::is_same_v<Entry::Prepare,std::remove_cv_t<decltype(fixture.prepare)>>);

static void verifySharedNativeFxControlRequest() {
// Same lease/epoch/revision envelope across all four built-in FX editors.
auto request=std::make_unique<juce::DynamicObject>();
request->setProperty("channelId","9007199254740993"); // exact >JS-safe uint64
request->setProperty("deviceEpoch","12");
request->setProperty("graphRevision","19");
request->setProperty("instanceId","g5c-707");
request->setProperty("slot",3);
request->setProperty("requestId","comp-1844674407370955161");
juce::var source(request.release());
using Target=armix::builtin_fx::NativeFxControlRequest;
const auto good=Target::parse(source,8);
assert(good.valid && !good.unbound && good.channel==9007199254740993ULL);
assert(good.epoch==12 && good.revision==19 && good.slot==3);
assert(good.sequence("comp-")==1844674407370955161ULL);
assert(good.sequence("harm-")==0 && good.sequence("throw-")==0);
auto alter=[](const juce::var& before,const char* name,juce::var value) {
auto copy=juce::JSON::parse(juce::JSON::toString(before));
copy.getDynamicObject()->setProperty(name,value);
return copy;
};
assert(!Target::parse(alter(source,"channelId",juce::var(9007199254740993.0)),8).valid);
assert(!Target::parse(alter(source,"channelId",juce::var("00")),8).valid);
assert(!Target::parse(alter(source,"deviceEpoch",juce::var("0")),8).valid);
assert(!Target::parse(alter(source,"graphRevision",juce::var("18446744073709551616")),8).valid);
assert(!Target::parse(alter(source,"instanceId",juce::var("")),8).valid);
assert(!Target::parse(alter(source,"instanceId",juce::var(1)),8).valid);
assert(!Target::parse(alter(source,"slot",juce::var(8)),8).valid);
assert(!Target::parse(alter(source,"slot",juce::var(-1)),8).valid);
assert(!Target::parse(alter(source,"requestId",juce::var("")),8).valid);
assert(!Target::parse(alter(source,"requestId",juce::var(juce::String::repeatedString("a",73))),8).valid);
const auto logical=Target::parse(alter(source,"workspaceToken",juce::var("persisted-mixer")),8);
assert(logical.valid && logical.unbound && logical.sequence("comp-")==good.sequence("comp-"));
for(const auto& id:{"eq-1","harm-17","throw-99","comp-0008"}) {
const auto candidate=Target::parse(alter(source,"requestId",juce::var(id)),8);
assert(candidate.valid);
assert(candidate.sequence(juce::String(id).upToFirstOccurrenceOf("-",true,false).toRawUTF8())>0);
}
for(const auto& id:{"comp-","comp--1","comp-1x","comp-1.0",
"comp-12345678901234567890","comp-0000000000000000000"}) {
const auto candidate=Target::parse(alter(source,"requestId",juce::var(id)),8);
assert(candidate.sequence("comp-")==0);
}
const auto max19=Target::parse(alter(source,"requestId",
juce::var("comp-9999999999999999999")),8);
assert(max19.valid && max19.sequence("comp-")==9999999999999999999ULL);
}

int main() {
verifySharedNativeFxControlRequest();
const auto* found=findNativeBuiltInFxIn(injected,"armix.test.fixture-gain.v1");
assert(found==&injected[0]);
assert(!findNativeBuiltInFxIn(injected,""));
Expand Down
Loading