Przeglądaj źródła

FL import: muted playlist clips stay muted (issue #110)

FL's clip mute is bit 0x2000 of the playlist item flags (+0x12): FL keeps the
record as loaded and its 'flip mute' action toggles bit 0x20 of byte +0x13
(REA round 182e). Pattern, audio and automation clips now import muted, and
Export to FL writes the bit instead of leaving muted clips out.
Ka1-S 3 tygodni temu
rodzic
commit
ab7d4e9a24

+ 28 - 0
docs/analise/REA_rodada182e.md

@@ -0,0 +1,28 @@
+# Round 182e: FL import fixes from issues #110-#113
+
+Read from FL Studio 2026's own binaries (`FLEngine_x64.dll` in the headless Ghidra project `r167g`; outputs in
+`/mnt/e/lynx-work/flp182e/dec/`). Clean-room: behaviour documented, no code copied.
+
+## 1. Playlist clip mute (issue #110) [DECOMP]
+
+- FL keeps each playlist item in memory as the record it loads from the file: the post-load fix-up (`FUN_00f55690`)
+  works on the loaded items with the file's offsets (`+0x04` base `0x50000000`, `+0x0C` track, `+0x20` clip id from
+  `FUN_0105f2e0`, `+0x24` fade, `+0x3C…+0x50` the 80/88 B tail via `FUN_01064e20`).
+- The clip mute is **bit `0x20` of byte `+0x13`**, i.e. **bit `0x2000` of the u16 flags at `+0x12`**:
+  - `FUN_00e84110`, the playlist's track-header action with the undo name **"flip mute"**, toggles
+    `byte[+0x13] ^= 0x20` on every clip of that track;
+  - `FUN_0105f3c0` and `FUN_010646c0` are the clip's set-mute helpers (`|= 0x20` / `&= 0xDF`), called from 7 and 5
+    places;
+  - Merge pattern clips (round 180c) leaves out clips with that bit, and its "similar" test compares it.
+- The reporter's FL renders (issue #110: 20/91 and 10/191 clips with the bit) match only with those clips silent.
+- LYNX: `flp::PlaylistItem::muted()` → `Clip::muted` for pattern, audio and automation clips. Export to FL writes
+  `0x40 | 0x2000` for a muted clip (before: the clip was left out of the file).
+
+### Best way?
+
+- **FL:** a muted clip stays in the playlist, greyed out and silent, and the file keeps it with bit 0x2000 (above).
+- **Ableton:** a deactivated clip stays in the arrangement and is saved as `Disabled` (LYNX's .als import/export maps
+  it to `Clip::muted`, `AlsImport.cpp` / `AlsExport.cpp`).
+- **Users:** the reporter's stacked alternative takes are the usual reason to mute a clip: it keeps the take without
+  playing it. Leaving muted clips out of an export to FL (LYNX before) lost those takes.
+- **Verdict:** FL-exact. Import and export now keep the clip and its mute.

+ 1 - 1
docs/analise/REA_rodada2.md

@@ -489,7 +489,7 @@ Layout (validated on 10,576 records of 80 B):
 | 0x0C | u16 | Playlist track, inverted: `track = 499 − value` **[HYP from the value; the load adds +100 in files < 9.?]** |
 | 0x0E | u16 | Group |
 | 0x10 | u16 | 120 (default clip fine pitch) |
-| 0x12 | u16 | Flags: 0x0040 default; **0x2000 = muted/disabled** **[HYP]** (205 cases) |
+| 0x12 | u16 | Flags: 0x0040 default; **0x2000 = muted** **[DECOMP, round 182e]** (205 cases); 0x8000 = selected (round 180c) |
 | 0x14 | 4×u8 | 64, 100, 128, 128: default clip pan, vel, modX, modY |
 | 0x18 | f32 | **Offset start** (−1 = none). In automation clips, it is the start point within the envelope |
 | 0x1C | f32 | **Offset end** (−1 = none) |

+ 2 - 12
src/core/FlpExport.cpp

