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

Browser: ALL / PROJECT tabs, top-level folders with their own colours, Current project section (patterns, effects, generators, automation, audio files, history) with colours, details, hints, menus and drag (WIP)

Ka1-S 1 месяц назад
Родитель
Сommit
2fe6ef4eaa

+ 1 - 0
CMakeLists.txt

@@ -140,6 +140,7 @@ target_sources(lynx_core PRIVATE
     src/core/ExportOptions.cpp
     src/core/Mp3Encoder.cpp
     src/core/PluginMonitor.cpp
+    src/core/ProjectContents.cpp
     src/core/PlaylistOps.cpp)
 
 # LAME's libmp3lame (LGPL; third_party/lame, encoder only, configured by third_party/lame/src/config.h)

+ 1 - 1
scripts/build-local.sh

@@ -47,7 +47,7 @@ CORE="$CORE src/core/DirectWave.cpp"
 # Ogg Vorbis decoding as FL does (REA round 77)
 CORE="$CORE src/core/OggVorbis.cpp"
 # export options, MP3 encoding, plugin performance monitor, clip properties / arrangements (round 84)
-CORE="$CORE src/core/ExportOptions.cpp src/core/Mp3Encoder.cpp src/core/PluginMonitor.cpp src/core/PlaylistOps.cpp"
+CORE="$CORE src/core/ExportOptions.cpp src/core/Mp3Encoder.cpp src/core/PluginMonitor.cpp src/core/PlaylistOps.cpp src/core/ProjectContents.cpp"
 # LYNX's Facet EQ and Apex Limiter (round 99)
 CORE="$CORE src/core/FacetEq.cpp src/core/ApexLimiter.cpp"
 # LYNX's dynamics suite and FabFilter state translation (round 108)

+ 1 - 1
scripts/build-windows-zig.sh

@@ -120,7 +120,7 @@ APP_SOURCES+=(src/core/DirectWave.cpp)
 # Ogg Vorbis decoding as FL does (REA round 77)
 APP_SOURCES+=(src/core/OggVorbis.cpp)
 # export options + MP3, plugin performance monitor, clip properties / arrangements, new project, touch keyboard (round 84)
-APP_SOURCES+=(src/core/ExportOptions.cpp src/core/Mp3Encoder.cpp src/core/PluginMonitor.cpp src/core/PlaylistOps.cpp)
+APP_SOURCES+=(src/core/ExportOptions.cpp src/core/Mp3Encoder.cpp src/core/PluginMonitor.cpp src/core/PlaylistOps.cpp src/core/ProjectContents.cpp)
 APP_SOURCES+=(src/ui/NewProjectDialog.cpp src/ui/ClipProperties.cpp src/ui/PluginMonitorWindow.cpp src/ui/TouchKeyboard.cpp)
 # native plugin editors in FL's arrangement (round 93)
 APP_SOURCES+=(src/core/PluginLayout.cpp src/core/StateParams.cpp src/ui/PluginEditors.cpp)

+ 173 - 0
src/core/ProjectContents.cpp

