Explorar el Código

WIP vocal107: FL route levels on the fader curve, route-to-Master level, compressor auto gain for substitutes, scan timeout by class count

Ka1-S hace 1 mes
padre
commit
4a0cc8d9fa

+ 29 - 1
docs/analise/REA_rodada107.md

@@ -3,5 +3,33 @@
 User report: whenever the user's girlfriend opens one of her vocal projects in LYNX, the voice is much quieter than
 in FL Studio. Goal: find the cause, fix it generally, verify within ~0.5 dB of FL on the vocal sections.
 
+## 1. Her projects and her setup
+
+[DATA] The projects she opened in LYNX (LYNX `recentes.txt`): `kwe.flp` (FL 24.2.2), `luisa sonsa.flp` (FL 25.2.5),
+`game over.flp` (FL 25.2.5), each in its own folder with the beat stems and her vocal takes (`untitled_<date>_Insert
+N.wav`: 44.1 kHz stereo float, both channels identical, raw level about −20 dBFS RMS). Every vocal take goes to an
+insert with the same vocal chain (her "PRINCIPAL" preset): Auto-Tune Pro, Waves SSL E-Channel, NS1, Renaissance
+Compressor, DeEsser, CLA-2A, (Fresh Air), with sends to an FX insert (H-Delay, Doubler2, Reeverb 2, Filterverse,
+Stereo Enhancer, Decapitator). `luisa sonsa` uses UADx Neve 1073 / 1176 / LA-2A, Pro-Q 4, Pro-DS, Decapitator,
+ValhallaVintageVerb, Waves Tune and NS1 instead.
+
+[DATA] LYNX's plugin list on her laptop (`%APPDATA%\LYNX\plugins.xml`): 136 plugins, but the only Waves entries are
+"L4 Ultramaximizer" from `WaveShell1-VST3 16.3_x64.vst3`; `WaveShell1-VST3 16.0_x64.vst3` — the shell that holds her
+whole Waves bundle — is in the BLACKLISTED list. So none of the Waves plugins of her vocal chain could be hosted:
+LYNX played its substitutes (round 98) in their place, with the Waves settings not translated.
+
+## 2. Cause 1: a Waves shell is "hung" for LYNX's plugin scan
+
+[SRC JUCE 8.0.4, our own dependency] `VST3PluginFormat::findAllTypesForFile` has a fast path (the bundle's
+`moduleinfo.json`) and a slow path that creates and initialises every audio-effect class of the module's factory to
+read its bus layout. A Waves shell has no moduleinfo.json and declares one class per Waves plugin (hundreds for a
+bundle). LYNX scans each file in a child process and killed it after a fixed 30 s, then blacklisted the file as hung.
+
+Fix: the scan child first loads the module, asks its factory how many classes it has and writes that number next to
+its result file; the parent then waits `30 s + 2 s × (classes − 1)` (capped at 45 min) instead of 30 s
+(core/PluginScanPolicy.h). Files blacklisted by older versions are retried once (`scan-retry.txt` marker).
+
 ## Where I stopped / next steps
-- Started; collecting her vocal projects.
+- Waiting for her laptop (offline since ~14:25) to (a) time the WaveShell 16.0 scan, (b) render FL vs LYNX.
+- Export report now lists plugin_found / plugin_missing lines and each insert's chain (Main.cpp runExport).
+- renderwav: LYNX_SUBSTITUTES=1 / LYNX_DISABLE="t.k" for substitute experiments.

+ 17 - 0
src/Main.cpp

@@ -1485,6 +1485,23 @@ private:
             lynx::AudioEngine loader (false);
             const juce::File input (inputPath);
 
+            // --find-plugins: first the targeted scan opening the project in the app runs (its plugins not known yet)
+            if (input.hasFileExtension ("flp") && juce::JUCEApplication::getCommandLineParameters().contains ("--find-plugins"))
+            {
+                juce::MemoryBlock data;
+                if (input.loadFileAsData (data))
+                    try
+                    {
+                        const auto uses = lynx::flpForeignPlugins (flp::parseProject ({ static_cast<const std::uint8_t*> (data.getData()), data.getSize() }));
+                        auto& host = loader.getPluginHost();
+                        report << "scanned=" << host.filesToScanFor (uses).joinIntoString (";") << "\n";
+                        host.scanFiles (host.filesToScanFor (uses), {});
+                    }
+                    catch (const flp::Error&)
+                    {
+                    }
+            }
+
             if (input.hasFileExtension ("flp"))
                 ok = loader.importFlpFile (input, error);
             else if (auto song = lynx::ProjectFile::load (input, error))

+ 29 - 3
src/core/Effects.cpp

