Sfoglia il codice sorgente

Sections lane UI: GarageBand's Arrangement track in Simple (the title bar's Sections button adds the first section), a LYNX extra in Pattern (Playlist menu › View, off by default; FL's marker tags), none in Clip-launch; drag moves, Ctrl+drag copies, drop onto swaps, Shift replaces, right edge resizes, Delete empties then removes; Create scenes from sections in the clip grid; One file per section in the Export window; Simple ruler: Change time signature here..., the top bar's 4 / 4 as BandLab's two lists

Ka1-S 2 settimane fa
parent
commit
ea391edaf8

+ 5 - 0
src/core/LynxExtras.h

@@ -115,6 +115,11 @@ inline constexpr Item items[] = {
     { "playlist.rulerSeeksAnyTool", TR_NOOP ("Playlist"), TR_NOOP ("A click on the ruler moves the song position with every tool"),
       TR_NOOP ("In FL Studio a click on the Playlist's or Piano roll's ruler with the Select or Zoom tool selects or zooms a time range and leaves the song position. On: those tools move the song position too, like the others; Ctrl+drag, a double-click drag or a right drag still select a range. Off by default. Also in the Playlist ruler's right-click menu."),
       "ui-options.txt:rulerSeeksAnyTool" },
+    // round 190ol (research190oe P1, owner decision O-1): the Pattern layout's Sections lane (the Simple layout shows it once
+    // the song has a section; the Clip-launch layout has none)
+    { "playlist.sectionsLane", TR_NOOP ("Playlist"), TR_NOOP ("Sections lane"),
+      TR_NOOP ("A lane under the Playlist's ruler with named song sections (Intro, Verse, Chorus...): drag one to move it with every clip, automation and marker under it, Ctrl+drag to copy it, drop it onto another to swap them. FL Studio has only time markers; an .flp export writes a marker at each section's start. Also in the Playlist menu › View."),
+      "ui-options.txt:sectionsLane" },
     { "midi.gamepad", TR_NOOP ("Controllers"), TR_NOOP ("Use a game controller"),
       TR_NOOP ("A game controller plays the transport and can be linked to any control like a MIDI controller. Also on the MIDI page."),
       "midi-settings.txt:gamepad" },

+ 9 - 0
src/ui/ClipGridComponent.cpp

@@ -3,6 +3,7 @@
 #include "ui/TrackerComponent.h"
 #include "ui/PaintAB.h"
 #include "ui/PlaylistComponent.h"
+#include "core/SectionOps.h" // round 190ol (P1: scenes from sections)
 #include "core/CrossPaste.h"   // issue #232 stage 2 (round 190nz)
 #include "ui/WindowClipboard.h"
 
@@ -3297,6 +3298,14 @@ private:
 
     void addGridOptions (juce::PopupMenu& menu)
     {
+        // round 190ol (research190oe P1; Live users' "markers to scenes"): one scene per section of the arrangement's
+        // Sections lane, named and coloured after it, with each track's clip of that section (core/SectionOps.h)
+        const auto sectionCount = (int) engine.getSong().sections().size();
+        menu.addItem (tr ("Create scenes from sections") + (sectionCount > 0 ? " (" + juce::String (sectionCount) + ")" : juce::String()), sectionCount > 0, false, [this] {
+            engine.editSong ([] (Song& s) { sections::createScenes (s); });
+            clampScroll();
+            repaint();
+        });
         // round 190ef: the reference's View › Scene Tempo And Time Signature (a preference, kept with the UI settings)
         menu.addItem (tr ("Scene tempo and time signature"), true, sceneFieldsOn, [this] {
             sceneFieldsOn = ! sceneFieldsOn;

+ 31 - 2
src/ui/ExportDialog.cpp

@@ -371,6 +371,10 @@ public:
         additions = clip == nullptr && onlyTracks.empty();
         if (! additions)
             options.sections = false;
+        // round 190ol: "One file per section" only when the song has sections in its Sections lane
+        songSectionsShown = additions && ! engine.getSong().sections().empty();
+        if (! songSectionsShown)
+            options.songSections = false;
         if (persistent && additions)
         {
             presets = exportopts::presetsFromText (exportPresetsFile().loadFileAsString().toStdString());
@@ -425,6 +429,11 @@ public:
         sectionsToggle.onClick = [this] { readControls(); };
         addChildComponent (sectionsToggle);
         sectionsToggle.setVisible (additions);
+        // round 190ol: the same, cut at the Sections lane's sections (named after them)
+        songSectionsToggle.setButtonText (tr ("One file per section"));
+        songSectionsToggle.onClick = [this] { readControls(); };
+        addChildComponent (songSectionsToggle);
+        songSectionsToggle.setVisible (songSectionsShown);
         // round 190ap: named presets of these choices, and the last export again without the file dialog
         settingsui::styleLabel (presetLabel, tr ("Preset"));
         presetBox.setTextWhenNothingSelected (tr ("Choose a preset..."));
@@ -673,7 +682,8 @@ public:
         // (the Master export keeps its own window: no presets row, no sections; round 190ap)
         additions = false;
         options.sections = false;
-        for (auto* c : std::initializer_list<juce::Component*> { &sectionsToggle, &presetLabel, &presetBox, &savePresetButton, &deletePresetButton, &sameAsLastButton })
+        options.songSections = false;
+        for (auto* c : std::initializer_list<juce::Component*> { &sectionsToggle, &songSectionsToggle, &presetLabel, &presetBox, &savePresetButton, &deletePresetButton, &sameAsLastButton })
             c->setVisible (false);
         writeControls();
         setSize (620, wantedHeight());
@@ -785,6 +795,11 @@ public:
             left.removeFromTop (2);
             sectionsToggle.setBounds (left.removeFromTop (22).withTrimmedLeft (labelWidth));
         }
+        if (songSectionsToggle.isVisible())
+        {
+            left.removeFromTop (2);
+            songSectionsToggle.setBounds (left.removeFromTop (22).withTrimmedLeft (labelWidth));
+        }
         if (! onlyTracks.empty())
         {
             left.removeFromTop (gap);
@@ -858,7 +873,7 @@ private:
     int columnsHeight()
     {
         constexpr int rowHeight = 26, gap = 7;
-        const auto leftHeight = 26 + 8 + 5 * (rowHeight + gap) + 22 + (sectionsToggle.isVisible() ? 24 : 0) + (onlyTracks.empty() ? 0 : gap + rowHeight + gap);
+        const auto leftHeight = 26 + 8 + 5 * (rowHeight + gap) + 22 + (sectionsToggle.isVisible() ? 24 : 0) + (songSectionsToggle.isVisible() ? 24 : 0) + (onlyTracks.empty() ? 0 : gap + rowHeight + gap);
         const auto columnWidth = (620 - 32 - 24) / 2;
         const auto layout = alsoLayout (columnWidth);
         // the most rows a format has: FLAC (bit depth, compression) + rate, channels, dither
@@ -1066,6 +1081,7 @@ private:
         }
         stemsMaster.setToggleState (options.stemsIncludeMaster, n);
         sectionsToggle.setToggleState (options.sections, n);
+        songSectionsToggle.setToggleState (options.songSections, n);
         formatButtons.setSelected ((int) options.format);
         depthBox.setSelectedItemIndex (options.format == Format::flac   ? (options.flacBits == 16 ? 0 : 1)
                                        : options.format == Format::aiff ? (options.aiffBits == 16 ? 0 : 1)
@@ -1221,6 +1237,7 @@ private:
         options.stems = (Stems) juce::jmax (0, stemsBox.getSelectedItemIndex());
         options.stemsIncludeMaster = stemsMaster.getToggleState();
         options.sections = additions && sectionsToggle.getToggleState();
+        options.songSections = songSectionsShown && songSectionsToggle.getToggleState(); // (round 190ol)
         if (naming) // (round 190ng)
             options.nameTemplate = nameEditor.getText().toStdString();
         options.format = (Format) formatButtons.getSelected();
@@ -1298,6 +1315,16 @@ private:
                                                            : tr ("The song is cut at its Playlist markers and each section becomes a file named after its marker; with stems, each section gets its stems. Sections: {0}",
                                                                  { names.joinIntoString (", ") }));
         }
+        if (songSectionsShown) // (round 190ol)
+        {
+            const auto lane = laneSections (songNow);
+            songSectionsToggle.setEnabled (! realtime && options.range == Range::song && ! lane.empty());
+            juce::StringArray names;
+            for (const auto& section : lane)
+                names.add (juce::String::fromUTF8 (section.name.c_str()));
+            songSectionsToggle.setTooltip (tr ("The song is cut at the sections of its Sections lane and each section becomes a file named after it; with stems, each section gets its stems. Sections: {0}",
+                                               { names.joinIntoString (", ") }));
+        }
         updatePresetButtons();
         loopsBox.setEnabled (! realtime && clip == nullptr && ! sectioned);
         // a real-time bounce (round 165c): the device's rate, the song or the selection once, the Master's effects, the
@@ -1539,6 +1566,8 @@ private:
     // round 190ap: "One file per marker section", the presets row and "Same as last time"
     bool additions = false;
     juce::ToggleButton sectionsToggle;
+    juce::ToggleButton songSectionsToggle; // round 190ol: "One file per section" (the Sections lane)
+    bool songSectionsShown = false;
     juce::Label presetLabel;
     juce::ComboBox presetBox;
     juce::TextButton savePresetButton { tr ("Save...") }, deletePresetButton { tr ("Delete") }, sameAsLastButton { tr ("Same as last time") };

+ 7 - 0
src/ui/MainComponent.cpp

@@ -3,6 +3,7 @@
 #include "ui/KeyFocus.h"
 #include "ui/TrackIcons.h"
 #include "ui/WindowPlaces.h" // (round 190oa, DF-130)
+#include "core/Sections.h"
 #include "core/EscClose.h"
 #include "core/DetailChain.h"
 #include "core/MeterScale.h"
@@ -4353,6 +4354,7 @@ void MainComponent::setLayoutStyle (layoutstyle::Style style, bool swapLayout)
                 toggleTouchKeyboard (engine);
         };
         host.setTitleAccessory = [this] (juce::Component* c, int width) { workspace.setTitleAccessory (Panel::playlist, c, width); };
+        host.toggleSections = [this] { playlist.toggleSimpleSections(); }; // round 190ol (P1): the Simple title bar's Sections button
         host.toggleLoops = [this] { // round 190lx (DS-42): the Simple title bar's Loops button
             if (isLoopsDockShowing())
                 hideLoopsDock();
@@ -5182,6 +5184,11 @@ void MainComponent::addPanelMenuItems (Panel panel, juce::PopupMenu& menu)
                     playlist.headerOptionsChanged();
                     saveUiSettings();
                 });
+                // round 190ol (research190oe P1, owner decision O-1): LYNX's Sections lane, off by default in this layout (the
+                // Simple layout has its title bar button, the Clip-launch layout none)
+                view.addSeparator();
+                view.addItem (tr ("Sections lane") + " (LYNX)", layoutStyle == layoutstyle::Style::pattern, sections::patternLaneOn(),
+                              [] { workflowextras::setExtra ("playlist.sectionsLane", ! sections::patternLaneOn()); });
                 menu.addSubMenu (tr ("View"), view);
             }
             {

+ 75 - 7
src/ui/PlaylistComponent.cpp

@@ -104,6 +104,9 @@
 #include "ui/QuickPick.h"
 #include "ui/Icons.h"
 #include "ui/SimpleLook.h"
+#include "core/SectionOps.h"    // round 190ol (the Sections lane)
+#include "core/SignatureEdit.h" // round 190ol (P6: Simple time signature changes)
+#include "ui/SectionsLane190ol.h" // round 190ol (P1: the Sections lane)
 #include "core/LoopAnalysis.h" // round 190kx
 #include "core/TrackClips.h" // round 190ne
 #include "ui/LoopInfo.h"
@@ -537,6 +540,8 @@ void paintClipOutline (juce::Graphics& g, juce::Rectangle<float> r, juce::Colour
 
 } // namespace
 
+#include "SectionsLane190ol.inc" // round 190ol (research190oe P1): the Sections lane
+
 // Zoomed far out, a song of chopped audio shows a thousand clips a few pixels wide. Painted one by one, each is a
 // handful of rounded paths (frame, header, waveform, outline), and the GPU renderer pays per path: Thief's Playlist
 // took 33-47 ms a frame to scroll (round 151). These clips are gathered here, rectangles per colour and waveforms per
@@ -1206,6 +1211,8 @@ PlaylistComponent::PlaylistComponent (AudioEngine& e)
     addChildComponent (*blocksView);
     videoLanes = std::make_unique<VideoLanesView> (engine, *this);
     addChildComponent (*videoLanes);
+    sectionsLane = std::make_unique<SectionsLaneView> (engine, *this); // round 190ol
+    addChildComponent (*sectionsLane);
 
     grid::fillEditorBox (snapBox);
     snapBox.setTooltip (tr ("Playlist snap (magnet): \"Main\" follows the snap in the toolbar, or pick this window's own; hold Alt while dragging to ignore it"));
@@ -1435,7 +1442,7 @@ int PlaylistComponent::videoSectionHeight() const
     if (natural <= 0)
         return 0;
     // (the clip tracks keep two rows; with the Pattern Blocks section too, the video lanes take at most half)
-    const auto available = getHeight() - headerHeight;
+    const auto available = getHeight() - headerHeight - sectionsLaneHeight();
     const auto least = VideoLanesView::dividerHeight + 20;
     const auto most = juce::jmax (least, engine.getSong().patternBlocksOn ? available / 2 : available - 2 * baseRowHeight());
     return juce::jlimit (least, most, videoHeight > 0 ? videoHeight : natural);
@@ -1873,7 +1880,11 @@ void PlaylistComponent::resized()
     blocksView->setBounds (0, getHeight() - blocks, getWidth(), blocks);
     blocksView->setVisible (blocksShown);
     const auto video = videoSectionHeight();
-    videoLanes->setBounds (0, headerHeight, getWidth(), video);
+    const auto lane = sectionsLaneHeight(); // round 190ol: the Sections lane, right under the ruler
+    laidOutSectionsHeight = lane;
+    sectionsLane->setBounds (0, headerHeight, getWidth(), lane);
+    sectionsLane->setVisible (lane > 0);
+    videoLanes->setBounds (0, headerHeight + lane, getWidth(), video);
     videoLanes->setVisible (video > 0);
     updateScrollBars();
 
@@ -8159,7 +8170,8 @@ void PlaylistComponent::insertTimeSelection()
         return;
 
     setSelection ({});
-    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::insertTime (s.playlist, s.markers(), from, to - from); });
+    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::insertTime (s.playlist, s.markers(), from, to - from);
+                                                                      sections::insertTime (s.sections(), from, to - from); }); // (round 190ol)
     sortClips();
 }
 
