Skip to content

Commit

Permalink
Added Rescan option to the PluginRegistrationDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksoze95 committed Sep 6, 2022
1 parent 18d277e commit c4d60a6
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 38 deletions.
58 changes: 53 additions & 5 deletions libraries/lib-module-manager/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void PluginManager::Initialize(FileConfigFactory factory)
// Allow the module to auto-register children
module->AutoRegisterPlugins(*this);
}

InitializePlugins();
}

Expand Down Expand Up @@ -1035,10 +1035,17 @@ int PluginManager::GetPluginCount(PluginType type)

const PluginDescriptor *PluginManager::GetPlugin(const PluginID & ID) const
{
if (auto iter = mRegisteredPlugins.find(ID); iter == mRegisteredPlugins.end())
return nullptr;
else
if (auto iter = mRegisteredPlugins.find(ID); iter != mRegisteredPlugins.end())
return &iter->second;

auto iter2 = make_iterator_range(mEffectPluginsCleared)
.find_if([&ID](const PluginDescriptor& plug) {
return plug.GetID() == ID;
});
if (iter2 != mEffectPluginsCleared.end())
return &(*iter2);

return nullptr;
}

void PluginManager::Iterator::Advance(bool incrementing)
Expand Down Expand Up @@ -1143,6 +1150,41 @@ ComponentInterface *PluginManager::Load(const PluginID & ID)
return nullptr;
}

void PluginManager::ClearEffectPlugins()
{
mEffectPluginsCleared.clear();

for ( auto it = mRegisteredPlugins.cbegin(); it != mRegisteredPlugins.cend(); )
{
const auto& desc = it->second;
const auto type = desc.GetPluginType();

if (type == PluginTypeEffect || type == PluginTypeStub)
{
mEffectPluginsCleared.push_back(desc);
it = mRegisteredPlugins.erase(it);
}
else
{
++it;
}
}

// Repeat what usually happens at startup
// This prevents built-in plugins to appear in the plugin validation list
for (auto& [_, provider] : ModuleManager::Get().Providers())
provider->AutoRegisterPlugins(*this);

// Remove auto registered plugins from "cleared" list
for ( auto it = mEffectPluginsCleared.begin(); it != mEffectPluginsCleared.end(); )
{
if ( mRegisteredPlugins.find(it->GetID()) != mRegisteredPlugins.end() )
it = mEffectPluginsCleared.erase(it);
else
++it;
}
}

std::map<wxString, std::vector<wxString>> PluginManager::CheckPluginUpdates()
{
wxArrayString pathIndex;
Expand Down Expand Up @@ -1171,8 +1213,14 @@ std::map<wxString, std::vector<wxString>> PluginManager::CheckPluginUpdates()
for(const auto& path : paths)
{
const auto modulePath = path.BeforeFirst(';');
if(!make_iterator_range(pathIndex).contains(modulePath))
if (!make_iterator_range(pathIndex).contains(modulePath) ||
make_iterator_range(mEffectPluginsCleared).any_of([&modulePath](const PluginDescriptor& plug) {
return plug.GetPath().BeforeFirst(wxT(';')) == modulePath;
})
)
{
newPaths[modulePath].push_back(id);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/lib-module-manager/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <functional>
#include <map>
#include <memory>
#include <vector>

#include "EffectInterface.h"
#include "PluginInterface.h"
Expand Down Expand Up @@ -153,6 +154,8 @@ class MODULE_MANAGER_API PluginManager final : public PluginManagerInterface
const ComponentInterfaceSymbol & GetSymbol(const PluginID & ID);
ComponentInterface *Load(const PluginID & ID);

void ClearEffectPlugins();

/**
* \brief Ensures that all currently registered plugins still exist
* and scans for new ones.
Expand Down Expand Up @@ -220,6 +223,7 @@ class MODULE_MANAGER_API PluginManager final : public PluginManagerInterface

PluginMap mRegisteredPlugins;
std::map<PluginID, std::unique_ptr<ComponentInterface>> mLoadedInterfaces;
std::vector<PluginDescriptor> mEffectPluginsCleared;

PluginRegistryVersion mRegver;
};
Expand Down
102 changes: 70 additions & 32 deletions src/PluginRegistrationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include "EffectInterface.h"
#include "ModuleManager.h"
#include "PluginManager.h"
#include "PluginStartupRegistration.h"
#include "ShuttleGui.h"
#include "widgets/AudacityMessageBox.h"
#include "widgets/ProgressDialog.h"

#include <wx/setup.h> // for wxUSE_* macros
#include <wx/app.h>
#include <wx/defs.h>
#include <wx/dir.h>
#include <wx/dynlib.h>
Expand Down Expand Up @@ -359,6 +361,7 @@ enum
ID_List,
ID_ClearAll,
ID_SelectAll,
ID_Rescan,
ID_Enable,
ID_Disable,
};
Expand All @@ -376,6 +379,7 @@ BEGIN_EVENT_TABLE(PluginRegistrationDialog, wxDialogWrapper)
EVT_LIST_COL_CLICK(ID_List, PluginRegistrationDialog::OnSort)
EVT_BUTTON(wxID_OK, PluginRegistrationDialog::OnOK)
EVT_BUTTON(wxID_CANCEL, PluginRegistrationDialog::OnCancel)
EVT_BUTTON(ID_Rescan, PluginRegistrationDialog::OnRescan)
EVT_BUTTON(ID_ClearAll, PluginRegistrationDialog::OnClearAll)
EVT_BUTTON(ID_SelectAll, PluginRegistrationDialog::OnSelectAll)
EVT_BUTTON(ID_Enable, PluginRegistrationDialog::OnEnable)
Expand Down Expand Up @@ -510,6 +514,7 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
{
S.Id(ID_SelectAll).AddButton(XXO("&Select All"));
S.Id(ID_ClearAll).AddButton(XXO("C&lear All"));
S.Id(ID_Rescan).AddButton(XXO("Rescan"));

S.StartHorizontalLay(wxALIGN_CENTER);
{
Expand Down Expand Up @@ -543,45 +548,20 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
}

PluginManager & pm = PluginManager::Get();
for (auto &plug : pm.AllPlugins()) {
PluginType plugType = plug.GetPluginType();
if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
continue;
PopulateItemsList(pm);

const auto &path = plug.GetPath();
ItemData & item = mItems[path]; // will create NEW entry
item.plugs.push_back(&plug);
item.path = path;
item.state = plug.IsEnabled() ? STATE_Enabled : STATE_Disabled;
item.valid = plug.IsValid();

if (plugType == PluginTypeEffect)
{
item.name = plug.GetSymbol().Translation();
}
// This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed
// by then.
else if (plugType == PluginTypeStub)
{
wxFileName fname { path };
item.name = fname.GetName().Trim(false).Trim(true);
#ifndef DISABLE_STATE_NEW
if (!item.valid)
{
item.state = STATE_New;
}
#endif
}
for (const auto& item : mItems)
{
const auto& itemData = item.second;

int x;
mEffects->GetTextExtent(item.name, &x, NULL);
mEffects->GetTextExtent(itemData.name, &x, NULL);
colWidths[COL_Name] = wxMax(colWidths[COL_Name], x);

mEffects->GetTextExtent(item.path, &x, NULL);
mEffects->GetTextExtent(itemData.path, &x, NULL);
if (x > colWidths[COL_Path])
{
mLongestPath = item.path;
mLongestPath = itemData.path;
}
colWidths[COL_Path] = wxMax(colWidths[COL_Path], x);
}
Expand Down Expand Up @@ -626,6 +606,42 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)

}

void PluginRegistrationDialog::PopulateItemsList(PluginManager& pm)
{
for (auto& plug : pm.AllPlugins())
{
PluginType plugType = plug.GetPluginType();
if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
continue;

const auto& path = plug.GetPath();
ItemData& item = mItems[path]; // will create NEW entry
item.plugs.push_back(&plug);
item.path = path;
item.state = plug.IsEnabled() ? STATE_Enabled : STATE_Disabled;
item.valid = plug.IsValid();

if (plugType == PluginTypeEffect)
{
item.name = plug.GetSymbol().Translation();
}
// This is not right and will not work when other plugin types are added.
// But it's presumed that the plugin manager dialog will be fully developed
// by then.
else if (plugType == PluginTypeStub)
{
wxFileName fname{ path };
item.name = fname.GetName().Trim(false).Trim(true);
#ifndef DISABLE_STATE_NEW
if (!item.valid)
{
item.state = STATE_New;
}
#endif
}
}
}

void PluginRegistrationDialog::RegenerateEffectsList(int filter)
{
mFilter = filter;
Expand Down Expand Up @@ -851,6 +867,28 @@ void PluginRegistrationDialog::OnClearAll(wxCommandEvent & WXUNUSED(evt))
}
}

void PluginRegistrationDialog::OnRescan(wxCommandEvent& WXUNUSED(evt))
{
mItems.clear();
mEffects->DeleteAllItems();
mEffects->Update();

wxTheApp->CallAfter([this] {
auto& pm = PluginManager::Get();
pm.ClearEffectPlugins();

auto newPlugins = PluginManager::Get().CheckPluginUpdates();
if (!newPlugins.empty())
{
PluginStartupRegistration reg(newPlugins);
reg.Run();
}

PopulateItemsList(pm);
RegenerateEffectsList(mFilter);
});
}

void PluginRegistrationDialog::OnEnable(wxCommandEvent & WXUNUSED(evt))
{
std::vector<long> items;
Expand Down
3 changes: 3 additions & 0 deletions src/PluginRegistrationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class CheckListAx;
enum EffectType : int;
class PluginDescriptor;
class PluginManager;
class ShuttleGui;
class wxListEvent;
class wxListCtrl;
Expand Down Expand Up @@ -44,6 +45,7 @@ class PluginRegistrationDialog final : public wxDialogWrapper

void Populate();
void PopulateOrExchange(ShuttleGui & S);
void PopulateItemsList(PluginManager& pm);
void RegenerateEffectsList(int iShowWhat);
void SetState(int i, bool toggle, bool state = true);

Expand All @@ -58,6 +60,7 @@ class PluginRegistrationDialog final : public wxDialogWrapper
void OnCancel(wxCommandEvent & evt);
void OnSelectAll(wxCommandEvent & evt);
void OnClearAll(wxCommandEvent & evt);
void OnRescan(wxCommandEvent & evt);
void OnEnable(wxCommandEvent & evt);
void OnDisable(wxCommandEvent & evt);

Expand Down
1 change: 0 additions & 1 deletion src/PluginStartupRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void PluginStartupRegistration::OnInternalError(const wxString& error)

void PluginStartupRegistration::OnPluginFound(const PluginDescriptor& desc)
{
auto& pluginManager = PluginManager::Get();
//Multiple providers can report same module paths
if(desc.GetPluginType() == PluginTypeStub)
//do not register until all associated providers have tried to load the module
Expand Down

0 comments on commit c4d60a6

Please sign in to comment.