Ver Fonte

Mixer: "Show only used inserts" keeps the selected insert and any insert receiving audio

The option exists since round 163 (Mixer menu, off by default). Its rule is now one function,
mixerops::hiddenUnusedInserts, and two holes are closed: an unused insert selected from outside the mixer (the
Channel Rack, a menu, the keyboard) was selected but invisible, and an insert fed by something the song model
does not show as a link stayed hidden while its meter moved.

An insert hides only when it is not the Master, is not selected, was not brought back with "+", shows no level
and nothing uses it (Song::insertInUse). An insert that came back stays until the option is switched again, so
no strip moves under the mouse. --snapshot writes the mixer before and after both mixer extras.
Ka1-S há 3 semanas atrás
pai
commit
d883bc71d4

+ 41 - 0
src/Main.cpp

@@ -11152,6 +11152,47 @@ private:
                 offline.dispatchPendingMessages();
             }
             saveSnapshot (ui, prefix + "-mixer.png");
+            // round 190am: LYNX's two mixer extras, before and after (the demo project leaves most inserts unused). The
+            // loudness panel shows a real measurement of 12 s of a test tone (a 1 kHz sine at -14 dBFS after a quieter
+            // stretch, pushed through the Master's tap as the audio thread does)
+            {
+                auto& strips = ui.getMixerForSnapshot().getStripsForSnapshot();
+                saveSnapshot (ui, prefix + "-mixer190am-before.png");
+                strips.setShowUsedOnly (true);
+                offline.dispatchPendingMessages();
+                saveSnapshot (ui, prefix + "-mixer190am-usedonly.png");
+                strips.setShowUsedOnly (false);
+                strips.setShowLoudness (true);
+                {
+                    const double sr = 48000.0;
+                    std::vector<float> tone (480);
+                    auto& tap = offline.getMeters().loudness;
+                    for (int block = 0; block < 1200; ++block)
+                    {
+                        const auto gain = std::pow (10.0, (block < 400 ? -20.0 : -14.0) / 20.0);
+                        for (int i = 0; i < 480; ++i)
+                            tone[(std::size_t) i] = (float) (gain * std::sin (2.0 * juce::MathConstants<double>::pi * 1000.0 * (block * 480 + i) / sr));
+                        tap.push (tone.data(), tone.data(), 480, sr);
+                    }
+                }
+                strips.refreshLoudnessForSnapshot();
+                offline.dispatchPendingMessages();
+                saveSnapshot (ui, prefix + "-mixer190am-loudness.png");
+                for (const auto l : { lynx::mixerlayout::Layout::compact, lynx::mixerlayout::Layout::extraLarge })
+                {
+                    const auto was = lynx::MixerStrips::layout;
+                    strips.setLayout (l);
+                    offline.dispatchPendingMessages();
+                    saveSnapshot (ui, prefix + "-mixer190am-loudness-" + juce::String ((int) l) + ".png");
+                    strips.setLayout (was);
+                }
+                strips.setShowUsedOnly (true);
+                offline.dispatchPendingMessages();
+                saveSnapshot (ui, prefix + "-mixer190am-both.png");
+                strips.setShowUsedOnly (false);
+                strips.setShowLoudness (false);
+                offline.dispatchPendingMessages();
+            }
             // round 168h (issue #52): FL's 8 Mixer layouts
             {
                 const auto before = lynx::MixerStrips::layout;

+ 9 - 0
src/core/MixerOps.cpp

@@ -359,6 +359,15 @@ bool insertTrack (Song& song, int at)
     return insertTracks (song, at, 1) == 1;
 }
 
