Răsfoiți Sursa

Channel rack: FL's automation clip channels as rows between the channels (button in the clip colour, curve glyph, idle steps; click opens the clip, menu edit/rename/move/delete); Automation::rackSlot from the .flp's channel order, saved in .lynx, kept through channel insert/remove/move; tests and --selftest rackauto190oo (round 190oo, design review 2: PAT-7)

Ka1-S 2 săptămâni în urmă
părinte
comite
1656bacb87

+ 40 - 1
src/Main.cpp

@@ -207,6 +207,7 @@
 #include "ui/TrackIcons.h"
 #include "core/MeterScale.h"
 #include "core/RackOps.h"
+#include "core/RackAutomation.h" // round 190oo (PAT-7, --selftest rackauto190oo)
 #include "core/Layer.h"
 #include "core/XyController.h"
 #include "core/FlCurve.h"
@@ -8420,6 +8421,43 @@ private:
             folder.deleteRecursively();
         }
 
+        // round 190oo (design review 2, PAT-7; core/RackAutomation.h): the automation clips' Channel rack rows. A .lynx
+        // round trip keeps each clip's place; a clip without one (every clip of an older file) writes nothing and reads
+        // back after the channels; the copy for 0.1.30 drops the key without a loss line.
+        juce::String rackauto190ooResult = "OK";
+        {
+            auto song = lynx::Song::makeDefault();
+            for (int c = 0; c < 3; ++c)
+                song.channels.emplace_back().name = "R" + std::to_string (c);
+            lynx::Automation placed, appended;
+            placed.name = "placed";
+            placed.points = { { 0, 0.2f, 0.0f }, { lynx::ppq, 0.8f, 0.0f } };
+            placed.rackSlot = 1;
+            appended = placed;
+            appended.name = "appended";
+            appended.rackSlot = -1;
+            song.automations.push_back (placed);
+            song.automations.push_back (appended);
+            juce::String why;
+            const auto json = lynx::ProjectFile::toJson (song);
+            const auto back = lynx::ProjectFile::fromJson (json, why);
+            if (! back || back->automations.size() != 2 || back->automations[0].rackSlot != 1 || back->automations[1].rackSlot != -1
+                || lynx::rackauto::order (*back) != lynx::rackauto::order (song))
+                rackauto190ooResult = "ERROR round trip " + why;
+            const auto plain = lynx::Song::makeDefault();
+            const auto plainJson = lynx::ProjectFile::toJson (plain);
+            if (rackauto190ooResult == "OK" && plainJson.contains ("rackSlot"))
+                rackauto190ooResult = "ERROR rackSlot written for a project without placed clips";
+            auto older = song;
+            older.automations[0].rackSlot = -1; // (as a file saved before round 190oo)
+            if (const auto reread = lynx::ProjectFile::fromJson (lynx::ProjectFile::toJson (older), why); rackauto190ooResult == "OK"
+                && (! reread || reread->automations.size() != 2 || reread->automations[0].rackSlot != -1 || lynx::ProjectFile::toJson (older).contains ("rackSlot")))
+                rackauto190ooResult = "ERROR an older project's clips";
+            const auto copy = lynx::olderlynx::forRelease (song, "0.1.30");
+            if (rackauto190ooResult == "OK" && (! copy.ok || copy.json.contains ("rackSlot")))
+                rackauto190ooResult = "ERROR copy for 0.1.30";
+        }
+
         const auto motionOverlayResult = lynx::ui::MotionOverlay::selfTest(); // (round 190ip)
         // round 190bm (0.1.25 showed the Mixer and the Playlist black): their cached pictures shown on native and
         // software targets against straight paints (ui/PictureCheck.h; --picturetest runs more sizes and scales)
@@ -8459,7 +8497,7 @@ private:
                         && mixerBasics == "OK" && fontsResult == "OK" && paintCachesResult.startsWith ("OK") && picturesResult == "OK" && audioOk && projectOk && trackModes122Ok && richOk && hwOutOk && hostKeysOk && pluginLevelsOk && flp168jOk && clipFades180dOk && blocksOk && takeoverOk && compOk && polyOk && latencyOk && preSendOk && lowLatencyOk && previewInTimeOk && substituteOk && patcherOk && rackResult == "OK" && nativesOk && undoOk && projectSaveOk && recordOk && recordUndoOk && cancelRecordOk && midiOk && packageOk
                         && sessionResult == "OK" && liveResult.startsWith ("OK")
                         && wavpack != "ERROR" && effectsOk && driverPanel == "OK" && deviceChange.startsWith ("OK") && exportParity.startsWith ("OK") && exportLive.startsWith ("OK") && midiHotplug.startsWith ("OK") && midiOutPorts.startsWith ("OK") && metronomeOk && artResult == "OK" && effectParamsResult == "OK"
-                        && sidechainResult == "OK" && lanesResult == "OK" && arrange190cgResult == "OK" && livescr190drResult == "OK" && livewf190efResult == "OK" && livewf190emResult == "OK" && trackclips190neResult == "OK" && tracker190nwResult == "OK" && versionsResult == "OK" && pluginsOffResult == "OK" && missingFilesResult == "OK"
+                        && sidechainResult == "OK" && lanesResult == "OK" && arrange190cgResult == "OK" && livescr190drResult == "OK" && livewf190efResult == "OK" && livewf190emResult == "OK" && trackclips190neResult == "OK" && tracker190nwResult == "OK" && rackauto190ooResult == "OK" && versionsResult == "OK" && pluginsOffResult == "OK" && missingFilesResult == "OK"
                         && midigen190fmResult == "OK" && clipenv190giResult == "OK" && beatslaw190gxResult == "OK" && warplaw190ikResult == "OK" && editorScale190heResult == "OK" && sfModBase190heResult == "OK" && trackauto190gzResult == "OK" && community190hqResult == "OK" && rollup030Result == "OK" && rollup031Result == "OK" && rollup031s2Result == "OK"
                         && keys190nuResult == "OK" && rollup031s3Result == "OK"
                         && remoteHistoryResult.startsWith ("OK") && hostedStateLockResult.startsWith ("OK")
@@ -8535,6 +8573,7 @@ private:
                << "livewf190em=" << livewf190emResult << "\n"
                << "trackclips190ne=" << trackclips190neResult << "\n"
                << "tracker190nw=" << tracker190nwResult << "\n"
+               << "rackauto190oo=" << rackauto190ooResult << "\n"
                << "midigen190fm_saved=" << midigen190fmResult << "\n"
                << "trackauto190gz_saved=" << trackauto190gzResult << "\n"
                << "clipenv190gi_saved=" << clipenv190giResult << "\n"

+ 14 - 0
src/core/FlpImport.cpp

@@ -1,5 +1,6 @@
 #include "core/FlCurve.h"
 #include "core/FlpImport.h"
+#include "core/RackAutomation.h" // round 190oo (PAT-7)
 #include "core/FlmImport.h" // round 190fn: the FL Studio Mobile Rack generator
 #include "core/FruityDance.h"
 #include "core/FlpExport.h"
@@ -667,6 +668,9 @@ void splitDrumChannel (Song& song, int channel, const std::vector<DrumPad>& pads
              || t.kind == AutomationTargetKind::channelParam || t.kind == AutomationTargetKind::channelAdjust) && t.index >= 0)
             t.index = shift (t.index);
     });
