Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PluginRegistrationDialog Class Referencefinal

#include <PluginRegistrationDialog.h>

Inheritance diagram for PluginRegistrationDialog:
[legend]
Collaboration diagram for PluginRegistrationDialog:
[legend]

Public Member Functions

 PluginRegistrationDialog (wxWindow *parent, int defaultEffectCategory=-1)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Member Functions

void Populate ()
 
void PopulateOrExchange (ShuttleGui &S)
 Defines the dialog and does data exchange with it. More...
 
void ReloadModel ()
 
void OnSearchTextChanged (wxCommandEvent &evt)
 
void OnStateFilterValueChanged (wxCommandEvent &evt)
 
void OnTypeFilterValueChanged (wxCommandEvent &evt)
 
void OnCategoryFilterValueChanged (wxCommandEvent &evt)
 
void OnOK (wxCommandEvent &evt)
 
void OnCancel (wxCommandEvent &evt)
 
void OnRescan (wxCommandEvent &evt)
 

Private Attributes

wxArrayString mPluginProviderIDs
 
wxDataViewCtrl * mPluginList {}
 
wxObjectDataPtr< PluginDataModelmPluginsModel
 

Detailed Description

Definition at line 20 of file PluginRegistrationDialog.h.

Constructor & Destructor Documentation

◆ PluginRegistrationDialog()

PluginRegistrationDialog::PluginRegistrationDialog ( wxWindow *  parent,
int  defaultEffectCategory = -1 
)
Parameters
defaultCategory- sets the default effect plugins filter. Could be one of EffectType or set to -1 to disable it.

Definition at line 72 of file PluginRegistrationDialog.cpp.

