Browse Source

Track-only mode and the Simple layout: a clip on an instrument track opens its instrument's notes, empty or not (Discord, 0.1.31)

A double-click on a pattern clip used FL's Auto rule (Piano roll when the pattern has notes, else the Channel rack), so
a freshly drawn instrument-track clip, empty, opened the Channel rack: hidden by Track-only mode, no use in the Simple
layout. trackonly::pianoRollChannelOf: in Track-only mode (Pattern layout) and the Simple layout a pattern clip on an
instrument track whose pattern is empty or holds only that channel's notes opens that channel's notes: the Piano roll
(Track-only mode) or the Simple dock's Editor tab on that track and that clip. Alt+double-click still opens the other
editor; the Pattern layout with Track-only mode off keeps FL's rule. The Simple dock's Editor tab showed the track's
first clip always (it re-selected it on every refresh); it now follows the current pattern while a clip on the track
plays it (simpletracks::editorPattern). The Simple layout's hint over an empty instrument track says how to draw a MIDI
clip and open it. Tests: tests/Hotfix190qpWfTests.inc.
Ka1-S 1 week ago
parent
commit
1970e4e05a

+ 12 - 0
src/core/SimpleTracks.cpp

@@ -874,6 +874,18 @@ int patternOf (const Song& song, int track)
     return first != nullptr ? first->pattern : -1;
 }
 
+int editorPattern (const Song& song, int track)
+{
+    const auto first = patternOf (song, track);
+    if (first < 0)
+        return -1;
+    const auto current = song.currentPattern;
+    for (const auto& c : song.playlist)
+        if (c.kind == ClipKind::pattern && c.track == track && c.pattern == current)
+            return current;
+    return first;
+}
+
 int ensurePattern (Song& song, int track, int bars, bool* made)
 {
     if (made != nullptr)

+ 3 - 0
src/core/SimpleTracks.h

@@ -122,6 +122,9 @@ Result addTrack (Song& song, const Request& request);
 int ensurePattern (Song& song, int track, int bars = 4, bool* made = nullptr);
 // The pattern ensurePattern would give without making one (-1: none yet)
 int patternOf (const Song& song, int track);
+// Round 190qp: the pattern the dock's Editor tab shows: the current pattern while a pattern clip on the track plays it
+// (a double-clicked clip, a clip drawn there), else patternOf. -1 as patternOf.
+int editorPattern (const Song& song, int track);
 
 // Renames a Simple track everywhere: the Playlist track, its insert and its channel (Drums: its group and its pattern
 // when they carry the old name). An empty name is ignored. Returns the name given (made unique among the tracks).

+ 24 - 0
src/core/TrackOnly.h

@@ -19,6 +19,7 @@
 //
 // Plain edits for AudioEngine::editSong. No JUCE: tested in tests/Workflow190iuTests.inc.
 
+#include <algorithm>
 #include <atomic>
 #include <cstddef>
 
@@ -55,6 +56,29 @@ inline int follow (Song& song, std::size_t channelsBefore)
     return made;
 }
 
+// Round 190qp (Discord, 0.1.31: "double-clicking an empty clip opens the rack"): the channel whose Piano roll a
+// double-click on Playlist clip `clip` opens in Track-only mode and in the Simple layout. A pattern clip on an
+// instrument track is that instrument's part, so it opens in the instrument's Piano roll even while it is empty — FL's
+// "Auto" rule (Piano roll when the pattern has notes, else the Channel rack) would open the rack, which Track-only mode
+// hides and the Simple layout doesn't have. -1 when the clip is not a pattern clip on an instrument track, or when its
+// pattern holds notes of another channel (an imported pattern played on the track: the usual rule decides).
+// The Pattern layout with Track-only mode off keeps FL's rule (the caller asks only in those two cases).
+inline int pianoRollChannelOf (const Song& song, int clip)
+{
+    if (clip < 0 || clip >= (int) song.playlist.size())
+        return -1;
+    const auto& c = song.playlist[(std::size_t) clip];
+    if (c.kind != ClipKind::pattern || c.track < 0 || c.track >= (int) song.playlistTracks.size() || c.pattern < 0
+        || c.pattern >= (int) song.patterns.size())
+        return -1;
+    const auto& track = song.playlistTracks[(std::size_t) c.track];
+    const auto channel = track.channel;
+    if (track.mode != PlaylistTrackMode::instrument || channel < 0 || channel >= (int) song.channels.size())
+        return -1;
+    const auto& notes = song.patterns[(std::size_t) c.pattern].notes;
+    return std::all_of (notes.begin(), notes.end(), [channel] (const Note& n) { return n.channel == channel; }) ? channel : -1;
+}
+
 // "Give every instrument its own track" (offered when the mode is switched on for a project made with the rack): each
 // instrument channel without an instrument track gets one. Returns how many.
 inline int assignAll (Song& song) { return follow (song, 0); }