@@ -0,0 +1,173 @@
+#include "core/ProjectContents.h"
+
+#include <algorithm>
+
+#include "core/Effects.h"
+#include "core/PluginSubstitutes.h"
+
+namespace lynx::projectcontents
+{
+bool playsSampleFile (InstrumentKind kind) noexcept
+{
+    return kind == InstrumentKind::sampler || kind == InstrumentKind::audioClip || kind == InstrumentKind::granulizer;
+}
+
+std::string insertName (const Song& song, int track)
+{
+    if (track >= 0 && track < (int) song.mixer.size() && ! song.mixer[(std::size_t) track].name.empty())
+        return song.mixer[(std::size_t) track].name;
+    return track == 0 ? std::string ("Master") : "Insert " + std::to_string (track);
+}
+
+std::string effectSlotName (const EffectSlot& slot)
+{
+    if (slot.kind == EffectKind::plugin)
+        return slot.plugin.name;
+    if (slot.isSubstitute())
+        return substituteOriginalName (slot);
+    return effectInfo (slot.kind).name;
+}
+
+std::vector<Item> patterns (const Song& song)
+{
+    std::vector<Item> list;
+    for (int p = 0; p < (int) song.patterns.size(); ++p)
+    {
+        Item item;
+        item.kind = Kind::pattern;
+        item.index = p;
+        item.name = song.patterns[(std::size_t) p].name;
+        if (item.name.empty())
+            item.name = "Pattern " + std::to_string (p + 1);
+        item.colour = song.patterns[(std::size_t) p].colour;
+        for (const auto& c : song.playlist)
+            if (c.kind == ClipKind::pattern && c.pattern == p)
+                ++item.uses;
+        list.push_back (std::move (item));
+    }
+    return list;
+}
+
+std::vector<Item> samples (const Song& song)
+{
+    std::vector<Item> list;
+
+    auto add = [&list] (const std::string& path, int channel, std::uint32_t colour) {
+        if (path.empty())
+            return;
+        auto it = std::find_if (list.begin(), list.end(), [&path] (const Item& i) { return i.path == path; });
+        if (it == list.end())
+        {
+            Item item;
+            item.kind = Kind::sample;
+            item.index = channel;
+            item.path = path;
+            const auto slash = path.find_last_of ("/\\");
+            item.name = slash == std::string::npos ? path : path.substr (slash + 1);
+            if (const auto dot = item.name.find_last_of ('.'); dot != std::string::npos && dot > 0)
+                item.name.erase (dot);
+            item.colour = colour;
+            list.push_back (std::move (item));
+            it = list.end() - 1;
+        }
+        else if (it->colour == 0)
+            it->colour = colour;
+        ++it->uses;
+    };
+
+    for (int c = 0; c < (int) song.channels.size(); ++c)
+    {
+        const auto& ch = song.channels[(std::size_t) c];
+        if (! playsSampleFile (ch.instrument))
+            continue;
+        if (ch.zones.empty())
+            add (ch.samplePath, c, ch.colour);
+        else
+            for (const auto& z : ch.zones)
+                add (z.path, c, ch.colour);
+    }
+
+    for (int t = 0; t < (int) song.mixer.size(); ++t)
+        for (const auto& slot : song.mixer[(std::size_t) t].effects)
+            add (slot.samplePath, -1, song.mixer[(std::size_t) t].colour);
+
+    // the detail: how many places play it
+    for (auto& item : list)
+        if (item.uses > 1)
+            item.detail = std::to_string (item.uses) + "x";
+    return list;
+}
+
+std::vector<Item> generators (const Song& song)
+{
+    std::vector<Item> list;
+    for (int c = 0; c < (int) song.channels.size(); ++c)
+    {
+        const auto& ch = song.channels[(std::size_t) c];
+        Item item;
+        item.kind = Kind::generator;
+        item.index = c;
+        item.name = ch.name.empty() ? "Channel " + std::to_string (c + 1) : ch.name;
+        item.plugin = ch.instrument == InstrumentKind::plugin;
+        if (ch.mixerTrack > 0 && ch.mixerTrack < (int) song.mixer.size())
+            item.detail = insertName (song, ch.mixerTrack);
+        item.colour = ch.colour;
+        if (playsSampleFile (ch.instrument))
+            item.path = ch.samplePath;
+        list.push_back (std::move (item));
+    }
+    return list;
+}
+
+std::vector<Item> effects (const Song& song)
+{
+    std::vector<Item> list;
+    for (int t = 0; t < (int) song.mixer.size(); ++t)
+    {
+        const auto& track = song.mixer[(std::size_t) t];
+        for (int s = 0; s < (int) track.effects.size(); ++s)
+        {
+            Item item;
+            item.kind = Kind::effect;
+            item.index = t;
+            item.slot = s;
+            item.name = effectSlotName (track.effects[(std::size_t) s]);
+            item.detail = insertName (song, t);
+            item.colour = track.colour;
+            item.plugin = track.effects[(std::size_t) s].kind == EffectKind::plugin;
+            list.push_back (std::move (item));
+        }
+    }
+    return list;
+}
+
+std::vector<Item> automations (const Song& song)
+{
+    std::vector<Item> list;
+    for (int a = 0; a < (int) song.automations.size(); ++a)
+    {
+        const auto& automation = song.automations[(std::size_t) a];
+        Item item;
+        item.kind = Kind::automation;
+        item.index = a;
+        item.name = automation.name.empty() ? "Automation " + std::to_string (a + 1) : automation.name;
+        for (const auto& c : song.playlist)
+            if (c.kind == ClipKind::automation && c.automation == a)
+                ++item.uses;
+        // the colour of what it moves: a channel's or an insert's
+        const auto& t = automation.target;
+        if ((t.kind == AutomationTargetKind::channelVolume || t.kind == AutomationTargetKind::channelPan
+             || t.kind == AutomationTargetKind::channelParam)
+            && t.index >= 0 && t.index < (int) song.channels.size())
+            item.colour = song.channels[(std::size_t) t.index].colour;
+        else if ((t.kind == AutomationTargetKind::mixerVolume || t.kind == AutomationTargetKind::mixerPan
+                  || t.kind == AutomationTargetKind::effectParam || t.kind == AutomationTargetKind::effectMix)
+                 && t.index >= 0 && t.index < (int) song.mixer.size())
+            item.colour = song.mixer[(std::size_t) t.index].colour;
+        if (automation.isLive())
+            item.detail = "live";
+        list.push_back (std::move (item));
+    }
+    return list;
+}
+} // namespace lynx::projectcontents