73: wxDialogWrapper(parent,
74 wxID_ANY,
75 XO("Manage Plugins"),
76 wxDefaultPosition, wxDefaultSize,
77 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
78{
79 mPluginsModel = safenew PluginDataModel(defaultEffectCategory);
80 SetName();
81 Populate();
82}
XO("Cut/Copy/Paste")
#define safenew
Definition: MemoryX.h:9
!brief A plugins list model that can be attached to wxDataViewCtrl
wxObjectDataPtr< PluginDataModel > mPluginsModel

References mPluginsModel, Populate(), safenew, and wxDialogWrapper::SetName().

Here is the call graph for this function:

Member Function Documentation

◆ OnCancel()

void PluginRegistrationDialog::OnCancel ( wxCommandEvent &  evt)
private

Definition at line 382 of file PluginRegistrationDialog.cpp.

383{
384 EndModal(wxID_CANCEL);
385}

◆ OnCategoryFilterValueChanged()

void PluginRegistrationDialog::OnCategoryFilterValueChanged ( wxCommandEvent &  evt)
private

Definition at line 267 of file PluginRegistrationDialog.cpp.

268{
269 const auto index = evt.GetInt();
270 if(index >= 0 && index < CategoryFilterValues.size())
271 mPluginsModel->SetFilterCategory(CategoryFilterValues[index].first);
272}
static const std::vector< std::pair< int, TranslatableString > > CategoryFilterValues

References CategoryFilterValues, and mPluginsModel.

◆ OnOK()

void PluginRegistrationDialog::OnOK ( wxCommandEvent &  evt)
private

Definition at line 339 of file PluginRegistrationDialog.cpp.

340{
341 auto result = ProgressResult::Success;
342 {
343 // Make sure the progress dialog is deleted before we call EndModal() or
344 // we will leave the project window in an unusable state on OSX.
345 // See bug #1192.
346 std::unique_ptr<ProgressDialog> dialog;
347 wxArrayString last3;
348 auto updateProgress = [&](int num, int denom, const wxString& msg)
349 {
350 last3.insert(last3.begin(), msg);
351 if(last3.size() > 3)
352 last3.pop_back();
353 if(!dialog)
354 {
355 dialog = std::make_unique<ProgressDialog>(
356 Verbatim( GetTitle() ),
359 );
360 dialog->CenterOnParent();
361 }
362 result = dialog->Update(
363 num,
364 denom,
365 TranslatableString(wxJoin(last3, '\n'), {})
366 );
367 return result == ProgressResult::Success;
368 };
369 auto onError = [](const TranslatableString& error) {
370 AudacityMessageBox(error);
371 };
372
373 mPluginsModel->ApplyChanges(updateProgress, onError);
374 }
375 if(result == ProgressResult::Success)
376 EndModal(wxID_OK);
377 else
378 ReloadModel();
379
380}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
@ pdlgHideStopButton
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Holds a msgid for the translation catalog; may also bind format arguments.

References AudacityMessageBox(), mPluginsModel, pdlgHideStopButton, ReloadModel(), BasicUI::Success, and Verbatim().

Here is the call graph for this function:

◆ OnRescan()

void PluginRegistrationDialog::OnRescan ( wxCommandEvent &  evt)
private

Definition at line 274 of file PluginRegistrationDialog.cpp.

275{
276 wxTheApp->CallAfter([self = wxWeakRef(this)] {
277 std::set<PluginPath> disabledPlugins;
278 std::vector<wxString> failedPlugins;
279
280 auto& pm = PluginManager::Get();
281
282 // Record list of plugins that are currently disabled
283 for (auto& plug : pm.AllPlugins())
284 {
285 PluginType plugType = plug.GetPluginType();
286 if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
287 continue;
288
289 if (!plug.IsEnabled())
290 disabledPlugins.insert(plug.GetPath());
291 }
292
293 //PluginManager::ClearEffectPlugins() removes all effects
294 //making all pointers cached in PluginDataModel invalid.
295 //Reset model pointer before clearing effects so that
296 //nothing attempts to access it.
297 if(self)
298 self->mPluginList->AssociateModel(nullptr);
299
300 pm.ClearEffectPlugins();
301
302 auto newPlugins = PluginManager::Get().CheckPluginUpdates();
303 if (!newPlugins.empty())
304 {
305 PluginStartupRegistration reg(newPlugins);
306 reg.Run();
307
308 failedPlugins = reg.GetFailedPluginsPaths();
309 }
310
311 // Disable all plugins which were previously disabled
312 for (auto& plug : pm.AllPlugins())
313 {
314 PluginType plugType = plug.GetPluginType();
315 if (plugType != PluginTypeEffect && plugType != PluginTypeStub)
316 continue;
317
318 const auto& path = plug.GetPath();
319 if (disabledPlugins.find(path) != disabledPlugins.end())
320 plug.SetEnabled(false);
321 }
322
323 pm.Save();
324 pm.NotifyPluginsChanged();
325
326 if(self)
327 {
328 self->ReloadModel();
329 if (!failedPlugins.empty())
330 {
331 auto dialog = safenew IncompatiblePluginsDialog(self.get(), wxID_ANY, ScanType::Manual, failedPlugins);
332 dialog->ShowModal();
333 self->Refresh();
334 }
335 }
336 });
337}
PluginType
@ PluginTypeStub
@ PluginTypeEffect
std::map< wxString, std::vector< wxString > > CheckPluginUpdates()
Ensures that all currently registered plugins still exist and scans for new ones.
static PluginManager & Get()
BuiltinCommandsModule::Registration< CompareAudioCommand > reg

References PluginManager::CheckPluginUpdates(), PluginManager::Get(), Manual, PluginTypeEffect, PluginTypeStub, anonymous_namespace{CompareAudioCommand.cpp}::reg, and safenew.

Here is the call graph for this function:

◆ OnSearchTextChanged()

void PluginRegistrationDialog::OnSearchTextChanged ( wxCommandEvent &  evt)
private

Definition at line 246 of file PluginRegistrationDialog.cpp.

247{
248 mPluginsModel->SetFilterExpr(evt.GetString().Trim().Trim(true));
249}

References mPluginsModel.

Referenced by PopulateOrExchange().

Here is the caller graph for this function:

◆ OnStateFilterValueChanged()

void PluginRegistrationDialog::OnStateFilterValueChanged ( wxCommandEvent &  evt)
private

Definition at line 251 of file PluginRegistrationDialog.cpp.

252{
253 const auto index = evt.GetInt();
254
255 mPluginsModel->SetFilterState(
256 index == 2 ? 1 : (index == 1 ? 0 : -1)
257 );
258}

References mPluginsModel.

◆ OnTypeFilterValueChanged()

void PluginRegistrationDialog::OnTypeFilterValueChanged ( wxCommandEvent &  evt)
private

Definition at line 260 of file PluginRegistrationDialog.cpp.

261{
262 const auto index = evt.GetInt();
263 if(index >= 0 && index < mPluginProviderIDs.size())
264 mPluginsModel->SetFilterType(mPluginProviderIDs[index]);
265}

References mPluginProviderIDs, and mPluginsModel.

◆ Populate()

void PluginRegistrationDialog::Populate ( )
private

Definition at line 84 of file PluginRegistrationDialog.cpp.

85{
86 //------------------------- Main section --------------------
89 // ----------------------- End of main section --------------
90}
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
void PopulateOrExchange(ShuttleGui &S)
Defines the dialog and does data exchange with it.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640

References eIsCreating, PopulateOrExchange(), and S.

Referenced by PluginRegistrationDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopulateOrExchange()

void PluginRegistrationDialog::PopulateOrExchange ( ShuttleGui S)
private

Defines the dialog and does data exchange with it.

Definition at line 93 of file PluginRegistrationDialog.cpp.

94{
95 constexpr int Margin = 12;
96
97 static const std::unordered_map<TranslatableString, TranslatableString> extraProviders = {
98 { XO("Builtin Effects"), XO("Native Audacity") }
99 };
100
101 TranslatableStrings pluginProviderNames;
102 pluginProviderNames.push_back(XO("All"));
103 mPluginProviderIDs.clear();
104 mPluginProviderIDs.push_back({});
105 auto& moduleManager = ModuleManager::Get();
106 for(auto& [name, provider] : moduleManager.Providers())
107 {
108 //Use same name as in prefs
109 auto familySymbol = provider->GetOptionalFamilySymbol();
110 if(!familySymbol.empty())
111 pluginProviderNames.push_back(familySymbol.Msgid());
112 else
113 {
114 auto it = extraProviders.find(provider->GetSymbol().Msgid());
115 if(it != extraProviders.end())
116 pluginProviderNames.push_back(it->second);
117 else
118 continue;
119 }
120 mPluginProviderIDs.push_back(PluginManager::GetID(provider.get()));
121 }
122
123 S.Prop(1).StartPanel(wxEXPAND);
124 {
125 S.StartVerticalLay(true);
126 {
127 S.AddSpace(1, Margin);
128 S.StartHorizontalLay(wxEXPAND, 0);
129 {
130 S.AddSpace(Margin, 1);
131 S.StartHorizontalLay(wxALIGN_LEFT, 0);
132 {
133 TranslatableStrings categoryFilterNames;
134 std::transform(
135 CategoryFilterValues.begin(),
137 std::back_inserter(categoryFilterNames),
138 [](const auto& p) { return p.second; });
139 const auto selectedCategory =
140 std::distance(
141 CategoryFilterValues.begin(),
142 std::find_if(
143 CategoryFilterValues.begin(),
145 [category = mPluginsModel->GetFilterCategory()](const auto& p) {
146 return p.first == category;
147 }
148 ));
149 S
150 .Id(ID_FilterState)
151 .AddChoice(XXO("&Show:"), ShowFilterValues, 0)
152 ->SetMinSize(wxSize(120, -1));
153 S
154 .Id(ID_FilterType)
155 .AddChoice(XXO("&Type:"), pluginProviderNames, 0)
156 ->SetMinSize(wxSize(120, -1));
157 S
159 .AddChoice(XXO("C&ategory:"), categoryFilterNames, selectedCategory)
160 ->SetMinSize(wxSize(120, -1));
161 }
162 S.EndHorizontalLay();
163 S.AddSpace(1, 1, 1);
164 S.StartHorizontalLay(wxALIGN_CENTRE, 0);
165 {
166 const auto searchCtrl = S
167 .MinSize({240, -1})
168 .AddTextBox(XXO("Searc&h:"), wxEmptyString, 0);
169 if(searchCtrl != nullptr)
170 searchCtrl->Bind(wxEVT_TEXT, &PluginRegistrationDialog::OnSearchTextChanged, this);
171 }
172 S.EndHorizontalLay();
173 S.AddSpace(Margin, 1);
174 }
175 S.EndHorizontalLay();
176
177 {
178 const auto pluginsList = safenew PluginDataViewCtrl(
179 S.GetParent(), ID_List, wxDefaultPosition, wxDefaultSize,
180 wxSUNKEN_BORDER | wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES,
181 wxDefaultValidator,
182 _("Plugin")
183 );
184 mPluginList = pluginsList;
185 mPluginList->AssociateModel(mPluginsModel.get());
186 mPluginList->SetMinSize({728, 288});
187 mPluginList->GetColumn(PluginDataModel::ColumnName)->SetSortOrder(true);
188 mPluginsModel->Resort();
189 }
190
191 S.SetBorder(Margin);
192 S.Id(ID_List)
193 .Prop(1)
194 .AddWindow(mPluginList, wxEXPAND);
195 S.SetBorder(2);
196
197 S.AddSpace(1, Margin);
198
199 S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, 0);
200 {
201 S.AddSpace(Margin, 1);
202 S.Id(ID_Rescan).AddButton(XXO("&Rescan"));
203 S.AddSpace(1, 1, 1);
204
205 S.Id(wxID_OK).AddButton(XXO("&OK"));
206 S.Id(wxID_CANCEL).AddButton(XXO("&Cancel"));
207 S.AddSpace(Margin, 1);
208 }
209 S.EndHorizontalLay();
210 S.AddSpace(1, Margin);
211 }
212 S.EndVerticalLay();
213 }
214 S.EndStatic();
215
216 wxRect r = wxGetClientDisplayRect();
217
218 Layout();
219 Fit();
220
221 wxSize sz = GetSize();
222 sz.SetWidth(wxMin(sz.GetWidth(), r.GetWidth()));
223 sz.SetHeight(wxMin(sz.GetHeight(), r.GetHeight()));
224 SetMinSize(sz);
225
226 mPluginList->GetColumn(PluginDataModel::ColumnName)->SetWidth(200);
227 mPluginList->GetColumn(PluginDataModel::ColumnType)->SetWidth(80);
228 mPluginList->GetColumn(PluginDataModel::ColumnPath)->SetWidth(350);
229
230 // Parent window is usually not there yet, so centre on screen rather than on parent.
231 CenterOnScreen();
232
233}
const TranslatableString name
Definition: Distortion.cpp:76
XXO("&Cut/Copy/Paste Toolbar")
#define _(s)
Definition: Internat.h:73
static const TranslatableStrings ShowFilterValues
std::vector< TranslatableString > TranslatableStrings
static ModuleManager & Get()
static PluginID GetID(PluginProvider *provider)
void OnSearchTextChanged(wxCommandEvent &evt)

