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

177d review fixes: compile error, sort keeps clip sizes, MIDI clock holds no backup, savedBy stays out of hashes

- PatternPicker::pickerMenu: a local menu named sortPatterns hid the function (it did not compile).
- AudioEngine::editSongPatternOrder for sort and move: followPatternLengths compares by index and resized clips sized by hand.
- Backups wait only for channel messages: clock and active sensing from a plugged-in device no longer postpone them for good. backupMayRun takes a maximum wait (none for now).
- ProjectFile::toJson (song, false) for SessionPack::sourceHash, so a new version does not put every stand-in out of date.
- Ruler: a clip's offset past the song's start gives a real origin; bars before bar 1 have no number.
- Unused patterns count Loop Starter channels; identical patterns compare the Loop Starter genre.
- Slice 5's message says the picker's empty part has a right-click menu: it has none (as in FL).
Ka1-S 4 недель назад
Родитель
Сommit
c97fb5cea8

+ 20 - 9
src/core/EditorPolish.h

@@ -7,6 +7,7 @@
 #include <algorithm>
 #include <cmath>
 #include <cstdint>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -51,23 +52,33 @@ inline bool hasNoteInCell (const Pattern& pattern, int channel, int key, std::in
     });
 }
 
-// --- Piano Roll: hollow ghost notes from other clips (R12) -------------------------------------------
-
-// The notes of `channel` that play at the same time as the first Playlist clip of `pattern`, coming from
-// other pattern clips, mapped into `pattern`'s own time. FL draws these hollow. Muted clips are skipped; a clip longer
-// than its pattern loops it with stretchedClipsLoop() (LYNX extra), else plays it once (FL, round 168k). Empty when
-// the pattern is not in the Playlist.
 // Round 177d (pain point 25): the song tick of the pattern's tick 0 as it plays in the Playlist (its first unmuted
-// clip, as for the clip ghosts), or -1 when no clip of it is on the Playlist.
-inline std::int64_t patternSongOrigin (const Song& song, int pattern)
+// clip, as for the clip ghosts; negative when the clip's offset reaches past the song's start), or nothing when no clip
+// of it is on the Playlist.
+inline std::optional<std::int64_t> patternSongOrigin (const Song& song, int pattern)
 {
     const Clip* home = nullptr;
     for (const auto& c : song.playlist)
         if (c.kind == ClipKind::pattern && c.pattern == pattern && ! c.muted && (home == nullptr || c.start < home->start))
             home = &c;
-    return home == nullptr ? -1 : home->start - home->offset;
+    if (home == nullptr)
+        return std::nullopt;
+    return home->start - home->offset;
+}
+
+// The number the ruler prints for bar `bar` of the pattern, for a song origin: as the Playlist counts, 0 or less when
+// that bar of the pattern falls before the song's first bar (no number then).
+inline std::int64_t songBarNumber (std::int64_t origin, std::int64_t bar, std::int64_t barTicks)
+{
+    return (std::int64_t) std::floor ((double) (origin + bar * barTicks) / (double) barTicks) + 1;
 }
 