+ 54 - 0
src/core/ProjectContents.h

@@ -0,0 +1,54 @@
+#pragma once
+
+// What the Browser's "Current project" section lists (FL's Browser > Project, interpreted; REA_rodada115): the
+// patterns, the audio files the project uses, the generators (channels), the effects of every insert and the
+// automation clips, each with the colour of what it belongs to and a short detail. No JUCE, no file access.
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+#include "core/Song.h"
+
+namespace lynx::projectcontents
+{
+enum class Kind
+{
+    pattern,
+    sample,
+    generator,
+    effect,
+    automation
+};
+
+struct Item
+{
+    Kind kind = Kind::pattern;
+    int index = -1;  // pattern / channel / insert / automation index; samples: the first channel that uses the file
+    int slot = -1;   // effects: the slot in the insert
+    std::string name;
+    std::string detail;   // shown dimmed after the name: "(Kick)", the insert's name, "3 channels"...
+    std::string path;     // samples: the audio file
+    std::uint32_t colour = 0; // 0xFFRRGGBB of what the item belongs to; 0 = none (the UI picks one)
+    int uses = 0;         // samples: channels and effects that play the file; patterns: clips in the Playlist
+    bool plugin = false;  // generators / effects: a third-party plugin
+};
+
+// Does this instrument play `ChannelDef::samplePath` as audio (and not as the path of an engine file)?
+bool playsSampleFile (InstrumentKind kind) noexcept;
+
+std::vector<Item> patterns (const Song& song);
+// Every audio file used by a channel (sample, audio clip, sampler zones) or an effect (source sample), once, in the
+// order first used; `colour` and `index` come from the first channel using it.
+std::vector<Item> samples (const Song& song);
+// Channels: the instrument's name with the insert it plays into as the detail.
+std::vector<Item> generators (const Song& song);
+// Effect slots of every insert (Master first): the effect's name, the insert's name as the detail.
+std::vector<Item> effects (const Song& song);
+std::vector<Item> automations (const Song& song);
+
+// The name an effect slot shows (plugin name, the original plugin's for a LYNX substitute, else the built-in name).
+std::string effectSlotName (const EffectSlot& slot);
+// The insert's name ("Master", or "Insert N" when unnamed).
+std::string insertName (const Song& song, int track);
+} // namespace lynx::projectcontents

+ 83 - 1
src/core/ToolbarLayout.h

@@ -93,6 +93,8 @@ struct Layout
     std::vector<Entry> entries; // every group exactly once, in toolbar order
     IconSize iconSize = IconSize::medium;
     int uiScale = 100; // percent
+    bool separators = true; // hairlines between the panels (FL's "Separators")
+    bool visible = true;    // the whole toolbar (Ctrl+F11 hides it, as in FL)
 
     static Layout makeDefault()
     {
@@ -140,10 +142,31 @@ struct Layout
         return true;
     }
 
+    // Moves `g` so that it sits just before `before` (nullptr: at the end). Returns true if the order changed.
+    // Used by the toolbar's edit mode, where a panel is dropped between two others.
+    bool placeBefore (Group g, const Group* before)
+    {
+        const auto from = indexOf (g);
+        if (from < 0 || (before != nullptr && *before == g))
+            return false;
+        const auto old = entries;
+        const auto e = entries[(std::size_t) from];
+        entries.erase (entries.begin() + from);
+        auto to = before != nullptr ? indexOf (*before) : -1;
+        if (to < 0)
+            entries.push_back (e);
+        else
+            entries.insert (entries.begin() + to, e);
+        for (std::size_t i = 0; i < entries.size(); ++i)
+            if (entries[i].group != old[i].group)
+                return true;
+        return false;
+    }
+
     bool isDefault() const
     {
         const auto d = makeDefault();
-        if (iconSize != d.iconSize || uiScale != d.uiScale)
+        if (iconSize != d.iconSize || uiScale != d.uiScale || separators != d.separators || visible != d.visible)
             return false;
         for (std::size_t i = 0; i < entries.size(); ++i)
             if (entries[i].group != d.entries[i].group || ! entries[i].shown)
@@ -226,6 +249,65 @@ struct Layout
     }
 };
 