+std::vector<bool> hiddenUnusedInserts (const Song& song, const std::set<int>& keep)
+{
+    const auto tracks = (int) song.mixer.size();
+    std::vector<bool> hidden ((std::size_t) tracks + 1, false);
+    for (int t = 1; t < tracks; ++t)
+        hidden[(std::size_t) t] = keep.count (t) == 0 && ! song.insertInUse (t);
+    return hidden;
+}
+
 int removeUnusedTrailingInserts (Song& song, int keep)
 {
     int removed = 0;

+ 12 - 0
src/core/MixerOps.h

@@ -4,6 +4,7 @@
 // sidechain gestures, linking channels, effect slot reordering). Pure functions over the Song model:
 // no JUCE, unit-tested in tests/WorkflowP2Tests.inc.
 
+#include <set>
 #include <string>
 #include <vector>
 
@@ -62,6 +63,17 @@ std::vector<int> linkChannels (Song& song, const std::vector<int>& channels, int
 // Mixer › "Remove unused inserts at the end"). Returns how many were removed.
 int removeUnusedTrailingInserts (Song& song, int keep = 0);
 
+// Mixer menu › "Show only used inserts" (round 163; the rule made exact in round 190am): which strips take no room.
+// An insert is hidden only when ALL of these hold:
+//  - it is not the Master;
+//  - it is not in `keep` (the selected inserts, those brought back with "+", and those whose meter moved: an insert
+//    that receives audio always shows);
+//  - nothing uses it (Song::insertInUse): no channel plays into it, no insert sends to it and it sends nowhere but
+//    the Master, no effect slot, no audio input, no Playlist track link, no effect's sidechain or extra output points
+//    at it, its name, fader, pan, separation, mute, solo, colour, EQ and output are the defaults, nothing automates it.
+// Returns one flag per insert plus one for the "+" button (never hidden). Nothing in the song changes.
+std::vector<bool> hiddenUnusedInserts (const Song& song, const std::set<int>& keep);
+
 // Channels whose output goes to `track`.
 std::vector<int> channelsOn (const Song& song, int track);
 

+ 30 - 3
src/ui/MixerComponent.cpp

@@ -254,8 +254,12 @@ void MixerStrips::layoutStrips()
     // insert shows; selecting another strip doesn't move the strips under the mouse)
     hidden.assign ((std::size_t) tracks + 1, false);
     if (showUsedOnly)
-        for (int t = 1; t < tracks; ++t)
-            hidden[(std::size_t) t] = revealed.count (t) == 0 && ! song.insertInUse (t);
+    {
+        // round 190am: the selected inserts stay, and stay after the selection moves on (no strip jumps under the mouse)
+        revealed.insert (selected);
+        revealed.insert (selection.begin(), selection.end());
+        hidden = mixerops::hiddenUnusedInserts (song, revealed);
+    }
     // folded groups (round 177a): nothing is computed unless a group is folded
     foldShow.clear();
     tabOf.clear();
@@ -2254,6 +2258,7 @@ void MixerStrips::setSelection (std::vector<int> tracks, int primary)
     selection = tracks;
     const auto changed = primary != selected;
     selected = primary;
+    keepSelectionShown();
     repaint();
 
     if (changed && onSelectionChanged)
@@ -2601,10 +2606,21 @@ void MixerStrips::mouseDoubleClick (const juce::MouseEvent& e)
     }
 }
 
+void MixerStrips::keepSelectionShown()
+{
+    if (! showUsedOnly)
+        return;
+    const auto wasHidden = std::any_of (selection.begin(), selection.end(), [this] (int t) { return revealed.count (t) == 0 && isHidden (t); })
+                           || (revealed.count (selected) == 0 && isHidden (selected));
+    if (wasHidden) // (selected from the Channel Rack, a menu or the keyboard: its strip comes back)
+        updateSize();
+}
+
 void MixerStrips::selectTrack (int track)
 {
     selected = juce::jlimit (0, juce::jmax (0, (int) engine.getSong().mixer.size() - 1), track);
     selection = { selected };
+    keepSelectionShown();
     repaint();
 
     if (onSelectionChanged)
@@ -3962,11 +3978,16 @@ bool MixerStrips::liveFrame (double nowMs)
     // every meter row that changed by a pixel goes into one rectangle, repainted once per frame (round 174e2: the A/B
     // against one repaint per meter favoured the single rectangle, within the noise of the machine)
     juce::Rectangle<int> dirty;
+    int woken = -1;
     for (std::size_t i = 0; i < levels.size(); ++i)
     {
         auto& m = levels[i];
         const auto before = m;
-        m.advance (meters.takePeak ((int) (i / 2), (int) (i % 2)), elapsed); // ~20 dB/s falloff, 1.5 s peak hold
+        const auto peak = meters.takePeak ((int) (i / 2), (int) (i % 2));
+        m.advance (peak, elapsed); // ~20 dB/s falloff, 1.5 s peak hold
+        // "Show only used inserts" (round 190am): an insert that receives audio always shows, whatever feeds it
+        if (showUsedOnly && peak > 1.0e-4f && i >= 2 && revealed.count ((int) (i / 2)) == 0 && isHidden ((int) (i / 2)))
+            woken = (int) (i / 2);
         if (m.level != before.level || m.peak != before.peak)
             moving = true;
         if (! showing)
@@ -4040,6 +4061,12 @@ bool MixerStrips::liveFrame (double nowMs)
         repaint (dirty);
         meterRepaintOnly = false;
     }
+    if (woken > 0) // (one per frame is enough: the next frame brings the next)
+    {
+        revealed.insert (woken);
+        updateSize();
+        repaint();
+    }
     return moving;
 }
 

+ 3 - 1
src/ui/MixerComponent.h