+// --- Piano Roll: hollow ghost notes from other clips (R12) -------------------------------------------
+
+// The notes of `channel` that play at the same time as the first Playlist clip of `pattern`, coming from
+// other pattern clips, mapped into `pattern`'s own time. FL draws these hollow. Muted clips are skipped; a clip longer
+// than its pattern loops it with stretchedClipsLoop() (LYNX extra), else plays it once (FL, round 168k). Empty when
+// the pattern is not in the Playlist.
 inline std::vector<Note> clipGhostNotes (const Song& song, int pattern, int channel, std::size_t limit = 2000)
 {
     std::vector<Note> out;

+ 10 - 1
src/core/Preferences.h

@@ -27,12 +27,21 @@ int clampAutosaveKeep (int keep); // 1..100
 // "waitForQuiet" on (the default) a due backup also waits while the song plays and until `quietMs` after the last
 // MIDI input, not only while recording (FL postpones it for recording only).
 constexpr double backupQuietMs = 5000.0;
-inline bool backupMayRun (bool recording, bool playing, double msSinceMidi, bool waitForQuiet) noexcept
+// `maxWaitMs` > 0 ends the wait once the backup is that overdue (never during a recording); 0 = no limit, the current
+// behaviour (backupMaxWaitMs).
+constexpr double backupMaxWaitMs = 0.0;
+inline bool backupMayRun (bool recording, bool playing, double msSinceMidi, bool waitForQuiet, double msOverdue = 0.0,
+                          double maxWaitMs = backupMaxWaitMs) noexcept
 {
     if (recording)
         return false;
+    if (maxWaitMs > 0.0 && msOverdue >= maxWaitMs)
+        return true;
     return ! waitForQuiet || (! playing && msSinceMidi >= backupQuietMs);
 }
+// A MIDI message that means someone is playing: channel messages only. Clock, active sensing and the rest of the
+// system messages (0xF0 and up) run by themselves whenever a device is plugged in.
+constexpr bool midiMeansPlaying (unsigned char status) noexcept { return status >= 0x80 && status < 0xF0; }
 
 // Backup file name (without extension) of project `stem` saved at a date/time: "Night Drive (2026-10-16 19.50.03)".
 // Sorting these names sorts them by time.

+ 4 - 1
src/core/RackOps.cpp

@@ -249,6 +249,9 @@ std::vector<int> unusedPatterns (const Song& song)
             if (b.pattern >= 0 && b.pattern < (int) used.size())
                 used[(std::size_t) b.pattern] = 1;
     });
+    for (const auto& c : song.channels) // a Loop Starter channel plays from its pattern
+        if (c.loopStarterPattern >= 0 && c.loopStarterPattern < (int) used.size())
+            used[(std::size_t) c.loopStarterPattern] = 1;
     std::vector<int> out;
     for (int p = 0; p < (int) used.size(); ++p)
         if (! used[(std::size_t) p])
@@ -333,7 +336,7 @@ std::pair<int, int> colourKey (std::uint32_t argb)
 bool sameContent (const Pattern& a, const Pattern& b)
 {
     return a.notes == b.notes && a.lengthTicks == b.lengthTicks && a.events == b.events && a.loopOn == b.loopOn && a.loopMode == b.loopMode
-           && a.channelLoops == b.channelLoops && a.markers == b.markers;
+           && a.channelLoops == b.channelLoops && a.markers == b.markers && a.loopStarterGenre == b.loopStarterGenre;
 }
 } // namespace
 

+ 2 - 2
src/core/RackOps.h

@@ -101,7 +101,7 @@ bool movePattern (Song& song, int index, int delta);
 
 // --- pattern hygiene (round 177d; FL's Playlist picker "Select unused › Patterns" and "Sort patterns by name / color",
 // EEPickerSelectUnusedPatternsMenu / EEPickerSortPatternsBy*Menu in FLEngine; LYNX's own: merge identical patterns) ----
-// Patterns that no clip plays in any arrangement and no pattern block uses (ascending).
+// Patterns that no clip plays in any arrangement, no pattern block uses and no Loop Starter channel belongs to (ascending).
 std::vector<int> unusedPatterns (const Song& song);
 // Deletes the given patterns (clips follow, as Song::removePattern). Returns how many went.
 int deletePatterns (Song& song, std::vector<int> indices);
@@ -110,7 +110,7 @@ int deletePatterns (Song& song, std::vector<int> indices);
 void reorderPatterns (Song& song, const std::vector<int>& order);
 enum class PatternSort : std::uint8_t { name, colour };
 void sortPatterns (Song& song, PatternSort by);
-// Groups of patterns with the same content (notes, events, length, loops, markers; the name and colour may differ),
+// Groups of patterns with the same content (notes, events, length, loops, markers, Loop Starter genre; the name and colour may differ),
 // each group ascending, only groups of two or more.
 std::vector<std::vector<int>> identicalPatterns (const Song& song);
 // Every clip of a duplicate plays the group's first pattern instead, and the duplicates are deleted. Returns how many