+// Where a panel dragged in the toolbar's edit mode lands: `shown` lists the panels on the toolbar, left to right,
+// with the x of their centres; the dragged panel goes before the first other panel whose centre is right of `x`
+// (none: at the end). Returns that panel, or groupCount for "at the end".
+inline int dropBefore (const std::vector<std::pair<Group, int>>& shown, Group dragged, int x)
+{
+    for (const auto& [group, centre] : shown)
+        if (group != dragged && centre > x)
+            return (int) group;
+    return groupCount;
+}
+
+// Ready-made layouts (LYNX's own, like FL's toolbar presets): which groups show, in the default order.
+enum class Preset
+{
+    standard, // every group
+    compact,  // transport, master, snap and pattern, windows
+    minimal,  // transport and windows
+    mixing,   // transport, master, windows, meters, output
+    count_
+};
+
+constexpr int presetCount = (int) Preset::count_;
+
+inline const char* presetName (Preset p)
+{
+    static constexpr std::array<const char*, presetCount> names { TR_NOOP ("Default (everything)"), TR_NOOP ("Compact"),
+                                                                  TR_NOOP ("Minimal"), TR_NOOP ("Mixing") };
+    return names[(std::size_t) p];
+}
+
+// The preset applied to `from` (icon size, UI scale and the other options are kept).
+inline Layout applyPreset (Layout from, Preset p)
+{
+    const auto d = Layout::makeDefault();
+    from.entries = d.entries;
+    auto show = [&from] (std::initializer_list<Group> groups) {
+        for (auto& e : from.entries)
+            e.shown = std::find (groups.begin(), groups.end(), e.group) != groups.end();
+    };
+    switch (p)
+    {
+        case Preset::compact: show ({ Group::transport, Group::master, Group::snap, Group::windows }); break;
+        case Preset::minimal: show ({ Group::transport, Group::windows }); break;
+        case Preset::mixing: show ({ Group::transport, Group::master, Group::windows, Group::meters, Group::output }); break;
+        case Preset::standard:
+        case Preset::count_: break;
+    }
+    return from;
+}
+
+// The preset the layout's groups match, or presetCount (a custom layout).
+inline int matchingPreset (const Layout& l)
+{
+    for (int p = 0; p < presetCount; ++p)
+        if (applyPreset (l, (Preset) p).orderToString() == l.orderToString())
+            return p;
+    return presetCount;
+}
+
 // Decides which groups are visible for `room` px: every shown group needs widths[group] (+ `gap`); while
 // they don't fit with `minFlexible` px left for the hint column, the shown group with the lowest priority
 // (never the transport) is dropped. Returns visibility per group.

Разница между файлами не показана из-за своего большого размера
+ 759 - 51
src/ui/BrowserComponent.cpp


+ 47 - 10
src/ui/BrowserComponent.h

