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

Linked audio track and mixer track keep one name and colour, as FL (#235)

FL Studio 2026 (FLEngine, REA round 190ns: FUN_012e60f0 -> FUN_012e6010 and
FUN_012be6f0 -> FUN_012a7810) copies a Playlist audio track's rename /
recolour to its mixer track and a mixer track's rename / recolour to the
audio track linked to it. LYNX matched them only when the link was made.

- trackmodes::linkedNames / followLinkedNames, run by AudioEngine::editSong:
  whichever side of an audio track and its mixer track an edit changed is
  copied to the other (instrument tracks: only with LYNX's own link switch,
  as before).
- With "Link Playlist tracks to mixer tracks" on, opening a project matches
  a linked pair where one side still has the default colour
  (autolink::matchLinkedColours), the reporter's purple insert under a grey
  header.
Ka1-S 2 недель назад
Родитель
Сommit
f7046b1fca

+ 31 - 0
docs/analise/REA_rodada190ns.md

@@ -0,0 +1,31 @@
+# REA round 190ns — linked audio track and mixer track names / colours (issue #235)
+
+Target: FL Studio 2026 `FLEngine_x64.dll` (sha256 `6d9c5ab0…8e02`), Ghidra 12.1.4 through REA, snapshot
+`/mnt/e/lynx-work/win190ev/flengine.snapshot`. Clean-room: behaviour only, no code or data copied.
+
+## Playlist track → mixer track
+
+- `FUN_012e60f0 (arrangement, track, name, colour)` — the Playlist track's "Rename / color" result: sets the track's
+  name (`FUN_012e5da0`) and colour (`FUN_012e5dc0`), then calls `FUN_012e6010` for the track, then repaints.
+- `FUN_012e6010 (track context)` — only when the track record's mode (+0xd8) is 1 (**audio track**) and its mixer
+  track (+0xdc) is > 0: the mixer track's colour becomes the track's colour (+0x2c; FL's default track colour with the
+  "own colour" flag +0x70 clear maps to the mixer's default 0x716c63), its icon (+0x14) the track's icon (+0x30), then
+  `FUN_012be6f0 (mixer track, track name, notify)`.
+- Instrument tracks are not synced by this path.
+
+## Mixer track → Playlist track
+
+- `FUN_012be6f0 (mixer track, name, notify)` — sets the mixer track's name (+0xc), then for every arrangement
+  (`FUN_012f9f10` count, `FUN_012f9f00` item) looks up the Playlist track linked to that mixer track
+  (`FUN_012a7810`: the track list at +0x21c7c whose +0xdc equals it) and copies the mixer track's name (track +0x24),
+  icon (+0x30) and colour (+0x2c and +0x64; the mixer default 0x716c63 maps back to the default track colour). 23
+  callers (every mixer rename, recolour, group, routing, the Playlist path above).
+
+## LYNX
+
+`core/PlaylistOps.h` `trackmodes::linkedNames` / `followLinkedNames`, run by `AudioEngine::editSong`: after any edit,
+whichever side of an audio track ⇄ mixer track pair changed (name or colour) is copied to the other; an edit that set
+both (a new link) is left alone. LYNX's own "Link Playlist tracks to mixer tracks" switch keeps syncing instrument
+tracks too (`autolink::followNewContent`), and on open matches a linked pair where one side has the default colour
+(`autolink::matchLinkedColours`). Icons: LYNX's mixer tracks have no icon (the Playlist track's FL icon is kept and saved), so only names and colours are synced.
+Tests: `issues190ns_*` (tests/Issues190nsTests.inc), `--issuesshot190ns`.

+ 66 - 0
src/core/PlaylistOps.cpp

@@ -570,6 +570,51 @@ bool linkToMixerTrack (Song& song, int track, int mixer)
     return true;
 }
 