+ 11 - 0
src/engine/AudioEngine.cpp

@@ -2024,6 +2024,8 @@ void AudioEngine::handleIncomingMidiMessage (juce::MidiInput* source, const juce
         return;
 
     midiActivity.fetch_add (1, std::memory_order_relaxed); // the toolbar's MIDI input light
+    if (m.getRawDataSize() > 0 && prefs::midiMeansPlaying (m.getRawData()[0]))
+        midiPlayed.fetch_add (1, std::memory_order_relaxed); // what holds a backup back (not clock or active sensing)
 
     // FL's "Song marker jump (MIDI channel)": notes on that channel move the song to a marker instead of playing
     if (jumpChannel > 0 && m.getChannel() == jumpChannel && m.isNoteOnOrOff())
@@ -2488,6 +2490,15 @@ void AudioEngine::editSong (const std::function<void (Song&)>& edit, bool undoab
     publishSong();
 }
 
+void AudioEngine::editSongPatternOrder (const std::function<void (Song&)>& edit)
+{
+    saveUndoStep();
+    modified = true;
+    edit (song);
+    clipops::updateCrossfades (song);
+    publishSong();
+}
+
 void AudioEngine::editLevels (const std::function<void (Song&)>& edit, bool undoable)
 {
     // A fader or knob drag (round 171c, discussion #10): every mouse move used to go through editSong, i.e. a whole

+ 5 - 1
src/engine/AudioEngine.h

@@ -494,6 +494,7 @@ public:
     juce::StringArray getActiveMidiInputs() const;
     // Counts the messages received from the enabled MIDI inputs (the toolbar's MIDI activity light).
     std::uint32_t getMidiActivity() const noexcept { return midiActivity.load (std::memory_order_relaxed); }
+    std::uint32_t getMidiPlayed() const noexcept { return midiPlayed.load (std::memory_order_relaxed); }
     // Closes and opens again every enabled MIDI input (the MIDI light's click; Settings › MIDI › Refresh).
     void reconnectMidiInputs();
     const prefs::MidiPrefs& getMidiPrefs() const noexcept { return midiPrefs; }
@@ -526,6 +527,9 @@ public:
     // settings are copied into the Song first, so the undo step has them; the moved plugins keep their instances (the
     // rack matches them by instance tag, round 168s).
     void editSongStructural (const std::function<void (Song&)>& edit);
+    // An edit that gives the patterns other indices (sort, move): one undo step like editSong, but without
+    // followPatternLengths, which compares by index and would resize clips that were sized by hand (round 177d).
+    void editSongPatternOrder (const std::function<void (Song&)>& edit);
     // An edit that changes only levels (mixer volume / pan / separation, channel volume / pan), e.g. a fader drag: one
     // undo step per press like editSong, but the playing snapshot takes the values at once without a rebuild (round
     // 171c); the full publish follows when the mouse is released. Anything else falls back to editSong.
@@ -891,7 +895,7 @@ private:
     juce::MidiDeviceListConnection midiDevicesChanged;
     std::vector<std::string> lastMidiInputIds;       // the MIDI inputs available at the last check (UI thread)
     int midiCheckTicks = 0;
-    std::atomic<std::uint32_t> midiActivity { 0 };
+    std::atomic<std::uint32_t> midiActivity { 0 }, midiPlayed { 0 };
     prefs::MidiPrefs midiPrefs;                      // UI thread
     juce::SpinLock midiPrefsLock;                    // guards midiPrefsShared (UI writes, MIDI thread reads)
     prefs::MidiPrefs midiPrefsShared;

+ 3 - 2
src/engine/ProjectFile.cpp

@@ -1932,12 +1932,13 @@ MixerTrack mixerTrackFromVar (const juce::var& t)
     return track;
 }
 
-juce::String toJson (const Song& song)
+juce::String toJson (const Song& song, bool stampVersion)
 {
     auto root = std::make_unique<juce::DynamicObject>();
     root->setProperty ("format", "lynx-project");
     root->setProperty ("version", currentVersion);
-    root->setProperty ("savedBy", JUCE_APPLICATION_VERSION_STRING); // the build that wrote it (round 177d, pain point 37)
+    if (stampVersion)
+        root->setProperty ("savedBy", JUCE_APPLICATION_VERSION_STRING); // the build that wrote it (round 177d, pain point 37)
     root->setProperty ("bpm", song.bpm);
     root->setProperty ("beatsPerBar", song.beatsPerBar);
 

+ 2 - 1
src/engine/ProjectFile.h

@@ -15,7 +15,8 @@ namespace ProjectFile
 constexpr const char* extension = ".lynx";
 constexpr int currentVersion = 1;
 
-juce::String toJson (const Song& song);
+// `stampVersion` writes "savedBy"; false when the text is hashed (a new version must not change what a hash says).
+juce::String toJson (const Song& song, bool stampVersion = true);
 // `savedBy` (optional) receives the version of LYNX SHARE that wrote the project ("" for projects from before round
 // 177d, which did not write it): a newer one may hold things this build drops (safety::savedByNewerVersion).
 std::optional<Song> fromJson (const juce::String& json, juce::String& error, juce::String* savedBy = nullptr);

+ 1 - 1
src/engine/SessionPack.cpp

@@ -375,7 +375,7 @@ std::string sourceHash (const Song& song, bool insert, int index, int pattern, d
         mini.currentPattern = 0;
         mini.mode = PlayMode::song;
     }
-    const auto json = ProjectFile::toJson (mini) + "|" + (insert ? "insert " : "channel ") + juce::String (index) + "|"
+    const auto json = ProjectFile::toJson (mini, false) + "|" + (insert ? "insert " : "channel ") + juce::String (index) + "|"
                       + juce::String (pattern) + "|" + juce::String (sampleRate, 1);
     const auto bytes = json.toStdString();
     return sha256Hex ((const std::uint8_t*) bytes.data(), bytes.size());

+ 6 - 4
src/ui/MainComponent.cpp

@@ -3178,7 +3178,7 @@ void MainComponent::clonePatternNow()
 
 void MainComponent::movePatternNow (int delta)
 {
-    engine.editSong ([delta] (Song& s) { movePattern (s, s.currentPattern, delta); });
+    engine.editSongPatternOrder ([delta] (Song& s) { movePattern (s, s.currentPattern, delta); });
 }
 
 void MainComponent::splitPatternByChannelNow()
@@ -4040,14 +4040,16 @@ void MainComponent::timerCallback()
     // (not in the middle of a recording: FL also postpones the timed backup until the transport is free; round 177d:
     // with "Wait with backups..." on, also while playing and for a few seconds after MIDI input, so writing the plugin
     // states never stutters the sound)
-    if (const auto midi = engine.getMidiActivity(); midi != backupMidiSeen)
+    if (const auto midi = engine.getMidiPlayed(); midi != backupMidiSeen)
     {
         backupMidiSeen = midi;
         backupMidiMs = juce::Time::getMillisecondCounterHiRes();
     }
-    if (autosaveMinutes > 0 && ++autosaveTicks >= 30 * 60 * autosaveMinutes
+    const auto backupDueTicks = 30 * 60 * autosaveMinutes;
+    if (autosaveMinutes > 0 && ++autosaveTicks >= backupDueTicks
         && prefs::backupMayRun (engine.isRecording(), engine.getTransport().playing.load(),
-                                juce::Time::getMillisecondCounterHiRes() - backupMidiMs, backupWaitsForQuiet))
+                                juce::Time::getMillisecondCounterHiRes() - backupMidiMs, backupWaitsForQuiet,
+                                (autosaveTicks - backupDueTicks) * 1000.0 / 30.0))
     {
         autosaveTicks = 0;
 

+ 4 - 3
src/ui/PianoRollComponent.cpp

@@ -1133,14 +1133,15 @@ void PianoRollComponent::paint (juce::Graphics& g)
 
         // View › "Ruler: song bars" (round 177d, LYNX's own; off = FL's pattern bars): the bar numbers the Playlist shows
         // where the pattern's first clip plays
-        const auto songOrigin = songBarsRuler ? polish::patternSongOrigin (song, song.currentPattern) : (std::int64_t) -1;
+        const auto songOrigin = songBarsRuler ? polish::patternSongOrigin (song, song.currentPattern) : std::nullopt;
         for (auto b = firstBar; b <= lastBar; ++b)
         {
             const auto x = (int) tickToX ((double) (b * bar));
             g.setColour (textSecondary);
             g.drawVerticalLine (x, (float) rulerTop + 10.0f, (float) headerHeight);
-            const auto number = songOrigin >= 0 ? (std::int64_t) std::floor ((double) (songOrigin + b * bar) / (double) bar) + 1 : b + 1;
-            textcache::drawText (g, juce::String (number), x + 3, rulerTop + 2, 40, timelineHeight - 4, juce::Justification::centredLeft);
+            const std::int64_t number = songOrigin.has_value() ? polish::songBarNumber (*songOrigin, b, bar) : (std::int64_t) b + 1;
+            if (number > 0)
+                textcache::drawText (g, juce::String (number), x + 3, rulerTop + 2, 40, timelineHeight - 4, juce::Justification::centredLeft);
         }
 
         // the pattern's time markers (round 168g): a flag and the name in the ruler's lower half, like the Playlist's

+ 6 - 6
src/ui/PlaylistComponent.cpp

@@ -6655,7 +6655,7 @@ juce::PopupMenu PatternPicker::pickerMenu()
         }
     };
 
