Просмотр исходного кода

Plugin windows: FL's wrapper header and Wrapper settings page (processing, bridging, MIDI port, plugin info) (REA round 146a)

Ka1-S 1 месяц назад
Родитель
Сommit
cbc178dde8

+ 19 - 0
resources/i18n/pt-BR.txt

@@ -3889,3 +3889,22 @@ countries: br
 "Consolidating track..." = "Consolidando a trilha..."
 "(Audio track, linked to mixer track {0})" = "(Trilha de áudio, ligada à trilha {0} do mixer)"
 "(Instrument track)" = "(Trilha de instrumento)"
+"Bridging" = "Ponte (processo separado)"
+"Input port" = "Porta de entrada"
+"Latency" = "Latência"
+"Inputs / outputs" = "Entradas / saídas"
+"Parameters" = "Parâmetros"
+"instrument" = "instrumento"
+"Wrapper settings" = "Configurações do wrapper"
+"Use fixed size buffers" = "Usar buffers de tamanho fixo"
+"Process maximum size buffers" = "Processar buffers de tamanho máximo"
+"Make bridged" = "Rodar em ponte (processo separado)"
+"MIDI input port number" = "Número da porta de entrada MIDI"
+"The plugin's own editor" = "O editor do próprio plugin"
+"Plugin wrapper settings: processing, bridging and MIDI options" = "Configurações do wrapper do plugin: processamento, ponte e opções MIDI"
+"Constant 2 ms blocks, for plugins that need equal buffers (adds latency)" = "Blocos constantes de 2 ms, para plugins que precisam de buffers iguais (adiciona latência)"
+"With fixed size buffers: the whole device buffer instead of 2 ms blocks" = "Com buffers de tamanho fixo: o buffer inteiro do dispositivo em vez de blocos de 2 ms"
+"With fixed size buffers: prepare the plugin for the host's largest block" = "Com buffers de tamanho fixo: prepara o plugin para o maior bloco do host"
+"Allow the plugin to be multi-threaded (off: always on the audio thread)" = "Permite processar o plugin em várias threads (desligado: sempre na thread de áudio)"
+"Allow smart disable for the plugin (off: it is always processed)" = "Permite o smart disable do plugin (desligado: ele é sempre processado)"
+"Load the plugin in a separate process (bridged)" = "Carrega o plugin em um processo separado (ponte)"

+ 13 - 0
src/core/FlWrapper.cpp

@@ -329,4 +329,17 @@ std::vector<std::uint8_t> writeFlVst2State (const FlVst2State& s)
     }
     return out;
 }
+
+const std::vector<WrapperOption>& wrapperOptions()
+{
+    static const std::vector<WrapperOption> options = {
+        { "Processing", "Use fixed size buffers", "Constant 2 ms blocks, for plugins that need equal buffers (adds latency)", &PluginRef::fixedBuffers, true, false },
+        { "Processing", "Process maximum size buffers", "With fixed size buffers: the whole device buffer instead of 2 ms blocks", &PluginRef::maxSizeBuffers, true, true },
+        { "Processing", "Use maximum buffer size from host", "With fixed size buffers: prepare the plugin for the host's largest block", &PluginRef::hostMaxBuffer, true, true },
+        { "Processing", "Allow threaded processing", "Allow the plugin to be multi-threaded (off: always on the audio thread)", &PluginRef::threaded, false, false },
+        { "Processing", "Allow smart disable", "Allow smart disable for the plugin (off: it is always processed)", &PluginRef::allowSmartDisable, false, false },
+        { "Bridging", "Make bridged", "Load the plugin in a separate process (bridged)", &PluginRef::separateProcess, true, false },
+    };
+    return options;
+}
 } // namespace lynx

+ 15 - 0
src/core/FlWrapper.h

@@ -56,4 +56,19 @@ struct FlVst2State
 bool parseFlVst2State (const std::vector<std::uint8_t>& state, FlVst2State& out);
 // Writes the current (−9) layout; parseFlVst2State reads it back.
 std::vector<std::uint8_t> writeFlVst2State (const FlVst2State& state);
+
+// FL's plugin wrapper settings page (the wrapper's gear tab; REA round 146a: option names and hints from FLEngine's
+// string pool, e.g. "Use fixed size buffers", "|Allow plugin to be multi-threaded by FL Studio",
+// "|Load plugin in separate process (bridged)", "|MIDI input port number"): the options LYNX applies, in FL's
+// sections. `recreates`: changing it re-creates the plugin (its state kept); `needsFixed`: only with fixed buffers.
+struct WrapperOption
+{
+    const char* section;
+    const char* label;
+    const char* hint;
+    bool PluginRef::* member;
+    bool recreates;
+    bool needsFixed;
+};
+const std::vector<WrapperOption>& wrapperOptions();
 } // namespace lynx