@@ -164,10 +164,21 @@ class Compressor final : public Effect
 {
 public:
     void prepare (double sr) noexcept override { sampleRate = sr; reset(); }
-    void reset() noexcept override { envelopeDb = 0.0f; }
+    void reset() noexcept override
+    {
+        envelopeDb = 0.0f;
+        inPower = outPower = 0.0f;
+        autoGain = 1.0f;
+    }
 
     void process (float* l, float* r, int n, const EffectParams& params, double) noexcept override
     {
+        // "Auto gain" (round 107): the long-term level stays where it was (slow in/out power match, ±12 dB), so the
+        // compressor shapes the dynamics without making the track quieter. Used where its settings are a guess (a
+        // substitute for a missing plugin, whose own makeup gain is unknown).
+        const auto levelMatch = params[5] >= 0.5f;
+        const auto powerCoeff = (float) std::exp (-1.0 / (1.5 * sampleRate));
+        const auto gainCoeff = (float) std::exp (-1.0 / (0.05 * sampleRate));
         const auto threshold = compThresholdDb (params[0]);
         const auto ratio = compRatio (params[1]);
         const auto attack = (float) std::exp (-1.0 / (compAttackMs (params[2]) * 0.001 * sampleRate));
@@ -192,7 +203,20 @@ public:
             if (envelopeDb < 1.0e-4f)
                 envelopeDb = 0.0f; // no audible reduction: skip the pow
 
-            const auto gain = envelopeDb > 0.0f ? dbToGain (-envelopeDb) * makeup : makeup;
+            auto gain = envelopeDb > 0.0f ? dbToGain (-envelopeDb) * makeup : makeup;
+
+            if (levelMatch)
+            {
+                const auto in = 0.5f * (l[i] * l[i] + r[i] * r[i]);
+                inPower = in + powerCoeff * (inPower - in);
+                const auto out = in * gain * gain;
+                outPower = out + powerCoeff * (outPower - out);
+                // follow only while there is signal (silence keeps the last match)
+                const auto target = inPower > 1.0e-8f && outPower > 1.0e-12f ? std::clamp (std::sqrt (inPower / outPower), 0.25f, 4.0f) : autoGain;
+                autoGain = target + gainCoeff * (autoGain - target);
+                gain *= autoGain;
+            }
+
             l[i] *= gain;
             r[i] *= gain;
         }
@@ -208,6 +232,7 @@ public:
 private:
     double sampleRate = 44100.0;
     float envelopeDb = 0.0f;
+    float inPower = 0.0f, outPower = 0.0f, autoGain = 1.0f;
     const float* sideL = nullptr;
     const float* sideR = nullptr;
     bool useSidechain = false;
@@ -2134,7 +2159,7 @@ std::string widthText (const EffectParams& params, int band)
 const EffectInfo& effectInfo (EffectKind kind)
 {
     static const EffectInfo eq { "EQ", { { "Low", 0.5f }, { "Mid", 0.5f }, { "Mid freq.", 0.5f }, { "High", 0.5f }, { "Output", 0.5f } } };
-    static const EffectInfo comp { "Compressor", { { "Threshold", 0.7f }, { "Ratio", 3.0f / 19.0f }, { "Attack", 0.67f }, { "Release", 0.54f }, { "Makeup", 0.0f } } };
+    static const EffectInfo comp { "Compressor", { { "Threshold", 0.7f }, { "Ratio", 3.0f / 19.0f }, { "Attack", 0.67f }, { "Release", 0.54f }, { "Makeup", 0.0f }, { "Auto gain", 0.0f } } };
     static const EffectInfo delay { "Delay", { { "Time", 0.3f }, { "Feedback", 0.42f }, { "Mix", 0.3f }, { "Ping-pong", 0.0f }, { "Damping", 0.3f } } };
     static const EffectInfo reverb { "Reverb", { { "Room", 0.6f }, { "Damping", 0.5f }, { "Width", 1.0f }, { "Mix", 0.25f }, { "Dry", 1.0f },
                                                  { "Low cut", 0.0f }, { "High cut", 1.0f }, { "Predelay", 0.0f } } };
@@ -2510,6 +2535,7 @@ std::string formatEffectParam (EffectKind kind, int param, float v, double bpm)
                 case 1: std::snprintf (text, sizeof (text), "%.1f:1", compRatio (v)); break;
                 case 2: std::snprintf (text, sizeof (text), "%.1f ms", compAttackMs (v)); break;
                 case 3: std::snprintf (text, sizeof (text), "%.0f ms", compReleaseMs (v)); break;
+                case 5: return v >= 0.5f ? "on" : "off";
                 default: std::snprintf (text, sizeof (text), "+%.1f dB", compMakeupDb (v)); break;
             }
             return text;

+ 7 - 3
src/core/FlpImport.cpp

@@ -2109,7 +2109,9 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
 
         auto& track = song.mixer[(std::size_t) t];
 
-        // FL ranges: volume 0..16000 (12800 = 0 dB), pan ±6400, send 0..16000 (12800 = 100%)
+        // FL ranges: volume 0..16000 (12800 = 0 dB), pan ±6400, route levels 0..16000 on the fader curve too
+        // (12800 = 0 dB, 16000 = +5.6 dB; destination 0 = the route to Master). REA_rodada107 §3: FL renders with
+        // a route level of 16000 / 12800 / 6400 differ by +5.6 / 0 / −12.7 dB, the fader curve's values.
         if (p == flp::ControlId::mixerVolume)
             track.volume = std::clamp (control.value / 16000.0f, 0.0f, 1.0f);
         else if (p == flp::ControlId::mixerPan)
@@ -2130,10 +2132,12 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             else
                 track.eq.width[band] = (float) std::clamp (v / 65536.0, 0.0, 1.0);
         }