@@ -8171,7 +8183,8 @@ void PlaylistComponent::deleteTimeSelection()
         return;
 
     setSelection ({});
-    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::deleteTime (s.playlist, s.markers(), from, to); });
+    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::deleteTime (s.playlist, s.markers(), from, to);
+                                                                      sections::deleteTime (s.sections(), from, to); }); // (round 190ol)
     sortClips();
 }
 
@@ -8183,6 +8196,7 @@ void PlaylistComponent::setLiveStyle (bool on)
     liveStyle = on;
     refreshTrackLayout(); // (round 190gw: the Clip-launch layout keeps LYNX's 38 px default row; round 190jn: Live's 19 px in its look)
     updateHeaderWidth();  // (round 190jn: Live's header row is wider)
+    sectionsLaneChanged(); // (round 190ol: no Sections lane in the Clip-launch layout)
     updateScrollBars();
     repaint();
 }
@@ -8546,7 +8560,8 @@ void PlaylistComponent::sliceInsertTimeSelection()
         return;
 
     setSelection ({});
-    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::sliceInsertTime (s.playlist, s.markers(), from, to - from); });
+    engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) { noteedit::sliceInsertTime (s.playlist, s.markers(), from, to - from);
+                                                                      sections::insertTime (s.sections(), from, to - from); }); // (round 190ol)
     sortClips();
 }
 
@@ -8560,6 +8575,8 @@ void PlaylistComponent::trimTimeSelection()
     setSelection ({});
     engine.editSong ([from = song.loopStart, to = song.loopEnd] (Song& s) {
         noteedit::trimTime (s.playlist, s.markers(), from, to);
+        sections::deleteTime (s.sections(), to, std::numeric_limits<std::int64_t>::max() / 4); // (round 190ol)
+        sections::deleteTime (s.sections(), 0, from);
         s.loopStart = s.loopEnd = 0; // (FL clears the time selection after a trim, FUN_00eb35f0)
     });
     sortClips();
@@ -9441,6 +9458,7 @@ void PlaylistComponent::setSimpleHeaders (bool on)
     headerWidth = -1; // (always laid out again)
     updateHeaderWidth();
     refreshTrackLayout(); // (round 190jq: no automation lanes in Simple)
+    sectionsLaneChanged(); // (round 190ol: the lane's look and visibility follow the layout)
 }
 
 void PlaylistComponent::selectTrackChannel (int track)
@@ -10350,7 +10368,7 @@ void PlaylistComponent::editTempoMarker (std::int64_t tick, int existing)
                              true);
 }
 