+
+    // round 190oo (PAT-7): the automation clip rows under the kit stay under its pads
+    rackauto::channelsInserted (song, channel + 1, inserted);
 }
 
 bool isFlSynthPresetPlugin (const std::string& pluginName)
@@ -3978,6 +3982,16 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             lfo.fl.rawAmp = lfo.amp;
         }
 
+        // round 190oo (PAT-7, core/RackAutomation.h): the clip's row in the Channel rack where FL's channel order has it,
+        // above the next channel that is not an automation clip (none after it: after the last channel, −1)
+        for (auto next = (std::size_t) (&c - project.channels.data()) + 1; next < project.channels.size(); ++next)
+            if (const auto& n = project.channels[next]; n.type != flp::ChannelType::automationClip)
+            {
+                if (const auto mapped = channelMap.find (n.index); mapped != channelMap.end())
+                    a.rackSlot = mapped->second;
+                break;
+            }
+
         automationMap[c.index] = (int) song.automations.size();
         song.automations.push_back (std::move (a));
     }

+ 192 - 0
src/core/RackAutomation.h

@@ -0,0 +1,192 @@
+#pragma once
+
+// FL's automation clip channels in the Channel rack (round 190oo, design review 2 PAT-7; the blocker of details DE-123).
+//
+// FL keeps every automation clip as a channel of the rack (.flp channel type 5, "automation clip"): a row among the other
+// channels, its button in the clip's colour, a curve glyph where the mixer track box is, the two knobs (the clip's range),
+// the steps; its button opens the clip (Thief: "Volume Duck", "GROSS..w Bass", "CRASH REVERB" between YELP and
+// "Riser..Metal", design190ia shots/ref/fl-channelrack.png). LYNX keeps automation clips apart from the channels
+// (Song::automations), so the rack shows them as rows of their own between the channel rows and never as channels: no
+// audio, no notes, no mixer insert, not in the channel selection, the channel indices unchanged.
+//
+// Where a row sits is Automation::rackSlot, the gap it fills: above channel row `rackSlot` (FL's channel order from the
+// .flp); −1 = after the last channel. The model's choice: −1 is what every automation of an older LYNX project and every
+// clip made in LYNX has, so a project without automation clips keeps its rack row for row, and one with clips shows them
+// after its channels, where FL appends a channel made last (FL lists every automation clip in the rack). Inside one gap
+// the rows follow the automations' order. No JUCE: tests/RackAutomation190ooTests.inc.
+
+#include <algorithm>
+#include <utility>
+#include <vector>
+
+#include "core/RackFilter.h"
+#include "core/Song.h"
+
+namespace lynx::rackauto
+{
+// FL's built-in filter group of the automation clip channels (REA_rodada168t §3: FL files an automation clip channel
+// under "Automation clips"; an imported .flp keeps the group's name)
+constexpr const char* groupName = "Automation clips";
+
+struct Row
+{
+    int automation = -1; // index into Song::automations
+    int gap = 0;         // the row sits above channel row `gap` (channels.size(): after the last channel)
+    bool operator== (const Row&) const = default;
+};
+
+// The gap of automation `a`'s row (−1 and anything past the end: after the last channel).
+inline int gapOf (const Song& song, const Automation& a) noexcept
+{
+    const auto count = (int) song.channels.size();
+    return a.rackSlot < 0 || a.rackSlot > count ? count : a.rackSlot;
+}
+
+// The automations that are FL automation clips, so they get a row: a clip with points; not a live controller link (FL's
+// Peak / Envelope controller links are no clip), not the ruler's tempo markers (round 190hq) and not an automation lane
+// under a Playlist track (Live / Bitwig style, round 177b).
+inline std::vector<char> clipFlags (const Song& song)
+{
+    std::vector<char> flags (song.automations.size(), 1);
+    for (std::size_t i = 0; i < song.automations.size(); ++i)
+    {
+        const auto& a = song.automations[i];
+        if (a.isLive() || a.tempoMarkers || a.points.empty())
+            flags[i] = 0;
+    }
+    for (const auto& t : song.playlistTracks)
+        for (const auto& l : t.lanes)
+            if (l.automation >= 0 && l.automation < (int) flags.size())
+                flags[(std::size_t) l.automation] = 0;
+    return flags;
+}
+
+inline bool listed (const Song& song, int automation)
+{
+    if (automation < 0 || automation >= (int) song.automations.size())
+        return false;
+    return clipFlags (song)[(std::size_t) automation] != 0;
+}
+
+// The automation rows in the rack's order: by gap, then in the automations' order.
+inline std::vector<Row> rows (const Song& song)
+{
+    std::vector<Row> out;
+    const auto flags = clipFlags (song);
+    for (int i = 0; i < (int) song.automations.size(); ++i)
+        if (flags[(std::size_t) i] != 0)
+            out.push_back ({ i, gapOf (song, song.automations[(std::size_t) i]) });
+    std::stable_sort (out.begin(), out.end(), [] (const Row& x, const Row& y) { return x.gap < y.gap; });
+    return out;
+}
+
+// before[k] = how many of `rows` sit above channel row k (k = channels.size(): the "add channel" row).
+inline std::vector<int> rowsBefore (const Song& song, const std::vector<Row>& rows)
+{
+    std::vector<int> before (song.channels.size() + 1, 0);
+    for (const auto& r : rows)
+        if (r.gap >= 0 && r.gap < (int) before.size())
+            ++before[(std::size_t) r.gap];
+    for (std::size_t k = 1; k < before.size(); ++k)
+        before[k] += before[k - 1];
+    return before;
+}
+
+// The whole rack top to bottom: channel rows and automation rows interleaved (the "add channel" row not included).
+struct Entry
+{
+    bool automation = false;
+    int index = -1; // a channel, or an automation
+    bool operator== (const Entry&) const = default;
+};
+
+inline std::vector<Entry> order (const Song& song)
+{
+    std::vector<Entry> out;
+    const auto list = rows (song);
+    std::size_t next = 0;
+    for (int c = 0; c <= (int) song.channels.size(); ++c)
+    {
+        for (; next < list.size() && list[next].gap == c; ++next)
+            out.push_back ({ true, list[next].automation });
+        if (c < (int) song.channels.size())
+            out.push_back ({ false, c });
+    }
+    return out;
+}
+
+// Whether the rack shows the automation rows under its filter: "All", and FL's "Automation clips" group (a group of
+// that name from an imported .flp, whose channels are FL's automation clips). Every other view lists channels only.
+inline bool shownUnder (const Song& song, int filter)
+{
+    if (filter == rackfilter::all)
+        return true;
+    return filter >= 0 && filter < (int) song.channelGroups.size() && song.channelGroups[(std::size_t) filter] == groupName;
+}
+
+// --- keeping the rows in place while the channels change ------------------------------------------------------------
+
+// `count` channels were inserted at row `index`: the rows at or below it move down with the channels there (a channel
+// inserted where an automation row is goes above it, as FL puts a new channel right under the selected one).
+inline void channelsInserted (Song& song, int index, int count = 1) noexcept
+{
+    for (auto& a : song.automations)
+        if (a.rackSlot >= index)
+            a.rackSlot += count;
+}
+
+// --- moving rows (FL: an automation clip channel moves as any channel does, Alt+Up / Alt+Down) ----------------------
+
+// Moves automation `automation`'s row past the channel row above (delta < 0) or below it; false at the top / bottom.
+inline bool moveRow (Song& song, int automation, int delta)
+{
+    if (automation < 0 || automation >= (int) song.automations.size() || delta == 0)
+        return false;
+    auto& a = song.automations[(std::size_t) automation];
+    const auto count = (int) song.channels.size();
+    const auto from = gapOf (song, a);
+    const auto to = std::clamp (from + (delta < 0 ? -1 : 1), 0, count);
+    if (to == from)
+        return false;
+    a.rackSlot = to;
+    return true;
+}
+
+// The selected channels moved one row (delta < 0: up) pass an automation row next to them, as FL moves channels past an
+// automation clip channel: when the selection is one block of channels and an automation row sits right above it (up)
+// or right below it (down), that row goes to the block's other side and the channels keep their rows. Returns the
+// automation and its new rackSlot, {-1, 0} when there is none (the channels move as before, moveChannels).
+inline std::pair<int, int> passFor (const Song& song, std::vector<int> selection, int delta)
+{
+    std::sort (selection.begin(), selection.end());
+    selection.erase (std::unique (selection.begin(), selection.end()), selection.end());
+    const auto count = (int) song.channels.size();
+    if (selection.empty() || delta == 0 || selection.front() < 0 || selection.back() >= count
+        || selection.back() - selection.front() + 1 != (int) selection.size())
+        return { -1, 0 };
+    const auto first = selection.front(), last = selection.back();
+    const auto list = rows (song);
+    if (delta < 0) // the lowest row right above the block goes right below it
+    {
+        for (auto it = list.rbegin(); it != list.rend(); ++it)
+            if (it->gap == first)
+                return { it->automation, last + 1 };
+    }
+    else // the highest row right below the block goes right above it
+    {
+        for (const auto& r : list)
+            if (r.gap == last + 1)
+                return { r.automation, first };
+    }
+    return { -1, 0 };
+}
+
+inline bool passRow (Song& song, const std::vector<int>& selection, int delta)
+{
+    const auto [automation, slot] = passFor (song, selection, delta);
+    if (automation < 0)
+        return false;
+    song.automations[(std::size_t) automation].rackSlot = slot;
+    return true;
+}
+} // namespace lynx::rackauto