-        else if (p >= flp::ControlId::mixerSendBase && p < flp::ControlId::mixerSendBase + tracks)
+        else if (p == flp::ControlId::mixerSendBase)
+            track.masterLevel = faderGain (control.value / 16000.0f);
+        else if (p > flp::ControlId::mixerSendBase && p < flp::ControlId::mixerSendBase + tracks)
             for (auto& send : track.sends)
                 if (send.target == p - flp::ControlId::mixerSendBase)
-                    send.level = std::clamp (control.value / 12800.0f, 0.0f, 1.0f);
+                    send.level = faderGain (control.value / 16000.0f);
     }
 
     // the FL template routes every insert to the send tracks at level 0; that makes no sound, only wastes CPU

+ 1 - 1
src/core/History.cpp

@@ -44,7 +44,7 @@ bool sameEffects (const MixerTrack& a, const MixerTrack& b) noexcept
 
 bool sameRouting (const MixerTrack& a, const MixerTrack& b) noexcept
 {
-    return a.sends == b.sends && a.toMaster == b.toMaster;
+    return a.sends == b.sends && a.toMaster == b.toMaster && a.masterLevel == b.masterLevel;
 }
 
 bool sameTrack (const MixerTrack& a, const MixerTrack& b) noexcept

+ 24 - 0
src/core/PluginScanPolicy.h

@@ -0,0 +1,24 @@
+#pragma once
+
+// How long the plugin scan waits for the child process that describes one plugin file (engine/PluginHost.cpp).
+// A plugin file can hold many plugins: a Waves "WaveShell" VST3 declares hundreds of classes, and describing each one
+// means creating and initialising it. A fixed 30 s limit blacklisted whole Waves bundles as "hung" (REA_rodada107 §2),
+// so every Waves plugin of a project fell back to a substitute. The child now reports how many classes the file has
+// before describing them, and the limit grows with that number.
+
+#include <algorithm>
+
+namespace lynx::scanpolicy
+{
+constexpr int baseTimeoutMs = 30000;          // a file with one plugin (or whose class count is not known)
+constexpr int perClassMs = 2000;              // each further class
+constexpr int maxTimeoutMs = 45 * 60 * 1000;  // never wait longer than this for one file
+
+constexpr int timeoutMs (int classes) noexcept
+{
+    if (classes <= 1)
+        return baseTimeoutMs;
+    const auto extra = (long long) (classes - 1) * perClassMs;
+    return (int) std::min<long long> ((long long) baseTimeoutMs + extra, maxTimeoutMs);
+}
+} // namespace lynx::scanpolicy

+ 5 - 1
src/core/PluginSubstitutes.cpp

@@ -141,9 +141,11 @@ product = Renaissance Compressor
 vendor = Waves
 lynx = Compressor
 # [DATA] class ID (stereo component) and <PluginName> from real projects; its RealWorld values are readable but
-# their meaning is not confirmed, so the default preset is used
+# their meaning is not confirmed, so the default preset is used, with auto gain: the substitute shapes the dynamics
+# but keeps the level (its makeup gain is unknown; round 107: without it her vocals came out 4 dB quieter)
 vst3 = 5554535643527253636f6d7072657373
 waves = RComp
+preset = Auto gain=1
 
 [waves-cla-2a]
 product = CLA-2A
@@ -160,12 +162,14 @@ product = Waves compressor (CLA-76 / CLA-3A / C1 / SSLComp / API-2500)
 vendor = Waves
 lynx = Compressor
 waves = CLA-76; CLA-3A; C1 comp; C1comp; SSLComp; API-2500
+preset = Auto gain=1
 
 [fabfilter-pro-c]
 product = FabFilter Pro-C
 vendor = FabFilter
 lynx = Compressor
 names = FabFilter Pro-C 2; FabFilter Pro-C 3; Pro-C 2; Pro-C 3
+preset = Auto gain=1
 
 # ---------------------------------------------------------------- EQs and channel strips -> Parametric EQ (flat)
 [waves-ssl-channel]

+ 1 - 1
src/core/RackRenderer.cpp

@@ -312,7 +312,7 @@ void RackState::buildMixerGraph()
             depth[(std::size_t) listener] = std::max (depth[(std::size_t) listener], depth[(std::size_t) t] + 1);
 
         if (track.toMaster)
-            mixerInputs[0].push_back ({ t, 0, 1.0f });
+            mixerInputs[0].push_back ({ t, 0, track.masterLevel });
 
         for (std::size_t k = 0; k < track.sends.size(); ++k)
         {

+ 10 - 2
src/core/Song.cpp

@@ -231,9 +231,9 @@ void Song::setRoute (int from, int to, bool enabled, float level)
     }
 
     if (it != t.sends.end())
-        it->level = std::clamp (level, 0.0f, 1.0f);
+        it->level = std::clamp (level, 0.0f, maxFaderGain);
     else if (canRoute (from, to))