+LinkedNames linkedNames (const Song& song)
+{
+    LinkedNames n;
+    for (int t = 0; t < (int) song.playlistTracks.size(); ++t)
+    {
+        const auto& pt = song.playlistTracks[(std::size_t) t];
+        if (pt.mode != PlaylistTrackMode::audio || pt.mixerTrack <= 0 || pt.mixerTrack >= (int) song.mixer.size())
+            continue;
+        const auto& mt = song.mixer[(std::size_t) pt.mixerTrack];
+        n.pairs.push_back ({ t, pt.mixerTrack, pt.name, pt.colour, mt.name, mt.colour });
+    }
+    return n;
+}
+
+int followLinkedNames (Song& song, const LinkedNames& before)
+{
+    int changed = 0;
+    for (const auto& p : before.pairs)
+    {
+        if (p.track >= (int) song.playlistTracks.size() || p.mixer >= (int) song.mixer.size())
+            continue;
+        auto& t = song.playlistTracks[(std::size_t) p.track];
+        if (t.mode != PlaylistTrackMode::audio || t.mixerTrack != p.mixer)
+            continue; // (unlinked or relinked by the edit: the link itself set both)
+        auto& m = song.mixer[(std::size_t) p.mixer];
+        const auto trackChanged = t.name != p.trackName || t.colour != p.trackColour;
+        const auto insertChanged = m.name != p.insertName || m.colour != p.insertColour;
+        if (trackChanged && ! insertChanged)
+        {
+            // FUN_012e6010: the mixer track takes the track's colour and name (an unnamed track: FL's empty mixer name)
+            m.colour = t.colour;
+            m.name = t.name.empty() ? "Insert " + std::to_string (p.mixer) : t.name;
+            ++changed;
+        }
+        else if (insertChanged && ! trackChanged)
+        {
+            // FUN_012be6f0: the linked Playlist track takes the mixer track's name and colour
+            t.colour = m.colour;
+            t.name = hasOwnName (song, p.mixer) ? m.name : std::string();
+            ++changed;
+        }
+    }
+    return changed;
+}
+
 int assignAudioTracks (Song& song, const std::vector<int>& tracks, int mixer)
 {
     if (mixer != newMixerTrack && (mixer <= 0 || mixer >= (int) song.mixer.size()))
@@ -1664,6 +1709,27 @@ int followNewContent (Song& song, const Snapshot& before)
     return linked;
 }
 