-void PlaylistComponent::showRulerMenu (int x)
+juce::PopupMenu PlaylistComponent::rulerMenu (int x)
 {
     const auto& song = engine.getSong();
     const auto tick = juce::jmax<std::int64_t> (0, snap (xToTick (x), true));
@@ -10362,6 +10380,19 @@ void PlaylistComponent::showRulerMenu (int x)
             near = i;
 
     juce::PopupMenu menu;
+    // round 190ol (research190oe P6, GarageBand's complaint G1): the Simple layout's time signature change at the bar under
+    // the pointer (core/SignatureEdit.h); the FL items below stay
+    if (simpleHeaders)
+    {
+        const auto bar = signatureedit::barLine (song, (std::int64_t) juce::jmax (0.0, xToTick (x)));
+        menu.addItem (tr ("Change time signature here..."), [this, bar] { askSimpleSignature (bar); });
+        if (bar > 0 && signatureedit::changeAt (song, bar) >= 0)
+            menu.addItem (tr ("Delete this time signature change"), [this, bar] {
+                engine.editSong ([bar] (Song& s) { signatureedit::remove (s, bar); });
+                repaint();
+            });
+        menu.addSeparator();
+    }
     menu.addItem (tr ("Add marker here..."), [this, tick] { editMarkerName (tick, -1); });
 
     juce::PopupMenu signatures;
@@ -10596,7 +10627,42 @@ void PlaylistComponent::showRulerMenu (int x)
         menu.addSubMenu (tr ("Zoom"), zoom);
     }
 
-    menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
+    return menu;
+}
+
+void PlaylistComponent::showRulerMenu (int x)
+{
+    rulerMenu (x).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
+}
+
+// Round 190ol (P6): the Simple layout's "Change time signature here...": numerator 1-16, denominator 2 / 4 / 8 / 16, the
+// signature in force at that bar to start with; on bar 1 it is the song's own (the top bar's box shows it)
+void PlaylistComponent::askSimpleSignature (std::int64_t bar)
+{
+    const auto& song = engine.getSong();
+    const auto current = bar <= 0 ? signatureedit::atStart (song) : markers::signatureAt (song, bar);
+    auto* window = new juce::AlertWindow (tr ("Change time signature here..."), tr ("From bar {0}", { juce::String (song.barAt (bar).number) }),
+                                          juce::MessageBoxIconType::NoIcon, this);
+    juce::StringArray numerators, denominators;
+    for (int n = signatureedit::minNumerator; n <= signatureedit::maxNumerator; ++n)
+        numerators.add (juce::String (n));
+    for (const auto d : signatureedit::denominators)
+        denominators.add (juce::String (d));
+    window->addComboBox ("numerator", numerators, tr ("Numerator"));
+    window->addComboBox ("denominator", denominators, tr ("Denominator"));
+    window->getComboBoxComponent ("numerator")->setText (juce::String (current.first), juce::dontSendNotification);
+    window->getComboBoxComponent ("denominator")->setText (juce::String (signatureedit::clampDenominator (current.second)), juce::dontSendNotification);
+    window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
+    window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
+    window->enterModalState (true, juce::ModalCallbackFunction::create ([this, bar, window] (int result) {
+                                 if (result != 1)
+                                     return;
+                                 const auto n = window->getComboBoxComponent ("numerator")->getText().getIntValue();
+                                 const auto d = window->getComboBoxComponent ("denominator")->getText().getIntValue();
+                                 engine.editSong ([bar, n, d] (Song& s) { signatureedit::set (s, bar, n, d); });
+                                 repaint();
+                             }),
+                             true);
 }
 
 void PlaylistComponent::editMarkerName (std::int64_t tick, int existing)
@@ -14420,6 +14486,8 @@ void PlaylistComponent::changeListenerCallback (juce::ChangeBroadcaster* source)
         resized();
     if (videoSectionHeight() != videoLanes->getHeight()) // video tracks added / removed / resized (round 174d)
         resized();
+    else if (sectionsLaneHeight() != laidOutSectionsHeight) // round 190ol: the first section added, the last removed, undo
+        resized();
     blocksView->refresh();
     videoLanes->refresh();
     updateScrollBars();

+ 20 - 1
src/ui/PlaylistComponent.h

@@ -43,6 +43,7 @@ class PatternBlocksView;
 class EffectsPanel;
 class PatternPicker;
 class VideoLanesView;
+class SectionsLaneView;
 
 // FL-style Playlist (arrangement): tracks vertically, time horizontally.
 //  - a tool strip (Pencil, Brush, Eraser, Mute, Knife, Lasso, Zoom, Listen, Slip); with the Pencil:
@@ -461,7 +462,16 @@ public:
     // has video tracks. `height` = the section's height (the divider drag; 0 = fit the lanes), clamped to the window.
     void setVideoHeight (int height);
     int videoSectionHeight() const;
-    int tracksTop() const { return headerHeight + videoSectionHeight(); } // the clip tracks' top edge
+    int tracksTop() const { return headerHeight + sectionsLaneHeight() + videoSectionHeight(); } // the clip tracks' top edge
+    // The Sections lane (round 190ol, core/Sections.h; owner decision O-1): a thin lane under the ruler with the song's
+    // sections. Simple: shown once the song has a section (the title bar's "Sections" button adds the first one, or hides
+    // and shows it again); Pattern: the LYNX extra "Sections lane" (Playlist menu › View), off by default; Clip-launch: off.
+    bool sectionsLaneShown() const;
+    int sectionsLaneHeight() const; // 0 when hidden
+    static constexpr int sectionsLaneFlHeight = 18, sectionsLaneSimpleHeight = 44;
+    void toggleSimpleSections();   // the Simple title bar's "Sections" button
+    void sectionsLaneChanged();    // the extra switched, a layout change: lay the lane out again
+    SectionsLaneView* getSectionsLaneForSnapshot() { return sectionsLane.get(); }
     VideoLanesView* getVideoLanesForSnapshot() { return videoLanes.get(); }
     static juce::Colour audioClipColour (const ChannelDef& channel);
 
@@ -713,9 +723,13 @@ private:
     void askToMakeClipsUnique (std::vector<int> placed, std::vector<int> channels);
     void showClipMenu (int clip);
     void showRulerMenu (int x);                           // markers, time signature and loop
+public:
+    juce::PopupMenu rulerMenu (int x);                    // (round 190ol: the menu itself, also for the shots)
+private:
     static juce::String markerLabel (const Marker& m);   // the text of a marker's tag on the ruler
     int markerTagAt (int x, int y) const;                 // the marker whose tag is under (x, y), or -1
     void editMarkerName (std::int64_t tick, int existing); // existing = index, or -1 to create
+    void askSimpleSignature (std::int64_t bar);            // round 190ol (P6): the Simple ruler's time signature dialog
     // Round 190hq (B11, core/TempoMarkers.h): the tempo markers' tags on the ruler (LYNX extra): the one under (x, y), or
     // -1; the dialog that adds one at `tick` (existing −1) or edits marker `existing`; the tag being dragged
     int tempoTagAt (int x, int y) const;
@@ -1188,6 +1202,11 @@ private:
     friend class VideoLanesView;
     std::unique_ptr<VideoLanesView> videoLanes;
     int videoHeight = 0; // 0 = fit the lanes
+    // The Sections lane (round 190ol)
+    friend class SectionsLaneView;
+    std::unique_ptr<SectionsLaneView> sectionsLane;
+    bool simpleSectionsHidden = false; // the Simple "Sections" button hid a lane that has sections (view only)
+    int laidOutSectionsHeight = 0;
 
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PlaylistComponent)
 };

+ 671 - 0
src/ui/SectionsLane190ol.h