-        t.sends.push_back ({ to, std::clamp (level, 0.0f, 1.0f) });
+        t.sends.push_back ({ to, std::clamp (level, 0.0f, maxFaderGain) });
 }
 
 std::vector<int> Song::mixerOrder() const
@@ -775,6 +775,13 @@ float faderGain (float position) noexcept
     return (std::pow (11.0f, v) - 1.0f) / 10.0f;
 }
 
+float faderPosition (float gain) noexcept
+{
+    if (! (gain > 0.0f))
+        return 0.0f;
+    return std::clamp ((float) (std::log (10.0 * (double) gain + 1.0) / std::log (11.0) / 1.25), 0.0f, 1.0f);
+}
+
 Song makeExportSong (const Song& song, bool wholeSong, std::int64_t tailTicks, std::int64_t& musicLength)
 {
     Song out = song;
@@ -851,6 +858,7 @@ int applyBounce (Song& song, int track, const std::string& samplePath, std::int6
     MixerTrack copy;
     copy.name = original.name + " (audio)";
     copy.toMaster = original.toMaster;
+    copy.masterLevel = original.masterLevel;
     copy.sends = original.sends;
     original.muted = true;
     song.mixer.push_back (copy);

+ 7 - 1
src/core/Song.h

@@ -20,6 +20,11 @@ constexpr float unityFader = 0.8f;    // fader position that gives 0 dB, as in F
 // FL mixer fader curve: g = (11^v - 1) / 10 with v = position * 1.25 (0 dB at 0.8;
 // +5.6 dB at maximum). docs/analise/REA_rodada2.md §2.2.
 float faderGain (float position) noexcept;
+// Its inverse: the fader position (0..1) that gives `gain` (0 for gain <= 0, 1 for maxFaderGain and above).
+float faderPosition (float gain) noexcept;
+// Gain at the top of the fader: +5.6 dB. FL's insert-to-insert and insert-to-Master route levels use the same curve
+// and range (0..16000, 12800 = 0 dB; REA_rodada107 §3), so a send can reach it too.
+constexpr float maxFaderGain = 1.9031f;
 
 // Channel volume with the same curve, but 1.0 = 0 dB (FL's default, 0.78, gives -5.2 dB).
 // docs/analise/REA_rodada3.md §2.
@@ -415,7 +420,7 @@ struct EffectSlot
 struct MixerSend
 {
     int target = 0;      // destination track (> 0; Master is `toMaster`)
-    float level = 1.0f;  // 0..1 (linear gain)
+    float level = 1.0f;  // linear gain, 0..maxFaderGain (FL's send knob: the fader curve, 0 dB at 80%, +5.6 dB at 100%)
 
     bool operator== (const MixerSend& o) const noexcept { return target == o.target && level == o.level; }
 };
@@ -456,6 +461,7 @@ struct MixerTrack
     bool solo = false;
     std::vector<EffectSlot> effects; // up to maxEffectSlots, processed in order
     bool toMaster = true;            // inserts: output to Master (besides the sends)
+    float masterLevel = 1.0f;        // level of that route to Master (linear gain, 0..maxFaderGain; FL's route knob)
     float stereo = 0.0f;             // separation: -1 = widest, 0 = normal, +1 = mono (as in FL)
     std::uint32_t colour = 0;        // 0xFFRRGGBB; 0 = theme default
     bool invertPhase = false;

+ 80 - 3
src/engine/PluginHost.cpp

@@ -1,6 +1,7 @@
 #include "engine/PluginHost.h"
 
 #include "core/Preferences.h"
+#include "core/PluginScanPolicy.h"
 
 #include "core/FlWrapper.h"
 
@@ -228,6 +229,18 @@ PluginHost::PluginHost (bool keep)
         if (auto xml = juce::XmlDocument::parse (settingsFolder().getChildFile ("plugins.xml")))
             known.recreateFromXml (*xml);
         favouriteIds = prefs::parseFavourites (settingsFolder().getChildFile ("plugin-favourites.txt").loadFileAsString().toStdString());
+        // once: files marked as failed by scans before the class-count timeout (REA_rodada107 §2) get another try,
+        // since a large bundle (Waves shell) was marked "hung" only for taking longer than 30 s
+        const auto retried = settingsFolder().getChildFile ("scan-retry.txt");
+        if (retried.loadFileAsString().getIntValue() < 1)
+        {
+            if (! known.getBlacklistedFiles().isEmpty())
+            {
+                known.clearBlacklistedFiles();
+                save();
+            }
+            retried.replaceWithText ("1\n");
+        }
     }
 }
 
@@ -325,6 +338,52 @@ void PluginHost::save()
         xml->writeTo (settingsFolder().getChildFile ("plugins.xml"));
 }
 