@@ -643,8 +643,6 @@ struct Converter
         song.forEachClipList ([&] (const std::vector<Clip>& clips) {
             for (const auto& c : clips)
             {
-                if (c.muted)
-                    continue; // (left out)
                 use (c.start);
                 // (an audio clip's length goes unstretched, as playlistItem writes it)
                 use (c.kind == ClipKind::audio && c.stretch > 0.0 && c.stretch != 1.0 ? (std::int64_t) std::llround ((double) c.length / c.stretch)
@@ -1245,19 +1243,9 @@ struct Converter
             a.name = arrangement.name;
             for (const auto& m : current ? song.markers() : arrangement.markers)
                 a.markers.push_back (marker (m));
-            int muted = 0;
             for (const auto& clip : clips)
-            {
-                if (clip.muted)
-                {
-                    ++muted; // (FL's clip mute is not in the model: a muted clip is left out, as it is heard)
-                    continue;
-                }
                 if (auto item = playlistItem (clip))
                     a.items.push_back (*item);
-            }
-            if (muted > 0)
-                report.notes.push_back ("Arrangement '" + a.name + "': " + std::to_string (muted) + " muted clip(s) left out");
             std::stable_sort (a.items.begin(), a.items.end(), [] (const flp::PlaylistItem& x, const flp::PlaylistItem& y) { return x.position < y.position; });
             for (int t = 0; t < (int) song.playlistTracks.size() && t < 500; ++t)
                 a.tracks.push_back (trackInfo (song.playlistTracks[(std::size_t) t], t));
@@ -1272,6 +1260,8 @@ struct Converter
         item.track = std::clamp (clip.track, 0, 499);
         item.position = ticks (clip.start);
         item.length = std::max<std::uint32_t> (1, ticks (clip.length));
+        // FL's clip mute: bit 0x2000 of the item flags (issue #110, REA round 182e)
+        item.flags = (std::uint16_t) (flp::PlaylistItem::defaultFlags | (clip.muted ? flp::PlaylistItem::mutedFlag : 0));
         switch (clip.kind)
         {
             case ClipKind::pattern:

+ 3 - 0
src/core/FlpImport.cpp

@@ -3693,6 +3693,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                 clip.track = item.track;
                 clip.start = rescale (item.position);
                 clip.length = rescale (item.length);
+                clip.muted = item.muted(); // (issue #110)
 
                 // trim in beats (-1 = no trim)
                 if (std::isfinite (item.startOffset) && item.startOffset > 0.0f)
@@ -3715,6 +3716,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                 clip.track = item.track;
                 clip.start = rescale (item.position);
                 clip.length = rescale (item.length);
+                clip.muted = item.muted();
 
                 // The region start comes in beats or in milliseconds, depending on the clip;
                 // we find out by the unit in which (end - start) matches the length.
@@ -3779,6 +3781,7 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             clip.start = rescale (item.position);
             clip.length = rescale (item.length);
             clip.offset = item.patternStartTick > 0 ? rescale (item.patternStartTick) : 0;
+            clip.muted = item.muted();
             clips.push_back (clip);
         }
 

+ 6 - 1
src/flp/Flp.h

@@ -309,7 +309,12 @@ struct PlaylistItem
     int track = 0;               // 0 = first playlist track
     Kind kind = Kind::pattern;
     int index = 0;               // pattern index, or channel index (audio/automation clip)
-    std::uint16_t flags = 0;
+    std::uint16_t flags = 0;     // +0x12: 0x40 by default; see mutedFlag
+    // +0x12 bit 13: the clip is muted (the Mute tool / clip menu › Mute). FL keeps the record in memory as it is in the
+    // file and tests bit 0x20 of byte +0x13 (REA round 182e)
+    static constexpr std::uint16_t mutedFlag = 0x2000;
+    static constexpr std::uint16_t defaultFlags = 0x40;
+    bool muted() const noexcept { return (flags & mutedFlag) != 0; }
 
     // The same 8 bytes mean different things per clip type:
     //  - pattern: two int32 in ticks (start/end of the pattern section); -1 = no trimming

+ 79 - 0
tests/FlpMute182eTests.inc

@@ -0,0 +1,79 @@
+// --- Round 182e: FL import / export fixes from issues #110-#113 ---------------------------------------------------------
+
+TEST (flp182e_clip_mute_flag_round_trips_for_every_clip_kind)
+{
+    // Issue #110: FL's clip mute is bit 0x2000 of the playlist item flags (+0x12). FL tests bit 0x20 of byte +0x13 on the
+    // record it keeps as loaded (REA round 182e). Muted pattern, audio and automation clips must stay muted on import,
+    // and the export writes the bit back instead of leaving the clip out.
+    using namespace lynx;
+    auto song = Song::makeDefault();
+    song.playlist.clear();
+
+    ChannelDef audio;
+    audio.name = "take";
+    audio.instrument = InstrumentKind::audioClip;
+    audio.samplePath = "C:\\samples\\take.wav";
+    song.channels.push_back (audio);
+    const auto audioChannel = (int) song.channels.size() - 1;
+
+    Automation a;
+    a.target = { AutomationTargetKind::tempo, 0, 0, 0 };
+    a.points = { { 0, 0.5f, 0.0f }, { ppq * 4, 0.5f, 0.0f } };
+    song.automations.push_back (a);
+    const auto automation = (int) song.automations.size() - 1;
+
+    auto add = [&] (ClipKind kind, int track, std::int64_t start, bool muted) {
+        Clip c;
+        c.kind = kind;
+        c.track = track;
+        c.start = start;
+        c.length = ppq * 4;
+        c.muted = muted;
+        if (kind == ClipKind::pattern)
+            c.pattern = 0;
+        else if (kind == ClipKind::audio)
+            c.channel = audioChannel;
+        else
+            c.automation = automation;
+        song.playlist.push_back (c);
+    };
+    add (ClipKind::pattern, 0, 0, false);
+    add (ClipKind::pattern, 0, ppq * 4, true);
+    add (ClipKind::audio, 1, 0, false);
+    add (ClipKind::audio, 1, ppq * 4, true);
+    add (ClipKind::automation, 2, 0, false);
+    add (ClipKind::automation, 2, ppq * 4, true);
+
+    flpexport::Options options;
+    flpexport::Report report;
+    const auto project = flp::parseProject (flpexport::exportFlp (song, options, report));
+    CHECK (! project.arrangements.empty());
+    if (project.arrangements.empty())
+        return;
+    const auto& items = project.arrangements[0].items;
+    CHECK (items.size() == 6);
+    const auto fileBeat = (std::uint32_t) project.header.ppq;
+    for (const auto& item : items)
+    {
+        // the second clip of each row is the muted one; the rest of the flags stay FL's default 0x40
+        const bool muted = item.position == fileBeat * 4;
+        CHECK (item.muted() == muted);
+        CHECK ((item.flags & ~flp::PlaylistItem::mutedFlag) == flp::PlaylistItem::defaultFlags);
+    }
+
+    FlpImportOptions io;
+    io.fileExists = [] (const std::string&) { return true; };
+    io.sampleSeconds = [] (const std::string&) { return 2.0; };
+    const auto back = importFlp (project, io);
+    std::map<std::pair<int, int>, int> seen; // (kind, muted) -> count
+    for (const auto& c : back.playlist)
+    {
+        CHECK (c.muted == (c.start == ppq * 4));
+        ++seen[std::make_pair ((int) c.kind, c.muted ? 1 : 0)];
+    }
+    for (const auto kind : { ClipKind::pattern, ClipKind::audio, ClipKind::automation })
+    {
+        CHECK ((seen[{ (int) kind, 0 }] == 1));
+        CHECK ((seen[{ (int) kind, 1 }] == 1));
+    }
+}

+ 1 - 0
tests/tests.cpp

@@ -17120,6 +17120,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Merge180cTests.inc"
 #include "PluginExport180bTests.inc"
 #include "FlExport180dTests.inc"
+#include "FlpMute182eTests.inc"
 #include "Mixer177a2Tests.inc"
 #include "Mixer177a3Tests.inc"
 #include "Mixer177a4Tests.inc"