+ 2 - 0
src/core/RackOps.cpp

@@ -1,4 +1,5 @@
 #include "core/RackOps.h"
+#include "core/RackAutomation.h" // round 190oo (PAT-7)
 #include "core/TrackClips.h"
 
 #include "core/MidiControls.h"
@@ -835,6 +836,7 @@ int insertChannel (Song& song, int index, ChannelDef channel)
         order.push_back (i);
 
     permuteChannels (song, order);
+    rackauto::channelsInserted (song, index); // round 190oo (PAT-7): the automation clip rows below stay below
     return index;
 }
 

+ 4 - 0
src/core/Song.cpp

@@ -427,6 +427,10 @@ void Song::removeChannel (int index)
         else if (automation.source.channel > index)
             --automation.source.channel;
 
+    for (auto& automation : automations) // round 190oo (PAT-7): the automation clip rows keep their place in the rack
+        if (automation.rackSlot > index)
+            --automation.rackSlot;
+
     for (auto& c : channels) // Layer children (round 164)
     {
         auto& kids = c.layer.children;

+ 4 - 0
src/core/Song.h

@@ -2074,6 +2074,10 @@ struct Automation
     bool tempoMarkers = false;
     bool isLive() const noexcept { return source.track >= 0 || source.channel >= 0; }
     std::uint64_t uid = 0; // stable id (Online Sessions, round 168a)
+    // FL's automation clip channel in the Channel rack (round 190oo, design review 2 PAT-7; core/RackAutomation.h): the
+    // clip's row sits above channel row `rackSlot` (FL's channel order of an imported .flp); −1 = after the last channel
+    // (a clip made in LYNX, and every clip of a project saved before round 190oo). Saved as "rackSlot" when set.
+    int rackSlot = -1;
     float mapLive (float v) const noexcept; // applies the curve
 
     // Value at `tick` (before the first point = first value; after the last = last).

+ 7 - 0
src/engine/ProjectDowngrade.cpp

@@ -1480,6 +1480,13 @@ void toRelease0130 (juce::var& root, Losses& lost)
 
     // round 190nu (chord2_190nu): the Piano roll's key markers
     keyMarkersFor0130 (root, lost);
+
+    // round 190oo (PAT-7, core/RackAutomation.h): the automation clips' rows in the Channel rack. 0.1.30's rack has no
+    // automation rows and the clips play the same: dropped without a loss line
+    if (auto* automations = arrayOf (root["automations"]))
+        for (auto& a : *automations)
+            if (auto* ao = objectOf (a))
+                drop (*ao, "rackSlot");
 }
 
 struct Step

+ 3 - 0
src/engine/ProjectFile.cpp

@@ -3295,6 +3295,8 @@ juce::String toJson (const Song& song, bool stampVersion)
         }
         if (a.colour != 0) // round 190ig: the clip's colour (FL: its channel's); absent = none, as older files
             o->setProperty ("colour", (juce::int64) a.colour);
+        if (a.rackSlot >= 0) // round 190oo (PAT-7): its row in the Channel rack; absent = after the channels, as older files
+            o->setProperty ("rackSlot", a.rackSlot);
         if (const auto& l = a.lfo; ! l.isDefault()) // round 177b: FL's clip LFO
         {
             juce::Array<juce::var> amp;
@@ -4159,6 +4161,7 @@ std::optional<Song> fromJsonImpl (const juce::String& json, juce::String& error,
                 automation.source = { (int) source[0], (int) source[1], (int) source[2], source.size() >= 4 ? (int) source[3] : -1 };
             automation.recordLive = (bool) a["recordLive"];
             automation.colour = (std::uint32_t) (juce::int64) a.getProperty ("colour", 0);
+            automation.rackSlot = juce::jmax (-1, (int) a.getProperty ("rackSlot", -1)); // (round 190oo, PAT-7)
             automation.tempoMarkers = (bool) a["tempoMarkers"] && automation.target.kind == AutomationTargetKind::tempo; // (round 190hq)
             if (auto* links = a["links"].getArray()) // round 190gw
                 for (const auto& l : *links)

+ 1 - 1
src/engine/RemoteProjectDocument.cpp

@@ -150,7 +150,7 @@ const DocumentFields& editableDocumentFields (DocumentShape shape)
         add (S::pattern, "name uid length colour loopOn loopStarterGenre loopMode channelLoops markers notes");
         add (S::pattern, "events", S::events, true);
         add (S::events, "target events");
-        add (S::automation, "name uid target points source curve lfo lfoFl recordLive colour tempoMarkers");
+        add (S::automation, "name uid target points source curve lfo lfoFl recordLive colour tempoMarkers rackSlot");
         add (S::automation, "links", S::readOnly);
         add (S::modulator, "name shape sync beats hz phase unipolar seed routes");
         add (S::vca, "name colour level muted members parent");

+ 282 - 9
src/ui/ChannelRackComponent.cpp

@@ -407,6 +407,7 @@ void ChannelRackComponent::groupSelected()
 void ChannelRackComponent::updateSize()
 {
     refreshZipLayout(); // (round 190mk: zipped channels' strips)
+    refreshAutomationRows(); // (round 190oo, PAT-7: the automation clip rows, after the strips they keep whole)
     const auto rows = shownCount() + 1; // +1 = "add channel" row
     // FL's ghost steps: when the rack is wider than the pattern, the free width shows faint steps after its end;
     // clicking one adds a step there and makes the pattern longer (issue #11)
@@ -415,7 +416,7 @@ void ChannelRackComponent::updateSize()
     if (const auto* holder = getParentComponent())
         ghostSteps = juce::jmax (0, (holder->getWidth() - gridLeft() - 8 - loopColumn) / stepWidth - numSteps());
     setSize (gridLeft() + shownSteps() * stepWidth + 8 + loopColumn,
-             (zipLayout.top.empty() ? rows * rowHeight : zipLayout.total) + 8 + (graphRow() >= 0 ? laneHeight : 0));
+             (zipLayout.top.empty() ? rows * rowHeight : zipLayout.total) + (int) autoRows.size() * rowHeight + 8 + (graphRow() >= 0 ? laneHeight : 0));
 }
 
 // --- FL's Channel button width (round 190mk, DE-39) ---------------------------------------------------------------------
@@ -550,6 +551,14 @@ int ChannelRackComponent::graphRow() const
 }
 
 int ChannelRackComponent::rowY (int row) const