@@ -0,0 +1,671 @@
+#pragma once
+
+// Round 190ol (research190oe P1): the Sections lane --------------------------------------------------------------------
+// A child of the Playlist between the ruler and the video section / clip tracks (PlaylistComponent::sectionsLaneHeight):
+// the song's sections (core/Sections.h) as named blocks over the time line, with the commands of core/SectionOps.h. Looks:
+//  - Simple (44 px): GarageBand's Arrangement track — rounded blocks in the section's colour with the name, "+" in the
+//    header column adds an eight-bar section at the end;
+//  - Pattern (18 px, a LYNX extra): the Playlist's marker tags (the ruler's marker painting): a tag in the section's colour
+//    with its name at the start, the section's span tinted.
+// Mouse: drag a section to move it with everything under it (a line shows where it goes; dropped onto the middle of
+// another one, the two swap, GarageBand's drop onto a marker); Ctrl+drag (Option on macOS) copies it; Shift+drag onto
+// another replaces that one's content (GarageBand's Command-drag); the right edge resizes it (content stays); double-click
+// renames; Delete empties it (its clips go), Delete again removes it and closes the gap. Right-click: the section's menu,
+// or the lane's (add, from markers, to markers, scenes). Header only: included by PlaylistComponent.cpp (which defines
+// the Playlist's side in SectionsLane190ol.inc) and by the shot route (src/SectionsShot190ol.inc).
+
+// The name a new section gets in the language shown: GarageBand's names in order (translated), the first one no section
+// has yet, then "Section N"
+#include <algorithm>
+#include <cstdint>
+#include <iterator>
+#include <string>
+#include <vector>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+#include "core/SectionOps.h"
+#include "core/Sections.h"
+#include "engine/AudioEngine.h"
+#include "ui/ColourPicker.h"
+#include "ui/FlMods.h"
+#include "ui/I18n.h"
+#include "ui/PlaylistComponent.h"
+#include "ui/SimpleLook.h"
+#include "ui/TextCache.h"
+#include "ui/Theme.h"
+#include "ui/ValueControl.h"
+#include "ui/WorkflowExtras.h"
+
+namespace lynx
+{
+inline juce::String sectionPresetName (int index)
+{
+    switch (index)
+    {
+        case 0: return trc ("@song section: Intro");
+        case 1: return trc ("@song section: Verse");
+        case 2: return trc ("@song section: Chorus");
+        case 3: return trc ("@song section: Bridge");
+        default: return trc ("@song section: Outro");
+    }
+}
+
+inline std::string nextSectionName (const std::vector<SongSection>& list)
+{
+    const auto taken = [&list] (const juce::String& name) {
+        return std::any_of (list.begin(), list.end(), [&name] (const SongSection& s) { return juce::String::fromUTF8 (s.name.c_str()) == name; });
+    };
+    for (int i = 0; i < (int) std::size (sections::presetNames); ++i)
+        if (const auto name = sectionPresetName (i); ! taken (name))
+            return name.toStdString();
+    for (int n = (int) list.size() + 1;; ++n)
+        if (const auto name = tr ("Section {0}", { juce::String (n) }); ! taken (name))
+            return name.toStdString();
+}
+
+class SectionsLaneView final : public juce::Component,
+                               public ui::HintSource
+{
+public:
+    SectionsLaneView (AudioEngine& e, PlaylistComponent& p) : engine (e), playlist (p)
+    {
+        setWantsKeyboardFocus (true);
+        setMouseClickGrabsKeyboardFocus (true);
+        setComponentID ("playlist.sectionsLane");
+        setOpaque (true);
+    }
+
+    bool simpleLook() const noexcept { return playlist.simpleHeaders; }
+    int selected() const noexcept { return sections::indexOfUid (engine.getSong().sections(), selectedUid); }
+    void select (int index)
+    {
+        const auto& list = engine.getSong().sections();
+        selectedUid = index >= 0 && index < (int) list.size() ? list[(std::size_t) index].uid : 0;
+        repaint();
+    }
+
+    // --- geometry ------------------------------------------------------------------------------------------------------
+    juce::Rectangle<int> addButton() const
+    {
+        const auto size = simpleLook() ? 24 : 14;
+        return { playlist.headerWidth - size - (simpleLook() ? 10 : 4), (getHeight() - size) / 2, size, size };
+    }
+    juce::Rectangle<float> blockOf (const SongSection& s) const
+    {
+        const auto x0 = (float) playlist.tickToX ((double) s.start), x1 = (float) playlist.tickToX ((double) s.end());
+        return simpleLook() ? juce::Rectangle<float> (x0, 0.0f, juce::jmax (2.0f, x1 - x0), (float) getHeight() - 1.0f)
+                            : juce::Rectangle<float> (x0, 1.0f, juce::jmax (1.0f, x1 - x0), (float) getHeight() - 2.0f);
+    }
+
+    struct Hit
+    {
+        int section = -1;
+        enum Part { none, body, edge, add, header, lane } part = none;
+    };
+    Hit hitAt (juce::Point<int> p) const
+    {
+        Hit h;
+        if (p.x < playlist.headerWidth)
+        {
+            h.part = addButton().expanded (3).contains (p) ? Hit::add : Hit::header;
+            return h;
+        }
+        const auto& list = engine.getSong().sections();
+        for (int i = 0; i < (int) list.size(); ++i)
+        {
+            const auto r = blockOf (list[(std::size_t) i]);
+            if (std::abs ((float) p.x - r.getRight()) <= 4.0f && r.getWidth() > 10.0f)
+                return { i, Hit::edge };
+            if (r.contains (p.toFloat()) || ((float) p.x >= r.getX() && (float) p.x < r.getRight()))
+                return { i, Hit::body };
+        }
+        h.part = Hit::lane;
+        return h;
+    }
+
+    // --- painting --------------------------------------------------------------------------------------------------------
+    // The lane's picture is kept while nothing it shows changes (the sections, the selection, the hover, the view, the
+    // look): the Playlist repaints often (the playhead, meters) and the lane is then one image blit. A drag paints directly.
+    void paint (juce::Graphics& g) override
+    {
+        if (drag != Drag::none)
+        {
+            cacheValid = false;
+            paintLane (g);
+            return;
+        }
+        const auto scale = g.getInternalContext().getPhysicalPixelScaleFactor();
+        CacheKey key { engine.getSong().sections(), selectedUid, hover.section, (int) hover.part, playlist.scrollTicks, playlist.pixelsPerTick, getWidth(),
+                       getHeight(), playlist.headerWidth, simpleLook(), scale, theme::colour::bg1.getARGB(), theme::colour::warning.getARGB() };
+        if (! cacheValid || ! (key == cacheKey))
+        {
+            cache = juce::Image (juce::Image::RGB, juce::jmax (1, juce::roundToInt ((float) getWidth() * scale)),
+                                 juce::jmax (1, juce::roundToInt ((float) getHeight() * scale)), false);
+            juce::Graphics cg (cache);
+            cg.addTransform (juce::AffineTransform::scale (scale));
+            paintLane (cg);
+            cacheKey = std::move (key);
+            cacheValid = true;
+        }
+        g.drawImage (cache, getLocalBounds().toFloat());
+    }
+
+    void paintLane (juce::Graphics& g)
+    {
+        using namespace theme;
+        const auto& song = engine.getSong();
+        const auto& list = song.sections();
+        const auto simple = simpleLook();
+        const auto gridRight = getWidth() - PlaylistComponent::scrollBarSize;
+        g.fillAll (simple ? colour::bg1 : colour::bg2); // (opaque: the scroll bar's column too)
+        // header column: the lane's name and its "+"
+        g.setColour (simple ? colour::bg2 : colour::bg3);
+        g.fillRect (0, 0, playlist.headerWidth, getHeight());
+        g.setColour (colour::textSecondary);
+        g.setFont (font (simple ? type::small : type::caption, simple));
+        textcache::drawText (g, tr ("Sections"), simple ? 14 : 6, 0, playlist.headerWidth - 40, getHeight(), juce::Justification::centredLeft);
+        {
+            // (Simple: GarageBand's Add Marker button, a light disc with a dark "+" at the header's right end)
+            const auto plus = addButton().toFloat();
+            const auto over = hover.part == Hit::add;
+            if (simple)
+            {
+                g.setColour (over ? colour::textPrimary : colour::textPrimary.withAlpha (0.85f));
+                g.fillEllipse (plus);
+                ui::simplelook::drawGlyph (g, ui::simplelook::Glyph::plus, plus.reduced (6.0f), colour::bg1, 2.0f);
+            }
+            else
+            {
+                g.setColour (over ? colour::bg6 : colour::bg4);
+                g.fillRoundedRectangle (plus, 2.0f);
+                ui::simplelook::drawGlyph (g, ui::simplelook::Glyph::plus, plus.reduced (3.0f), over ? colour::textPrimary : colour::textSecondary, 1.3f);
+            }
+        }
+        g.setColour (colour::border);
+        g.fillRect (playlist.headerWidth - 1, 0, 1, getHeight());
+        // the lane
+        g.setColour (simple ? colour::bg1 : colour::bg2);
+        g.fillRect (playlist.headerWidth, 0, gridRight - playlist.headerWidth, getHeight());
+        g.setColour (colour::border);
+        g.fillRect (0, getHeight() - 1, getWidth(), 1);
+        juce::Graphics::ScopedSaveState clip (g);
+        g.reduceClipRegion (playlist.headerWidth, 0, gridRight - playlist.headerWidth, getHeight());
+        const auto sel = selected();
+        for (int i = 0; i < (int) list.size(); ++i)
+        {
+            const auto& s = list[(std::size_t) i];
+            const auto r = blockOf (s);
+            if (r.getRight() < (float) playlist.headerWidth || r.getX() > (float) gridRight)
+                continue;
+            const auto dragged = drag == Drag::move && s.uid == dragUid && moved;
+            paintBlock (g, s, i, r, i == sel, hover.section == i && hover.part != Hit::none, dragged ? 0.35f : 1.0f);
+        }
+        if (list.empty() && simple)
+        {
+            g.setColour (colour::textDisabled);
+            g.setFont (font (type::small));
+            textcache::drawText (g, tr ("Click + to add a section"), playlist.headerWidth + 10, 0, 400, getHeight(), juce::Justification::centredLeft);
+        }
+        // a drag: where the section lands
+        if (drag == Drag::move && moved)
+            if (const auto index = sections::indexOfUid (list, dragUid); index >= 0)
+            {
+                const auto target = dropTarget();
+                const auto copy = copyDrag;
+                auto ghost = blockOf (list[(std::size_t) index]).withX ((float) (dragX - grabOffset));
+                paintBlock (g, list[(std::size_t) index], index, ghost, true, false, 0.75f);
+                g.setColour (copy ? colour::info : colour::accent);
+                if (target.onto >= 0)
+                    g.drawRoundedRectangle (blockOf (list[(std::size_t) target.onto]).reduced (0.5f), simple ? 6.0f : 2.0f, 2.0f);
+                else if (target.before >= 0)
+                {
+                    const auto x = (float) playlist.tickToX ((double) boundaryTick (target.before));
+                    g.fillRect (juce::Rectangle<float> (x - 1.0f, 0.0f, 2.0f, (float) getHeight()));
+                }
+            }
+        if (drag == Drag::resize)
+            if (const auto index = sections::indexOfUid (list, dragUid); index >= 0)
+            {
+                const auto x = (float) playlist.tickToX ((double) resizeEnd);
+                g.setColour (colour::accent);
+                g.fillRect (juce::Rectangle<float> (x - 1.0f, 0.0f, 2.0f, (float) getHeight()));
+            }
+    }
+
+    void paintBlock (juce::Graphics& g, const SongSection& s, int index, juce::Rectangle<float> r, bool isSelected, bool hovered, float alpha) const
+    {
+        using namespace theme;
+        // an own colour, else the layout's: GarageBand's greys in Simple (the selected marker light), FL's marker colour in Pattern
+        const auto own = index >= 0 && index < (int) engine.getSong().sections().size() && s.colour != 0;
+        const auto fill = own ? juce::Colour (s.colour)
+                              : simpleLook() ? (isSelected ? juce::Colour (0xffb7b8bd) : juce::Colour (0xff47494f)) : colour::warning;
+        const auto name = s.name.empty() ? tr ("Section") : juce::String::fromUTF8 (s.name.c_str());
+        if (simpleLook())
+        {
+            // GarageBand's Arrangement track (Apple's guide, "Add arrangement markers"): flat blocks the lane's height side by
+            // side, a dark line between two, the name centred; the selected one light grey
+            const auto body = fill.withMultipliedBrightness (hovered && ! isSelected ? 1.12f : 1.0f).brighter (own && isSelected ? 0.35f : 0.0f);
+            g.setColour (body.withMultipliedAlpha (alpha));
+            g.fillRect (r);
+            g.setColour (colour::bg0.withMultipliedAlpha (alpha));
+            g.fillRect (juce::Rectangle<float> (r.getX(), r.getY(), 1.0f, r.getHeight()));
+            g.setColour (ui::simplelook::inkOn (body).withMultipliedAlpha (alpha));
+            g.setFont (font (type::body, false));
+            textcache::drawText (g, name, r.reduced (8.0f, 0.0f), juce::Justification::centred, true);
+            if (hovered && r.getWidth() > 24.0f) // the right edge's grip
+            {
+                g.setColour (ui::simplelook::inkOn (fill).withAlpha (0.5f * alpha));
+                g.fillRoundedRectangle (juce::Rectangle<float> (r.getRight() - 5.0f, r.getCentreY() - 7.0f, 2.0f, 14.0f), 1.0f);
+            }
+            return;
+        }
+        // the Pattern layout: the Playlist's marker tag (ruler paint: a small flag with the name, a line at its place) in the
+        // section's colour, over the span tinted with it
+        g.setColour (fill.withAlpha ((isSelected ? 0.34f : hovered ? 0.26f : 0.18f) * alpha));
+        g.fillRect (r);
+        g.setColour (fill.withMultipliedAlpha (alpha));
+        g.fillRect (juce::Rectangle<float> (r.getX(), 0.0f, 1.0f, (float) getHeight()));
+        g.setFont (font (type::caption, true));
+        const auto width = juce::jmin (r.getWidth(), (float) juce::GlyphArrangement::getStringWidthInt (g.getCurrentFont(), name) + 8.0f);
+        const auto tag = juce::Rectangle<float> (r.getX(), (float) getHeight() - 13.0f, width, 11.0f);
+        g.fillRoundedRectangle (tag, 2.0f);
+        g.setColour (colour::bg0.withMultipliedAlpha (alpha));
+        textcache::drawText (g, name, tag.reduced (3.0f, 0.0f), juce::Justification::centredLeft, false);
+        if (isSelected)
+        {
+            g.setColour (colour::textPrimary.withMultipliedAlpha (alpha));
+            g.drawRect (r, 1.0f);
+        }
+    }
+
+    // --- dragging ------------------------------------------------------------------------------------------------------
+    struct Target
+    {
+        int before = -1; // insert before this section (size(): after the last)
+        int onto = -1;   // dropped onto this section (swap / replace)
+    };
+    std::int64_t boundaryTick (int before) const
+    {
+        const auto& list = engine.getSong().sections();
+        if (list.empty())
+            return 0;
+        return before < (int) list.size() ? list[(std::size_t) before].start : list.back().end();
+    }
+    Target dropTarget() const
+    {
+        Target t;
+        const auto& list = engine.getSong().sections();
+        const auto index = sections::indexOfUid (list, dragUid);
+        if (index < 0)
+            return t;
+        const auto tick = playlist.xToTick (dragX);
+        if (const auto over = sections::indexAt (list, (std::int64_t) tick); over >= 0 && over != index)
+        {
+            const auto& s = list[(std::size_t) over];
+            const auto quarter = (double) s.length / 4.0;
+            if (tick >= (double) s.start + quarter && tick <= (double) s.end() - quarter)
+            {
+                t.onto = over;
+                return t;
+            }
+        }
+        // the nearest section edge
+        double best = 1.0e300;
+        for (int k = 0; k <= (int) list.size(); ++k)
+            if (const auto d = std::abs ((double) boundaryTick (k) - tick); d < best)
+            {
+                best = d;
+                t.before = k;
+            }
+        if (! copyDrag && (t.before == index || t.before == index + 1))
+            t.before = -1; // (where it is already)
+        return t;
+    }
+
+    static bool copyModifier (const juce::ModifierKeys& m)
+    {
+       #if JUCE_MAC
+        return m.isAltDown(); // (macOS: Option-drag, as GarageBand)
+       #else
+        return flmods::ctrl (m); // (FL's Ctrl role, ui/FlMods.h)
+       #endif
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override
+    {
+        const auto h = hitAt (e.getPosition());
+        drag = Drag::none;
+        moved = false;
+        if (flmods::popup (e.mods))
+        {
+            if (h.section >= 0)
+            {
+                select (h.section);
+                sectionMenu (h.section).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
+            }
+            else
+                laneMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMousePosition());
+            return;
+        }
+        if (h.part == Hit::add)
+        {
+            addSection();
+            return;
+        }
+        if (h.section < 0)
+        {
+            select (-1);
+            return;
+        }
+        select (h.section);
+        const auto& s = engine.getSong().sections()[(std::size_t) h.section];
+        dragUid = s.uid;
+        if (h.part == Hit::edge)
+        {
+            drag = Drag::resize;
+            resizeEnd = s.end();
+        }
+        else
+        {
+            drag = Drag::move;
+            dragX = e.x;
+            grabOffset = e.x - (int) blockOf (s).getX();
+        }
+    }
+
+    void mouseDrag (const juce::MouseEvent& e) override
+    {
+        if (drag == Drag::resize)
+        {
+            const auto index = sections::indexOfUid (engine.getSong().sections(), dragUid);
+            if (index < 0)
+                return;
+            const auto& s = engine.getSong().sections()[(std::size_t) index];
+            resizeEnd = std::max (sections::nearestBar (engine.getSong(), (std::int64_t) std::max (0.0, playlist.xToTick (e.x))),
+                                  sections::barsAfter (engine.getSong(), s.start, 1));
+            repaint();
+            return;
+        }
+        if (drag != Drag::move)
+            return;
+        moved = moved || e.getDistanceFromDragStart() > 3;
+        dragX = e.x;
+        copyDrag = copyModifier (e.mods);
+        replaceDrag = e.mods.isShiftDown();
+        repaint();
+    }
+
+    void mouseUp (const juce::MouseEvent& e) override
+    {
+        const auto was = drag;
+        drag = Drag::none;
+        const auto index = sections::indexOfUid (engine.getSong().sections(), dragUid);
+        if (was == Drag::resize && index >= 0)
+        {
+            engine.editSong ([index, end = resizeEnd] (Song& s) { sections::resize (s, index, end); });
+        }
+        else if (was == Drag::move && moved && index >= 0)
+        {
+            copyDrag = copyModifier (e.mods);
+            replaceDrag = e.mods.isShiftDown();
+            const auto target = dropTarget();
+            const auto copy = copyDrag, replace = replaceDrag;
+            if (target.onto >= 0)
+                engine.editSong ([index, onto = target.onto, replace, copy] (Song& s) {
+                    if (replace || copy)
+                        sections::replace (s, index, onto);
+                    else
+                        sections::swap (s, index, onto);
+                });
+            else if (target.before >= 0)
+                engine.editSong ([index, before = target.before, copy] (Song& s) {
+                    if (copy)
+                        sections::copy (s, index, before);
+                    else
+                        sections::move (s, index, before);
+                });
+            playlist.setSelection ({});
+            playlist.sortClips();
+        }
+        moved = false;
+        playlist.repaint();
+    }
+
+    void mouseDoubleClick (const juce::MouseEvent& e) override
+    {
+        const auto h = hitAt (e.getPosition());
+        if (h.section >= 0)
+            rename (h.section);
+        else if (h.part == Hit::lane)
+            addSection();
+    }
+
+    void mouseMove (const juce::MouseEvent& e) override
+    {
+        const auto h = hitAt (e.getPosition());
+        if (h.section != hover.section || h.part != hover.part)
+        {
+            hover = h;
+            setMouseCursor (h.part == Hit::edge ? juce::MouseCursor::LeftRightResizeCursor : juce::MouseCursor::NormalCursor);
+            repaint();
+        }
+    }
+    void mouseExit (const juce::MouseEvent&) override
+    {
+        hover = {};
+        repaint();
+    }
+    void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
+    {
+        playlist.mouseWheelMove (e.getEventRelativeTo (&playlist), wheel); // (time scroll and zoom: the Playlist's)
+    }
+
+    bool keyPressed (const juce::KeyPress& key) override
+    {
+        const auto index = selected();
+        if (index < 0)
+            return false;
+        if (key == juce::KeyPress::deleteKey || key == juce::KeyPress::backspaceKey)
+        {
+            // GarageBand: Delete empties the section; Delete again removes it and closes the gap
+            const auto empty = sections::clipsIn (engine.getSong(), index).empty();
+            engine.editSong ([index, empty] (Song& s) {
+                if (empty)
+                    sections::remove (s, index, true);
+                else
+                    sections::clear (s, index);
+            });
+            playlist.setSelection ({});
+            if (empty)
+                select (-1);
+            playlist.repaint();
+            return true;
+        }
+        if (key == juce::KeyPress::F2Key)
+        {
+            rename (index);
+            return true;
+        }
+        return false;
+    }
+
+    // --- commands ------------------------------------------------------------------------------------------------------
+    void addSection()
+    {
+        engine.editSong ([name = nextSectionName (engine.getSong().sections())] (Song& s) { sections::add (s, name); });
+        select ((int) engine.getSong().sections().size() - 1);
+        playlist.sectionsLaneChanged();
+    }
+
+    void rename (int index)
+    {
+        const auto& list = engine.getSong().sections();
+        if (index < 0 || index >= (int) list.size())
+            return;
+        auto* window = new juce::AlertWindow (tr ("Rename section"), {}, juce::MessageBoxIconType::NoIcon, this);
+        window->addTextEditor ("name", juce::String::fromUTF8 (list[(std::size_t) index].name.c_str()));
+        window->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
+        window->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
+        window->enterModalState (true, juce::ModalCallbackFunction::create ([this, uid = list[(std::size_t) index].uid, window] (int result) {
+                                     if (result != 1)
+                                         return;
+                                     const auto name = window->getTextEditorContents ("name").trim().toStdString();
+                                     setName (uid, name);
+                                 }),
+                                 true);
+    }
+
+    void setName (std::uint64_t uid, const std::string& name)
+    {
+        engine.editSong ([uid, name] (Song& s) {
+            if (const auto i = sections::indexOfUid (s.sections(), uid); i >= 0)
+                s.sections()[(std::size_t) i].name = name;
+        });
+        repaint();
+    }
+
+    juce::PopupMenu sectionMenu (int index)
+    {
+        juce::PopupMenu menu;
+        const auto& list = engine.getSong().sections();
+        if (index < 0 || index >= (int) list.size())
+            return menu;
+        const auto& s = list[(std::size_t) index];
+        const auto uid = s.uid;
+        menu.addSectionHeader (s.name.empty() ? tr ("Section") : juce::String::fromUTF8 (s.name.c_str()));
+        {
+            // GarageBand's name menu: its names, then Rename
+            juce::PopupMenu names;
+            for (int i = 0; i < (int) std::size (sections::presetNames); ++i)
+            {
+                const auto name = sectionPresetName (i);
+                names.addItem (name, true, juce::String::fromUTF8 (s.name.c_str()) == name, [this, uid, n = name.toStdString()] { setName (uid, n); });
+            }
+            names.addSeparator();
+            names.addItem (tr ("Rename..."), [this, index] { rename (index); });
+            menu.addSubMenu (tr ("Name"), names);
+        }
+        menu.addItem (tr ("Rename...") + "\tF2", [this, index] { rename (index); });
+        menu.addSubMenu (tr ("Change color"),
+                         ui::colourMenu (s.colour, [this, uid] (std::uint32_t c) {
+                             engine.editSong ([uid, c] (Song& song) {
+                                 if (const auto i = sections::indexOfUid (song.sections(), uid); i >= 0)
+                                     song.sections()[(std::size_t) i].colour = c;
+                             });
+                             repaint();
+                         },
+                                         juce::Rectangle<int> (juce::Desktop::getMousePosition(), juce::Desktop::getMousePosition()).withSizeKeepingCentre (1, 1)));
+        menu.addSeparator();
+        menu.addItem (tr ("Duplicate"), [this, index] {
+            engine.editSong ([index] (Song& song) { sections::duplicate (song, index); });
+            playlist.sortClips();
+            playlist.repaint();
+        });
+        const auto hasClips = ! sections::clipsIn (engine.getSong(), index).empty();
+        menu.addItem (tr ("Delete its clips") + "\tDel", hasClips, false, [this, index] {
+            engine.editSong ([index] (Song& song) { sections::clear (song, index); });
+            playlist.setSelection ({});
+            playlist.repaint();
+        });
+        menu.addItem (tr ("Delete the section (keep its clips)"), [this, index] {
+            engine.editSong ([index] (Song& song) { sections::remove (song, index, false); });
+            select (-1);
+            playlist.sectionsLaneChanged();
+        });
+        menu.addItem (tr ("Delete and close the gap"), [this, index] {
+            engine.editSong ([index] (Song& song) { sections::remove (song, index, true); });
+            playlist.setSelection ({});
+            select (-1);
+            playlist.sectionsLaneChanged();
+        });
+        menu.addSeparator();
+        menu.addItem (tr ("Loop this section"), [this, from = s.start, to = s.end()] {
+            engine.editSong ([from, to] (Song& song) {
+                song.loopStart = from;
+                song.loopEnd = to;
+            }, false);
+            playlist.repaint();
+        });
+        menu.addItem (tr ("Select its clips"), [this, index] {
+            playlist.setSelection (sections::clipsIn (engine.getSong(), index));
+            playlist.repaint();
+        });
+        return menu;
+    }
+
+    juce::PopupMenu laneMenu()
+    {
+        juce::PopupMenu menu;
+        const auto& song = engine.getSong();
+        menu.addItem (tr ("Add a section at the end"), [this] { addSection(); });
+        const auto plainMarkers = std::any_of (song.markers().begin(), song.markers().end(), [] (const Marker& m) { return sections::isPlainMarker (m); });
+        menu.addItem (tr ("Sections from markers"), plainMarkers, false, [this] {
+            engine.editSong ([] (Song& s) { sections::fromMarkers (s); });
+            playlist.sectionsLaneChanged();
+        });
+        menu.addItem (tr ("Markers from sections"), ! song.sections().empty(), false, [this] {
+            engine.editSong ([] (Song& s) { sections::toMarkers (s); });
+            playlist.repaint();
+        });
+        menu.addItem (tr ("Create scenes from sections"), ! song.sections().empty(), false, [this] {
+            engine.editSong ([] (Song& s) { sections::createScenes (s); });
+        });
+        menu.addSeparator();
+        if (simpleLook())
+            menu.addItem (tr ("Hide the Sections lane"), [this] { playlist.toggleSimpleSections(); });
+        else
+            menu.addItem (tr ("Sections lane") + " (LYNX)", true, true, [] { workflowextras::setExtra ("playlist.sectionsLane", false); });
+        return menu;
+    }
+
+    ui::Hint hintAt (juce::Point<int> p) override
+    {
+        const auto h = hitAt (p);
+        const auto& list = engine.getSong().sections();
+        if (h.part == Hit::add)
+            return { tr ("Add a section of eight bars at the end of the last one"), {} };
+        if (h.part == Hit::header)
+            return { tr ("Sections: named parts of the song. Drag one to move it with everything under it"), {}, false, true };
+        if (h.section >= 0 && h.section < (int) list.size())
+        {
+            const auto& s = list[(std::size_t) h.section];
+            const auto first = engine.getSong().barAt (s.start).number;
+            const auto bars = juce::String (first) + juce::String::fromUTF8 ("–") + juce::String (engine.getSong().barAt (std::max<std::int64_t> (0, s.end() - 1)).number);
+            if (h.part == Hit::edge)
+                return { tr ("Drag to resize the section (its clips stay where they are)"), bars };
+            return { tr ("[LMB] drag to move it with its clips, Ctrl+drag a copy, drop onto another section to swap, Shift: replace it  [2xLMB] rename  [Del] delete its clips, again the section  [RMB] menu"),
+                     juce::String::fromUTF8 (s.name.c_str()) + "  " + bars, false, true };
+        }
+        return { tr ("[2xLMB] add a section at the end  [RMB] menu"), {}, false, true };
+    }
+
+private:
+    struct CacheKey
+    {
+        std::vector<SongSection> sections;
+        std::uint64_t selected = 0;
+        int hoverSection = -1, hoverPart = 0;
+        double scrollTicks = 0.0, pixelsPerTick = 0.0;
+        int width = 0, height = 0, headerWidth = 0;
+        bool simple = false;
+        float scale = 1.0f;
+        juce::uint32 ground = 0, marker = 0;
+        bool operator== (const CacheKey&) const = default;
+    };
+    AudioEngine& engine;
+    PlaylistComponent& playlist;
+    CacheKey cacheKey;
+    juce::Image cache;
+    bool cacheValid = false;
+    enum class Drag { none, move, resize };
+    Drag drag = Drag::none;
+    std::uint64_t dragUid = 0, selectedUid = 0;
+    int dragX = 0, grabOffset = 0;
+    bool moved = false, copyDrag = false, replaceDrag = false;
+    std::int64_t resizeEnd = 0;
+    Hit hover;
+
+    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SectionsLaneView)
+};
+} // namespace lynx