@@ -6,21 +6,27 @@
 
 namespace lynx
 {
-// File browser (like FL's Browser): FL and user sample folders, drawn by LYNX itself so it can show
-// what the mouse is over and explain it in the hint bar.
+// File browser (like FL's Browser): drawn by LYNX itself so it can show what the mouse is over and explain it
+// in the hint bar.
+//  - two tabs, as FL's Browser: ALL (the current project, then every sample folder: FL's folders, Documents,
+//    Music, Desktop, Downloads and the user's folders, each with its own colour) and PROJECT (only the current
+//    project, opened)
+//  - "Current project" (REA_rodada115): history, patterns, effects, generators, automation, the project folder
+//    and the audio files the project uses, each item in the colour of what it belongs to, with a short detail
+//    (the insert, how often it is used, "missing"); click / double-click / drag / right-click act on it
 //  - a click on a folder opens / closes it; a click on an audio file previews it (the strip at the bottom
 //    shows its waveform and the playback position); double-click: new sampler channel with it
 //  - drag a file onto the Channel Rack (new channel, or onto a row: replaces its sample), the Playlist (audio
-//    clip where it is dropped) or a mixer insert (effect presets)
+//    clip where it is dropped) or a mixer insert (effect presets); drag a pattern onto the Playlist (a clip)
 //  - double-click a .lynx/.flp/.mid: opens it (onOpenProject)
-//  - search box (Ctrl+F): searches the current folder and below (core/SearchQuery syntax); Esc clears
+//  - search box (Ctrl+F): ALL searches the folder of the selection (or every folder) and below
+//    (core/SearchQuery syntax); PROJECT filters the project's items; Esc clears
 //  - keys while the Browser has focus: Up/Down step and preview, Shift+Up/Down step and load each file
 //    into the selected channel, Enter loads the selected file into the selected channel, Left/Right
 //    close / open folders
-//  - right-click: folder menu (collapse all, open in the file manager, add folder)
-//  - the folder list has "Add folder..." for user folders (kept in the user settings)
 class BrowserComponent final : public juce::Component,
                                private juce::TextEditor::Listener,
+                               private juce::ChangeListener,
                                private juce::Timer
 {
 public:
@@ -30,6 +36,26 @@ public:
     std::function<void (const juce::File&)> onOpenProject;
     // Enter / Shift+Up/Down: put this file into the selected channel; returns false if it can't take it.
     std::function<bool (const juce::File&)> onLoadIntoChannel;
+    // Current project items (set by the main window)
+    std::function<void (int)> onOpenPattern;     // double-click a pattern: it opens in the Piano Roll
+    std::function<void (int)> onPatternMenu;     // right-click a pattern (already selected): the pattern menu
+    std::function<void (int)> onOpenChannel;     // double-click a generator: its settings / plugin window
+    std::function<void (int, int)> onOpenEffect; // double-click an effect (insert, slot): its editor
+    std::function<void (int)> onShowInsert;      // an effect's / generator's insert in the Mixer
+    std::function<void (int)> onOpenAutomation;  // double-click an automation clip: its editor
+    std::function<void (const juce::File&)> onSendToPlaylist; // a sample's "Send to the Playlist as an audio clip"
+
+    // The project's file (.lynx, or the imported .flp): its folder shows as "Project folder".
+    void setProjectFile (const juce::File& file);
+
+    enum Tab
+    {
+        allTab,
+        projectTab,
+        tabCount
+    };
+    void setTab (int tab);
+    int getTab() const noexcept { return tab; }
 
     void focusSearch();
     void addUserFolder(); // asks for a folder and adds it to the folder list
@@ -38,6 +64,8 @@ public:
     // For snapshots: selects (and "previews" without sound) the first audio file under the first folder,
     // and puts the mouse over the row after it.
     void selectFirstSampleForSnapshot();
+    // --snapshot: the PROJECT tab with the patterns, generators and samples open, a sample selected
+    void showProjectForSnapshot();
     // --snapshot: shows this audio file in the preview strip (without playing it)
     void showPreviewForSnapshot (const juce::File& file);
     // Up/Down (load = false) or Shift+Up/Down (load = true); Enter = loadSelected()
@@ -50,6 +78,8 @@ public:
     // Drags from the Browser (tree or search results): is it one, and which file it carries.
     static bool isBrowserDrag (const juce::DragAndDropTarget::SourceDetails& details);
     static juce::File draggedFile (const juce::DragAndDropTarget::SourceDetails& details);
+    // A pattern dragged from "Current project > Patterns": its index, else -1.
+    static int draggedPattern (const juce::DragAndDropTarget::SourceDetails& details);
     static bool isAudioFile (const juce::File& file);
 
     void resized() override;
@@ -59,40 +89,47 @@ public:
     void paint (juce::Graphics& g) override;
 
     static constexpr const char* dragDescription = "lynx-arquivo";
+    static constexpr const char* patternDragDescription = "lynx-pattern";
     static constexpr int addFolderId = 1000;
 
-    class FileTree;    // the folder tree / search results (implementation detail)
+    class FileTree;     // the folder tree / search results (implementation detail)
     class PreviewStrip; // waveform of the selected sample
+    class TabBar;       // ALL / PROJECT
 
 private:
-    void setRoot (int index);
     void textEditorTextChanged (juce::TextEditor&) override;
     void textEditorEscapeKeyPressed (juce::TextEditor&) override;
     void textEditorReturnKeyPressed (juce::TextEditor&) override;
+    void changeListenerCallback (juce::ChangeBroadcaster*) override;
     void timerCallback() override;
     void runSearch();
     void rebuildRoots();
+    void rebuildTree();
     static juce::File userFoldersFile();
     void openFile (const juce::File& file); // what a double-click does
     void fileSelected (const juce::File& file, bool preview);
     void showFolderMenu (const juce::File& folder);
     void showFileMenu (const juce::File& file);
     FileTree& activeList() const;
+    juce::Array<juce::File> searchRoots() const;
     juce::File previewedFile; // the sample last sent to the preview player
     bool isPreviewPlaying() const;
 
     std::unique_ptr<FileTree> tree, results;
     std::unique_ptr<juce::Viewport> treeView, resultsView;
     std::unique_ptr<PreviewStrip> strip;
+    std::unique_ptr<TabBar> tabs;
     class SearchJob;
     std::unique_ptr<SearchJob> job;
     juce::TextEditor searchBox;
     std::unique_ptr<juce::FileChooser> chooser;
-    int currentRoot = 0;
+    int tab = allTab;
+    bool searchPending = false, projectDirty = false;
+    juce::File projectFile;
 
     AudioEngine& engine;
-    juce::ComboBox rootBox;
     juce::Array<juce::File> roots;
+    juce::StringArray rootNames;
 
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BrowserComponent)
 };