+namespace
+{
+// Child side of the scan: how many classes a VST3 module's factory declares (0 = unknown). The module stays loaded
+// (and initialised) for the description that follows, which loads the same module again. Windows only for now.
+int countVst3Classes (const juce::String& path)
+{
+   #if JUCE_WINDOWS
+    juce::File binary (path);
+    if (binary.isDirectory()) // bundle: Contents/x86_64-win/<name>.vst3
+        binary = binary.getChildFile ("Contents").getChildFile ("x86_64-win").getChildFile (binary.getFileName());
+    if (! binary.existsAsFile())
+        return 0;
+    // the leading part of IPluginFactory's vtable (FUnknown, then getFactoryInfo, countClasses)
+    struct Factory
+    {
+        virtual int queryInterface (const char*, void**) = 0;
+        virtual unsigned addRef() = 0;
+        virtual unsigned release() = 0;
+        virtual int getFactoryInfo (void*) = 0;
+        virtual int countClasses() = 0;
+    };
+    static juce::DynamicLibrary module; // kept open until the child exits
+    if (! module.open (binary.getFullPathName()))
+        return 0;
+    if (auto* init = (bool (*)()) module.getFunction ("InitDll"))
+        if (! init())
+            return 0;
+    auto* get = (Factory* (*)()) module.getFunction ("GetPluginFactory");
+    auto* factory = get != nullptr ? get() : nullptr;
+    if (factory == nullptr)
+        return 0;
+    const auto classes = factory->countClasses();
+    factory->release();
+    return juce::jmax (0, classes);
+   #else
+    juce::ignoreUnused (path);
+    return 0;
+   #endif
+}
+
+juce::File classCountFile (const juce::File& result)
+{
+    return result.withFileExtension ("classes");
+}
+} // namespace
+
 bool PluginHost::scanOne (juce::AudioPluginFormat& format, const juce::String& file)
 {
     // a result file of our own: several LYNX processes (and scans) may run at once
@@ -335,16 +394,27 @@ bool PluginHost::scanOne (juce::AudioPluginFormat& format, const juce::String& f
     auto ok = child.start (juce::StringArray { exe.getFullPathName(), "--scan-one", format.getName(), file, result.getFullPathName() }, 0);
     if (ok)
     {
-        // wait in short steps so a cancelled scan (or LYNX closing) doesn't wait for a slow plugin
-        const auto deadline = juce::Time::getMillisecondCounter() + (juce::uint32) scanTimeoutMs;
-        while (child.isRunning() && ! stopScan && juce::Time::getMillisecondCounter() < deadline)
+        // wait in short steps so a cancelled scan (or LYNX closing) doesn't wait for a slow plugin; a file holding
+        // many plugins (Waves shell) gets more time once the child has said how many (core/PluginScanPolicy.h)
+        const auto started = juce::Time::getMillisecondCounter();
+        auto timeout = (juce::uint32) scanpolicy::baseTimeoutMs;
+        auto classesKnown = false;
+        while (child.isRunning() && ! stopScan && juce::Time::getMillisecondCounter() - started < timeout)
+        {
             child.waitForProcessToFinish (100);
+            if (! classesKnown && classCountFile (result).existsAsFile())
+            {
+                classesKnown = true;
+                timeout = (juce::uint32) scanpolicy::timeoutMs (classCountFile (result).loadFileAsString().getIntValue());
+            }
+        }
         if (child.isRunning())
         {
             child.kill();
             if (stopScan) // not the plugin's fault: try it again next time
             {
                 result.deleteFile();
+                classCountFile (result).deleteFile();
                 return false;
             }
             ok = false; // hung: blacklist
@@ -363,6 +433,7 @@ bool PluginHost::scanOne (juce::AudioPluginFormat& format, const juce::String& f
     else if (! ok)
         known.addToBlacklist (file);
     result.deleteFile();
+    classCountFile (result).deleteFile();
     return true;
 }
 
@@ -473,8 +544,14 @@ void PluginHost::cancelBackgroundScan()
     }
 }
 
+
 int PluginHost::scanOneFile (const juce::String& formatName, const juce::String& file, const juce::File& output)
 {
+    // first tell the parent how many plugins this file holds, so it waits long enough for a large bundle
+    if (formatName == "VST3")
+        if (const auto classes = countVst3Classes (file); classes > 1)
+            classCountFile (output).replaceWithText (juce::String (classes));
+
     juce::AudioPluginFormatManager manager;
     addPluginFormats (manager);
     juce::OwnedArray<juce::PluginDescription> found;

+ 1 - 1
src/engine/PluginHost.h

@@ -127,7 +127,7 @@ public:
     // Scan child mode: describes a file's plugins into `output` (XML). Returns the number found.
     static int scanOneFile (const juce::String& formatName, const juce::String& file, const juce::File& output);
 
-    static constexpr int scanTimeoutMs = 30000;
+    // (the parent waits core/PluginScanPolicy.h's time for each file; the child first reports a VST3's class count)
 
     // Adds a specific file (e.g. a .vst3 outside the default folders).
     int addPluginFile (const juce::File& file);

+ 4 - 1
src/engine/ProjectFile.cpp

@@ -866,6 +866,8 @@ juce::String toJson (const Song& song)
 
         if (! t.toMaster)
             o->setProperty ("toMaster", false);
+        if (t.masterLevel != 1.0f)
+            o->setProperty ("masterLevel", juce::roundToInt (t.masterLevel * 10000.0f) / 10000.0);
         if (t.colour != 0)
             o->setProperty ("colour", juce::String::toHexString ((juce::int64) (t.colour & 0xFFFFFF)).paddedLeft ('0', 6));
         if (t.stereo != 0.0f)
@@ -1331,6 +1333,7 @@ std::optional<Song> fromJson (const juce::String& json, juce::String& error)
             track.muted = (bool) t.getProperty ("muted", false);
             track.solo = (bool) t.getProperty ("solo", false);
             track.toMaster = (bool) t.getProperty ("toMaster", true);
+            track.masterLevel = juce::jlimit (0.0f, maxFaderGain, (float) (double) t.getProperty ("masterLevel", 1.0));
             track.stereo = juce::jlimit (-1.0f, 1.0f, (float) (double) t.getProperty ("stereo", 0.0));
 
             if (t.hasProperty ("colour"))
@@ -1352,7 +1355,7 @@ std::optional<Song> fromJson (const juce::String& json, juce::String& error)
             if (auto* sends = t["sends"].getArray())
                 for (const auto& send : *sends)
                     if (send.isArray() && send.size() == 2)
-                        track.sends.push_back ({ (int) send[0], juce::jlimit (0.0f, 1.0f, (float) (double) send[1]) });
+                        track.sends.push_back ({ (int) send[0], juce::jlimit (0.0f, maxFaderGain, (float) (double) send[1]) });
 
             if (auto* effects = t["effects"].getArray())
                 for (const auto& e : *effects)

+ 6 - 5
src/ui/MixerComponent.cpp

@@ -90,7 +90,8 @@ ui::ValueSpec stereoSpec (const juce::String& name)
 
 ui::ValueSpec sendSpec (const juce::String& name)
 {
-    auto spec = ui::percentSpec (name, 1.0);
+    // FL's send knob: the fader curve (0 dB at 80 %, +5.6 dB at the top); the value is the knob position
+    auto spec = ui::faderSpec (name, unityFader);
     spec.pixelsForRange = 120.0;
     return spec;
 }
@@ -547,7 +548,7 @@ void MixerStrips::paint (juce::Graphics& g)
                 if (on && t > 0)
                     for (const auto& send : song.mixer[(std::size_t) selected].sends)
                         if (send.target == t)
-                            drawKnob (g, sendArea (t).toFloat().withSizeKeepingCentre (22.0f, 22.0f), send.level, false,
+                            drawKnob (g, sendArea (t).toFloat().withSizeKeepingCentre (22.0f, 22.0f), faderPosition (send.level), false,
                                       dragging (Part::send) ? colour::accent : colour::accentHover, hovered (Part::send) || dragging (Part::send));
             }
             else if (feedsSelected) // this insert sends into the selected one
@@ -689,7 +690,7 @@ void MixerStrips::mouseDown (const juce::MouseEvent& e)
 
         if (ui::isResetClick (e))
         {
-            setValue (Part::send, t, 1.0);
+            setValue (Part::send, t, unityFader); // 0 dB
             showTip (Part::send, t, true);
             return;
         }
@@ -913,7 +914,7 @@ double MixerStrips::valueOf (Part part, int t) const
         if (selected > 0 && selected < (int) song.mixer.size())
             for (const auto& send : song.mixer[(std::size_t) selected].sends)
                 if (send.target == t)
-                    return send.level;
+                    return faderPosition (send.level);
         return 0.0;
     }
 
@@ -928,7 +929,7 @@ void MixerStrips::setValue (Part part, int t, double value)
     if (part == Part::send)
     {
         const auto from = selected;
-        engine.editSong ([from, t, v = (float) value] (Song& s) { s.setRoute (from, t, true, v); });
+        engine.editSong ([from, t, v = faderGain ((float) value)] (Song& s) { s.setRoute (from, t, true, v); });
         return;
     }
 

+ 150 - 0
tests/VocalLevel107Tests.inc

@@ -0,0 +1,150 @@
+// --- round 107: vocals quieter than in FL (a Waves shell blacklisted by the plugin scan) -----------------------------
+
+#include "core/PluginScanPolicy.h"
+#include "core/PluginSubstitutes.h"
+
+TEST (plugin_scan_waits_longer_for_files_with_many_plugins)
+{
+    using namespace lynx::scanpolicy;
+    // one plugin (or an unknown count): the old 30 s
+    CHECK (timeoutMs (0) == 30000);
+    CHECK (timeoutMs (1) == 30000);
+    // a Waves shell (hundreds of classes, each created and initialised to be described) gets minutes, not 30 s
+    CHECK (timeoutMs (2) == 32000);
+    CHECK (timeoutMs (400) == 30000 + 399 * 2000);
+    CHECK (timeoutMs (400) > 10 * 60 * 1000);
+    // never unbounded
+    CHECK (timeoutMs (100000) == maxTimeoutMs);
+    CHECK (timeoutMs (1 << 30) == maxTimeoutMs);
+}
+
+namespace vocal107
+{
+// a project with Master, insert 1 → insert 2 → Master, and FL's route levels for both routes (0xE1)
+lynx::Song importRoutes (std::int32_t sendLevel, std::int32_t masterLevel)
+{
+    FlpBuilder b (96);
+    b.ascii (0xC7, "24.2.2.4646");
+    auto insert = [&b] (std::vector<std::uint8_t> routes) {
+        std::vector<std::uint8_t> params (12, 0);
+        params[4] = 0x08; // enabled
+        b.data (0xEC, params);
+        routes.resize (127, 0);
+        b.data (0xEB, routes);
+    };
+    insert ({});
+    insert ({ 0, 0, 1 });  // insert 1 → insert 2 only
+    insert ({ 1 });        // insert 2 → Master
+    std::vector<std::uint8_t> controls;
+    auto control = [&controls] (std::uint32_t id, std::int32_t value) {
+        for (auto v : { 0u, id, (std::uint32_t) value })
+            for (int k = 0; k < 4; ++k)
+                controls.push_back ((std::uint8_t) (v >> (8 * k)));
+    };
+    // FL 24.2 stores the mixer class as 0x2…, routes at 0x1F40 + destination (normalised on load)
+    control (0x20000000u + (1u << 22) + 0x1F40u + 2u, sendLevel);
+    control (0x20000000u + (2u << 22) + 0x1F40u, masterLevel);
+    b.data (0xE1, controls);
+    return lynx::importFlp (flp::parseProject (b.bytes));
+}
+} // namespace vocal107
+
+TEST (flp_route_levels_use_the_fader_curve_and_reach_plus_5_6_db)
+{
+    // REA_rodada107 §3 [EXEC]: FL renders of the user's song with the vocal route at 16000 / 12800 / 6400 differ by
+    // +5.6 / 0 / −12.7 dB, and the route to Master counts the same way. LYNX read 16000 as 100 % (0 dB) and 6400 as
+    // 50 % (−6 dB): her vocals, routed insert → FX insert → Master at 16000 each, came out 11 dB quieter than in FL.
+    auto db = [] (float g) { return 20.0f * std::log10 (g); };
+    const auto full = vocal107::importRoutes (16000, 16000);
+    CHECK (full.mixer.size() > 2 && full.mixer[1].sends.size() == 1 && full.mixer[1].sends[0].target == 2);
+    CHECK (! full.mixer[1].toMaster && full.mixer[2].toMaster);
+    CHECK (std::abs (db (full.mixer[1].sends[0].level) - 5.59f) < 0.02f);
+    CHECK (std::abs (db (full.mixer[2].masterLevel) - 5.59f) < 0.02f);
+    CHECK (std::abs (full.mixer[1].sends[0].level - lynx::maxFaderGain) < 1e-3f);
+
+    const auto unity = vocal107::importRoutes (12800, 12800);
+    CHECK (std::abs (unity.mixer[1].sends[0].level - 1.0f) < 1e-5f && std::abs (unity.mixer[2].masterLevel - 1.0f) < 1e-5f);
+
+    const auto low = vocal107::importRoutes (6400, 6400);
+    CHECK (std::abs (db (low.mixer[1].sends[0].level) - (-12.7f)) < 0.05f);
+    CHECK (std::abs (db (low.mixer[2].masterLevel) - (-12.7f)) < 0.05f);
+
+    // no level record: the route plays at 0 dB
+    const auto none = lynx::Song::defaultMixer (3);
+    CHECK (none[1].masterLevel == 1.0f);
+}
+
+TEST (mixer_route_to_master_level_and_hot_sends_are_rendered)
+{
+    // two channels of 0.5 DC on inserts 1 and 2 → 1.0 on Master; the route levels scale each path
+    CHECK (std::abs (renderMixerCase ([] (lynx::Song& s) { s.mixer[1].masterLevel = 0.5f; }) - 0.75f) < 1e-4f);
+    // insert 1 → insert 3 at +5.6 dB (FL's top), insert 1 not to Master
+    CHECK (std::abs (renderMixerCase ([] (lynx::Song& s) {
+                         s.setRoute (1, 3, true, lynx::maxFaderGain);
+                         s.setRoute (1, 0, false);
+                     }) - (0.5f + 0.5f * lynx::maxFaderGain)) < 1e-3f);
+    // the old 0..1 clamp is gone, but a send never exceeds the fader's top
+    lynx::Song s;
+    s.mixer = lynx::Song::defaultMixer (4);
+    s.setRoute (1, 2, true, 5.0f);
+    CHECK (s.mixer[1].sends.size() == 1 && std::abs (s.mixer[1].sends[0].level - lynx::maxFaderGain) < 1e-6f);
+}
+
+TEST (fader_position_inverts_fader_gain)
+{
+    for (float p : { 0.05f, 0.25f, 0.5f, 0.8f, 0.95f, 1.0f })
+        CHECK (std::abs (lynx::faderPosition (lynx::faderGain (p)) - p) < 1e-4f);
+    CHECK (lynx::faderPosition (0.0f) == 0.0f && lynx::faderPosition (-1.0f) == 0.0f);
+    CHECK (std::abs (lynx::faderPosition (1.0f) - lynx::unityFader) < 1e-5f);
+    CHECK (lynx::faderPosition (10.0f) == 1.0f);
+    CHECK (std::abs (lynx::faderGain (1.0f) - lynx::maxFaderGain) < 1e-3f);
+}
+
+TEST (compressor_auto_gain_keeps_the_long_term_level)
+{
+    // a vocal-like signal (a 220 Hz tone with a slow 2 Hz swell, peaks near −6 dBFS) through LYNX's Compressor at its
+    // defaults (−18 dB, 4:1, no makeup): quieter; with "Auto gain" the level after a few seconds is the input's
+    auto run = [] (bool autoGain) {
+        auto fx = lynx::makeEffect (lynx::EffectKind::compressor);
+        auto slot = lynx::makeEffectSlot (lynx::EffectKind::compressor);
+        slot.params[5] = autoGain ? 1.0f : 0.0f;
+        fx->prepare (48000.0);
+        double in = 0.0, out = 0.0;
+        std::vector<float> l (480), r (480);
+        for (int block = 0; block < 1000; ++block) // 10 s
+        {
+            for (int i = 0; i < 480; ++i)
+            {
+                const auto t = (block * 480 + i) / 48000.0;
+                l[(std::size_t) i] = r[(std::size_t) i] = (float) (0.5 * (0.6 + 0.4 * std::sin (2.0 * 3.14159265 * 2.0 * t)) * std::sin (2.0 * 3.14159265 * 220.0 * t));
+            }
+            if (block >= 600)
+                for (auto v : l)
+                    in += (double) v * v;
+            fx->process (l.data(), r.data(), 480, slot.params, 0.0);
+            if (block >= 600)
+                for (auto v : l)
+                    out += (double) v * v;
+        }
+        return 10.0 * std::log10 (out / in);
+    };
+    const auto plain = run (false), matched = run (true);
+    std::printf ("  compressor: %.2f dB without auto gain, %.2f dB with\n", plain, matched);
+    CHECK (plain < -2.0);
+    CHECK (std::abs (matched) < 0.5);
+}
+
+TEST (compressor_substitutes_keep_the_level)
+{
+    // Renaissance Compressor (missing on the user's laptop, in FL too): the substitute shapes dynamics with auto gain
+    lynx::PluginIdentity id;
+    id.format = lynx::ForeignPlugin::Format::vst3;
+    id.hasClassId = true;
+    const char* hex = "5554535643527253636f6d7072657373";
+    for (int i = 0; i < 16; ++i)
+        id.classId[(std::size_t) i] = (std::uint8_t) std::stoi (std::string (hex + 2 * i, 2), nullptr, 16);
+    lynx::EffectSlot slot;
+    slot.kind = lynx::EffectKind::plugin;
+    CHECK (lynx::substituteEffectSlot (slot, id));
+    CHECK (slot.kind == lynx::EffectKind::compressor && slot.params[5] >= 0.5f);
+}

+ 1 - 0
tests/tests.cpp

@@ -15473,3 +15473,4 @@ TEST (plugin_layout_options_match_the_engine_values)
 }
 #include "FabMeasureTests99.inc"
 #include "LynxTuneTests95.inc"
+#include "VocalLevel107Tests.inc"

+ 23 - 0
tools/renderwav.cpp

@@ -20,6 +20,7 @@
 #include <algorithm>
 #include <filesystem>
 #include <map>
+#include <sstream>
 #include <string>
 #include <chrono>
 #include <thread>
@@ -33,6 +34,7 @@
 
 #include "WavReader.h"
 #include "core/FlpImport.h"
+#include "core/PluginSubstitutes.h"
 #include "core/RackRenderer.h"
 #include "core/WorkerPool.h"
 
@@ -132,6 +134,27 @@ int main (int argc, char** argv)
         return 1;
     }
 