+ 40 - 0
src/ui/SectionsLane190ol.inc

@@ -0,0 +1,40 @@
+// Round 190ol (research190oe P1): the Playlist's side of the Sections lane (ui/SectionsLane190ol.h). Included in
+// PlaylistComponent.cpp (namespace lynx).
+
+// --- the Playlist's side -----------------------------------------------------------------------------------------------
+bool PlaylistComponent::sectionsLaneShown() const
+{
+    if (simpleHeaders)
+        return ! engine.getSong().sections().empty() && ! simpleSectionsHidden;
+    if (liveStyle)
+        return false; // (owner decision O-1: off in the Clip-launch layout)
+    return sections::patternLaneOn();
+}
+
+int PlaylistComponent::sectionsLaneHeight() const
+{
+    return sectionsLaneShown() ? (simpleHeaders ? sectionsLaneSimpleHeight : sectionsLaneFlHeight) : 0;
+}
+
+void PlaylistComponent::toggleSimpleSections()
+{
+    if (engine.getSong().sections().empty())
+    {
+        // GarageBand's Show Arrangement Track then "+": the first section (Intro, eight bars) and the lane appears
+        simpleSectionsHidden = false;
+        engine.editSong ([name = nextSectionName (engine.getSong().sections())] (Song& s) { sections::add (s, name); });
+    }
+    else
+        simpleSectionsHidden = ! simpleSectionsHidden;
+    sectionsLaneChanged();
+}
+
+void PlaylistComponent::sectionsLaneChanged()
+{
+    if (sectionsLane == nullptr || videoLanes == nullptr || blocksView == nullptr)
+        return; // (not built yet)
+    if (sectionsLaneHeight() != laidOutSectionsHeight)
+        resized();
+    sectionsLane->repaint();
+    repaint();
+}