+ 6 - 0
src/ui/MainComponent.cpp

@@ -821,6 +821,12 @@ MainComponent::MainComponent (AudioEngine& e, bool restoreUserSettings)
             engine.setSelectedChannel (notes.front().channel);
         openPianoRoll();
     };
+    // round 190qp: a clip of an instrument track in Track-only mode / the Simple layout (its channel already selected)
+    playlist.onOpenTrackClipNotes = [this] (int track) {
+        if (layoutStyle == layoutstyle::Style::simple && simpleWorkflow != nullptr && simpleWorkflow->openNotesOf (track))
+            return;
+        openPianoRoll();
+    };
     picker.onOpenPattern = [this] { showPanel (Panel::channelRack); };
     picker.onPatternMenu = [this] { makePatternMenu (picker.pickedPatterns()).showMenuAsync (juce::PopupMenu::Options().withMousePosition()); };
     picker.onNewPattern = [this] { newPatternButton.onClick(); };

+ 2 - 0
src/ui/MainComponent.h

@@ -236,6 +236,8 @@ public:
     bool welcomeUpdatesForCheck() const noexcept { return welcomeUpdates; } // (rollup 0.1.31 step 2, issue #233)
     onboarding::Context& onboardingContextForCheck() noexcept { return onboardCtx; }
     bool mixerShownForCheck() const { return workspace.isPanelVisible (workspace::Panel::mixer); }
+    bool panelShownForCheck (workspace::Panel panel) const { return workspace.isPanelVisible (panel); } // (round 190qp)
+    void hidePanelForCheck (workspace::Panel panel) { workspace.hide (panel); refreshPanelButtons(); }
     void updateOnboarding(); // the song or the view changed: the Next-3 ticks and the empty-state hint
     // --demo (ui/DemoMode.cpp): the Remote Control API's ui.* / session.* operations, run on the message thread
     juce::var handleDemoOp (const juce::String& op, const juce::var& args);

+ 17 - 0
src/ui/PlaylistComponent.cpp

@@ -73,6 +73,7 @@
 #include "ui/WindowClipboard.h"
 #include "core/KeyFollow.h"
 #include "core/SimpleTracks.h"
+#include "core/TrackOnly.h"
 #include "core/RegionLoop.h"
 #include "core/QuickRender.h"
 #include "core/TempoDetect.h"