+ 35 - 0
src/ui/MainComponent.cpp

@@ -87,6 +87,32 @@ MainComponent::MainComponent (AudioEngine& e, bool restoreUserSettings)
     heldKeys.setSender ([this] (int channel, int key, float velocity, bool on) { engine.sendLiveNote (channel, key, velocity, on, true); });
     browser.onOpenProject = [this] (const juce::File& file) { confirmDiscard ([this, file] { openFile (file); }); };
     browser.onLoadIntoChannel = [this] (const juce::File& file) { return rack.loadSampleIntoSelected (file); };
+    // the Browser's "Current project" items (REA_rodada115)
+    browser.onOpenPattern = [this] (int pattern) {
+        selectPattern (pattern);
+        openPianoRoll();
+    };
+    browser.onPatternMenu = [this] (int pattern) {
+        selectPattern (pattern);
+        makePatternMenu().showMenuAsync (juce::PopupMenu::Options().withMousePosition());
+    };
+    browser.onOpenChannel = [this] (int channel) {
+        engine.setSelectedChannel (channel);
+        rack.toggleEditor (channel, true);
+    };
+    browser.onOpenEffect = [this] (int track, int slot) {
+        showPanel (Panel::mixer);
+        mixer.openSlotEditor (track, slot);
+    };
+    browser.onShowInsert = [this] (int track) {
+        showPanel (Panel::mixer);
+        mixer.selectTrack (track);
+    };
+    browser.onOpenAutomation = [this] (int automation) { openAutomationEditor (engine, automation); };
+    browser.onSendToPlaylist = [this] (const juce::File& file) {
+        playlist.addAudioClipAtPlayhead (file);
+        showPanel (Panel::playlist);
+    };
     if (persistent)
     {
         loadUiSettings();
@@ -980,6 +1006,10 @@ void MainComponent::loadUiSettings()
             toolbarLayout.orderFromString (line.fromFirstOccurrenceOf ("=", false, false).trim().toStdString());
         else if (key == "toolbarIcons")
             toolbarLayout.iconSize = toolbarlayout::Layout::iconSizeFromString (line.fromFirstOccurrenceOf ("=", false, false).trim().toStdString());
+        else if (key == "toolbarSeparators")
+            toolbarLayout.separators = on;
+        else if (key == "toolbarVisible")
+            toolbarLayout.visible = on;
         else if (key == "uiScale")
             toolbarLayout.uiScale = toolbarlayout::clampScale (line.fromFirstOccurrenceOf ("=", false, false).trim().getIntValue());
         else if (key == "editPatternsIn")
@@ -1017,6 +1047,8 @@ void MainComponent::saveUiSettings()
                                       + "\ntoolbarGroups=" + juce::String (toolbarLayout.orderToString())
                                       + "\ntoolbarIcons=" + toolbarlayout::Layout::iconSizeId (toolbarLayout.iconSize)
                                       + "\nuiScale=" + juce::String (toolbarLayout.uiScale)
+                                      + "\ntoolbarSeparators=" + juce::String (toolbarLayout.separators ? 1 : 0)
+                                      + "\ntoolbarVisible=" + juce::String (toolbarLayout.visible ? 1 : 0)
                                       + "\nautosaveMinutes=" + juce::String (autosaveMinutes) + "\nautosaveKeep=" + juce::String (autosaveKeep)
                                       + "\nundoLevels=" + juce::String (engine.getUndoLevels())
                                       + "\naskWhatToRecord=" + juce::String (engine.getRecordOptions().askWhatToRecord ? 1 : 0)
@@ -2060,6 +2092,9 @@ void MainComponent::timerCallback()
         updateTitle();
     }
 