+ 20 - 4
src/ui/SimpleWorkflow.cpp

@@ -552,15 +552,18 @@ public:
 class SimpleTitleTools final : public juce::Component
 {
 public:
-    SimpleTitleTools (juce::Component& a, juce::Component& c, juce::Component& d, juce::Component& e) : add (a), lyrics (c), automation (d), loops (e)
+    SimpleTitleTools (juce::Component& a, juce::Component& c, juce::Component& d, juce::Component& e, juce::Component& f)
+        : add (a), lyrics (c), automation (d), loops (e), sections (f)
     {
         addAndMakeVisible (add);
         addAndMakeVisible (automation);
         addAndMakeVisible (lyrics);
+        addAndMakeVisible (sections);
         addAndMakeVisible (loops);
     }
-    static constexpr int automationWidth = 96;
-    static constexpr int width = 110 + 6 + automationWidth + 6 + 80 + 6 + 80 + 10; // (round 190jr: + Automation; round 190lx: + Loops)
+    static constexpr int automationWidth = 96, sectionsWidth = 86;
+    // (round 190jr: + Automation; round 190lx: + Loops; round 190ol: + Sections)
+    static constexpr int width = 110 + 6 + automationWidth + 6 + 80 + 6 + sectionsWidth + 6 + 80 + 10;
     void resized() override
     {
         auto r = getLocalBounds();
@@ -570,6 +573,8 @@ public:
         r.removeFromLeft (6);
         lyrics.setBounds (r.removeFromLeft (80));
         r.removeFromLeft (6);
+        sections.setBounds (r.removeFromLeft (sectionsWidth)); // (round 190ol: GarageBand's Arrangement track, research190oe P1)
+        r.removeFromLeft (6);
         loops.setBounds (r.removeFromLeft (80)); // (round 190lx, DS-42: BandLab's Sounds button beside Lyrics / Notes)
     }
 
@@ -578,6 +583,7 @@ private:
     juce::Component& lyrics;
     juce::Component& automation;
     juce::Component& loops;
+    juce::Component& sections;
 };
 
 SimpleWorkflow::SimpleWorkflow (AudioEngine& e, Host h) : engine (e), host (std::move (h))