-    juce::PopupMenu menu, select, sort, sortPatterns;
+    juce::PopupMenu menu, select, sort, sortMenu;
     menu.addSectionHeader (tr ("Tools")); // (FL: Playlist menu › Picker panel › Tools, checked in FL in round 177d)
     select.addItem (tr ("Patterns ({0})", { juce::String ((int) unused.size()) }), ! unused.empty(), false, [safe, unused] {
         if (safe == nullptr)
@@ -6667,15 +6667,15 @@ juce::PopupMenu PatternPicker::pickerMenu()
         safe->repaint();
     });
     menu.addSubMenu (tr ("Select unused"), select);
-    sortPatterns.addItem (tr ("By name"), song.patterns.size() > 1, false, [this, edited] {
-        engine.editSong ([] (Song& s) { sortPatterns (s, PatternSort::name); });
+    sortMenu.addItem (tr ("By name"), song.patterns.size() > 1, false, [this, edited] {
+        engine.editSongPatternOrder ([] (Song& s) { sortPatterns (s, PatternSort::name); });
         edited();
     });
-    sortPatterns.addItem (tr ("By color"), song.patterns.size() > 1, false, [this, edited] {
-        engine.editSong ([] (Song& s) { sortPatterns (s, PatternSort::colour); });
+    sortMenu.addItem (tr ("By color"), song.patterns.size() > 1, false, [this, edited] {
+        engine.editSongPatternOrder ([] (Song& s) { sortPatterns (s, PatternSort::colour); });
         edited();
     });
-    sort.addSubMenu (tr ("Patterns"), sortPatterns);
+    sort.addSubMenu (tr ("Patterns"), sortMenu);
     menu.addSubMenu (tr ("Sort"), sort);
     menu.addSeparator();
     // LYNX's own (not in FL)

+ 1 - 1
src/ui/SettingsPages.cpp

@@ -428,7 +428,7 @@ private:
     juce::Label animationLabel, animationNote, languageLabel, languageNote, scaleLabel, menuLabel, wavesLabel, noteNamesLabel, blackNotesLabel, pluginStyleLabel, editInLabel, undoLabel, autosaveLabel, keepLabel, sandboxNote, substitutesNote, shortcutsNote, crashLabel, crashNote, updatesNote;
     juce::HyperlinkButton translationLink;
     juce::ComboBox animationBox, crashBox, languageBox, scaleBox, menuBox, wavesBox, noteNamesBox, blackNotesBox, pluginStyleBox, editInBox, undoBox, autosaveBox, keepBox;
-    juce::ToggleButton stereoWaves, everyKeyNames, rackColumn, rackStepColour, artMotion, reducedEffects, gpuRendering, splash, startupSound, scanAtStart, menuEntry, typingPiano, keepEditors, rememberSeek, clipsLoop, firstChannel, hoverValues, alternateUndo, sandbox, substitutes, unusedTakes, checkUpdates;
+    juce::ToggleButton stereoWaves, everyKeyNames, rackColumn, rackStepColour, artMotion, reducedEffects, gpuRendering, splash, startupSound, scanAtStart, menuEntry, typingPiano, keepEditors, rememberSeek, clipsLoop, firstChannel, hoverValues, alternateUndo, sandbox, substitutes, backupQuiet, unusedTakes, checkUpdates;
     juce::TextButton openBackups { tr ("Open backup folder") }, managePlugins { tr ("Plugin manager...") }, manageShortcuts { tr ("Manage shortcuts...") },
         checkNow { tr ("Check now") };
 };

+ 8 - 1
tests/Edit177dTests.inc

@@ -6,7 +6,7 @@ TEST (pain177d_song_bars_ruler_origin)
 {
     lynx::Song s;
     s.patterns.resize (2);
-    CHECK (lynx::polish::patternSongOrigin (s, 1) == -1); // not on the Playlist: pattern bars
+    CHECK (! lynx::polish::patternSongOrigin (s, 1).has_value()); // not on the Playlist: pattern bars
     lynx::Clip late, early, muted;
     late.pattern = early.pattern = muted.pattern = 1;
     late.start = 8 * 3840;
@@ -16,6 +16,13 @@ TEST (pain177d_song_bars_ruler_origin)
     muted.muted = true;
     s.playlist = { late, early, muted };
     CHECK (lynx::polish::patternSongOrigin (s, 1) == 3 * 3840); // the first unmuted clip, minus its offset
+    CHECK (lynx::polish::songBarNumber (3 * 3840, 0, 3840) == 4);
+    // an offset past the song's start: the origin is negative but real, and the bars before bar 1 have no number
+    s.playlist = { early };
+    s.playlist[0].start = 0;
+    CHECK (lynx::polish::patternSongOrigin (s, 1) == -3840);
+    CHECK (lynx::polish::songBarNumber (-3840, 0, 3840) == 0);
+    CHECK (lynx::polish::songBarNumber (-3840, 1, 3840) == 1);
 }
 
 TEST (pain177d_instruments_only_channel_stems)

+ 10 - 0
tests/Pain177dTests.inc

@@ -39,6 +39,16 @@ TEST (pain177d_backups_wait_for_a_quiet_moment)
     CHECK (! backupMayRun (false, true, 1e9, true));
     CHECK (! backupMayRun (false, false, 1000.0, true));
     CHECK (backupMayRun (false, false, lynx::prefs::backupQuietMs, true));
+    // no limit on the wait for now (the user decides); a limit ends it, but never during a recording
+    CHECK (lynx::prefs::backupMaxWaitMs == 0.0);
+    CHECK (! backupMayRun (false, true, 1e9, true, 1e12));
+    CHECK (backupMayRun (false, true, 1e9, true, 60000.0, 60000.0));
+    CHECK (! backupMayRun (false, true, 1e9, true, 59999.0, 60000.0));
+    CHECK (! backupMayRun (true, true, 1e9, true, 1e12, 60000.0));
+    // clock and active sensing are not someone playing
+    using lynx::prefs::midiMeansPlaying;
+    CHECK (midiMeansPlaying (0x90) && midiMeansPlaying (0xB3) && midiMeansPlaying (0xE0));
+    CHECK (! midiMeansPlaying (0xF8) && ! midiMeansPlaying (0xFE) && ! midiMeansPlaying (0xF0) && ! midiMeansPlaying (0x40));
 }
 
 TEST (pain177d_saved_by_newer_version)

+ 30 - 0
tests/Patterns177dTests.inc

@@ -45,6 +45,11 @@ TEST (pain177d_unused_patterns_and_delete)
     CHECK (lynx::deletePatterns (s, { 0 }) == 1);
     CHECK (s.patterns.size() == 2 && s.patterns[0].name == "drums" && s.playlist[0].pattern == 0 && s.blocks[0].pattern == 1);
     CHECK (s.currentPattern == 1); // (it was "Arp", which moved up)
+    // a pattern a Loop Starter channel belongs to is in use
+    auto ls = pain177d::threePatterns();
+    ls.channels.resize (1);
+    ls.channels[0].loopStarterPattern = 1;
+    CHECK ((lynx::unusedPatterns (ls) == std::vector<int> { 0, 2 }));
     // the last pattern is never deleted
     auto one = pain177d::threePatterns();
     CHECK (lynx::deletePatterns (one, { 0, 1, 2 }) == 2 && one.patterns.size() == 1);
@@ -67,6 +72,25 @@ TEST (pain177d_sort_patterns_keeps_clips_on_their_pattern)
     CHECK (s.playlist[0].pattern == 0 && s.playlist[1].pattern == 1);
 }
 
+TEST (pain177d_sort_leaves_hand_sized_clips_alone)
+{
+    // why the sort goes through AudioEngine::editSongPatternOrder and not editSong: followPatternLengths compares by
+    // index, so after a sort it would take a pattern's move for a change of length
+    auto s = pain177d::threePatterns();
+    s.patterns[0].lengthTicks = 3840;     // "Bass", 1 bar
+    s.patterns[1].lengthTicks = 4 * 3840; // "drums", 4 bars
+    s.patterns[2].lengthTicks = 2 * 3840; // "Arp", 2 bars
+    auto bass = pain177d::clipOf (0, 0);
+    bass.length = 4 * 3840; // stretched by hand to 4 bars
+    s.playlist.push_back (bass);
+    const auto before = lynx::patternLengths (s);
+    lynx::sortPatterns (s, lynx::PatternSort::name); // Arp, Bass, drums: Bass now sits where the 4-bar pattern was
+    CHECK (s.playlist[0].pattern == 1 && s.playlist[0].length == 4 * 3840);
+    auto followed = s;
+    lynx::followPatternLengths (before, followed);
+    CHECK (followed.playlist[0].length == 3840); // what going through editSong did to the clip
+}
+
 TEST (pain177d_merge_identical_patterns)
 {
     auto s = pain177d::threePatterns(); // every pattern holds the same note
@@ -80,6 +104,12 @@ TEST (pain177d_merge_identical_patterns)
     CHECK (s.patterns.size() == 2 && s.patterns[0].name == "Bass" && s.patterns[1].name == "drums");
     CHECK (s.playlist[0].pattern == 0 && s.playlist[1].pattern == 1);
     CHECK (s.currentPattern == 0); // the current pattern was the duplicate
+    // another Loop Starter genre is another pattern
+    auto g = pain177d::threePatterns();
+    g.patterns[1].notes = g.patterns[0].notes;
+    g.patterns[2].notes = g.patterns[0].notes;
+    g.patterns[2].loopStarterGenre = "House";
+    CHECK (lynx::identicalPatterns (g).size() == 1 && (lynx::identicalPatterns (g)[0] == std::vector<int> { 0, 1 }));
     // empty patterns are never merged
     auto e = pain177d::threePatterns();
     for (auto& p : e.patterns)