+ 4 - 1
src/ui/ChannelRackComponent.cpp

@@ -2200,7 +2200,10 @@ void ChannelRackComponent::openPluginWindow (int channel)
             return;
         }
         PluginWindows::open (instrument, plugin->getInstance(),
-                             juce::String::fromUTF8 (engine.getSong().channels[(std::size_t) channel].name.c_str()));
+                             juce::String::fromUTF8 (engine.getSong().channels[(std::size_t) channel].name.c_str()),
+                             { &engine, [channel] (Song& song) -> PluginRef* {
+                                  return channel < (int) song.channels.size() ? &song.channels[(std::size_t) channel].plugin : nullptr;
+                              } });
         return;
     }
 

+ 68 - 1
src/ui/I18nData.h

@@ -10909,6 +10909,73 @@ inline constexpr unsigned char ptBR[] = {
 161, 117, 100, 105, 111, 44, 32, 108, 105, 103, 97, 100, 97, 32, 195, 160, 32, 116, 114, 105, 108, 104, 97, 32,
 123, 48, 125, 32, 100, 111, 32, 109, 105, 120, 101, 114, 41, 34, 10, 34, 40, 73, 110, 115, 116, 114, 117, 109,
 101, 110, 116, 32, 116, 114, 97, 99, 107, 41, 34, 32, 61, 32, 34, 40, 84, 114, 105, 108, 104, 97, 32, 100,
-101, 32, 105, 110, 115, 116, 114, 117, 109, 101, 110, 116, 111, 41, 34, 10,
+101, 32, 105, 110, 115, 116, 114, 117, 109, 101, 110, 116, 111, 41, 34, 10, 34, 66, 114, 105, 100, 103, 105, 110,
+103, 34, 32, 61, 32, 34, 80, 111, 110, 116, 101, 32, 40, 112, 114, 111, 99, 101, 115, 115, 111, 32, 115, 101,
+112, 97, 114, 97, 100, 111, 41, 34, 10, 34, 73, 110, 112, 117, 116, 32, 112, 111, 114, 116, 34, 32, 61, 32,
+34, 80, 111, 114, 116, 97, 32, 100, 101, 32, 101, 110, 116, 114, 97, 100, 97, 34, 10, 34, 76, 97, 116, 101,
+110, 99, 121, 34, 32, 61, 32, 34, 76, 97, 116, 195, 170, 110, 99, 105, 97, 34, 10, 34, 73, 110, 112, 117,
+116, 115, 32, 47, 32, 111, 117, 116, 112, 117, 116, 115, 34, 32, 61, 32, 34, 69, 110, 116, 114, 97, 100, 97,
+115, 32, 47, 32, 115, 97, 195, 173, 100, 97, 115, 34, 10, 34, 80, 97, 114, 97, 109, 101, 116, 101, 114, 115,
+34, 32, 61, 32, 34, 80, 97, 114, 195, 162, 109, 101, 116, 114, 111, 115, 34, 10, 34, 105, 110, 115, 116, 114,
+117, 109, 101, 110, 116, 34, 32, 61, 32, 34, 105, 110, 115, 116, 114, 117, 109, 101, 110, 116, 111, 34, 10, 34,
+87, 114, 97, 112, 112, 101, 114, 32, 115, 101, 116, 116, 105, 110, 103, 115, 34, 32, 61, 32, 34, 67, 111, 110,
+102, 105, 103, 117, 114, 97, 195, 167, 195, 181, 101, 115, 32, 100, 111, 32, 119, 114, 97, 112, 112, 101, 114, 34,
+10, 34, 85, 115, 101, 32, 102, 105, 120, 101, 100, 32, 115, 105, 122, 101, 32, 98, 117, 102, 102, 101, 114, 115,
+34, 32, 61, 32, 34, 85, 115, 97, 114, 32, 98, 117, 102, 102, 101, 114, 115, 32, 100, 101, 32, 116, 97, 109,
+97, 110, 104, 111, 32, 102, 105, 120, 111, 34, 10, 34, 80, 114, 111, 99, 101, 115, 115, 32, 109, 97, 120, 105,
+109, 117, 109, 32, 115, 105, 122, 101, 32, 98, 117, 102, 102, 101, 114, 115, 34, 32, 61, 32, 34, 80, 114, 111,
+99, 101, 115, 115, 97, 114, 32, 98, 117, 102, 102, 101, 114, 115, 32, 100, 101, 32, 116, 97, 109, 97, 110, 104,
+111, 32, 109, 195, 161, 120, 105, 109, 111, 34, 10, 34, 77, 97, 107, 101, 32, 98, 114, 105, 100, 103, 101, 100,
+34, 32, 61, 32, 34, 82, 111, 100, 97, 114, 32, 101, 109, 32, 112, 111, 110, 116, 101, 32, 40, 112, 114, 111,
+99, 101, 115, 115, 111, 32, 115, 101, 112, 97, 114, 97, 100, 111, 41, 34, 10, 34, 77, 73, 68, 73, 32, 105,
+110, 112, 117, 116, 32, 112, 111, 114, 116, 32, 110, 117, 109, 98, 101, 114, 34, 32, 61, 32, 34, 78, 195, 186,
+109, 101, 114, 111, 32, 100, 97, 32, 112, 111, 114, 116, 97, 32, 100, 101, 32, 101, 110, 116, 114, 97, 100, 97,
+32, 77, 73, 68, 73, 34, 10, 34, 84, 104, 101, 32, 112, 108, 117, 103, 105, 110, 39, 115, 32, 111, 119, 110,
+32, 101, 100, 105, 116, 111, 114, 34, 32, 61, 32, 34, 79, 32, 101, 100, 105, 116, 111, 114, 32, 100, 111, 32,
+112, 114, 195, 179, 112, 114, 105, 111, 32, 112, 108, 117, 103, 105, 110, 34, 10, 34, 80, 108, 117, 103, 105, 110,
+32, 119, 114, 97, 112, 112, 101, 114, 32, 115, 101, 116, 116, 105, 110, 103, 115, 58, 32, 112, 114, 111, 99, 101,
+115, 115, 105, 110, 103, 44, 32, 98, 114, 105, 100, 103, 105, 110, 103, 32, 97, 110, 100, 32, 77, 73, 68, 73,
+32, 111, 112, 116, 105, 111, 110, 115, 34, 32, 61, 32, 34, 67, 111, 110, 102, 105, 103, 117, 114, 97, 195, 167,
+195, 181, 101, 115, 32, 100, 111, 32, 119, 114, 97, 112, 112, 101, 114, 32, 100, 111, 32, 112, 108, 117, 103, 105,
+110, 58, 32, 112, 114, 111, 99, 101, 115, 115, 97, 109, 101, 110, 116, 111, 44, 32, 112, 111, 110, 116, 101, 32,
+101, 32, 111, 112, 195, 167, 195, 181, 101, 115, 32, 77, 73, 68, 73, 34, 10, 34, 67, 111, 110, 115, 116, 97,
+110, 116, 32, 50, 32, 109, 115, 32, 98, 108, 111, 99, 107, 115, 44, 32, 102, 111, 114, 32, 112, 108, 117, 103,
+105, 110, 115, 32, 116, 104, 97, 116, 32, 110, 101, 101, 100, 32, 101, 113, 117, 97, 108, 32, 98, 117, 102, 102,
+101, 114, 115, 32, 40, 97, 100, 100, 115, 32, 108, 97, 116, 101, 110, 99, 121, 41, 34, 32, 61, 32, 34, 66,
+108, 111, 99, 111, 115, 32, 99, 111, 110, 115, 116, 97, 110, 116, 101, 115, 32, 100, 101, 32, 50, 32, 109, 115,
+44, 32, 112, 97, 114, 97, 32, 112, 108, 117, 103, 105, 110, 115, 32, 113, 117, 101, 32, 112, 114, 101, 99, 105,
+115, 97, 109, 32, 100, 101, 32, 98, 117, 102, 102, 101, 114, 115, 32, 105, 103, 117, 97, 105, 115, 32, 40, 97,
+100, 105, 99, 105, 111, 110, 97, 32, 108, 97, 116, 195, 170, 110, 99, 105, 97, 41, 34, 10, 34, 87, 105, 116,
+104, 32, 102, 105, 120, 101, 100, 32, 115, 105, 122, 101, 32, 98, 117, 102, 102, 101, 114, 115, 58, 32, 116, 104,
+101, 32, 119, 104, 111, 108, 101, 32, 100, 101, 118, 105, 99, 101, 32, 98, 117, 102, 102, 101, 114, 32, 105, 110,
+115, 116, 101, 97, 100, 32, 111, 102, 32, 50, 32, 109, 115, 32, 98, 108, 111, 99, 107, 115, 34, 32, 61, 32,
+34, 67, 111, 109, 32, 98, 117, 102, 102, 101, 114, 115, 32, 100, 101, 32, 116, 97, 109, 97, 110, 104, 111, 32,
+102, 105, 120, 111, 58, 32, 111, 32, 98, 117, 102, 102, 101, 114, 32, 105, 110, 116, 101, 105, 114, 111, 32, 100,
+111, 32, 100, 105, 115, 112, 111, 115, 105, 116, 105, 118, 111, 32, 101, 109, 32, 118, 101, 122, 32, 100, 101, 32,
+98, 108, 111, 99, 111, 115, 32, 100, 101, 32, 50, 32, 109, 115, 34, 10, 34, 87, 105, 116, 104, 32, 102, 105,
+120, 101, 100, 32, 115, 105, 122, 101, 32, 98, 117, 102, 102, 101, 114, 115, 58, 32, 112, 114, 101, 112, 97, 114,
+101, 32, 116, 104, 101, 32, 112, 108, 117, 103, 105, 110, 32, 102, 111, 114, 32, 116, 104, 101, 32, 104, 111, 115,
+116, 39, 115, 32, 108, 97, 114, 103, 101, 115, 116, 32, 98, 108, 111, 99, 107, 34, 32, 61, 32, 34, 67, 111,
+109, 32, 98, 117, 102, 102, 101, 114, 115, 32, 100, 101, 32, 116, 97, 109, 97, 110, 104, 111, 32, 102, 105, 120,
+111, 58, 32, 112, 114, 101, 112, 97, 114, 97, 32, 111, 32, 112, 108, 117, 103, 105, 110, 32, 112, 97, 114, 97,
+32, 111, 32, 109, 97, 105, 111, 114, 32, 98, 108, 111, 99, 111, 32, 100, 111, 32, 104, 111, 115, 116, 34, 10,
+34, 65, 108, 108, 111, 119, 32, 116, 104, 101, 32, 112, 108, 117, 103, 105, 110, 32, 116, 111, 32, 98, 101, 32,
+109, 117, 108, 116, 105, 45, 116, 104, 114, 101, 97, 100, 101, 100, 32, 40, 111, 102, 102, 58, 32, 97, 108, 119,
+97, 121, 115, 32, 111, 110, 32, 116, 104, 101, 32, 97, 117, 100, 105, 111, 32, 116, 104, 114, 101, 97, 100, 41,
+34, 32, 61, 32, 34, 80, 101, 114, 109, 105, 116, 101, 32, 112, 114, 111, 99, 101, 115, 115, 97, 114, 32, 111,
+32, 112, 108, 117, 103, 105, 110, 32, 101, 109, 32, 118, 195, 161, 114, 105, 97, 115, 32, 116, 104, 114, 101, 97,
+100, 115, 32, 40, 100, 101, 115, 108, 105, 103, 97, 100, 111, 58, 32, 115, 101, 109, 112, 114, 101, 32, 110, 97,
+32, 116, 104, 114, 101, 97, 100, 32, 100, 101, 32, 195, 161, 117, 100, 105, 111, 41, 34, 10, 34, 65, 108, 108,
+111, 119, 32, 115, 109, 97, 114, 116, 32, 100, 105, 115, 97, 98, 108, 101, 32, 102, 111, 114, 32, 116, 104, 101,
+32, 112, 108, 117, 103, 105, 110, 32, 40, 111, 102, 102, 58, 32, 105, 116, 32, 105, 115, 32, 97, 108, 119, 97,
+121, 115, 32, 112, 114, 111, 99, 101, 115, 115, 101, 100, 41, 34, 32, 61, 32, 34, 80, 101, 114, 109, 105, 116,
+101, 32, 111, 32, 115, 109, 97, 114, 116, 32, 100, 105, 115, 97, 98, 108, 101, 32, 100, 111, 32, 112, 108, 117,
+103, 105, 110, 32, 40, 100, 101, 115, 108, 105, 103, 97, 100, 111, 58, 32, 101, 108, 101, 32, 195, 169, 32, 115,
+101, 109, 112, 114, 101, 32, 112, 114, 111, 99, 101, 115, 115, 97, 100, 111, 41, 34, 10, 34, 76, 111, 97, 100,
+32, 116, 104, 101, 32, 112, 108, 117, 103, 105, 110, 32, 105, 110, 32, 97, 32, 115, 101, 112, 97, 114, 97, 116,
+101, 32, 112, 114, 111, 99, 101, 115, 115, 32, 40, 98, 114, 105, 100, 103, 101, 100, 41, 34, 32, 61, 32, 34,
+67, 97, 114, 114, 101, 103, 97, 32, 111, 32, 112, 108, 117, 103, 105, 110, 32, 101, 109, 32, 117, 109, 32, 112,
+114, 111, 99, 101, 115, 115, 111, 32, 115, 101, 112, 97, 114, 97, 100, 111, 32, 40, 112, 111, 110, 116, 101, 41,
+34, 10,
 };
 } // namespace lynx::i18n::data