+    // the Browser's "Project folder" follows the project's file (.lynx, or the .flp it was imported from)
+    browser.setProjectFile (currentFile != juce::File() ? currentFile : importedFlpFile);
+
     // a backup copy every few minutes (Settings › General) when there are changes
     if (autosaveMinutes > 0 && ++autosaveTicks >= 30 * 60 * autosaveMinutes)
     {

+ 8 - 0
src/ui/MixerComponent.h

@@ -171,6 +171,7 @@ public:
         selectedSlot = slot;
         repaint();
     }
+    void openSlotEditor (int slot) { openEditor (slot); }
 
     void paint (juce::Graphics& g) override;
     void mouseDown (const juce::MouseEvent& e) override;
@@ -270,6 +271,13 @@ public:
     void selectFirstTrackWithEffects();
     void selectTrack (int track); // also scrolls the strip into view
     void selectSlot (int slot) { effects.selectSlot (slot); }
+    // Selects the insert and slot and opens the effect's editor (the Browser's "Current project > Effects")
+    void openSlotEditor (int track, int slot)
+    {
+        selectTrack (track);
+        effects.selectSlot (slot);
+        effects.openSlotEditor (slot);
+    }
 
     // The key map's mixer.* actions.
     bool runAction (const std::string& id);

+ 81 - 29
src/ui/PlaylistComponent.cpp

@@ -3526,49 +3526,83 @@ bool PlaylistComponent::isInterestedInFileDrag (const juce::StringArray& files)
     return false;
 }
 