+{
+    const auto base = baseRowY (row);
+    if (autoBefore.empty() || row < 0) // (round 190oo: no automation clip rows, the rows as before)
+        return base;
+    return base + autoBefore[(std::size_t) juce::jmin (row, (int) autoBefore.size() - 1)] * rowHeight;
+}
+
+int ChannelRackComponent::baseRowY (int row) const
 {
     const auto lane = graphRow();
     const auto offset = lane >= 0 && row > lane ? laneHeight : 0;
@@ -563,9 +572,29 @@ int ChannelRackComponent::rowAtY (int y) const
     if (y < 4)
         return -1;
 
+    // round 190oo (PAT-7): the automation clip rows above y move it up a row each; on one, the channel row under it
+    // answers (the drags and drops that look for a channel; areaAt finds the automation row itself first)
+    if (! autoRows.empty())
+    {
+        int above = 0;
+        for (int i = 0; i < (int) autoRows.size(); ++i)
+        {
+            const auto top = automationRowTop (i);
+            if (y >= top + rowHeight)
+                ++above;
+            else
+            {
+                if (y >= top)
+                    return autoRows[(std::size_t) i].gap;
+                break;
+            }
+        }
+        y -= above * rowHeight;
+    }
+
     if (const auto lane = graphRow(); lane >= 0)
     {
-        const auto laneTop = rowY (lane) + rowHeight;
+        const auto laneTop = baseRowY (lane) + rowHeight;
         if (y >= laneTop && y < laneTop + laneHeight)
             return lane;
         if (y >= laneTop + laneHeight)
@@ -845,12 +874,20 @@ void ChannelRackComponent::burnMidi (int channel, bool toNewPattern)
 ChannelRackComponent::Area ChannelRackComponent::areaAt (int x, int y, int& row) const
 {
     const auto channels = (int) engine.getSong().channels.size();
-    row = rowAtY (y);
     const auto rackX = x;
 
     if (x < stickyX + gridLeft()) // the controls column (painted at the visible left edge)
         x -= stickyX;
 
+    // round 190oo (PAT-7): an automation clip row (FL's automation clip channel): its button, or the rest of the row
+    if (const auto automationRow = autoRows.empty() ? -1 : automationRowAt (y); automationRow >= 0)
+    {
+        row = autoRows[(std::size_t) automationRow].automation;
+        return x >= nameLeft() && x < selectLeft() ? Area::autoName : Area::autoRow;
+    }
+
+    row = rowAtY (y);
+
     if (row < 0 || row > channels)
         return Area::none;
 
@@ -1161,6 +1198,9 @@ void ChannelRackComponent::paint (juce::Graphics& g)
         }
     }
 
+    if (! autoRows.empty()) // round 190oo (PAT-7): the automation clip rows' steps
+        paintAutomationSteps (g, clip);
+
     paintLane (g);
     const auto addY = rowY ((int) song.channels.size());
     g.setColour (theme::colour::textSecondary); // (round 190oo PAT-14: an informative hint, 7:1; was textDisabled 2.9:1)
@@ -1354,6 +1394,9 @@ void ChannelRackComponent::paint (juce::Graphics& g)
             }
         }
 
+        if (! autoRows.empty()) // round 190oo (PAT-7): the automation clip rows' controls and buttons
+            paintAutomationButtons (g, column);
+
         paintLane (g);
         {
             const auto box = racklayout::addChannelBox (nameLeft(), nameWidth, addY, rowHeight);
@@ -1387,6 +1430,195 @@ void ChannelRackComponent::paint (juce::Graphics& g)
         paintLoopColumn (g);
 }
 