+ 6 - 1
src/ui/MixerComponent.cpp

@@ -3534,7 +3534,12 @@ void EffectsPanel::openPluginWindow (int slot)
             return;
         }
         const auto& s = engine.getSong().mixer[(std::size_t) track].effects[(std::size_t) slot];
-        PluginWindows::open (effect, plugin->getInstance(), juce::String::fromUTF8 (s.plugin.name.c_str()));
+        PluginWindows::open (effect, plugin->getInstance(), juce::String::fromUTF8 (s.plugin.name.c_str()),
+                             { &engine, [t = track, slot] (Song& song) -> PluginRef* {
+                                  if (t >= (int) song.mixer.size() || slot >= (int) song.mixer[(std::size_t) t].effects.size())
+                                      return nullptr;
+                                  return &song.mixer[(std::size_t) t].effects[(std::size_t) slot].plugin;
+                              } });
         return;
     }
 

+ 273 - 9
src/ui/PluginWindow.cpp

@@ -4,6 +4,7 @@
 #include <algorithm>
 #include <map>
 
+#include "core/FlWrapper.h"
 #include "engine/PluginSandbox.h"
 #include "engine/Text.h"
 #include "platform/CrashGuard.h"
@@ -15,10 +16,252 @@ namespace lynx
 {
 namespace
 {
+void toggleWrapperOption (AudioEngine& engine, const std::function<PluginRef* (Song&)>& find, juce::AudioPluginInstance* instance,
+                          bool PluginRef::*option, bool recreates);
+
+// FL's plugin wrapper settings page (REA round 146a), in LYNX's style: what the plugin reports, then the wrapper
+// options LYNX applies in FL's sections (Processing, Bridging, MIDI). Options that re-create the plugin keep its state
+// and close this window (open it again from the channel or the slot).
+class WrapperSettingsPage final : public juce::Component, private juce::ChangeListener
+{
+public:
+    WrapperSettingsPage (AudioEngine& e, std::function<PluginRef* (Song&)> f, juce::AudioPluginInstance& p)
+        : engine (e), find (std::move (f)), plugin (p)
+    {
+        const auto& options = wrapperOptions();
+        for (std::size_t i = 0; i < options.size(); ++i)
+        {
+            auto* t = toggles.add (new juce::ToggleButton (tr (options[i].label)));
+            t->setTooltip (tr (options[i].hint));
+            t->setColour (juce::ToggleButton::textColourId, theme::colour::textPrimary);
+            t->setColour (juce::ToggleButton::tickColourId, theme::colour::accent);
+            t->onClick = [this, i] {
+                auto* en = &engine;
+                auto fn = find;
+                auto* inst = &plugin;
+                const auto& o = wrapperOptions()[i];
+                juce::MessageManager::callAsync ([en, fn, inst, member = o.member, re = o.recreates] { toggleWrapperOption (*en, fn, inst, member, re); });
+            };
+            addAndMakeVisible (t);
+        }
+        port.addItem (tr ("None"), 1);
+        for (int i = 0; i < 32; ++i)
+            port.addItem (tr ("Port {0}", { juce::String (i) }), i + 2);
+        port.setTooltip (tr ("MIDI input port number"));
+        port.onChange = [this] {
+            const auto value = port.getSelectedId() - 2;
+            engine.editSong ([fn = find, value] (Song& song) {
+                if (auto* ref = fn (song))
+                    ref->midiInPort = value;
+            });
+        };
+        addAndMakeVisible (port);
+        engine.addChangeListener (this);
+        refresh();
+        setSize (460, preferredHeight());
+    }
+
+    ~WrapperSettingsPage() override { engine.removeChangeListener (this); }
+
+    int preferredHeight() const { return top() + (int) wrapperOptions().size() * rowHeight + 4 * headerHeight + rowHeight + 24; }
+
+    void paint (juce::Graphics& g) override
+    {
+        using namespace theme;
+        g.fillAll (colour::bg1);
+        auto header = [&g] (const juce::String& text, int y) {
+            g.setColour (colour::textSecondary);
+            g.setFont (font (type::caption, true));
+            g.drawText (caps (text), 16, y, 400, headerHeight - 4, juce::Justification::bottomLeft);
+            g.setColour (colour::border);
+            g.fillRect (16, y + headerHeight - 2, 428, 1);
+        };
+        header (tr ("Plugin"), 8);
+        g.setFont (font (type::body));
+        int y = 8 + headerHeight + 2;
+        for (const auto& [label, value] : infoLines())
+        {
+            g.setColour (colour::textSecondary);
+            g.drawText (label, 16, y, 130, infoHeight, juce::Justification::centredLeft);
+            g.setColour (colour::textPrimary);
+            g.drawFittedText (value, 150, y, getWidth() - 166, infoHeight, juce::Justification::centredLeft, 1);
+            y += infoHeight;
+        }
+        juce::String last;
+        for (std::size_t i = 0; i < wrapperOptions().size(); ++i)
+            if (const juce::String section = wrapperOptions()[i].section; section != last)
+            {
+                header (tr (section), toggles[(int) i]->getY() - headerHeight);
+                last = section;
+            }
+        header (tr ("MIDI"), port.getY() - headerHeight);
+        g.setColour (colour::textSecondary);
+        g.drawText (tr ("Input port"), 16, port.getY(), 130, port.getHeight(), juce::Justification::centredLeft);
+    }
+
+    void resized() override
+    {
+        int y = top();
+        juce::String last;
+        for (std::size_t i = 0; i < wrapperOptions().size(); ++i)
+        {
+            if (const juce::String section = wrapperOptions()[i].section; section != last)
+            {
+                y += headerHeight;
+                last = section;
+            }
+            toggles[(int) i]->setBounds (24, y, getWidth() - 40, rowHeight);
+            y += rowHeight;
+        }
+        y += headerHeight;
+        port.setBounds (150, y + 2, 140, rowHeight - 4);
+    }
+
+private:
+    static constexpr int headerHeight = 24, rowHeight = 24, infoHeight = 18;
+
+    int top() const { return 8 + headerHeight + 2 + (int) infoLines().size() * infoHeight + 6; }
+
+    std::vector<std::pair<juce::String, juce::String>> infoLines() const
+    {
+        const auto d = plugin.getPluginDescription();
+        const auto rate = plugin.getSampleRate() > 0 ? plugin.getSampleRate() : 44100.0;
+        const auto latency = plugin.getLatencySamples();
+        return {
+            { tr ("Name"), d.name + (d.version.isNotEmpty() ? "  " + d.version : juce::String()) },
+            { tr ("Vendor"), d.manufacturerName },
+            { tr ("Format"), d.pluginFormatName + (d.isInstrument ? "  (" + tr ("instrument") + ")" : juce::String()) },
+            { tr ("File"), d.fileOrIdentifier },
+            { tr ("Latency"), tr ("{0} samples ({1} ms)", { juce::String (latency), juce::String (latency * 1000.0 / rate, 1) }) },
+            { tr ("Inputs / outputs"), juce::String (plugin.getTotalNumInputChannels()) + " / " + juce::String (plugin.getTotalNumOutputChannels()) },
+            { tr ("Parameters"), juce::String (plugin.getParameters().size()) },
+        };
+    }
+
+    void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
+
+    void refresh()
+    {
+        auto* ref = find (const_cast<Song&> (engine.getSong()));
+        if (ref == nullptr)
+            return;
+        const auto& options = wrapperOptions();
+        for (std::size_t i = 0; i < options.size(); ++i)
+        {
+            toggles[(int) i]->setToggleState (ref->*(options[i].member), juce::dontSendNotification);
+            toggles[(int) i]->setEnabled (! options[i].needsFixed || ref->fixedBuffers);
+        }
+        // with Options › "Run plugins in a separate process" every plugin already runs bridged
+        for (std::size_t i = 0; i < options.size(); ++i)
+            if (options[i].member == &PluginRef::separateProcess && pluginSandboxEnabled())
+                toggles[(int) i]->setToggleState (true, juce::dontSendNotification), toggles[(int) i]->setEnabled (false);
+        port.setSelectedId (ref->midiInPort + 2, juce::dontSendNotification);
+    }
+
+    AudioEngine& engine;
+    std::function<PluginRef* (Song&)> find;
+    juce::AudioPluginInstance& plugin;
+    juce::OwnedArray<juce::ToggleButton> toggles;
+    juce::ComboBox port;
+};
+
+// The window's content with FL's wrapper header: the plugin's editor, or the wrapper settings page (gear).
+class WrappedEditor final : public juce::Component
+{
+public:
+    WrappedEditor (juce::AudioProcessorEditor* e, AudioEngine& engine, std::function<PluginRef* (Song&)> find, juce::AudioPluginInstance& plugin)
+        : editor (e), page (engine, std::move (find), plugin)
+    {
+        for (auto* b : { &pluginTab, &settingsTab })
+        {
+            b->setClickingTogglesState (false);
+            b->setColour (juce::TextButton::buttonColourId, theme::colour::bg2);
+            b->setColour (juce::TextButton::buttonOnColourId, theme::colour::bg4);
+            b->setColour (juce::TextButton::textColourOffId, theme::colour::textSecondary);
+            b->setColour (juce::TextButton::textColourOnId, theme::colour::textPrimary);
+            addAndMakeVisible (b);
+        }
+        pluginTab.setTooltip (tr ("The plugin's own editor"));
+        settingsTab.setTooltip (tr ("Plugin wrapper settings: processing, bridging and MIDI options"));
+        pluginTab.onClick = [this] { show (false); };
+        settingsTab.onClick = [this] { show (true); };
+        addAndMakeVisible (editor.get());
+        addChildComponent (page);
+        pluginTab.setToggleState (true, juce::dontSendNotification);
+        fitEditor();
+    }
+
+    ~WrappedEditor() override
+    {
+        editor = nullptr; // the editor goes first (the plugin may be released right after the window)
+    }
+
+    bool isEditorResizable() const { return editor != nullptr && editor->isResizable(); }
+
+    void paint (juce::Graphics& g) override
+    {
+        g.setColour (theme::colour::bg0);
+        g.fillRect (getLocalBounds().removeFromTop (headerHeight));
+    }
+
+    void resized() override
+    {
+        auto area = getLocalBounds();
+        auto header = area.removeFromTop (headerHeight).reduced (4, 3);
+        pluginTab.setBounds (header.removeFromLeft (80));
+        header.removeFromLeft (4);
+        settingsTab.setBounds (header.removeFromLeft (130));
+        page.setBounds (area);
+        if (editor != nullptr && ! settings)
+        {
+            const juce::ScopedValueSetter<bool> guard (laying, true);
+            if (editor->isResizable())
+                editor->setBounds (area);
+            else
+                editor->setTopLeftPosition (area.getPosition());
+        }
+    }
+
+    void childBoundsChanged (juce::Component* child) override
+    {
+        if (child == editor.get() && ! laying && ! settings)
+            fitEditor();
+    }
+
+private:
+    static constexpr int headerHeight = 30;
+
+    void fitEditor()
+    {
+        if (editor != nullptr)
+            setSize (juce::jmax (220, editor->getWidth()), editor->getHeight() + headerHeight);
+    }
+
+    void show (bool showSettings)
+    {
+        settings = showSettings;
+        pluginTab.setToggleState (! settings, juce::dontSendNotification);
+        settingsTab.setToggleState (settings, juce::dontSendNotification);
+        page.setVisible (settings);
+        if (editor != nullptr)
+            editor->setVisible (! settings);
+        if (settings)
+            setSize (juce::jmax (getWidth(), page.getWidth()), juce::jmax (getHeight(), page.preferredHeight() + headerHeight));
+        else
+            fitEditor();
+        resized();
+    }
+
+    std::unique_ptr<juce::AudioProcessorEditor> editor;
+    WrapperSettingsPage page;
+    juce::TextButton pluginTab { tr ("Plugin") }, settingsTab { juce::String::fromUTF8 ("\xe2\x9a\x99 ") + tr ("Wrapper settings") };
+    bool settings = false, laying = false;
+};
+
 class PluginWindow final : public juce::DocumentWindow, private juce::AudioProcessorListener
 {
 public:
-    PluginWindow (std::shared_ptr<void> keepAlive, juce::AudioPluginInstance& p, const juce::String& title)
+    PluginWindow (std::shared_ptr<void> keepAlive, juce::AudioPluginInstance& p, const juce::String& title, PluginWindows::WrapperContext context)
         : DocumentWindow (title, theme::colour::bg1, DocumentWindow::closeButton | DocumentWindow::minimiseButton),
           owner (std::move (keepAlive)),
           plugin (p)
@@ -26,14 +269,17 @@ public:
         setUsingNativeTitleBar (true);
 
         crashguard::note (("opening the editor of " + plugin.getName()).toStdString()); // session breadcrumb (round 111)
-        if (auto* editor = plugin.createEditorIfNeeded())
-            setContentOwned (editor, true);
-        else
-            setContentOwned (new juce::GenericAudioProcessorEditor (plugin), true); // plugin without a UI
+        juce::AudioProcessorEditor* editor = plugin.createEditorIfNeeded();
+        if (editor == nullptr)
+            editor = new juce::GenericAudioProcessorEditor (plugin); // plugin without a UI
         crashguard::note (("editor open: " + plugin.getName()).toStdString());
 
-        if (auto* editor = dynamic_cast<juce::AudioProcessorEditor*> (getContentComponent()))
-            setResizable (editor->isResizable(), false);
+        const auto resizable = editor->isResizable();
+        if (context.engine != nullptr && context.find) // FL's wrapper header and settings page (round 146a)
+            setContentOwned (new WrappedEditor (editor, *context.engine, std::move (context.find), plugin), true);
+        else
+            setContentOwned (editor, true);
+        setResizable (resizable, false);
         centreWithSize (getWidth(), getHeight());
         setVisible (true);
         keepAboveMainWindow (*this);
@@ -127,7 +373,7 @@ private:
 
 namespace PluginWindows
 {
-void open (std::shared_ptr<void> owner, juce::AudioPluginInstance& plugin, const juce::String& title)
+void open (std::shared_ptr<void> owner, juce::AudioPluginInstance& plugin, const juce::String& title, WrapperContext context)
 {
     auto& open = windows();
 
@@ -137,7 +383,7 @@ void open (std::shared_ptr<void> owner, juce::AudioPluginInstance& plugin, const
         return;
     }
 
-    open[&plugin] = std::make_unique<PluginWindow> (std::move (owner), plugin, title);
+    open[&plugin] = std::make_unique<PluginWindow> (std::move (owner), plugin, title, std::move (context));
 }
 
 void closeAll()
@@ -161,6 +407,24 @@ void scanPluginsWithProgress (AudioEngine& engine, std::function<void (int)> onD
     (new ScanThread (engine, std::move (onDone)))->launchThread(); // deletes itself when done
 }
 
+namespace
+{
+void toggleWrapperOption (AudioEngine& engine, const std::function<PluginRef* (Song&)>& find, juce::AudioPluginInstance* instance,
+                          bool PluginRef::*option, bool recreates)
+{
+    if (recreates)
+    {
+        if (instance != nullptr && PluginWindows::isOpen (*instance))
+            PluginWindows::close (*instance);
+        engine.capturePluginStates(); // the new instance starts from the current settings
+    }
+    engine.editSong ([find, option] (Song& song) {
+        if (auto* ref = find (song))
+            ref->*option = ! (ref->*option);
+    });
+}
+} // namespace
+
 juce::PopupMenu pluginProcessingMenu (AudioEngine& engine, const PluginRef& current, juce::AudioPluginInstance* instance,
                                       std::function<PluginRef* (Song&)> find)
 {

+ 9 - 1
src/ui/PluginWindow.h

@@ -12,8 +12,16 @@ namespace lynx
 // it is open (even if the channel is removed), and only one window per plugin.
 namespace PluginWindows
 {
+// Where the plugin's wrapper options live (REA round 146a: FL's plugin wrapper settings page). With an engine, the
+// window gets FL's wrapper header: the plugin's own editor and a "Wrapper settings" page with its processing, bridging
+// and MIDI options and what the plugin reports. `find` locates the PluginRef in the song (nullptr: gone).
+struct WrapperContext
+{
+    AudioEngine* engine = nullptr;
+    std::function<PluginRef* (Song&)> find;
+};
 // `owner` is the adapter (PluginInstrument/PluginEffect) that holds the plugin.
-void open (std::shared_ptr<void> owner, juce::AudioPluginInstance& plugin, const juce::String& title);
+void open (std::shared_ptr<void> owner, juce::AudioPluginInstance& plugin, const juce::String& title, WrapperContext context = {});
 void closeAll();
 bool isOpen (const juce::AudioPluginInstance& plugin);
 void close (const juce::AudioPluginInstance& plugin);

+ 17 - 0
tests/Rea146aTests.inc

@@ -205,3 +205,20 @@ TEST (rea146a_consolidate_track)
             ++onTrack;
     CHECK (onTrack == 2 && song.playlist.size() == 3); // the new clip and the muted one; track 0 keeps its clip
 }
+
+#include "core/FlWrapper.h"
+
+TEST (rea146a_wrapper_settings_page_options)
+{
+    // FL's wrapper settings page: the Processing options first, then Bridging; the buffer sub-options need fixed buffers
+    const auto& o = lynx::wrapperOptions();
+    CHECK (o.size() == 6);
+    if (o.size() == 6)
+    {
+        CHECK (std::string (o[0].label) == "Use fixed size buffers" && o[0].member == &lynx::PluginRef::fixedBuffers && o[0].recreates);
+        CHECK (o[1].needsFixed && o[2].needsFixed && ! o[0].needsFixed && ! o[3].needsFixed);
+        CHECK (! o[3].recreates && ! o[4].recreates && o[5].recreates && std::string (o[5].section) == "Bridging");
+        lynx::PluginRef ref;
+        CHECK (ref.*(o[3].member) && ref.*(o[4].member) && ! (ref.*(o[0].member))); // FL's defaults
+    }
+}