-void PlaylistComponent::filesDropped (const juce::StringArray& files, int x, int y)
+namespace
 {
-    auto start = juce::jmax<std::int64_t> (0, snap (xToTick (x), true));
-    auto track = yToTrack (y);
-
-    for (const auto& f : files)
-    {
-        const juce::File file (f);
+// An audio clip of `file` at `start` on `track` (one undo step); `reuse`: an existing audio-clip channel of the same
+// file plays it instead of a new one. False when the file can't be read.
+bool addAudioClip (AudioEngine& engine, const juce::File& file, std::int64_t start, int track, bool reuse)
+{
+    if (! file.hasFileExtension ("wav;aif;aiff;flac;ogg;mp3;wv"))
+        return false;
 
-        if (! file.hasFileExtension ("wav;aif;aiff;flac;ogg;mp3"))
-            continue;
+    const auto data = engine.getSampleLibrary().load (file.getFullPathName());
 
-        const auto data = engine.getSampleLibrary().load (file.getFullPathName());
+    if (data == nullptr)
+        return false;
 
-        if (data == nullptr)
-            continue;
+    // audio length converted to ticks at the current BPM
+    const auto seconds = (double) data->frames() / data->sampleRate;
+    const auto length = juce::jmax<std::int64_t> (ppq / 4, (std::int64_t) (seconds * engine.getSong().bpm / 60.0 * ppq));
+    const auto path = file.getFullPathName().toStdString();
+    const auto name = file.getFileNameWithoutExtension().toStdString();
 
-        // audio length converted to ticks at the current BPM
-        const auto seconds = (double) data->frames() / data->sampleRate;
-        const auto length = juce::jmax<std::int64_t> (ppq / 4, (std::int64_t) (seconds * engine.getSong().bpm / 60.0 * ppq));
-        const auto path = file.getFullPathName().toStdString();
-        const auto name = file.getFileNameWithoutExtension().toStdString();
+    engine.editSong ([=] (Song& s) {
+        int channel = -1;
+        if (reuse)
+            for (int c = 0; c < (int) s.channels.size(); ++c)
+                if (s.channels[(std::size_t) c].instrument == InstrumentKind::audioClip && s.channels[(std::size_t) c].samplePath == path)
+                    channel = c;
 
-        engine.editSong ([=] (Song& s) {
+        if (channel < 0)
+        {
             ChannelDef c;
             c.name = name;
             c.instrument = InstrumentKind::audioClip;
             c.samplePath = path;
             c.mixerTrack = s.nextFreeInsert();
             s.channels.push_back (c);
+            channel = (int) s.channels.size() - 1;
+        }
 
-            Clip clip;
-            clip.kind = ClipKind::audio;
-            clip.channel = (int) s.channels.size() - 1;
-            clip.track = track;
-            clip.start = start;
-            clip.length = length;
-            s.playlist.push_back (clip);
-            s.mode = PlayMode::song;
-        });
+        Clip clip;
+        clip.kind = ClipKind::audio;
+        clip.channel = channel;
+        clip.track = track;
+        clip.start = start;
+        clip.length = length;
+        s.playlist.push_back (clip);
+        s.mode = PlayMode::song;
+    });
+    return true;
+}
+} // namespace
+
+void PlaylistComponent::filesDropped (const juce::StringArray& files, int x, int y)
+{
+    auto start = juce::jmax<std::int64_t> (0, snap (xToTick (x), true));
+    auto track = yToTrack (y);
 
-        ++track; // multiple files: one below the other
+    for (const auto& f : files)
+        if (addAudioClip (engine, juce::File (f), start, track, false))
+            ++track; // multiple files: one below the other
+}
+
+void PlaylistComponent::addAudioClipAtPlayhead (const juce::File& file)
+{
+    const auto& song = engine.getSong();
+    const auto start = song.mode == PlayMode::song ? juce::jmax<std::int64_t> (0, snap ((std::int64_t) engine.getTransport().positionTicks.load(), false))
+                                                   : std::int64_t (0);
+    // the first track with nothing at the start
+    int track = 0;
+    for (;; ++track)
+    {
+        const auto busy = std::any_of (song.playlist.begin(), song.playlist.end(), [&] (const Clip& c) {
+            return c.track == track && c.start <= start && c.end() > start;
+        });
+        if (! busy)
+            break;
     }
+    addAudioClip (engine, file, start, track, true);
 }
 
 void PlaylistComponent::glideBy (double ticks, double pixels)
@@ -3746,11 +3780,29 @@ void PlaylistComponent::timerCallback()
 
 bool PlaylistComponent::isInterestedInDragSource (const SourceDetails& details)
 {
-    return BrowserComponent::isBrowserDrag (details);
+    return BrowserComponent::isBrowserDrag (details) || BrowserComponent::draggedPattern (details) >= 0;
 }
 
 void PlaylistComponent::itemDropped (const SourceDetails& details)
 {
+    // a pattern from the Browser's "Current project": a clip of it where it is dropped
+    if (const auto pattern = BrowserComponent::draggedPattern (details); pattern >= 0 && pattern < (int) engine.getSong().patterns.size())
+    {
+        const auto start = juce::jmax<std::int64_t> (0, snap (xToTick (details.localPosition.x), true));
+        const auto track = juce::jmax (0, yToTrack (details.localPosition.y));
+        engine.editSong ([=] (Song& s) {
+            Clip clip;
+            clip.kind = ClipKind::pattern;
+            clip.pattern = pattern;
+            clip.track = track;
+            clip.start = start;
+            clip.length = juce::jmax<std::int64_t> (ppq, s.patterns[(std::size_t) pattern].effectiveLength (s.beatsPerBar));
+            s.playlist.push_back (clip);
+            s.mode = PlayMode::song;
+        });
+        return;
+    }
+
     if (const auto file = BrowserComponent::draggedFile (details); file.existsAsFile())
         filesDropped ({ file.getFullPathName() }, details.localPosition.x, details.localPosition.y);
 }

+ 3 - 0
src/ui/PlaylistComponent.h

@@ -101,6 +101,9 @@ public:
     // files dragged from the LYNX browser
     bool isInterestedInDragSource (const SourceDetails& details) override;
     void itemDropped (const SourceDetails& details) override;
+    // The Browser's "Send to the Playlist as an audio clip": at the playhead (song mode) or the start, on the
+    // first track that is free there; an audio-clip channel of the same file is reused.
+    void addAudioClipAtPlayhead (const juce::File& file);
 
     // For snapshots: the tool in use and a time selection over [fromBar, toBar).
     void setToolForSnapshot (EditTool tool) { tools.setTool (tool); }

Некоторые файлы не были показаны из-за большого количества измененных файлов