Skip to content
Closed
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
11 changes: 7 additions & 4 deletions engine/builtin_fx/ChannelHarmonyProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor,
void getStateInformation(juce::MemoryBlock& out) override {
juce::MemoryOutputStream stream(out,false);
stream.writeInt(0x41484d31); // AHM1
stream.writeInt(2);
stream.writeInt(3);
stream.writeInt(accepted_.key);
stream.writeInt(accepted_.scale);
stream.writeInt(accepted_.voices);
Expand All @@ -176,29 +176,32 @@ class ChannelHarmonyProcessor final : public juce::AudioProcessor,
stream.writeFloat(accepted_.gainDb);
stream.writeInt(accepted_.guideMode);
stream.writeInt64(static_cast<juce::int64>(accepted_.guideChannelId));
stream.writeInt(accepted_.voiceMode);
}
bool restoreUnpublishedState(const void* bytes,int len) {
if(published_||!bytes||len<=0||len>128)return false;
juce::MemoryInputStream stream(bytes,static_cast<std::size_t>(len),false);
if(stream.readInt()!=0x41484d31)return false;
const int version=stream.readInt();
if(version!=1&&version!=2)return false;
if(version!=1&&version!=2&&version!=3)return false;
armix::harmony::Settings incoming{};
incoming.key=stream.readInt();incoming.scale=stream.readInt();
incoming.voices=stream.readInt();incoming.correction=stream.readBool();
incoming.wet=stream.readFloat();incoming.space=stream.readFloat();
incoming.color=stream.readFloat();incoming.gainDb=stream.readFloat();
if(version==2){
if(version>=2){
incoming.guideMode=stream.readInt();
const auto guide=stream.readInt64();
if(guide<0)return false;
incoming.guideChannelId=static_cast<std::uint64_t>(guide);
}
if(version==3)incoming.voiceMode=stream.readInt();
// v1/v2 lacked an explicit Doubler; they stay pitched Harmony.
if(stream.getPosition()!=stream.getTotalLength()||
!armix::harmony::valid(incoming))return false;
if(ready_&&!dsp_.setSettings(incoming))return false;
// NativeMixerSessionFxRestore restores AFTER prepareToPlay. An accepted
// v2 ChannelId must become the actual AUDIO guide source, not merely a
// v2/v3 ChannelId must become the actual AUDIO guide source, not merely a
// saved GUI value. This is unpublished/control-thread only.
if(ready_) {
guide_.reset();
Expand Down
47 changes: 40 additions & 7 deletions engine/builtin_fx/HarmonyDsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace armix::harmony {
struct Settings {
int key=0, scale=0, voices=3; // C=0..B=11; 0=major, 1=natural minor; 2..5 voices
int voiceMode=0; // 0=pitched harmony (2-5), 1=true unison doubler (one wet take)
bool correction=false;
// Manual is always the trusted fallback. Music follows another accepted
// ChannelId only after stable chroma confidence (never a PCM route).
Expand All @@ -29,6 +30,7 @@ struct Settings {
};
inline bool valid(const Settings& s) noexcept {
return s.key>=0&&s.key<12&&s.scale>=0&&s.scale<=1&&
s.voiceMode>=0&&s.voiceMode<=1&&
s.guideMode>=0&&s.guideMode<=1&&
(s.guideMode==0?s.guideChannelId==0:s.guideChannelId>0)&&
s.voices>=2&&s.voices<=5&&std::isfinite(s.wet)&&s.wet>=0&&s.wet<=1&&
Expand Down Expand Up @@ -157,6 +159,19 @@ class Engine final {
prepared.settings=next;
prepared.gain=std::pow(10.f,next.gainDb/20.f);
constexpr float pi=3.14159265358979323846f;
if(next.voiceMode==1){
// Real unison double, NOT 2 pitched harmony voices. One
// independently windowed take follows source F0 at unity ratio.
// A tiny prepared left-back offset plus the existing shared
// room/detune/arrival give a second-take character.
const float pan=-.40f*next.space;
const float angle=(pan+1.f)*pi*.25f;
const float amount=next.wet*(.77f+.38f*next.wet)*.74f;
prepared.mixL[0]=amount*std::cos(angle);
prepared.mixR[0]=amount*std::sin(angle);
out=prepared;
return true;
}
float profileEnergy=0.f;
for(const auto& singer:singers)
if(singerActive(singer.role,next.voices))
Expand Down Expand Up @@ -192,6 +207,12 @@ class Engine final {
}
if(settings_.correction&&!next.settings.correction)
leadTune_.release();
if(next.settings.voiceMode!=settings_.voiceMode){
// Re-evaluate note targets on the next accepted analysis,
// without stopping the dry singer or reinitializing the room.
tonalTransitionPending_=true;
if(next.settings.voiceMode==1)targetRatio_.fill(1.f);
}
settings_=next.settings;
targetWet_=next.settings.wet;targetColor_=next.settings.color;
targetSpace_=next.settings.space;
Expand Down Expand Up @@ -563,7 +584,11 @@ class Engine final {
}
const int activeKey=effectiveKey(),activeScale=effectiveScale();
const int degree=nearestDegree(midi,activeKey,activeScale);
int note=noteAt(degree,activeKey,activeScale);
// In DOUBLE the source's own melody is authoritative, not the key
// wheel's diatonic quantization. Harmony keeps the existing scale.
int note=settings_.voiceMode==1?
static_cast<int>(std::lround(midi)):
noteAt(degree,activeKey,activeScale);
if(!tonalTransitionPending_ &&
!pitchChangeHasMargin(currentNote_,note,midi)){
note=currentNote_;
Expand All @@ -586,7 +611,9 @@ class Engine final {
leadTune_.observe(midi,note,confidence);
}
if(note!=currentNote_||tonalTransitionPending_){
voicePlanner_.plan(note,activeKey,activeScale==0?major:minor);
if(settings_.voiceMode==0)
voicePlanner_.plan(note,activeKey,activeScale==0?major:minor);
else voicePlanner_.reset();
ensemble_.beginNote();
}
currentNote_=note;voiced_=true;tonalTransitionPending_=false;
Expand All @@ -606,11 +633,17 @@ class Engine final {
}else weakSyncHops_=0;
// Integer intervals come from the prepared LUT. The single
// fractional ratio tracks the current microphone pitch.
const float baseRatio=std::exp2((note-midi)/12.f);
for(std::size_t v=0;v<singers.size();++v){
const int target=voicePlanner_.target(v);
targetRatio_[v]=target<0?1.f:std::clamp(
baseRatio*pitchIntervals_.ratio(target-note),.50f,2.f);
if(settings_.voiceMode==1){
// Preserve the exact sung melody with only EnsembleSpace's
// small individual cents/vibrato, no scale transposition.
targetRatio_.fill(1.f);
}else{
const float baseRatio=std::exp2((note-midi)/12.f);
for(std::size_t v=0;v<singers.size();++v){
const int target=voicePlanner_.target(v);
targetRatio_[v]=target<0?1.f:std::clamp(
baseRatio*pitchIntervals_.ratio(target-note),.50f,2.f);
}
}
}
double rate_=0.; int grain_=0,latency_=0,decimation_=4,detectEvery_=320;
Expand Down
16 changes: 16 additions & 0 deletions site/preview-v2/assets/mixer-fx-rack.css
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,22 @@
}
.mx-harm-voice-glyph{display:block;flex:0 0 11px;width:11px;height:11px}
.mx-harm-voices button span{display:block;font-variant-numeric:tabular-nums}
.mx-harm-type{display:flex;gap:3px;width:100%;margin-top:2px}
.mx-harm-type button{
appearance:none;flex:1;min-width:0;height:23px;padding:0 2px;
border:1px solid #486673;border-radius:4px;
background:linear-gradient(#1b3540,#142c37);
color:#9bbac3;font-size:8px;font-weight:500;letter-spacing:.25px;
box-shadow:inset 0 1px 3px #081c264f;
cursor:pointer
}
.mx-harm-type button.active{
background:linear-gradient(#3d7a72,#285d59);
border-color:#69b6a5;color:#f3fcf9
}
.mx-harm-type button.queued:not(.active){outline:1px solid #d8ae64;outline-offset:1px}
.mx-harm-type button:focus-visible{outline:2px solid #a5dfde;outline-offset:1px}
.mx-harm-voices button:disabled{opacity:.5;cursor:default}
.mx-harm-voices button.active{
background:linear-gradient(180deg,#438d7d,#326c63);
color:#f6fffb;border-color:#77bdac;
Expand Down
55 changes: 43 additions & 12 deletions site/preview-v2/assets/mixer-native-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ root.innerHTML=`
<span class="mx-harm-channel" id="mxHChannel"></span>
<select id="mxHPreset" aria-label="Harmonice preset" title="Preset">
<option value="custom">Custom</option>
<option value="doubleLight">Double Light</option><option value="doubleWide">Double Wide</option>
<option value="duo">Natural Duo</option><option value="trio">Soft Trio</option>
<option value="quartet">Wide Quartet</option><option value="quintet">Lush Five</option><option value="choir">Tight Choir</option>
</select>
Expand All @@ -33,6 +34,10 @@ root.innerHTML=`
<nav class="mx-harm-voices" id="mxHVoices" aria-label="Harmonice voice count">
<button type="button" data-voices="2" aria-label="2 harmony voices plus lead — Natural Duo" aria-pressed="false">${voiceGlyph}<span>2</span></button><button type="button" data-voices="3" aria-label="3 harmony voices" aria-pressed="true">${voiceGlyph}<span>3</span></button><button type="button" data-voices="4" aria-label="4 harmony voices" aria-pressed="false">${voiceGlyph}<span>4</span></button><button type="button" data-voices="5" aria-label="5 harmony voices" aria-pressed="false">${voiceGlyph}<span>5</span></button>
</nav>
<nav class="mx-harm-type" id="mxHType" aria-label="Vocal ensemble type">
<button type="button" data-voice-mode="0" aria-label="Pitched harmony voices" aria-pressed="true">HARMONY</button>
<button type="button" data-voice-mode="1" aria-label="Unison vocal doubler" aria-pressed="false">DOUBLER</button>
</nav>
<button type="button" id="mxHCorrection" class="mx-harm-correction" role="switch"
aria-checked="false" aria-busy="true" disabled>
<span class="mx-harm-switch-track" aria-hidden="true"></span><span>PITCH TUNE</span>
Expand Down Expand Up @@ -94,15 +99,17 @@ for(const [key,label,min,max,step] of sliderDefs){
box.innerHTML=`<span class="mx-harm-dial-face" aria-hidden="true"><i class="mx-harm-dial-pointer"></i></span><span class="mx-harm-dial-label">${label}</span><output data-out="${key}"></output><input data-field="${key}" type="range" min="${min}" max="${max}" step="${step}" aria-label="${label}" title="Drag horizontally or use arrow keys">`;
el("mxHSliders").append(box);
}
const fresh=()=>({key:0,scale:0,voices:3,correction:false,
const fresh=()=>({key:0,scale:0,voices:3,voiceMode:0,correction:false,
guideMode:0,guideChannelId:"0",
color:0.5,space:0.6,wet:0.45,gainDb:0});
const presets={
duo:{voices:2,color:.45,space:.35,wet:.31,gainDb:0},
trio:{voices:3,color:.50,space:.56,wet:.40,gainDb:0},
quartet:{voices:4,color:.66,space:.95,wet:.52,gainDb:-2},
quintet:{voices:5,color:.61,space:.88,wet:.45,gainDb:-3},
choir:{voices:4,color:.24,space:.30,wet:.58,gainDb:-3}
doubleLight:{voiceMode:1,space:.35,color:.57,wet:.38,gainDb:0},
doubleWide:{voiceMode:1,space:.82,color:.48,wet:.52,gainDb:-1},
duo:{voiceMode:0,voices:2,color:.45,space:.35,wet:.31,gainDb:0},
trio:{voiceMode:0,voices:3,color:.50,space:.56,wet:.40,gainDb:0},
quartet:{voiceMode:0,voices:4,color:.66,space:.95,wet:.52,gainDb:-2},
quintet:{voiceMode:0,voices:5,color:.61,space:.88,wet:.45,gainDb:-3},
choir:{voiceMode:0,voices:4,color:.24,space:.30,wet:.58,gainDb:-3}
};
const native=()=>Boolean(window.__JUCE__?.backend?.emitEvent);
const backend=()=>window.__JUCE__?.backend;
Expand All @@ -115,6 +122,7 @@ let detectedKey=-1,detectedScale=-1,detectedConfidence=0,lastGuideRead=0;
let effectiveKey=-1,effectiveScale=-1,sourceSignature="",availableSources=[];
const noteButtons=[...root.querySelectorAll("[data-key]")];
const voiceButtons=[...root.querySelectorAll("[data-voices]")];
const typeButtons=[...root.querySelectorAll("[data-voice-mode]")];
const scaleButtons=[...root.querySelectorAll("[data-scale]")];
const guideButtons=[...root.querySelectorAll("[data-guide-mode]")];
const sliders=sliderDefs.map(([key])=>({
Expand Down Expand Up @@ -195,6 +203,7 @@ const hint=t=>showText(el("mxHStatus"),t);
const valid=s=>s&&Number.isInteger(s.key)&&s.key>=0&&s.key<12&&
Number.isInteger(s.scale)&&s.scale>=0&&s.scale<=1&&
Number.isInteger(s.voices)&&s.voices>=2&&s.voices<=5&&
Number.isInteger(s.voiceMode)&&[0,1].includes(s.voiceMode)&&
typeof s.correction==="boolean"&&
["wet","space","color"].every(k=>Number.isFinite(s[k])&&s[k]>=0&&s[k]<=1)&&
Number.isFinite(s.gainDb)&&s.gainDb>=-24&&s.gainDb<=12&&
Expand Down Expand Up @@ -263,34 +272,49 @@ function paint(){
b.classList.toggle("active",active);
b.setAttribute("aria-pressed",String(active));
}
el("mxHSourcePicker").hidden=!auto;
el("mxHSourcePicker").hidden=!auto||v.voiceMode===1;
const source=el("mxHGuideSource");
const chosen=inGraph?v.guideChannelId:"0";
if(source.value!==chosen)source.value=chosen;
for(const b of noteButtons){
b.disabled=v.voiceMode===1;
b.classList.toggle("active",
reliable&&Number(b.dataset.key)===displayKey);
b.classList.toggle("queued",Number(b.dataset.key)===queuedKey);
}
for(const b of voiceButtons){
b.disabled=v.voiceMode===1;
const active=Number(b.dataset.voices)===v.voices;
b.classList.toggle("active",active);
b.setAttribute("aria-pressed",String(active));
}
for(const b of scaleButtons)b.classList.toggle("active",
reliable&&Number(b.dataset.scale)===displayScale);
for(const b of typeButtons){
const active=Number(b.dataset.voiceMode)===settings.voiceMode;
b.classList.toggle("active",active);
b.classList.toggle("queued",Number(b.dataset.voiceMode)===v.voiceMode&&!active);
b.setAttribute("aria-pressed",String(active));
}
for(const b of guideButtons)b.disabled=v.voiceMode===1;
for(const b of scaleButtons){
b.disabled=v.voiceMode===1;
b.classList.toggle("active",
reliable&&Number(b.dataset.scale)===displayScale);
}
const correction=el("mxHCorrection");
const syncing=nativeView&&!verified;
const correctionPending=nativeView&&v.correction!==settings.correction;
correction.disabled=syncing;
correction.setAttribute("aria-busy",String(syncing||correctionPending));
correction.setAttribute("aria-checked",String(!syncing&&settings.correction));
showText(el("mxHKeyReadout"),reliable?keys[displayKey]+(displayScale?"m":""):"—");
showText(el("mxHNote"),reliable?(displayScale?"MINOR":"MAJOR"):"KEY");
showText(el("mxHKeyReadout"),v.voiceMode===1?"UNI":
reliable?keys[displayKey]+(displayScale?"m":""):"—");
showText(el("mxHNote"),v.voiceMode===1?"DOUBLE":
reliable?(displayScale?"MINOR":"MAJOR"):"KEY");
el("mxHKeyReadout").setAttribute("aria-label",
reliable?"Active Harmony key "+keys[displayKey]+(displayScale?" minor":" major"):
"Harmony key awaiting native readback");
const status=!auto?"MANUAL":!inGraph?"SAFE":detected?"AUTO":"LISTEN";
const status=v.voiceMode===1?"UNISON":
!auto?"MANUAL":!inGraph?"SAFE":detected?"AUTO":"LISTEN";
showText(el("mxHGuideStatus"),status);
el("mxHGuideStatus").dataset.state=status.toLowerCase();
if(el("mxHPreset").value!==preset)el("mxHPreset").value=preset;
Expand Down Expand Up @@ -362,6 +386,13 @@ function edit(patch){
noteButtons.forEach(b=>b.addEventListener("click",()=>
edit({key:Number(b.dataset.key),guideMode:0,guideChannelId:"0"})));
voiceButtons.forEach(b=>b.addEventListener("click",()=>edit({voices:Number(b.dataset.voices)})));
typeButtons.forEach(b=>b.addEventListener("click",()=>{
const nextMode=Number(b.dataset.voiceMode);
// Doubler follows the mic melody and must NEVER depend on a possibly
// disconnected Music Track. Retain key/scale but safely select Manual.
edit(nextMode===1?{voiceMode:1,guideMode:0,guideChannelId:"0"}:
{voiceMode:0});
}));
scaleButtons.forEach(b=>b.addEventListener("click",()=>
edit({scale:Number(b.dataset.scale),guideMode:0,guideChannelId:"0"})));
guideButtons.forEach(b=>b.addEventListener("click",()=>{
Expand Down
12 changes: 8 additions & 4 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2541,14 +2541,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
reply->setProperty("deviceEpoch",epoch);
reply->setProperty("graphRevision",revision);
reply->setProperty("instanceId",instanceId);
reply->setProperty("schemaVersion",2);
reply->setProperty("schemaVersion",3);
reply->setProperty("status",processor?"ACCEPTED":"REJECTED");
if(processor) {
const auto s=processor->acceptedSettings();
auto settings=std::make_unique<juce::DynamicObject>();
settings->setProperty("key",s.key);
settings->setProperty("scale",s.scale);
settings->setProperty("voices",s.voices);
settings->setProperty("voiceMode",s.voiceMode);
settings->setProperty("correction",s.correction);
settings->setProperty("wet",s.wet);
settings->setProperty("space",s.space);
Expand Down Expand Up @@ -3643,21 +3644,24 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
}
const auto v=args.getProperty("settings",{});
const auto k=v.getProperty("key",{}),sc=v.getProperty("scale",{});
const auto voices=v.getProperty("voices",{}),tune=v.getProperty("correction",{});
const auto voices=v.getProperty("voices",{}),mode=v.getProperty("voiceMode",{});
const auto tune=v.getProperty("correction",{});
auto num=[](const juce::var& value,float& output) {
if(!value.isDouble()&&!value.isInt())return false;
const auto x=static_cast<double>(value);
if(!std::isfinite(x))return false;
output=static_cast<float>(x);return std::isfinite(output);
};
armix::harmony::Settings settings{};
const bool typed=k.isInt()&&sc.isInt()&&voices.isInt()&&tune.isBool()&&
const bool typed=k.isInt()&&sc.isInt()&&voices.isInt()&&mode.isInt()&&tune.isBool()&&
num(v.getProperty("wet",{}),settings.wet)&&
num(v.getProperty("space",{}),settings.space)&&
num(v.getProperty("color",{}),settings.color)&&
num(v.getProperty("gainDb",{}),settings.gainDb);
settings.key=static_cast<int>(k);settings.scale=static_cast<int>(sc);
settings.voices=static_cast<int>(voices);settings.correction=static_cast<bool>(tune);
settings.voices=static_cast<int>(voices);
settings.voiceMode=static_cast<int>(mode);
settings.correction=static_cast<bool>(tune);
// Exact ChannelId is never parsed from a JS number. Validate
// against the currently admitted native graph, not a UI track
// index or a remembered localStorage name.
Expand Down
Loading
Loading