References _, CategoryFilterValues, PluginDataModel::ColumnName, PluginDataModel::ColumnPath, PluginDataModel::ColumnType, ModuleManager::Get(), PluginManager::GetID(), ID_FilterCategory, ID_FilterState, ID_FilterType, ID_List, ID_Rescan, mPluginList, mPluginProviderIDs, mPluginsModel, name, OnSearchTextChanged(), S, safenew, ShowFilterValues, XO(), and XXO().

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReloadModel()

void PluginRegistrationDialog::ReloadModel ( )
private

Definition at line 235 of file PluginRegistrationDialog.cpp.

236{
238 mPluginsModel->GetFilterCategory(),
239 mPluginsModel->GetFilterState(),
240 mPluginsModel->GetFilterType(),
241 mPluginsModel->GetFilterExpr()
242 ));
243 mPluginList->AssociateModel(mPluginsModel.get());
244}

References mPluginList, mPluginsModel, and safenew.

Referenced by OnOK().

Here is the caller graph for this function:

Member Data Documentation

◆ mPluginList

wxDataViewCtrl* PluginRegistrationDialog::mPluginList {}
private

Definition at line 43 of file PluginRegistrationDialog.h.

Referenced by PopulateOrExchange(), and ReloadModel().

◆ mPluginProviderIDs

wxArrayString PluginRegistrationDialog::mPluginProviderIDs
private

Definition at line 41 of file PluginRegistrationDialog.h.

Referenced by OnTypeFilterValueChanged(), and PopulateOrExchange().

◆ mPluginsModel

wxObjectDataPtr<PluginDataModel> PluginRegistrationDialog::mPluginsModel
private

The documentation for this class was generated from the following files: