Skip to content

Commit

Permalink
Orchestra pit: rework sorting/filtering the plugins list (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrudenko committed Aug 18, 2024
1 parent 9db567d commit 4aa2a0c
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 57 deletions.
35 changes: 24 additions & 11 deletions Source/Core/Audio/Instruments/PluginScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "SoundFontSynthAudioPlugin.h"
#include "SerializablePluginDescription.h"

#if PLATFORM_DESKTOP
# define SAFE_SCAN 1
#else
#if PLATFORM_MOBILE || JUCE_MAC
# define SAFE_SCAN 0
#else
# define SAFE_SCAN 1
#endif

PluginScanner::PluginScanner() : Thread("Plugin Scanner") {}
Expand Down Expand Up @@ -81,6 +81,7 @@ void PluginScanner::removePlugin(const PluginDescription &description)
void PluginScanner::sortList(KnownPluginList::SortMethod fieldToSortBy, bool forwards)
{
this->pluginsList.sort(fieldToSortBy, forwards);
this->sendChangeMessage();
}

bool PluginScanner::isWorking() const
Expand Down Expand Up @@ -214,6 +215,9 @@ void PluginScanner::run()
}
}

const auto pluginSorting = App::Config().getUiFlags()->getPluginSorting();
const auto pluginSortingForwards = App::Config().getUiFlags()->isPluginSortingForwards();

try
{
for (const auto &pluginPath : this->filesToScan)
Expand Down Expand Up @@ -266,8 +270,8 @@ void PluginScanner::run()
pluginDescription.deserialize(e);
this->pluginsList.addType(pluginDescription);
}
this->sendChangeMessage();

this->sortList(pluginSorting, pluginSortingForwards); // will also sendChangeMessage();
}
}
catch (...) {}
Expand All @@ -278,7 +282,7 @@ void PluginScanner::run()
#else
KnownPluginList knownPluginList;
OwnedArray<PluginDescription> typesFound;

try
{
for (int j = 0; j < formatManager.getNumFormats(); ++j)
Expand All @@ -296,9 +300,10 @@ void PluginScanner::run()
{
this->pluginsList.addType(*type);
}

this->sortList(pluginSorting, pluginSortingForwards); // will also sendChangeMessage();
}

this->sendChangeMessage();

Thread::sleep(150);
#endif
}
Expand All @@ -312,7 +317,7 @@ void PluginScanner::run()
DBG("Done scanning audio plugins");
this->sendChangeMessage();
}

WaitableEvent::wait();
}
}
Expand Down Expand Up @@ -407,13 +412,21 @@ void PluginScanner::deserialize(const SerializedData &data)

if (!root.isValid()) { return; }

Array<SerializablePluginDescription> descriptions;
for (const auto &child : root)
{
SerializablePluginDescription pluginDescription;
pluginDescription.deserialize(child);
if (pluginDescription.isValid())
descriptions.add(move(pluginDescription));
}

// for whatever reason addType inserts in the beginning of the array,
// so we have to iterate backwards to preserve the serialized order
for (int i = descriptions.size(); i --> 0 ;)
{
if (descriptions.getUnchecked(i).isValid())
{
this->pluginsList.addType(pluginDescription);
this->pluginsList.addType(descriptions.getUnchecked(i));
}
}

Expand Down
8 changes: 2 additions & 6 deletions Source/Core/Audio/Instruments/PluginScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ class PluginScanner final :
bool hasInstruments() const;

void removePlugin(const PluginDescription &description);
void sortList(KnownPluginList::SortMethod method, bool forwards);
void sortList(KnownPluginList::SortMethod method =
KnownPluginList::SortMethod::sortByFormat, bool forwards = true);

inline const Array<PluginDescription> getPlugins() const noexcept
{
return this->pluginsList.getTypes();
}

inline const int getNumPlugins() const noexcept
{
return this->pluginsList.getNumTypes();
}

void runInitialScan();
void scanFolderAndAddResults(const File &dir);
void cancelRunningScan();
Expand Down
30 changes: 30 additions & 0 deletions Source/Core/Configuration/UserInterfaceFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,29 @@ AffineTransform UserInterfaceFlags::getScaledTransformFor(Component *component)
return component->getTransform().scaled(this->uiScaleFactor, this->uiScaleFactor);
}

KnownPluginList::SortMethod UserInterfaceFlags::getPluginSorting() const noexcept
{
return this->pluginSorting;
}

bool UserInterfaceFlags::isPluginSortingForwards() const noexcept
{
return this->pluginSortingForwards;
}

void UserInterfaceFlags::setPluginSorting(KnownPluginList::SortMethod sorting, bool forwards)
{
if (this->pluginSorting == sorting && this->pluginSortingForwards == forwards)
{
return;
}

this->pluginSorting = sorting;
this->pluginSortingForwards = forwards;
// no listener event here, not needed yet
this->startTimer(UserInterfaceFlags::saveTimeoutMs);
}

//===----------------------------------------------------------------------===//
// Serializable
//===----------------------------------------------------------------------===//
Expand All @@ -297,6 +320,9 @@ SerializedData UserInterfaceFlags::serialize() const

tree.setProperty(UI::Flags::metronomeEnabled, this->metronomeEnabled);

const auto pluginSortingValue = int(this->pluginSorting) * (this->pluginSortingForwards ? 1 : -1);
tree.setProperty(UI::Flags::pluginsSorting, pluginSortingValue);

// skips experimentalFeaturesOn, it's read only

return tree;
Expand Down Expand Up @@ -336,6 +362,10 @@ void UserInterfaceFlags::deserialize(const SerializedData &data)

this->metronomeEnabled = root.getProperty(UI::Flags::metronomeEnabled, this->metronomeEnabled);

const int pluginsSortMethod = root.getProperty(UI::Flags::pluginsSorting, int(this->pluginSorting));
this->pluginSorting = KnownPluginList::SortMethod(abs(pluginsSortMethod));
this->pluginSortingForwards = pluginsSortMethod >= 0;

this->editorPanelVisible = false; // not serializing that

this->experimentalFeaturesOn = root.getProperty(UI::Flags::experimentalFeaturesOn, this->experimentalFeaturesOn);
Expand Down
10 changes: 9 additions & 1 deletion Source/Core/Configuration/UserInterfaceFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class UserInterfaceFlags final : public Serializable, private Timer
bool isMetronomeEnabled() const noexcept;
void toggleMetronome();

KnownPluginList::SortMethod getPluginSorting() const noexcept;
bool isPluginSortingForwards() const noexcept;
void setPluginSorting(KnownPluginList::SortMethod sorting, bool forwards);

//===------------------------------------------------------------------===//
// Serializable
//===------------------------------------------------------------------===//
Expand Down Expand Up @@ -174,11 +178,15 @@ class UserInterfaceFlags final : public Serializable, private Timer

bool metronomeEnabled = false;

bool pluginSortingForwards = true;
KnownPluginList::SortMethod pluginSorting =
KnownPluginList::SortMethod::sortByFormat;

private:

// all these options are expected to be toggled by hotkeys,
// so let's have a sensible delay before we serialize anything:
static constexpr auto saveTimeoutMs = 3000;
static constexpr auto saveTimeoutMs = 2000;

void timerCallback() override;
ListenerList<Listener> listeners;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Serialization/SerializationKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ namespace Serialization
static const Identifier mouseWheelVerticalPanningByDefault = "wheelVerticalPan";
static const Identifier mouseWheelVerticalZoomingByDefault = "wheelVerticalZoom";
static const Identifier metronomeEnabled = "metronome";
static const Identifier pluginsSorting = "pluginsSorting";
} // namespace Flags

namespace Hotkeys
Expand Down
Loading

0 comments on commit 4aa2a0c

Please sign in to comment.