@@ -630,7 +636,17 @@ SimpleWorkflow::SimpleWorkflow (AudioEngine& e, Host h) : engine (e), host (std:
             host.setAutomation (b->getToggleState());
     };
     automationButton = std::move (automation);
-    titleTools = std::make_unique<SimpleTitleTools> (*addButton, *lyricsButton, *automationButton, *loopsButton);
+    // round 190ol (research190oe P1, owner decision O-1): the Sections lane — the first press adds the first section (the
+    // lane appears with it), later presses hide and show the lane
+    auto sectionsTool = std::make_unique<juce::TextButton> (tr ("Sections"));
+    sectionsTool->setComponentID ("simple.sections");
+    sectionsTool->setTooltip (tr ("Sections: name the parts of the song (Intro, Verse, Chorus...) and move or copy each with everything under it"));
+    sectionsTool->onClick = [this] {
+        if (host.toggleSections)
+            host.toggleSections();
+    };
+    sectionsButton = std::move (sectionsTool);
+    titleTools = std::make_unique<SimpleTitleTools> (*addButton, *lyricsButton, *automationButton, *loopsButton, *sectionsButton);
 
     // round 190dv: the Welcome screen and the first-song tour
     FirstSongTour::Host t;

+ 2 - 0
src/ui/SimpleWorkflow.h

@@ -32,6 +32,7 @@ public:
         std::function<void (juce::Component*, int)> setTitleAccessory; // the Playlist title bar's accessory (nullptr: none)
         std::function<void()> showLoops;                   // the sample browser, to drag loops onto the timeline
         std::function<void()> toggleLoops;                 // round 190lx (DS-42): the Loops dock shown / hidden
+        std::function<void()> toggleSections;              // round 190ol (P1): the Sections lane (adds the first section)
         // round 190ch: the Lyrics / Notes panel (the main window's, the same in every layout), Reference match, and a
         // new project from the "Start from" list
         std::function<void()> toggleLyrics;
@@ -188,6 +189,7 @@ private:
     std::unique_ptr<juce::Component> startFrom, lyricsButton; // round 190ch
     std::unique_ptr<juce::Component> automationButton;        // round 190jr
     std::unique_ptr<juce::Component> loopsButton;             // round 190lx (DS-42)
+    std::unique_ptr<juce::Component> sectionsButton;          // round 190ol (P1)
     std::unique_ptr<juce::Button> tunerButton;                // round 190ke
     juce::Component::SafePointer<juce::Component> tunerBox;   // the open tuner's call-out (null: closed)
     std::unique_ptr<Chooser> chooser;

+ 53 - 2
src/ui/Toolbar.cpp

@@ -7,6 +7,7 @@
 #include "core/Details190mv.h" // (round 190mv: Master pitch in Hz)
 #include "core/LayoutStyle.h"
 #include "core/MarkerPlan.h"
+#include "core/SignatureEdit.h"
 #include "core/Timecode.h"
 #include "core/TempoMap.h"
 #include "core/ValueMath.h" // (round 190mv: the phase nudge)
@@ -2632,6 +2633,8 @@ void SignatureBox::setLook (toolbarlayout::Look l)
 juce::String SignatureBox::text() const
 {
     const auto& song = engine.getSong();
+    if (look == toolbarlayout::Look::simple) // round 190ol (P6): the signature at the song's start (a change at bar 1 included)
+        return juce::String (signatureedit::text (signatureedit::atStart (song)));
     return juce::String (song.beatsPerBar) + " / " + juce::String (song.beatUnit);
 }
 