@@ -14683,6 +14684,10 @@ ui::Hint PlaylistComponent::hintAt (juce::Point<int> p)
     {
         if (projection.isChild (h.track))
             hint.text = tr ("Automation lane: [LMB] song position  [LMB] drag: select  (its clips: drag left / right)");
+        // round 190qp (Discord, 0.1.31: "not sure how to make a MIDI clip"): the Simple layout's instrument tracks say how
+        else if (simpleHeaders && brush.kind == ClipKind::pattern && h.track >= 0 && h.track < (int) song.playlistTracks.size()
+                 && song.playlistTracks[(std::size_t) h.track].mode == PlaylistTrackMode::instrument)
+            hint.text = tr ("MIDI clip: [LMB] click or drag draws one on this track  [2xLMB] on a clip: edit its notes below");
         else if (trackclips::owns (song, h.track) && brush.kind == ClipKind::pattern) // round 190ne
             hint.text = tr ("Track clips: [LMB] draw a new empty clip  [Shift] drag a clip: a unique copy  [Shift+L] drag: a linked copy  [Ctrl+Alt+B] linked copies");
         else if (pointerclick::on)
@@ -14863,6 +14868,18 @@ void PlaylistComponent::openClipSource (int hit, bool other)
     }
     else if (clip.kind == ClipKind::pattern)
     {
+        // round 190qp (Discord, 0.1.31): in Track-only mode and the Simple layout a clip on an instrument track opens its
+        // instrument's notes, empty or not (Alt: the other editor, as below). The Pattern layout keeps FL's rule.
+        if (! other && (trackonly::active() || simpleHeaders))
+            if (const auto channel = trackonly::pianoRollChannelOf (engine.getSong(), hit); channel >= 0)
+            {
+                engine.setSelectedChannel (channel);
+                if (onOpenTrackClipNotes)
+                    onOpenTrackClipNotes (clip.track);
+                else if (onOpenPianoRoll)
+                    onOpenPianoRoll();
+                return;
+            }
         auto pianoRoll = editPatternsIn == 2
                          || (editPatternsIn == 0 && clip.pattern < (int) engine.getSong().patterns.size()
                              && hasPianoRollNotes (engine.getSong().patterns[(std::size_t) clip.pattern]));

+ 4 - 0
src/ui/PlaylistComponent.h

@@ -101,6 +101,10 @@ public:
 
     std::function<void()> onOpenPattern;
     std::function<void()> onOpenPianoRoll;
+    // round 190qp: a pattern clip on an instrument track double-clicked in Track-only mode or the Simple layout opens its
+    // instrument's notes (core/TrackOnly.h pianoRollChannelOf): the Simple dock's Editor tab, else the Piano roll. The
+    // channel is selected and the clip's pattern made current before the call.
+    std::function<void (int track)> onOpenTrackClipNotes;
     std::function<void (int pattern)> onRenamePattern;  // clip menu: Rename and color (pattern clips)
     std::function<void (int channel)> onOpenInSampler;  // clip menu: the audio clip's file in a new Sampler channel
     // round 190dx: a new instrument track's channel was made (or its generator replaced): the main window opens it as the

+ 2 - 2
src/ui/SimpleDock.cpp

@@ -1641,7 +1641,7 @@ public:
     void update()
     {
         const auto& song = engine.getSong();
-        const auto pattern = track >= 0 ? simpletracks::patternOf (song, track) : -1;
+        const auto pattern = track >= 0 ? simpletracks::editorPattern (song, track) : -1;
         const auto canHave = track >= 0 && (simpletracks::kindOf (song, track) == simpletracks::Kind::instrument
                                             || simpletracks::kindOf (song, track) == simpletracks::Kind::sampler);
         if (! shownInTree() || ! canHave)
@@ -1749,7 +1749,7 @@ public:
         g.fillAll (colour::bg1);
         const auto& song = engine.getSong();
         auto bar = getLocalBounds().removeFromTop (barHeight).reduced (12, 0);
-        const auto pattern = track >= 0 ? simpletracks::patternOf (song, track) : -1;
+        const auto pattern = track >= 0 ? simpletracks::editorPattern (song, track) : -1;
         g.setColour (colour::textSecondary);
         g.setFont (font (type::small));
         if (pattern >= 0)

+ 21 - 0
src/ui/SimpleWorkflow.cpp

@@ -1008,6 +1008,27 @@ void SimpleWorkflow::showEffectsOfInsert (int insert)
         dock->setTab (SimpleDock::Tab::effects);
 }
 
+bool SimpleWorkflow::openNotesOf (int track)
+{
+    if (! active)
+        return false;
+    const auto kind = simpletracks::kindOf (engine.getSong(), track);
+    if (kind != simpletracks::Kind::instrument && kind != simpletracks::Kind::sampler)
+        return false;
+    dockTrack = track;
+    if (! SimpleDock::shownSetting)
+    {
+        SimpleDock::shownSetting = true;
+        if (host.settingsChanged)
+            host.settingsChanged();
+    }
+    updateDock();
+    if (dock == nullptr)
+        return false;
+    dock->setTab (SimpleDock::Tab::editor);
+    return true;
+}
+
 void SimpleWorkflow::toggleDock()
 {
     SimpleDock::shownSetting = ! SimpleDock::shownSetting;

+ 4 - 0
src/ui/SimpleWorkflow.h

@@ -121,6 +121,10 @@ public:
     // timeline. Made the first time it shows.
     void trackSelected (int track);      // a click on a track header
     void showEffectsOfInsert (int insert); // "+FX" on a header: the dock, on its Effects tab, for the track of `insert`
+    // round 190qp: a double-clicked clip of an instrument track: the dock, on its Editor tab, for that track (the clip's
+    // pattern is the current one, so the tab shows it). False when the dock can't show it (not a Simple instrument /
+    // sampler track).
+    bool openNotesOf (int track);
     void toggleDock();                   // Ctrl+Alt+L
     void cycleDockTab();                 // Shift+Tab
     bool isDockShowing() const noexcept;

+ 111 - 0
tests/Hotfix190qpWfTests.inc

@@ -0,0 +1,111 @@
+// Round 190qp (0.1.31.1 hotfix): a clip on an instrument track opens its instrument's notes in Track-only mode and the
+// Simple layout, empty or not (Discord, 0.1.31); the Simple dock's Editor tab follows the clip that was opened.
+
+#include "core/SimpleTracks.h"
+#include "core/TrackClips.h"
+#include "core/TrackOnly.h"
+
+namespace hotfix190qpwf
+{
+// a song with an instrument track (channel `c`, its own empty pattern clip) and an unassigned track playing a pattern of
+// several channels
+inline lynx::Song instrumentTrackSong (int& channel, int& emptyClip, int& sharedClip)
+{
+    using namespace lynx;
+    auto s = Song::makeDefault();
+    s.playlist.clear();
+    for (auto& p : s.patterns)
+        p.notes.clear();
+    ChannelDef synth;
+    synth.name = "Lead";
+    synth.instrument = InstrumentKind::synth;
+    channel = trackmodes::addInstrumentTrack (s, synth);
+    const auto track = trackmodes::instrumentTracksOf (s, channel).front();
+    const auto p = trackmodes::instrumentTrackPattern (s, track); // (the pencil's pattern: empty, named after the channel)
+    s.playlist.push_back ({ p, track, 0, s.barTicks(), 0 });
+    s.playlist.back().kind = ClipKind::pattern;
+    emptyClip = (int) s.playlist.size() - 1;
+    Pattern shared;
+    shared.name = "Shared";
+    shared.notes.push_back ({ 0, ppq, 0, 60, 0.8f });
+    shared.notes.push_back ({ 0, ppq, channel, 64, 0.8f });
+    s.patterns.push_back (shared);
+    s.playlist.push_back ({ (int) s.patterns.size() - 1, track, s.barTicks(), s.barTicks(), 0 });
+    s.playlist.back().kind = ClipKind::pattern;
+    sharedClip = (int) s.playlist.size() - 1;
+    return s;
+}
+} // namespace hotfix190qpwf
+
+TEST (hotfix190qp_track_clip_opens_its_instruments_piano_roll)
+{
+    using namespace lynx;
+    int channel = -1, emptyClip = -1, sharedClip = -1;
+    auto s = hotfix190qpwf::instrumentTrackSong (channel, emptyClip, sharedClip);
+    CHECK (channel >= 0);
+    if (! (channel >= 0))
+        return;
+    // an empty clip on the instrument track: that channel's Piano roll (FL's Auto rule would open the rack)
+    CHECK (trackonly::pianoRollChannelOf (s, emptyClip) == channel);
+    // notes of that channel only: still that channel
+    s.patterns[(std::size_t) s.playlist[(std::size_t) emptyClip].pattern].notes.push_back ({ 0, ppq, channel, 60, 0.8f });
+    CHECK (trackonly::pianoRollChannelOf (s, emptyClip) == channel);
+    // a pattern with another channel's notes on the track: the usual rule decides
+    CHECK (trackonly::pianoRollChannelOf (s, sharedClip) == -1);
+    // a clip on an unassigned track, an automation clip, out of range: none
+    auto unassigned = s;
+    unassigned.playlist[(std::size_t) emptyClip].track = 30;
+    CHECK (trackonly::pianoRollChannelOf (unassigned, emptyClip) == -1);
+    auto automation = s;
+    automation.playlist[(std::size_t) emptyClip].kind = ClipKind::automation;
+    CHECK (trackonly::pianoRollChannelOf (automation, emptyClip) == -1);
+    CHECK (trackonly::pianoRollChannelOf (s, -1) == -1 && trackonly::pianoRollChannelOf (s, 99) == -1);
+}
+
+TEST (hotfix190qp_simple_editor_tab_follows_the_opened_clip)
+{
+    using namespace lynx;
+    auto s = Song::makeDefault();
+    s.playlist.clear();
+    simpletracks::Request q;
+    q.kind = simpletracks::Kind::instrument;
+    ChannelDef c;
+    c.instrument = InstrumentKind::synth;
+    q.channel = c;
+    q.emptyBars = 4;
+    const auto r = simpletracks::addTrack (s, q);
+    CHECK (r.ok());
+    if (! (r.ok()))
+        return;
+    const auto first = simpletracks::ensurePattern (s, r.track, 4);
+    CHECK (first >= 0);
+    if (! (first >= 0))
+        return;
+    // a second clip drawn later on the track (the pencil on a Simple instrument track: a new empty clip of its own)
+    const auto second = trackclips::newClip (s, r.track, s.barTicks());
+    CHECK (second >= 0 && second != first);
+    if (! (second >= 0 && second != first))
+        return;
+    Clip clip;
+    clip.kind = ClipKind::pattern;
+    clip.pattern = second;
+    clip.track = r.track;
+    clip.start = 8 * s.barTicks();
+    clip.length = s.barTicks();
+    s.playlist.push_back (clip);
+    // the dock showed the first clip, always; now the current pattern while it is one of the track's clips
+    s.currentPattern = first;
+    CHECK (simpletracks::editorPattern (s, r.track) == first);
+    s.currentPattern = second;
+    CHECK (simpletracks::editorPattern (s, r.track) == second);
+    CHECK (simpletracks::patternOf (s, r.track) == first); // (patternOf unchanged)
+    // a current pattern that plays elsewhere: the track's first clip
+    Pattern other;
+    s.patterns.push_back (other);
+    s.currentPattern = (int) s.patterns.size() - 1;
+    CHECK (simpletracks::editorPattern (s, r.track) == first);
+    // both clips on the track open its channel's Piano roll, empty as they are
+    for (int i = 0; i < (int) s.playlist.size(); ++i)
+        if (s.playlist[(std::size_t) i].track == r.track && s.playlist[(std::size_t) i].kind == ClipKind::pattern)
+            CHECK (trackonly::pianoRollChannelOf (s, i) == r.channels.front());
+}

+ 1 - 0
tests/tests.cpp

@@ -18110,3 +18110,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Issues190qbTests.inc" // round 190qb: issue follow-ups (#215 folders in the export name)
 #include "Hotfix190qpTests.inc" // round 190qp (0.1.31.1): imported FL volume / send / filter automation, linked clips shown
 #include "Issue269_190qmTests.inc" // round 190qm: issue #269, the hint bar's right-click crash
+#include "Hotfix190qpWfTests.inc" // round 190qp: 0.1.31.1 hotfix (track clips open their notes)