@@ -173,6 +173,7 @@ public:
 
     // Mixer menu › "Show only used inserts" (round 163; ui-options.txt "mixerUsedOnly"): inserts nothing uses
     // (Song::insertInUse) take no room; "+" brings back the first unused insert before adding one.
+    // Round 190am: the selected inserts and any insert whose meter moves always show (mixerops::hiddenUnusedInserts).
     static inline bool showUsedOnly = false;
     // Mixer menu › "Loudness meter beside the Master (LYNX)" (round 190am; ui-options.txt "mixerLoudness"; off = FL's
     // mixer, and nothing is measured): a narrow panel right of the Master with the short-term and integrated loudness
@@ -220,7 +221,8 @@ private:
     std::vector<int> stripXs;                                    // layout x (before pinning)
     std::vector<bool> hidden;                                    // per track: not shown (unused, "Show only used inserts")
     static constexpr int hiddenX = -100000;
-    std::set<int> revealed;                                      // unused inserts shown anyway (added with "+")
+    std::set<int> revealed;                                      // unused inserts shown anyway (added with "+", selected, or receiving audio)
+    void keepSelectionShown();                                   // "Show only used inserts": the selection never hides
     // the loudness panel (round 190am): its layout x (hiddenX while off), what it shows now and its hover state
     static constexpr int loudnessWidth = 58;
     int loudnessX = hiddenX;

+ 61 - 0
tests/UsedOnly190amTests.inc

@@ -0,0 +1,61 @@
+// Round 190am: the exact rule of Mixer menu > "Show only used inserts" (mixerops::hiddenUnusedInserts).
+
+#include "core/MixerOps.h"
+
+TEST (extras190am_show_only_used_inserts_rule)
+{
+    using namespace lynx;
+    auto song = Song::makeDefault(); // channels play into inserts 1..5
+    const auto count = (int) song.mixer.size();
+    CHECK (count >= 16);
+    const auto shown = [&song] (int t, const std::set<int>& keep = {}) { return ! mixerops::hiddenUnusedInserts (song, keep)[(std::size_t) t]; };
+
+    // one flag per insert and one for the "+" button, which never hides; the Master never hides
+    CHECK ((int) mixerops::hiddenUnusedInserts (song, {}).size() == count + 1);
+    CHECK (shown (0) && shown (count));
+    // a channel routed to it: stays. Nothing at all: hidden
+    for (int t = 1; t <= 5; ++t)
+        CHECK (shown (t));
+    for (int t = 6; t < count; ++t)
+        CHECK (! shown (t));
+
+    // the selected insert (and whatever else the mixer asks to keep) always stays
+    CHECK (shown (7, { 7 }) && ! shown (8, { 7 }) && shown (8, { 7, 8 }));
+
+    // anything that can receive audio stays: a send into it ...
+    song.mixer[1].sends.push_back ({ 9, 1.0f });
+    CHECK (shown (9) && ! shown (10));
+    // ... an audio input ...
+    song.mixer[10].inputChannel = 0;
+    CHECK (shown (10));
+    // ... a Playlist track linked to it ...
+    CHECK (! shown (11));
+    song.playlistTracks.resize (std::max<std::size_t> (song.playlistTracks.size(), 1));
+    song.playlistTracks[0].mixerTrack = 11;
+    CHECK (shown (11));
+    // ... an effect's sidechain input or extra output ...
+    CHECK (! song.mixer[0].effects.empty());
+    song.mixer[2].effects.push_back (song.mixer[0].effects[0]);
+    song.mixer[2].effects.back().sidechain = 12;
+    CHECK (shown (12));
+    // ... and a channel routed there later
+    CHECK (! shown (13));
+    song.channels[0].mixerTrack = 13;
+    CHECK (shown (13));
+
+    // an effect on it, or an output that no longer goes to the Master: stays
+    CHECK (! shown (14) && ! shown (15));
+    song.mixer[14].effects.push_back (song.mixer[0].effects[0]);
+    song.mixer[15].toMaster = false;
+    CHECK (shown (14) && shown (15));
+
+    // the option only looks: nothing in the song changed
+    const auto before = song.mixer.size();
+    (void) mixerops::hiddenUnusedInserts (song, { 3 });
+    CHECK (song.mixer.size() == before);
+
+    // a song without a mixer: only the "+" flag
+    Song empty;
+    empty.mixer.clear();
+    CHECK (mixerops::hiddenUnusedInserts (empty, { 0, 4 }) == std::vector<bool> { false });
+}

+ 1 - 0
tests/tests.cpp

@@ -17403,3 +17403,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Surge190xTests.inc"
 #include "TruePeak190amTests.inc"
 #include "Loudness190amTests.inc"
+#include "UsedOnly190amTests.inc"