+// --- FL's automation clip channels (round 190oo, design review 2 PAT-7; core/RackAutomation.h) ------------------------
+// FL lists every automation clip as a channel of the rack (Thief: "Volume Duck", "GROSS..w Bass", "CRASH REVERB" between
+// YELP and "Riser..Metal", design190ia shots/ref/fl-channelrack.png). Here they are rows of their own between the channel
+// rows: the channel rows keep their indices, so the selection, the filter groups, the Piano roll's channel, the mixer
+// routing and the steps never see them.
+
+void ChannelRackComponent::refreshAutomationRows()
+{
+    autoRows.clear();
+    autoBefore.clear();
+    const auto& song = engine.getSong();
+    if (song.automations.empty() || ! rackauto::shownUnder (song, filterGroup))
+        return;
+    autoRows = rackauto::rows (song);
+    if (autoRows.empty())
+        return;
+    // a row inside a zipped strip (round 190mk) goes right below the strip: the strip stays whole
+    if (! zipLayout.first.empty())
+    {
+        const auto count = (int) song.channels.size();
+        for (auto& r : autoRows)
+            while (r.gap < count && r.gap < (int) zipLayout.first.size() && zipLayout.first[(std::size_t) r.gap] != r.gap)
+                ++r.gap;
+        std::stable_sort (autoRows.begin(), autoRows.end(), [] (const rackauto::Row& a, const rackauto::Row& b) { return a.gap < b.gap; });
+    }
+    autoBefore = rackauto::rowsBefore (song, autoRows);
+}
+
+int ChannelRackComponent::automationRowTop (int i) const
+{
+    // the channel rows above its gap (the graph lane and the zipped strips included) and the automation rows before it
+    return baseRowY (autoRows[(std::size_t) i].gap) + i * rowHeight;
+}
+
+int ChannelRackComponent::automationRowAt (int y) const
+{
+    for (int i = 0; i < (int) autoRows.size(); ++i)
+    {
+        const auto top = automationRowTop (i);
+        if (y < top)
+            return -1; // (top to bottom: the others are lower)
+        if (y < top + rowHeight)
+            return i;
+    }
+    return -1;
+}
+
+juce::Rectangle<int> ChannelRackComponent::automationRowBounds (int automation) const
+{
+    for (int i = 0; i < (int) autoRows.size(); ++i)
+        if (autoRows[(std::size_t) i].automation == automation)
+            return { 0, automationRowTop (i), getWidth(), rowHeight };
+    return {};
+}
+
+// FL draws an automation clip channel's steps as any channel's (idle: LYNX does not start a clip from steps, the triggered
+// playback of details DE-123); the piano roll overview leaves the row empty (a clip has no notes)
+void ChannelRackComponent::paintAutomationSteps (juce::Graphics& g, juce::Rectangle<int> clip)
+{
+    if (pianoRollView)
+        return;
+    using namespace theme::colour;
+    const auto steps = shownSteps(), realSteps = numSteps();
+    for (int i = 0; i < (int) autoRows.size(); ++i)
+    {
+        const auto y = automationRowTop (i);
+        if (y > clip.getBottom() || y + rowHeight < clip.getY())
+            continue;
+        for (int start = 0; start < steps; start += 8)
+        {
+            const auto first = juce::Rectangle<int> (gridLeft() + start * stepWidth + 1, y + 5, stepWidth - 3, rowHeight - 10); // (stepBounds)
+            if (first.getX() + 8 * stepWidth < clip.getX() || first.getX() > clip.getRight())
+                continue;
+            if (start + 8 <= realSteps)
+                drawIdleStepStrip (g, first, stepWidth, theme::stepOff (start), theme::stepOff (start + 4), bg2);
+            else if (start >= realSteps && start + 8 <= steps)
+                theme::drawStepStripOver (g, first, stepWidth, theme::stepOff (start), theme::stepOff (start + 4), true, bg2);
+            else
+                for (int step = start; step < juce::jmin (start + 8, steps); ++step)
+                {
+                    const auto r = first.withX (gridLeft() + step * stepWidth + 1);
+                    const auto fill = theme::stepOff (step);
+                    if (step < realSteps)
+                    {
+                        paintKeycap (g, r, fill, false);
+                        continue;
+                    }
+                    theme::fillRoundRect (g, r.toFloat(), keycapRadius, fill.withMultipliedAlpha (0.35f)); // (a ghost step)
+                    g.setColour (fill.brighter (0.25f).withMultipliedAlpha (0.55f));
+                    g.drawRoundedRectangle (r.toFloat().reduced (0.5f), keycapRadius, 1.0f);
+                }
+        }
+    }
+}
+
+// FL's row (fl-channelrack.png rows y 834-894): the mute light on, the two knobs (FL's are the clip's range, minimum and
+// maximum; a LYNX clip spans its target's whole range: 0 and 1), the curve glyph where the mixer track box is, the button
+// in the clip's colour (FL's grey #485156 without one) with the name in white and no icon, the selector's empty slot
+void ChannelRackComponent::paintAutomationButtons (juce::Graphics& g, juce::Rectangle<int> column)
+{
+    using namespace theme::colour;
+    const auto& song = engine.getSong();
+    for (int i = 0; i < (int) autoRows.size(); ++i)
+    {
+        const auto a = autoRows[(std::size_t) i].automation;
+        const auto y = automationRowTop (i);
+        if (a < 0 || a >= (int) song.automations.size() || y > column.getBottom() || y + rowHeight < column.getY())
+            continue;
+        const auto& automation = song.automations[(std::size_t) a];
+
+        if (column.getX() < selectLeft() || ! ui::paintSavings()) // (as the channel rows: a playhead frame skips them)
+        {
+            g.setColour (theme::muteLed (false));
+            g.fillEllipse (juce::Rectangle<float> (9.0f, (float) y + rowHeight / 2.0f - 4.5f, 9.0f, 9.0f));
+
+            const auto knob = [y] (int left) { return juce::Rectangle<float> ((float) left, (float) y, (float) knobWidth, (float) rowHeight).reduced (1.0f, 2.0f); };
+            theme::drawKnob (g, knob (muteWidth), 0.0f, false, knobArc, false);
+            theme::drawKnob (g, knob (muteWidth + knobWidth), 1.0f, false, knobArc, false);
+
+            if (showMixerSelectors) // FL's curve glyph: two small rings joined by a rising line
+            {
+                const auto box = juce::Rectangle<float> ((float) (muteWidth + 2 * knobWidth + 1), (float) y + 7.0f, (float) routeWidth - 3.0f, (float) rowHeight - 14.0f);
+                const auto centre = box.getCentre();
+                const juce::Point<float> low (centre.x - 5.0f, centre.y + 3.5f), high (centre.x + 5.0f, centre.y - 3.5f);
+                const auto along = (high - low) / low.getDistanceFrom (high) * 2.0f;
+                g.setColour (textSecondary.withAlpha (0.75f));
+                g.drawEllipse (juce::Rectangle<float> (4.0f, 4.0f).withCentre (low), 1.0f);
+                g.drawEllipse (juce::Rectangle<float> (4.0f, 4.0f).withCentre (high), 1.0f);
+                g.drawLine (juce::Line<float> (low + along, high - along), 1.0f);
+            }
+
+            const auto nameArea = juce::Rectangle<float> ((float) nameLeft(), (float) y + 3, (float) nameWidth, (float) rowHeight - 6);
+            auto fill = theme::colourFill (automation.colour != 0 ? juce::Colour (automation.colour) : juce::Colour (0xff485156), 0.42f, 0.58f);
+            if (hoverArea == Area::autoName && hoverRow == a)
+                fill = fill.brighter (0.12f);
+            theme::fillPlate (g, nameArea, theme::radius::sm, fill.withMultipliedBrightness (1.06f), fill.withMultipliedBrightness (0.94f));
+            g.setColour (onAccent.withAlpha (0.92f));
+            g.setFont (theme::font (theme::type::body + 1.0f));
+            const auto textArea = nameArea.withTrimmedLeft (nameAlignLeft ? 7.0f : 6.0f).withTrimmedRight (nameAlignLeft ? 5.0f : 6.0f);
+            const auto name = automation.name.empty() ? tr ("Automation clip") : juce::String::fromUTF8 (automation.name.c_str());
+            textcache::drawText (g, theme::fitMiddle (name, g.getCurrentFont(), textArea.getWidth()), textArea,
+                                 nameAlignLeft ? juce::Justification::centredLeft : juce::Justification::centred, false);
+            g.setFont (theme::font (theme::type::body));
+        }
+
+        const auto slot = juce::Rectangle<float> ((float) selectLeft() + 1.0f, (float) y + 3.0f, (float) selectWidth - 2.0f, (float) rowHeight - 6.0f);
+        theme::fillRoundRect (g, slot, 2.0f, border);
+        theme::fillRoundRect (g, slot.reduced (1.0f), 1.5f, bg1);
+    }
+}
+
+// Right-click on an automation clip row: what LYNX already does with a clip (the Playlist's automation clip items)
+void ChannelRackComponent::showAutomationMenu (int automation)
+{
+    const auto& song = engine.getSong();
+    if (automation < 0 || automation >= (int) song.automations.size())
+        return;
+    const auto& a = song.automations[(std::size_t) automation];
+    const auto gap = rackauto::gapOf (song, a);
+    const auto count = (int) song.channels.size();
+    juce::PopupMenu menu;
+    menu.addSectionHeader (a.name.empty() ? tr ("Automation clip") : juce::String::fromUTF8 (a.name.c_str()));
+    menu.addItem (tr ("Edit points..."), [this, automation] { openAutomationEditor (engine, automation); });
+    menu.addItem (tr ("Rename and color..."), [this, automation] {
+        const auto& s = engine.getSong();
+        if (automation >= (int) s.automations.size())
+            return;
+        const auto& clip = s.automations[(std::size_t) automation];
+        showNameAndColourDialog (tr ("Rename automation clip"), juce::String::fromUTF8 (clip.name.c_str()), clip.colour,
+                                 [this, automation] (const juce::String& name, std::uint32_t colour) {
+                                     engine.editSong ([automation, text = name.toStdString(), colour] (Song& edited) {
+                                         if (automation < (int) edited.automations.size())
+                                         {
+                                             edited.automations[(std::size_t) automation].name = text;
+                                             edited.automations[(std::size_t) automation].colour = colour;
+                                         }
+                                     });
+                                 });
+    });
+    menu.addSeparator();
+    menu.addItem (tr ("Move up"), gap > 0, false, [this, automation] { engine.editSong ([automation] (Song& s) { rackauto::moveRow (s, automation, -1); }); });
+    menu.addItem (tr ("Move down"), gap < count, false, [this, automation] { engine.editSong ([automation] (Song& s) { rackauto::moveRow (s, automation, 1); }); });
+    menu.addSeparator();
+    menu.addItem (tr ("Delete automation (all of its clips)"), [this, automation] {
+        engine.editSong ([automation] (Song& s) { s.removeAutomation (automation); });
+    });
+    menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
+}
+
 // The miniature of a channel's piano-roll notes across its step area (FL shows one once a channel has notes
 // that steps can't show); the notes keep their time and length, pitch maps onto the row's height.
 void ChannelRackComponent::paintNotePreview (juce::Graphics& g, int row, const Pattern& pattern, std::uint32_t channelColour)