@@ -2639,7 +2642,8 @@ void SignatureBox::update()
 {
     // (the timer's check compares two numbers; the text is made only when they changed)
     const auto& song = engine.getSong();
-    if (const auto now = song.beatsPerBar * 1000 + song.beatUnit; now != shownSignature)
+    const auto start = look == toolbarlayout::Look::simple ? signatureedit::atStart (song) : std::pair { song.beatsPerBar, song.beatUnit };
+    if (const auto now = start.first * 1000 + start.second; now != shownSignature)
     {
         shownSignature = now;
         shown = text();
@@ -2664,9 +2668,11 @@ void SignatureBox::paint (juce::Graphics& g)
 
 juce::PopupMenu SignatureBox::makeMenu()
 {
-    // (the Pattern menu's "Song time signature" list)
     juce::PopupMenu menu;
     const auto& song = engine.getSong();
+    if (look == toolbarlayout::Look::simple)
+        return simpleMenu (true); // (the numerator's list; mouseDown picks the half that was clicked)
+    // (the Pattern menu's "Song time signature" list)
     for (int beats : { 2, 3, 4, 5, 6, 7, 8, 9, 12 })
         menu.addItem (juce::String (beats) + "/4", true, song.beatsPerBar == beats && song.beatUnit == 4, [this, beats] {
             engine.editSong ([beats] (Song& s) {
@@ -2678,14 +2684,59 @@ juce::PopupMenu SignatureBox::makeMenu()
     return menu;
 }
 
+// Round 190ol (P6, BandLab live check s/ANSWERS.md): BandLab's "4 / 4" is two controls — a click on the top number opens a
+// list of numerators (1-6), one on the bottom number a list of denominators (1, 2, 4, 8); the "/" does nothing. They set
+// the signature at the song's start (core/SignatureEdit.h: a change at bar 1 is updated instead). LYNX's own values follow
+// after a separator: numerators 7-16 and the denominator 16. Changes from a bar on are on the ruler's right-click.
+juce::PopupMenu SignatureBox::simpleMenu (bool numerator)
+{
+    juce::PopupMenu menu;
+    const auto now = signatureedit::atStart (engine.getSong());
+    const auto set = [this, numerator] (int value) {
+        engine.editSong ([numerator, value] (Song& s) {
+            const auto sig = signatureedit::atStart (s);
+            signatureedit::set (s, 0, numerator ? value : sig.first, numerator ? sig.second : value);
+        });
+        update();
+    };
+    if (numerator)
+    {
+        for (int n = 1; n <= signatureedit::maxNumerator; ++n)
+        {
+            if (n == signatureedit::bandlabMaxNumerator + 1)
+                menu.addSeparator();
+            menu.addItem (juce::String (n), true, now.first == n, [set, n] { set (n); });
+        }
+    }
+    else
+    {
+        for (const auto d : signatureedit::bandlabDenominators)
+            menu.addItem (juce::String (d), true, now.second == d, [set, d] { set (d); });
+        menu.addSeparator();
+        menu.addItem ("16", true, now.second == 16, [set] { set (16); });
+    }
+    return menu;
+}
+
 void SignatureBox::mouseDown (const juce::MouseEvent& e)
 {
+    if (look == toolbarlayout::Look::simple)
+    {
+        // the half under the pointer: the numerator left of the "/", the denominator right of it (a narrow middle: nothing)
+        const auto centre = getWidth() / 2;
+        if (std::abs (e.x - centre) <= 3)
+            return;
+        simpleMenu (e.x < centre).showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
+        return;
+    }
     if (e.mods.isLeftButtonDown() || e.mods.isPopupMenu())
         makeMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this));
 }
 
 ui::Hint SignatureBox::hintAt (juce::Point<int>)
 {
+    if (look == toolbarlayout::Look::simple) // (round 190ol, P6)
+        return { tr ("Song time signature at the start; right-click the timeline's ruler to change it from a bar on"), {}, false, true };
     return { tr ("Song time signature"), {}, false, true };
 }
 

+ 1 - 0
src/ui/Toolbar.h

@@ -449,6 +449,7 @@ public:
     void update();
     juce::String text() const;
     juce::PopupMenu makeMenu();
+    juce::PopupMenu simpleMenu (bool numerator); // round 190ol (P6): the Simple look's two BandLab lists
     void paint (juce::Graphics& g) override;
     void mouseDown (const juce::MouseEvent& e) override;
     void mouseEnter (const juce::MouseEvent&) override { repaint(); }

+ 9 - 1
src/ui/WorkflowExtras.cpp

@@ -1,6 +1,7 @@
 #include "ui/WorkflowExtras.h"
 #include "core/EscClose.h"
 #include "core/RulerGestures.h" // round 190nq (#227)
+#include "core/Sections.h"      // round 190ol (P1)
 
 #include "core/TrackClips.h"
 
@@ -91,6 +92,8 @@ bool readUiOption (const juce::String& key, bool on)
         trackclips::setShownInSelector (on);
     else if (key == "rulerSeeksAnyTool") // issue #227 (round 190nq, LYNX extra)
         ruler::seekWithAnyTool() = on;
+    else if (key == "sectionsLane") // round 190ol (P1): the Pattern layout's Sections lane
+        sections::patternLaneOn() = on;
     else
         return false;
     return true;
@@ -116,7 +119,8 @@ juce::String uiOptionsText()
            + "\nsimpleLoopDetect=" + juce::String (loopanalysis::dropDetects().load() ? 1 : 0) // (round 190kx)
            + "\nescClosesWindows=" + juce::String (escclose::enabled() ? 1 : 0) // (round 190ng, issue #217)
            + "\ntrackClipsShown=" + juce::String (trackclips::shownInSelector() ? 1 : 0) // (round 190ne)
-           + "\nrulerSeeksAnyTool=" + juce::String (ruler::seekWithAnyTool() ? 1 : 0); // (round 190nq, issue #227)
+           + "\nrulerSeeksAnyTool=" + juce::String (ruler::seekWithAnyTool() ? 1 : 0) // (round 190nq, issue #227)
+           + "\nsectionsLane=" + juce::String (sections::patternLaneOn() ? 1 : 0); // (round 190ol, P1)
 }
 
 std::optional<bool> extraOn (std::string_view id)
@@ -143,6 +147,8 @@ std::optional<bool> extraOn (std::string_view id)
         return escclose::enabled();
     if (id == "playlist.rulerSeeksAnyTool") // round 190nq (issue #227)
         return ruler::seekWithAnyTool();
+    if (id == "playlist.sectionsLane") // round 190ol (P1)
+        return sections::patternLaneOn();
     return std::nullopt;
 }
 
@@ -174,6 +180,8 @@ bool setExtra (std::string_view id, bool on)
         escclose::enabled() = on;
     else if (id == "playlist.rulerSeeksAnyTool") // round 190nq (issue #227)
         ruler::seekWithAnyTool() = on;
+    else if (id == "playlist.sectionsLane") // round 190ol (P1)
+        sections::patternLaneOn() = on;
     else
         return false;
     if (onChanged)

+ 1 - 1
tests/Extras190amTests.inc

@@ -21,7 +21,7 @@ TEST (extras190am_extras_list)
         CHECK (item.note.back() == '.'); // one line of explanation, a sentence
         CHECK (item.note.find ("Also ") != std::string_view::npos); // ... that names the switch's own place
     }
-    CHECK (count == 26); // (round 190nq: playlist.rulerSeeksAnyTool; round 190ng: general.escCloses; round 190lo: polyEdit.prepareOnOpen; round 190kx: simple.loopDetect; round 190gz: project.linkTracks; round 190ht: playlist.trackInserts; round 190io: mixer.stripInserts; round 190iu: wheel zones, temporary tools, MIDI drop, Track-only; round 190jq: header width, pointer click, clip lanes; round 190jz: transport.wToStart)
+    CHECK (count == 27); // (round 190ol: playlist.sectionsLane; round 190nq: playlist.rulerSeeksAnyTool; round 190ng: general.escCloses; round 190lo: polyEdit.prepareOnOpen; round 190kx: simple.loopDetect; round 190gz: project.linkTracks; round 190ht: playlist.trackInserts; round 190io: mixer.stripInserts; round 190iu: wheel zones, temporary tools, MIDI drop, Track-only; round 190jq: header width, pointer click, clip lanes; round 190jz: transport.wToStart)
     for (const auto* id : { "mixer.loudness", "mixer.usedOnly", "mixer.keepLostLinks", "mixer.followPlaylist", "playlist.automationLanes",
                             "pianoRoll.songBarsRuler", "general.hoverValues", "playlist.trackInserts", "mixer.stripInserts" })
         CHECK (ids.count (id) == 1);