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

Issue #116: read and write FL's Detached plugin window flag in .flp (0xD4 flags bit 0x4)

Ka1-S 3 недель назад
Родитель
Сommit
d2ebf5455c

+ 6 - 0
docs/PARITY.md

@@ -2289,3 +2289,9 @@ for now (FL Studio Mobile reference shots and the matching layouts are the next
 Not yet (listed in the import report): Chorus, Spacer, Wow & Flutter, Phaser, Waveshaper, Compressor, Spreader,
 Stereoizer, Flanger, Autoduck (29), Tremolo. No per-effect render from FL Studio Mobile exists yet: an A/B in FL's
 FL Studio Mobile plugin is the open sound check.
+
+## Round 190i: the plugin window's Detached flag in `.flp` (issue #116)
+FL saves a plugin window's **Detached** state in the plugin record (`0xD4`, flags bit `0x4`; FL 2026 driven, see
+`docs/analise/REA_rodada190i.md`). LYNX reads it into a hosted plugin's Detached setting on import and writes it on
+export, so a plugin detached in FL opens detached in LYNX and the other way round. LYNX's own instruments and effects
+have no Detached state: their imported flags are kept as they were.

+ 43 - 0
docs/analise/REA_rodada190i.md

@@ -0,0 +1,43 @@
+# Round 190i: issue #116 leftovers (the .flp Detached flag, the editors macro, native panel fades) and issue #114's test
+
+Earlier steps: `REA_rodada181c.md` (design), `REA_rodada186a.md` §2 (slice 1), `REA_rodada188a.md` (slices 2, 3),
+`REA_rodada188j.md` (slice 4). Work files: `E:\lynx-work\iss190i\` (`fl\` projects and window listings, `shots\`,
+`scripts\d4.py` and `craft.py`).
+
+## 1. The plugin record's Detached flag (`.flp`) **[EXEC + DATA, FL Studio 2026 v26.1.7, 2026-11-10]**
+
+The plugin record `0xD4` (52 bytes, 13 × u32; `REA_rodada5.md` §1.1, `REA_rodada139.md` B6) holds its flags at +16.
+Known so far: `0x1` window open, `0x10` generator, `0x20` Smart disable, `0x40` threaded, `0x100`. PyFLP names bit
+`0x4` "Detached" **[DOC]**. Checked here:
+
+| Step | What was done | Result |
+|---|---|---|
+| a | FL's `Render tests\3OSC.flp` copied; its only `0xD4` has flags `0x51` (`a-docked.flp`) | FL opens the 3x Osc window as a **child** of the workspace (`TPluginForm`, style `54000000`, parent = the `TWPControl` desktop): docked. `wins-fl-a-docked.txt`, `shots\fl-a-docked.png` |
+| b | The same file with only that u32 changed to `0x55` (`b-detached.flp`, `craft.py`) | FL opens it as a **top-level window owned by the main window** (`TPluginForm`, style `94010000`, owner = `TFruityLoopsMainForm`): detached. `wins-fl-b-detached.txt`, `shots\fl-b-detached.png` |
+| c | In (a): Tools › Macros › **Switch all plugin editors to › Detached**, then Ctrl+S | The window becomes the owned top-level one (`wins-fl2-03.txt`); the saved record: `0x51` → **`0x55`**, and the rect at +36 changes from `10 80` (inside the desktop) to `e1 d2` (the screen). `a-after-detached-macro.flp` |
+| d | Then **… › Attached**, Ctrl+S | Child window again (`wins-fl2-07.txt`); the record is back to `0x51`, rect `10 80`. `a-after-attached-macro.flp` |
+| e | A copy of the Breakbeat template (48 plugin records, one window open): **… › Detached**, Ctrl+S | **Every** record gets `0x4`: `0x50`→`0x54` (7 samplers), `0x60`→`0x64`, `0x70`→`0x74`, `0x140`→`0x144` (7), `0x160`→`0x164` (28); the two that had it keep it. So the macro sets the flag of all plugins, open or not, generators and effects, FL's own and wrapped ones. `c-orig.flp` / `c-many.flp` |
+
+Corpus (FL's 165 demo and template projects, `d4.py`): 310 of the plugin records carry `0x4` (`0x54`, `0x64`, `0x74`,
+`0x144`, `0x154`, `0x164`, `0x165`, `0x174` …) **[DATA]**.
+
+No FL setting was changed. FL was started by `Start-Process` under both locks and closed by its PID; input: three
+menu clicks and Ctrl+S per run, each after `safeinput.ps1`; no new line in the input wall's log.
+
+### LYNX
+- Import: a hosted plugin (a "Fruity Wrapper" channel or mixer slot) takes `PluginRef::detached` from bit `0x4` of its
+  own record (`core/FlWrapper.h` `flDetached`).
+- Export: a hosted plugin's record gets `0x4` when `PluginRef::detached` is set and loses it when it is not, whatever
+  the imported flags were (`withFlDetached`); FL's other flags of an imported channel stay as they were
+  (`ChannelDef::flWrapperFlags`). Channels that are not hosted plugins keep the flags they were imported with: LYNX's
+  own editors have no Detached state to set the bit from.
+- Not read: the window's place and size at +36…+51 (docked: inside FL's desktop; detached: on the screen).
+- Test: `issue116_flp_detached_flag_round_trips` (`tests/Issue116DetachedTests.inc`).
+
+## 2. Best way?
+- **FL:** above. Detached is per plugin, saved in the project, and travels in the `.flp`.
+- **Ableton:** Live's plugin windows always float (`REA_rodada188a.md` §3); a Live set stores no such choice, so there
+  is nothing to map in `.als`.
+- **Users:** the requests are about detached as a default and a quick way to detach everything (forum threads in
+  `REA_rodada188a.md` §3): FL's own answers are "Detach all new plugins" (slice 3) and the macro of step (c).
+- **Verdict:** FL-exact. A project detached in FL opens detached in LYNX and the other way round.

+ 10 - 0
src/core/FlWrapper.h

@@ -57,6 +57,16 @@ 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);
 
+// The plugin record's flags (0xD4, u32 at +16; −1 = no record): 0x4 = the plugin's window is Detached (the window
+// menu's "Detached": a window of its own, in front of FL's panels) instead of docked in FL's workspace. Round 190i,
+// issue #116 [EXEC + DATA FL 2026: docs/analise/REA_rodada190i.md; PyFLP names the bit the same way, DOC].
+constexpr int flDetachedFlag = 0x4;
+constexpr bool flDetached (int recordFlags) noexcept { return recordFlags >= 0 && (recordFlags & flDetachedFlag) != 0; }
+constexpr int withFlDetached (int recordFlags, bool detached) noexcept
+{
+    return detached ? recordFlags | flDetachedFlag : recordFlags & ~flDetachedFlag;
+}
+
 // 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

+ 5 - 0
src/core/FlpExport.cpp

@@ -10,6 +10,7 @@
 
 #include "core/Effects.h"
 #include "core/FlEffects.h"
+#include "core/FlWrapper.h"
 #include "core/PatternBlocks.h"
 #include "core/ThreeOsc.h"
 #include "core/TimeStretch.h"
@@ -796,6 +797,9 @@ struct Converter
         // FL keeps a Smart disabled generator from running through silence, so it changes the phase of what it plays
         // (Thief without FL's own flags: xcorr 0.891, same spectrum; round 180d)
         c.wrapperFlags = def.flWrapperFlags;
+        // a hosted plugin's window: FL's "Detached" is flag 0x4 of the same record (issue #116, REA_rodada190i.md)
+        if (def.instrument == InstrumentKind::plugin || def.plugin.foreign.format != ForeignPlugin::Format::none)
+            c.wrapperFlags = withFlDetached (def.flWrapperFlags >= 0 ? def.flWrapperFlags : 0x150, def.plugin.detached);
         c.enabled = ! def.muted;
         c.soloLock = def.soloLock;
         c.ghostShown = ! def.ghostHidden;
@@ -1505,6 +1509,7 @@ struct Converter
                     {
                         slot.plugin = "Fruity Wrapper";
                         slot.state = writeWrapper (*record, false, fx.plugin.foreign.format == ForeignPlugin::Format::none ? &fx.plugin : nullptr);
+                        slot.wrapperFlags = withFlDetached (slot.wrapperFlags, fx.plugin.detached); // (issue #116)
                         what = record->name + " (Fruity Wrapper)";
                     }
                 }

+ 3 - 0
src/core/FlpImport.cpp

@@ -1485,6 +1485,8 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             applyFlWrapperOptions (def.plugin.foreign, def.plugin);
             def.plugin.midiInPort = def.plugin.foreign.midiInPort; // the MIDI Out channels on that port play it
             def.plugin.midiOutPort = def.plugin.foreign.midiOutPort; // its notes play the plugins on that port
+            // the plugin window's "Detached" (0xD4 flag 0x4, issue #116 [EXEC + DATA: REA_rodada190i.md])
+            def.plugin.detached = flDetached (c.wrapperFlags);
         }
 
         // MIDI Out (REA_rodada16 §1): a silent channel whose notes the renderer sends to the plugins on its port
@@ -2962,6 +2964,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                     made->plugin.name = foreign.name;
                     applyFlWrapperOptions (foreign, made->plugin);
                     made->plugin.foreign = std::move (foreign);
+                    made->plugin.detached = flDetached (slot.wrapperFlags); // (0xD4 flag 0x4, issue #116)
                 }
                 else
                 {

+ 96 - 0
tests/Issue116DetachedTests.inc

@@ -0,0 +1,96 @@
+// Round 190i, issue #116: FL's "Detached" plugin window flag in the .flp (plugin record 0xD4, flags bit 0x4
+// [EXEC + DATA FL 2026: docs/analise/REA_rodada190i.md]) <-> PluginRef::detached.
+
+namespace issue116d
+{
+lynx::ForeignPlugin vst (const char* name, std::uint32_t id)
+{
+    lynx::ForeignPlugin f;
+    f.format = lynx::ForeignPlugin::Format::vst2;
+    f.vst2Id = id;
+    f.name = name;
+    return f;
+}
+
+// a hosted instrument on channel 0 and a hosted effect on insert 1, both as imported from FL (their wrapper records)
+lynx::Song song (bool channelDetached, bool effectDetached, int channelFlags)
+{
+    using namespace lynx;
+    auto s = Song::makeDefault();
+    s.channels.resize (1);
+    auto& c = s.channels[0];
+    c.instrument = InstrumentKind::plugin;
+    c.plugin.name = "Drums";
+    c.plugin.foreign = vst ("Drums", 0x44524D31);
+    c.plugin.detached = channelDetached;
+    c.flWrapperFlags = channelFlags;
+    EffectSlot fx;
+    fx.kind = EffectKind::plugin;
+    fx.plugin.name = "Echo";
+    fx.plugin.foreign = vst ("Echo", 0x4543484F);
+    fx.plugin.detached = effectDetached;
+    fx.smartDisable = false;
+    s.mixer[1].effects.push_back (fx);
+    return s;
+}
+
+flp::Project written (const lynx::Song& s)
+{
+    lynx::flpexport::Options options;
+    lynx::flpexport::Report report;
+    return flp::parseProject (lynx::flpexport::exportFlp (s, options, report));
+}
+
+lynx::Song back (const flp::Project& p)
+{
+    lynx::FlpImportOptions o;
+    o.fileExists = [] (const std::string&) { return true; };
+    return lynx::importFlp (p, o);
+}
+
+int slotFlags (const flp::Project& p)
+{
+    for (const auto& m : p.mixer)
+        if (m.index == 1 && ! m.slots.empty())
+            return m.slots[0].wrapperFlags;
+    return -1;
+}
+} // namespace issue116d
+
+TEST (issue116_flp_detached_flag_round_trips)
+{
+    using namespace issue116d;
+    CHECK (lynx::flDetached (0x155) && ! lynx::flDetached (0x151) && ! lynx::flDetached (-1));
+    CHECK (lynx::withFlDetached (0x151, true) == 0x155 && lynx::withFlDetached (0x155, false) == 0x151);
+
+    // docked (the default): FL's flags without 0x4 — a generator wrapper 0x150, an effect wrapper 0x140
+    auto p = written (song (false, false, -1));
+    CHECK (p.channels.at (0).wrapperFlags == 0x150 && slotFlags (p) == 0x140);
+    auto s = back (p);
+    CHECK (! s.channels.at (0).plugin.detached);
+    CHECK (s.mixer.at (1).effects.size() == 1 && ! s.mixer[1].effects[0].plugin.detached);
+
+    // detached: bit 0x4 on each plugin's own record, and back
+    p = written (song (true, false, -1));
+    CHECK (p.channels.at (0).wrapperFlags == 0x154 && slotFlags (p) == 0x140);
+    s = back (p);
+    CHECK (s.channels.at (0).plugin.detached && ! s.mixer.at (1).effects.at (0).plugin.detached);
+    p = written (song (false, true, -1));
+    CHECK (p.channels.at (0).wrapperFlags == 0x150 && slotFlags (p) == 0x144);
+    s = back (p);
+    CHECK (! s.channels.at (0).plugin.detached && s.mixer.at (1).effects.at (0).plugin.detached);
+
+    // FL's other flags of an imported channel stay (0x1 visible, 0x20 smart disable); LYNX's Detached decides 0x4:
+    // imported detached and docked again in LYNX, or the other way round
+    CHECK (written (song (false, false, 0x175)).channels.at (0).wrapperFlags == 0x171);
+    CHECK (written (song (true, false, 0x171)).channels.at (0).wrapperFlags == 0x175);
+
+    // a channel that is not a hosted plugin keeps the flags it was imported with, 0x4 included (LYNX's own editors
+    // have no Detached state to set it from)
+    auto sampler = lynx::Song::makeDefault();
+    sampler.channels.resize (1);
+    sampler.channels[0].instrument = lynx::InstrumentKind::sampler;
+    sampler.channels[0].samplePath = "C:/x.wav";
+    sampler.channels[0].flWrapperFlags = 0x54;
+    CHECK (written (sampler).channels.at (0).wrapperFlags == 0x54);
+}

+ 1 - 0
tests/tests.cpp

@@ -17379,6 +17379,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "SimpleChooser184aTests.inc"
 #include "LayoutStyle184aTests.inc"
 #include "Rack116Tests.inc"
+#include "Issue116DetachedTests.inc"
 #include "Trial187bTests.inc"
 #include "ProjectKey184aTests.inc"
 #include "Render186bTests.inc"