@@ -1595,6 +1827,8 @@ void ChannelRackComponent::setHover (Area area, int row, int step)
             repaint (laneBounds());
         else if (a == Area::addRow)
             repaint (rowBounds ((int) engine.getSong().channels.size()));
+        else if (a == Area::autoName || a == Area::autoRow) // (round 190oo: `r` is an automation)
+            repaint (automationRowBounds (r));
         else if (r >= 0)
             repaint (rowBounds (r));
     };
@@ -1704,6 +1938,20 @@ bool ChannelRackComponent::moveSelected (int delta)
     bool moved = false;
     std::vector<int> after;
 
+    // round 190oo (PAT-7): FL moves channels past an automation clip channel as past any channel: an automation clip row
+    // right next to the selected block goes to its other side, the channels keep their rows (core/RackAutomation.h)
+    if (! autoRows.empty())
+        if (const auto pass = rackauto::passFor (engine.getSong(), rows, delta); pass.first >= 0)
+        {
+            engine.editSong ([pass] (Song& s) {
+                if (pass.first < (int) s.automations.size())
+                    s.automations[(std::size_t) pass.first].rackSlot = pass.second;
+            });
+            updateSize();
+            repaint();
+            return true;
+        }
+
     engine.editSongStructural ([&] (Song& s) {
         after = rows;
         moved = moveChannels (s, after, delta);
@@ -2465,6 +2713,14 @@ void ChannelRackComponent::mouseDown (const juce::MouseEvent& e)
         case Area::none:
             return;
 
+        case Area::autoName: // round 190oo (PAT-7): FL's automation clip channel; its button opens the clip
+        case Area::autoRow:
+            if (flmods::popup (e.mods))
+                showAutomationMenu (row);
+            else if (area == Area::autoName && e.mods.isLeftButtonDown())
+                openAutomationEditor (engine, row);
+            return;
+
         case Area::zipped: // round 190mk (FL's manual: "Right-Click the button of a zipped Channel to unzip it")
             if (flmods::popup (e.mods))
                 unzip (row);
@@ -2754,8 +3010,9 @@ void ChannelRackComponent::mouseDrag (const juce::MouseEvent& e)
         const auto count = (int) engine.getSong().channels.size();
         const auto target = juce::jlimit (0, count - 1, rowAtY (e.y));
 
-        // move the selection one row at a time until the grabbed channel is under the mouse
-        for (int guard = 0; guard < count && engine.getSelectedChannel() != target; ++guard)
+        // move the selection one row at a time until the grabbed channel is under the mouse (round 190oo: passing an
+        // automation clip row is a step too)
+        for (int guard = 0; guard < count + (int) autoRows.size() && engine.getSelectedChannel() != target; ++guard)
             if (! moveSelected (target < engine.getSelectedChannel() ? -1 : 1))
                 break;
         return;
@@ -2893,6 +3150,19 @@ ui::Hint ChannelRackComponent::hintAt (juce::Point<int> p)
     const auto& song = engine.getSong();
     ui::Hint h;
 
+    if (area == Area::autoName || area == Area::autoRow) // round 190oo (PAT-7): FL's automation clip channel
+    {
+        if (row >= 0 && row < (int) song.automations.size())
+        {
+            const auto& a = song.automations[(std::size_t) row];
+            h.text = (a.name.empty() ? tr ("Automation clip") : juce::String::fromUTF8 (a.name.c_str())) + " - "
+                     + tr ("Automation clip: [LMB] open it  [RMB] menu");
+            h.value = tr ("Automation clip"); // (FL names the channel's type on the right)
+            h.hasMenu = true;
+        }
+        return h;
+    }
+
     if (row >= 0 && row < (int) song.channels.size() && (area == Area::pan || area == Area::volume || area == Area::route))
     {
         const auto active = knobDrag != Area::none && drag.isActive();
@@ -2996,6 +3266,8 @@ void ChannelRackComponent::applyPaint (const juce::MouseEvent& e)
 
     if (laneBounds().contains (e.getPosition()) || (advancedLoopShown() && e.x >= loopBoxBounds (0).getX() - 3))
         return;
+    if (! autoRows.empty() && automationRowAt (e.y) >= 0) // (round 190oo: an automation clip row has no steps to draw)
+        return;
 
     if (row < 0 || row >= (int) song.channels.size() || step < 0 || step >= shownSteps() || e.x < stickyX + gridLeft()
         || showsNotePreview (song.activePattern(), row, pianoRollView)) // drag-paint skips note rows
@@ -3807,7 +4079,7 @@ void ChannelRackComponent::filesDropped (const juce::StringArray& files, int x,
 {
     int row = 0;
     const auto area = areaAt (x, y, row);
-    auto target = (area == Area::none || area == Area::addRow) ? -1 : row;
+    auto target = (area == Area::none || area == Area::addRow || area == Area::autoName || area == Area::autoRow) ? -1 : row; // (190oo: no channel)
 
     for (const auto& f : files)
     {
@@ -3981,7 +4253,8 @@ void ChannelRackComponent::itemDropped (const SourceDetails& details)
         {
             int row = 0;
             const auto area = areaAt (details.localPosition.x, details.localPosition.y, row);
-            if (area != Area::none && area != Area::addRow && row >= 0 && row < (int) engine.getSong().channels.size())
+            if (area != Area::none && area != Area::addRow && area != Area::autoName && area != Area::autoRow && row >= 0
+                && row < (int) engine.getSong().channels.size())
             {
                 closeEditor (row);
                 const auto kind = c->instrument;
@@ -4010,8 +4283,8 @@ void ChannelRackComponent::itemDropped (const SourceDetails& details)
         int row = 0;
         const auto area = areaAt (details.localPosition.x, details.localPosition.y, row);
         const auto& song = engine.getSong();
-        if (area != Area::none && area != Area::addRow && row >= 0 && row < (int) song.channels.size()
-            && song.channels[(std::size_t) row].instrument == InstrumentKind::soundfont)
+        if (area != Area::none && area != Area::addRow && area != Area::autoName && area != Area::autoRow && row >= 0
+            && row < (int) song.channels.size() && song.channels[(std::size_t) row].instrument == InstrumentKind::soundfont)
             loadSoundFontInto (engine, row, path, bank, program);
         else
             addSoundFontChannel (engine, path, bank, program);

+ 18 - 2
src/ui/ChannelRackComponent.h

@@ -11,6 +11,7 @@
 #include "core/HeldNotes.h"
 
 #include "core/RackOps.h"
+#include "core/RackAutomation.h"
 #include "core/RackZip.h"
 #include "engine/AudioEngine.h"
 #include "ui/TimerWhileShowing.h"
@@ -225,7 +226,9 @@ public:
     static constexpr int stepWidth = 18; // (round 190io, FM-11: FL's keycap pitch is 16, LYNX 18; was 22)
 
 private:
-    enum class Area { none, mute, pan, volume, route, name, select, grid, addRow, laneLevels, lane, loop, zipped };
+    // autoName / autoRow (round 190oo, PAT-7): an automation clip row's button / the rest of it; `row` is then the
+    // automation's index (Song::automations), never a channel
+    enum class Area { none, mute, pan, volume, route, name, select, grid, addRow, laneLevels, lane, loop, zipped, autoName, autoRow };
 
     void changeListenerCallback (juce::ChangeBroadcaster*) override;
     void timerCallback() override;
@@ -256,7 +259,20 @@ private:
     int gridLeft() const noexcept { return selectLeft() + selectWidth + 8; }
     juce::Rectangle<int> rowBounds (int row) const;
     juce::Rectangle<int> previewMuteBounds (int row) const; // (round 190mk: the preview's round mute button)
-    int rowY (int row) const;       // top of a row (rows below the graph lane shift down)
+    int rowY (int row) const;       // top of a row (rows below the graph lane and the automation clip rows shift down)
+    int baseRowY (int row) const;   // the same without the automation clip rows (round 190oo)
+    // FL's automation clip channels (round 190oo, design review 2 PAT-7; core/RackAutomation.h): the automation clips' rows
+    // between the channel rows, in the rack's order, while the filter shows them (empty: none, the code paths as before);
+    // autoBefore[k] = how many of them sit above channel row k (k = the channel count: the "add channel" row)
+    std::vector<rackauto::Row> autoRows;
+    std::vector<int> autoBefore;
+    void refreshAutomationRows();
+    int automationRowTop (int i) const; // i: index into autoRows
+    int automationRowAt (int y) const;  // index into autoRows of the row under y, -1 none
+    juce::Rectangle<int> automationRowBounds (int automation) const;
+    void paintAutomationSteps (juce::Graphics& g, juce::Rectangle<int> clip);
+    void paintAutomationButtons (juce::Graphics& g, juce::Rectangle<int> column);
+    void showAutomationMenu (int automation);
     // round 190mk (DE-38): the rows' places while any channel is zipped (empty: none is, FL's fixed 30 px rows)
     rackzip::Layout zipLayout;
     void refreshZipLayout();

+ 192 - 0
tests/RackAutomation190ooTests.inc

@@ -0,0 +1,192 @@
+// Round 190oo (design review 2, PAT-7; details DE-123's blocker): FL's automation clip channels in the Channel rack
+// (core/RackAutomation.h). The rows sit where FL's channel order has them (.flp import), stay in place while channels are
+// inserted, removed and moved, move as FL moves a channel, and go with their automation. The .lynx round trip, the
+// default of an older file and the copy for 0.1.30 are checked in the app's --selftest ("rackauto190oo": ProjectFile).
+
+#include "core/RackAutomation.h"
+#include "core/RackOps.h"
+
+namespace ra190oo
+{
+lynx::Automation clip (const std::string& name, int slot = -1)
+{
+    lynx::Automation a;
+    a.name = name;
+    a.points = { { 0, 0.2f, 0.0f }, { 4 * lynx::ppq, 0.8f, 0.0f } };
+    a.rackSlot = slot;
+    return a;
+}
+
+lynx::Song rack (int channels)
+{
+    lynx::Song s;
+    for (int c = 0; c < channels; ++c)
+        s.channels.emplace_back().name = std::string (1, (char) ('A' + c));
+    return s;
+}
+
+// the rack top to bottom as text: channels by name, automation rows by name in brackets
+std::string text (const lynx::Song& s)
+{
+    std::string out;
+    for (const auto& e : lynx::rackauto::order (s))
+        out += e.automation ? "[" + s.automations[(std::size_t) e.index].name + "]" : s.channels[(std::size_t) e.index].name;
+    return out;
+}
+} // namespace ra190oo
+
+TEST (rackauto190oo_flp_import_keeps_fl_channel_order)
+{
+    using namespace lynx;
+    flp::Project p;
+    const auto add = [&p] (int index, flp::ChannelType type, const char* name) {
+        flp::Channel c;
+        c.index = index;
+        c.type = type;
+        c.name = name;
+        if (type == flp::ChannelType::automationClip)
+        {
+            c.automation.push_back ({ 0.0, 0.2, 0.0f, 0 });
+            c.automation.push_back ({ 4.0, 0.8, 0.0f, 0 });
+        }
+        p.channels.push_back (c);
+    };
+    // Thief's rack around the finding: YELP, three automation clips, Riser..Metal; one more clip at the very end
+    add (0, flp::ChannelType::sampler, "Kick");
+    add (1, flp::ChannelType::sampler, "YELP");
+    add (2, flp::ChannelType::automationClip, "Volume Duck");
+    add (3, flp::ChannelType::automationClip, "GROSS Saw Bass");
+    add (4, flp::ChannelType::automationClip, "CRASH REVERB");
+    add (5, flp::ChannelType::sampler, "Riser Noise Metal");
+    add (6, flp::ChannelType::automationClip, "Last");
+    const auto song = importFlp (flp::parseProject (flp::writeProject (p)), fx171e::importOptions());
+    CHECK (song.channels.size() == 3 && song.automations.size() == 4);
+    if (song.channels.size() != 3 || song.automations.size() != 4)
+        return;
+    CHECK (song.automations[0].rackSlot == 2 && song.automations[1].rackSlot == 2 && song.automations[2].rackSlot == 2);
+    CHECK (song.automations[3].rackSlot == -1); // (after the last channel)
+    CHECK (ra190oo::text (song) == "KickYELP[Volume Duck][GROSS Saw Bass][CRASH REVERB]Riser Noise Metal[Last]");
+    const auto rows = rackauto::rows (song);
+    CHECK (rackauto::rowsBefore (song, rows) == (std::vector<int> { 0, 0, 3, 4 }));
+}
+
+TEST (rackauto190oo_old_project_rows_after_the_channels)
+{
+    using namespace lynx;
+    // a project saved before round 190oo: every clip at −1, so the channel rows keep their places and the clips follow
+    auto s = ra190oo::rack (3);
+    CHECK (rackauto::rows (s).empty() && rackauto::rowsBefore (s, {}) == (std::vector<int> { 0, 0, 0, 0 })); // (no clip: as before)
+    s.automations.push_back (ra190oo::clip ("x"));
+    s.automations.push_back (ra190oo::clip ("y"));
+    CHECK (Automation {}.rackSlot == -1);
+    CHECK (ra190oo::text (s) == "ABC[x][y]");
+    CHECK (rackauto::rowsBefore (s, rackauto::rows (s)) == (std::vector<int> { 0, 0, 0, 2 }));
+    // a slot past the end (a song that lost channels elsewhere) reads as "after the last channel"
+    s.automations[0].rackSlot = 9;
+    CHECK (ra190oo::text (s) == "ABC[x][y]");
+}
+
+TEST (rackauto190oo_only_clips_get_rows)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (2);
+    s.automations.push_back (ra190oo::clip ("clip", 1));
+    auto live = ra190oo::clip ("peak", 1); // a Peak Controller link: no clip
+    live.source.track = 1;
+    s.automations.push_back (live);
+    auto markers = ra190oo::clip ("tempo", 1); // the ruler's tempo markers
+    markers.target.kind = AutomationTargetKind::tempo;
+    markers.tempoMarkers = true;
+    s.automations.push_back (markers);
+    s.automations.push_back (ra190oo::clip ("lane", 1)); // an automation lane under a Playlist track
+    s.playlistTracks.resize (1);
+    s.playlistTracks[0].lanes.push_back ({ 3 });
+    auto empty = ra190oo::clip ("empty", 1);
+    empty.points.clear();
+    s.automations.push_back (empty);
+    CHECK (ra190oo::text (s) == "A[clip]B");
+    CHECK (rackauto::listed (s, 0) && ! rackauto::listed (s, 1) && ! rackauto::listed (s, 2) && ! rackauto::listed (s, 3) && ! rackauto::listed (s, 4));
+}
+
+TEST (rackauto190oo_rows_stay_put_while_channels_change)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (3); // A B C
+    s.automations.push_back (ra190oo::clip ("x", 2)); // A B [x] C
+    CHECK (ra190oo::text (s) == "AB[x]C");
+    insertChannel (s, 1, ChannelDef {}); // above it
+    s.channels[1].name = "N";
+    CHECK (ra190oo::text (s) == "ANB[x]C");
+    CHECK (s.automations[0].rackSlot == 3);
+    cloneChannel (s, 2); // B's clone goes right under B, above the row (FL: a new channel under the selected one)
+    CHECK (ra190oo::text (s) == "ANBB #2[x]C");
+    s.removeChannel (0); // a channel above it
+    CHECK (ra190oo::text (s) == "NBB #2[x]C" && s.automations[0].rackSlot == 3);
+    s.removeChannel (3); // the channel under it: the row is now after the last channel
+    CHECK (ra190oo::text (s) == "NBB #2[x]");
+    // moving channels as a block keeps the row in its gap (the channels' order changes, the row stays between rows 2 and 3)
+    auto t = ra190oo::rack (3);
+    t.automations.push_back (ra190oo::clip ("x", 1)); // A [x] B C
+    std::vector<int> selection { 2 };
+    CHECK (moveChannels (t, selection, -1)); // C up: A [x] C B
+    CHECK (ra190oo::text (t) == "A[x]CB");
+}
+
+TEST (rackauto190oo_reorder_like_fl)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (3); // A B C
+    s.automations.push_back (ra190oo::clip ("x")); // A B C [x]
+    CHECK (rackauto::moveRow (s, 0, -1) && ra190oo::text (s) == "AB[x]C");
+    CHECK (rackauto::moveRow (s, 0, -1) && rackauto::moveRow (s, 0, -1) && ra190oo::text (s) == "[x]ABC");
+    CHECK (! rackauto::moveRow (s, 0, -1)); // (at the top)
+    CHECK (rackauto::moveRow (s, 0, 1) && ra190oo::text (s) == "A[x]BC");
+    CHECK (! rackauto::moveRow (s, 5, 1));
+
+    // channels moved past the row (Alt+Up / Alt+Down, a drag): the row goes to the block's other side, the channels stay
+    CHECK (rackauto::passRow (s, { 1 }, -1) && ra190oo::text (s) == "AB[x]C"); // B up past [x]
+    auto t = ra190oo::rack (3);
+    t.automations.push_back (ra190oo::clip ("x", 2)); // A B [x] C
+    CHECK (rackauto::passRow (t, { 0, 1 }, 1) && ra190oo::text (t) == "[x]ABC"); // A B down past [x]
+    CHECK (rackauto::passRow (t, { 1, 0 }, -1) && ra190oo::text (t) == "AB[x]C"); // and back up
+    CHECK (rackauto::passRow (t, { 2 }, -1) && ra190oo::text (t) == "ABC[x]"); // C up past [x]
+    CHECK (! rackauto::passRow (t, { 0 }, -1)); // (nothing above A: the channels move as before, moveChannels)
+    CHECK (! rackauto::passRow (t, { 0 }, 1)); // (B is under A, no row)
+    CHECK (rackauto::passFor (t, { 0, 2 }, -1).first == -1); // (not one block)
+    CHECK (t.channels[0].name == "A" && t.channels[1].name == "B" && t.channels[2].name == "C"); // (no channel moved)
+}
+
+TEST (rackauto190oo_deleting_a_clip_removes_its_row)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (2);
+    s.automations.push_back (ra190oo::clip ("x", 1));
+    s.automations.push_back (ra190oo::clip ("y", 1));
+    s.automations.push_back (ra190oo::clip ("z"));
+    CHECK (ra190oo::text (s) == "A[x][y]B[z]");
+    s.removeAutomation (1);
+    CHECK (ra190oo::text (s) == "A[x]B[z]");
+    CHECK (rackauto::rows (s) == (std::vector<rackauto::Row> { { 0, 1 }, { 1, 2 } }));
+}
+
+TEST (rackauto190oo_filter_views)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (1);
+    s.channelGroups = { "Drums", rackauto::groupName };
+    CHECK (rackauto::shownUnder (s, rackfilter::all));
+    CHECK (! rackauto::shownUnder (s, rackfilter::unsorted) && ! rackauto::shownUnder (s, rackfilter::audioClips));
+    CHECK (! rackauto::shownUnder (s, 0) && rackauto::shownUnder (s, 1)); // (FL's "Automation clips" group of an imported .flp)
+}
+
+TEST (rackauto190oo_drum_kit_split_keeps_rows_under_the_kit)
+{
+    using namespace lynx;
+    auto s = ra190oo::rack (2); // A (the kit) B
+    s.automations.push_back (ra190oo::clip ("x", 1)); // A [x] B
+    std::vector<DrumPad> pads (3);
+    pads[0].name = "1", pads[1].name = "2", pads[2].name = "3";
+    pads[0].key = 60, pads[1].key = 61, pads[2].key = 62;
+    splitDrumChannel (s, 0, pads);
+    CHECK (s.channels.size() == 4 && s.automations[0].rackSlot == 3); // A - 1, A - 2, A - 3, [x], B
+}

+ 1 - 0
tests/tests.cpp

@@ -18065,3 +18065,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "SimpleFl190ooTests.inc" // round 190oo (design review 2, CS-24): S / volume / pan on an FL project's tracks in Simple
 #include "Pat6_190ooTests.inc" // round 190oo (design review 2): PAT-6, the Playlist row from FL's vertical zoom (event 0xF2)
 #include "DialogRules190ooTests.inc" // round 190oo: the one dialog system's button order and pixel bands (core/DialogRules.h)
+#include "RackAutomation190ooTests.inc" // round 190oo (design review 2, PAT-7): FL's automation clip channels in the Channel rack