+    // LYNX_SUBSTITUTES=1: third-party effects become their LYNX substitutes, as in the app when none is installed
+    // (otherwise they stay unresolved, i.e. silent pass-through); LYNX_DISABLE="t.k t.k": those insert slots off
+    if (const char* e = std::getenv ("LYNX_SUBSTITUTES"); e != nullptr && std::atoi (e) != 0)
+        for (std::size_t t = 0; t < song.mixer.size(); ++t)
+            for (auto& fx : song.mixer[t].effects)
+                if (fx.kind == lynx::EffectKind::plugin && fx.plugin.foreign.format != lynx::ForeignPlugin::Format::none
+                    && lynx::substituteEffectSlot (fx, lynx::pluginIdentity (fx.plugin.foreign)))
+                    std::printf ("insert %d: %s -> %s\n", (int) t, lynx::substituteOriginalName (fx).c_str(), lynx::effectInfo (fx.kind).name);
+    if (const char* e = std::getenv ("LYNX_DISABLE"))
+    {
+        std::istringstream list (e);
+        std::string item;
+        while (list >> item)
+            if (const auto dot = item.find ('.'); dot != std::string::npos)
+            {
+                const auto t = (std::size_t) std::atoi (item.substr (0, dot).c_str()), k = (std::size_t) std::atoi (item.substr (dot + 1).c_str());
+                if (t < song.mixer.size() && k < song.mixer[t].effects.size())
+                    song.mixer[t].effects[k].enabled = false;
+            }
+    }
+
     // "song" instead of the index: the whole song (playlist), like the app's export
     const bool wholeSong = argc > 3 && std::string (argv[3]) == "song";
     std::int64_t songTicks = 0;