+int matchLinkedColours (Song& song)
+{
+    if (! song.linkTracksToMixer)
+        return 0;
+    int changed = 0;
+    for (int t = 0; t < (int) song.playlistTracks.size(); ++t)
+        if (const auto m = linkedInsertOf (song, t); validInsert (song, m))
+        {
+            auto& track = song.playlistTracks[(std::size_t) t];
+            auto& insert = song.mixer[(std::size_t) m];
+            if (track.colour == insert.colour || (track.colour != 0 && insert.colour != 0))
+                continue;
+            if (track.colour == 0)
+                track.colour = insert.colour;
+            else
+                insert.colour = track.colour;
+            ++changed;
+        }
+    return changed;
+}
+
 int pairedTakeTrack (const Song& song, int insert)
 {
     const auto track = insert - 1;

+ 29 - 0
src/core/PlaylistOps.h

@@ -131,6 +131,30 @@ bool makeInstrumentTrack (Song& song, int track, int channel);
 // The audio clips already on the track follow it (followAudioTracks). False when canLinkToMixerTrack says no; the
 // insert the track already has changes nothing.
 bool linkToMixerTrack (Song& song, int track, int mixer);
+// FL 2026 keeps an audio track and its mixer track under one name and colour after the link, both ways (issue #235,
+// round 190ns; FLEngine 2026 [DECOMP]): the Playlist track's "Rename / color" (FUN_012e60f0) sets the track's name and
+// colour and then (FUN_012e6010, audio tracks only: mode 1 with a mixer track > 0) gives its mixer track the track's
+// colour (FL's default track colour = the mixer's default), icon and name; a mixer track's name / colour / icon change
+// (FUN_012be6f0, called by every mixer rename, recolour, group, route...) is copied to the Playlist track linked to it
+// (FUN_012a7810) in every arrangement. Instrument tracks are not synced by FL (LYNX's "Link Playlist tracks to mixer
+// tracks" switch syncs them too: autolink::followNewContent).
+// AudioEngine::editSong takes `linkedNames` before an edit and `followLinkedNames` after it: whichever side the edit
+// changed (name or colour) is copied to the other; when both changed (a link that sets both) nothing is touched.
+struct LinkedNames
+{
+    struct Pair
+    {
+        int track = -1, mixer = -1;
+        std::string trackName;
+        std::uint32_t trackColour = 0;
+        std::string insertName;
+        std::uint32_t insertColour = 0;
+    };
+    std::vector<Pair> pairs; // the audio tracks linked to an existing insert
+};
+LinkedNames linkedNames (const Song& song);
+// Returns how many tracks or inserts changed.
+int followLinkedNames (Song& song, const LinkedNames& before);
 // Whether `track` can be linked to `mixer`: an existing insert (never the Master), not linked to another Playlist
 // track (one track per insert, as makeAudioTrack keeps it) and not reserved for another participant of an online
 // session.
@@ -346,6 +370,11 @@ Snapshot snapshot (const Song& song);
 // that changes nothing that already sounded. A track set to Track mode › Unassigned that had content stays unassigned.
 // Returns how many tracks were newly linked.
 int followNewContent (Song& song, const Snapshot& before);
+// Issue #235 (round 190ns): a project saved with the switch on by an older version can hold a linked track and insert
+// of two colours (links kept from older rules, or edits before the colours were synced). On open (MainComponent::
+// openLynxProject), while the switch is on, a pair where one side has the default colour takes the other's colour; two
+// different colours of their own are left as they are. Returns how many pairs changed.
+int matchLinkedColours (Song& song);
 // Recording (core/TakeRecording.h) while the switch is on: the Playlist track a take of insert `insert` goes to when no
 // audio track is linked to it yet — track insert − 1 when it is unassigned, ungrouped and holds no clip; -1 otherwise.
 int pairedTakeTrack (const Song& song, int insert);

+ 2 - 0
src/engine/AudioEngine.cpp

@@ -4077,12 +4077,14 @@ void AudioEngine::editSong (const std::function<void (Song&)>& edit, bool undoab
     // LYNX's "Link Playlist tracks to mixer tracks" (rounds 190gz, 190ib): each instrument's home track and the linked
     // tracks' names before the edit
     const auto linkBefore = autolink::snapshot (song);
+    const auto namesBefore = trackmodes::linkedNames (song); // (round 190ns, issue #235: FL's audio track ⇄ mixer track)
     const auto channelsBefore = song.channels.size(); // (round 190iu: Track-only mode, core/TrackOnly.h)
     edit (song);
     song.keepOnePattern(); // (round 190ea: what follows, and every listener, may read the current pattern)
     mixerops::keepCurrentLast (song); // (round 190mv: FL's Current track stays the last mixer track)
     if (trackonly::active() && song.channels.size() > channelsBefore) // each new instrument gets its own instrument track
         trackonly::follow (song, channelsBefore);
+    trackmodes::followLinkedNames (song, namesBefore); // FL: an audio track and its mixer track keep one name and colour
     if (song.linkTracksToMixer && linkBefore.on) // new content goes through its track's insert; renames follow the link
         autolink::followNewContent (song, linkBefore);
     if (detachNewPluginsOn)

+ 3 - 0
src/ui/MainComponent.cpp

@@ -8942,6 +8942,9 @@ void MainComponent::openLynxProject (const juce::File& file, bool withoutPlugins
         return;
     }
     withoutPlugins = withoutPlugins || std::exchange (nextOpenWithoutPlugins, false);
+    // issue #235 (round 190ns): with "Link Playlist tracks to mixer tracks" on, a linked track and insert show one colour
+    if (const auto matched = autolink::matchLinkedColours (*song); matched > 0)
+        platform::testModeLog ("linked track colours matched on open: " + juce::String (matched));
 
     engine.stop();
     engine.rewind();

+ 130 - 0
tests/Issues190nsTests.inc

@@ -0,0 +1,130 @@
+// Round 190ns: GitHub issues #231 (Project info › Created), #233 (offline), #234 (Manage shortcuts link), #235 (linked
+// track and mixer track colours).
+#include "core/PlaylistOps.h"
+
+namespace issues190ns
+{
+// Song::makeDefault with an audio track linked to a new mixer track (FL's Track mode › Audio track)
+inline lynx::Song songWithAudioTrack (int& track, int& mixer)
+{
+    using namespace lynx;
+    auto song = Song::makeDefault();
+    song.playlistTracks.resize (4);
+    track = 2;
+    song.playlistTracks[2].name = "Vocals";
+    song.playlistTracks[2].colour = 0xff8040c0;
+    CHECK (trackmodes::makeAudioTrack (song, track));
+    mixer = song.playlistTracks[2].mixerTrack;
+    return song;
+}
+} // namespace issues190ns
+
+// #235 (FL 2026 [DECOMP] FUN_012e60f0 → FUN_012e6010): the Playlist track's Rename / color gives its mixer track the same
+// name and colour
+TEST (issues190ns_recoloured_audio_track_recolours_its_mixer_track)
+{
+    using namespace lynx;
+    int track = -1, mixer = -1;
+    auto song = issues190ns::songWithAudioTrack (track, mixer);
+    CHECK (mixer > 0);
+    // the link itself: one name and colour
+    CHECK (song.mixer[(std::size_t) mixer].colour == 0xff8040c0 && song.mixer[(std::size_t) mixer].name == "Vocals");
+
+    auto before = trackmodes::linkedNames (song);
+    song.playlistTracks[(std::size_t) track].colour = 0xff20a050;
+    song.playlistTracks[(std::size_t) track].name = "Lead vox";
+    CHECK (trackmodes::followLinkedNames (song, before) == 1);
+    CHECK (song.mixer[(std::size_t) mixer].colour == 0xff20a050);
+    CHECK (song.mixer[(std::size_t) mixer].name == "Lead vox");
+
+    // a track back to the default colour and no name: the mixer track's default colour, "Insert N"
+    before = trackmodes::linkedNames (song);
+    song.playlistTracks[(std::size_t) track].colour = 0;
+    song.playlistTracks[(std::size_t) track].name.clear();
+    trackmodes::followLinkedNames (song, before);
+    CHECK (song.mixer[(std::size_t) mixer].colour == 0u);
+    CHECK (song.mixer[(std::size_t) mixer].name == "Insert " + std::to_string (mixer));
+}
+
+// #235 (FUN_012be6f0 → FUN_012a7810): the mixer track's Rename / color reaches the Playlist track linked to it
+TEST (issues190ns_recoloured_mixer_track_recolours_its_audio_track)
+{
+    using namespace lynx;
+    int track = -1, mixer = -1;
+    auto song = issues190ns::songWithAudioTrack (track, mixer);
+    const auto before = trackmodes::linkedNames (song);
+    song.mixer[(std::size_t) mixer].colour = 0xffc03030;
+    song.mixer[(std::size_t) mixer].name = "Bus";
+    CHECK (trackmodes::followLinkedNames (song, before) == 1);
+    CHECK (song.playlistTracks[(std::size_t) track].colour == 0xffc03030);
+    CHECK (song.playlistTracks[(std::size_t) track].name == "Bus");
+
+    // an edit that sets both sides (a new link) and other inserts / unassigned tracks are left alone
+    auto again = trackmodes::linkedNames (song);
+    song.mixer[(std::size_t) mixer].colour = 0xff111111;
+    song.playlistTracks[(std::size_t) track].colour = 0xff222222;
+    const auto otherColour = song.mixer[1].colour;
+    song.playlistTracks[0].colour = 0xff333333; // unassigned
+    CHECK (trackmodes::followLinkedNames (song, again) == 0);
+    CHECK (song.mixer[(std::size_t) mixer].colour == 0xff111111 && song.playlistTracks[(std::size_t) track].colour == 0xff222222);
+    CHECK (song.mixer[1].colour == otherColour);
+
+    // instrument tracks are not FL-synced (FUN_012e6010 checks for an audio track)
+    auto inst = Song::makeDefault();
+    inst.playlistTracks.resize (2);
+    CHECK (trackmodes::makeInstrumentTrack (inst, 1, 0));
+    CHECK (trackmodes::linkedNames (inst).pairs.empty());
+}
+
+// #235: LYNX's "Link Playlist tracks to mixer tracks": after switching it on every linked pair carries one colour
+TEST (issues190ns_switching_the_link_on_leaves_one_colour_per_pair)
+{
+    using namespace lynx;
+    auto song = Song::makeDefault();
+    for (int c = 0; c < (int) song.channels.size(); ++c)
+        song.channels[(std::size_t) c].colour = 0xff000000u | (std::uint32_t) (0x203040 * (c + 1));
+    for (int c = 0; c < 3 && c < (int) song.patterns.size(); ++c)
+    {
+        Clip p;
+        p.track = c;
+        p.pattern = c;
+        p.length = 384;
+        song.playlist.push_back (p);
+    }
+    for (int m = 1; m < (int) song.mixer.size(); ++m) // inserts with colours of their own, tracks with the default
+        song.mixer[(std::size_t) m].colour = 0xff000000u | (std::uint32_t) (0x102030 * m);
+    autolink::setOn (song, true);
+    int pairs = 0;
+    for (int t = 0; t < (int) song.playlistTracks.size(); ++t)
+        if (const auto m = autolink::linkedInsertOf (song, t); m > 0 && m < (int) song.mixer.size())
+        {
+            std::printf ("  track %d -> insert %d: %08x / %08x\n", t, m, song.playlistTracks[(std::size_t) t].colour, song.mixer[(std::size_t) m].colour);
+            CHECK (song.playlistTracks[(std::size_t) t].colour == song.mixer[(std::size_t) m].colour);
+            CHECK (song.mixer[(std::size_t) m].colour != 0u);
+            ++pairs;
+        }
+    CHECK (pairs > 0);
+}
+
+// #235: a project saved with the switch on whose linked track has the default colour and its insert a colour (the
+// reporter's purple insert under a grey header) shows one colour when opened; switch off or two own colours: untouched
+TEST (issues190ns_open_matches_linked_colours_while_the_switch_is_on)
+{
+    using namespace lynx;
+    int track = -1, mixer = -1;
+    auto song = issues190ns::songWithAudioTrack (track, mixer);
+    song.playlistTracks[(std::size_t) track].colour = 0;
+    song.mixer[(std::size_t) mixer].colour = 0xff7a4bd1;
+    auto off = song;
+    CHECK (autolink::matchLinkedColours (off) == 0 && off.playlistTracks[(std::size_t) track].colour == 0);
+    song.linkTracksToMixer = true;
+    CHECK (autolink::matchLinkedColours (song) == 1);
+    CHECK (song.playlistTracks[(std::size_t) track].colour == 0xff7a4bd1);
+    // the other way: the track's colour reaches an insert with the default one
+    song.mixer[(std::size_t) mixer].colour = 0;
+    song.playlistTracks[(std::size_t) track].colour = 0xff3fa66b;
+    CHECK (autolink::matchLinkedColours (song) == 1 && song.mixer[(std::size_t) mixer].colour == 0xff3fa66b);
+    // two colours of their own: left alone
+    song.mixer[(std::size_t) mixer].colour = 0xff112233;
+    CHECK (autolink::matchLinkedColours (song) == 0 && song.playlistTracks[(std::size_t) track].colour == 0xff3fa66b);
+}

+ 1 - 0
tests/tests.cpp

@@ -17995,3 +17995,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Details190myTests.inc" // round details10_190my: the Current track follow-ups and details pass 10
 #include "Mixer221_190ngTests.inc" // round 190ng: issue #221 (Del with only the used inserts shown)
 #include "Issues190ngTests.inc" // round 190ng: issues #215, #217, #219, #220, #222
+#include "Issues190nsTests.inc" // round 190ns: issues #231, #233, #234, #235