Audacity 3.2.0
EffectPresetDialog.cpp
Go to the documentation of this file.
2#include "EffectManager.h" // GetUserPresets, ...
3#include "EffectPlugin.h"
4#include "ShuttleGui.h"
5
6enum
7{
8 ID_Type = 10000
9};
10
11BEGIN_EVENT_TABLE(EffectPresetsDialog, wxDialogWrapper)
13EVT_LISTBOX_DCLICK(wxID_ANY, EffectPresetsDialog::OnOk)
17
19 : wxDialogWrapper(parent, wxID_ANY, XO("Select Preset"))
20{
22 S.StartVerticalLay();
23 {
24 S.StartTwoColumn();
25 S.SetStretchyCol(1);
26 {
27 S.AddPrompt(XXO("Type:"));
28 mType = S.Id(ID_Type).AddChoice({}, {}, 0);
29
30 S.AddPrompt(XXO("&Preset:"));
31 mPresets = S.Style(wxLB_SINGLE | wxLB_NEEDED_SB).AddListBox({});
32 }
33 S.EndTwoColumn();
34
35 S.AddStandardButtons();
36 }
37 S.EndVerticalLay();
38
39 mUserPresets = GetUserPresets(*effect);
40 mFactoryPresets = effect->GetDefinition().GetFactoryPresets();
41
42 if (mUserPresets.size() > 0)
43 {
44 mType->Append(_("User Presets"));
45 }
46
47 if (mFactoryPresets.size() > 0)
48 {
49 mType->Append(_("Factory Presets"));
50 }
51
52 if (HasCurrentSettings(*effect))
53 {
54 mType->Append(_("Current Settings"));
55 }
56
57 if (HasFactoryDefaults(*effect))
58 {
59 mType->Append(_("Factory Defaults"));
60 }
61
62 UpdateUI();
63}
64
66{
67}
68
70{
71 return mSelection;
72}
73
74void EffectPresetsDialog::SetSelected(const wxString& parms)
75{
76 wxString preset = parms;
78 {
79 preset.Replace(EffectPlugin::kUserPresetIdent, wxEmptyString, false);
80 SetPrefix(XO("User Presets"), preset);
81 }
82 else if (preset.StartsWith(EffectPlugin::kFactoryPresetIdent))
83 {
84 preset.Replace(EffectPlugin::kFactoryPresetIdent, wxEmptyString, false);
85 SetPrefix(XO("Factory Presets"), preset);
86 }
88 {
89 SetPrefix(XO("Current Settings"), wxEmptyString);
90 }
92 {
93 SetPrefix(XO("Factory Defaults"), wxEmptyString);
94 }
95}
96
98 const TranslatableString& type, const wxString& prefix)
99{
100 mType->SetStringSelection(type.Translation());
101
102 if (type == XO("User Presets"))
103 {
104 mPresets->Clear();
105 for (const auto& preset : mUserPresets)
106 mPresets->Append(preset);
107 mPresets->Enable(true);
108 mPresets->SetStringSelection(prefix);
109 if (mPresets->GetSelection() == wxNOT_FOUND)
110 {
111 mPresets->SetSelection(0);
112 }
113 mSelection =
114 EffectPlugin::kUserPresetIdent + mPresets->GetStringSelection();
115 }
116 else if (type == XO("Factory Presets"))
117 {
118 mPresets->Clear();
119 for (size_t i = 0, cnt = mFactoryPresets.size(); i < cnt; i++)
120 {
121 auto label = mFactoryPresets[i];
122 if (label.empty())
123 {
124 label = _("None");
125 }
126 mPresets->Append(label);
127 }
128 mPresets->Enable(true);
129 mPresets->SetStringSelection(prefix);
130 if (mPresets->GetSelection() == wxNOT_FOUND)
131 {
132 mPresets->SetSelection(0);
133 }
134 mSelection =
135 EffectPlugin::kFactoryPresetIdent + mPresets->GetStringSelection();
136 }
137 else if (type == XO("Current Settings"))
138 {
139 mPresets->Clear();
140 mPresets->Enable(false);
142 }
143 else if (type == XO("Factory Defaults"))
144 {
145 mPresets->Clear();
146 mPresets->Enable(false);
148 }
149}
150
152{
153 int selected = mType->GetSelection();
154 if (selected == wxNOT_FOUND)
155 {
156 selected = 0;
157 mType->SetSelection(selected);
158 }
159 wxString type = mType->GetString(selected);
160
161 if (type == _("User Presets"))
162 {
163 selected = mPresets->GetSelection();
164 if (selected == wxNOT_FOUND)
165 {
166 selected = 0;
167 }
168
169 mPresets->Clear();
170 for (const auto& preset : mUserPresets)
171 mPresets->Append(preset);
172 mPresets->Enable(true);
173 mPresets->SetSelection(selected);
174 mSelection =
175 EffectPlugin::kUserPresetIdent + mPresets->GetString(selected);
176 }
177 else if (type == _("Factory Presets"))
178 {
179 selected = mPresets->GetSelection();
180 if (selected == wxNOT_FOUND)
181 {
182 selected = 0;
183 }
184
185 mPresets->Clear();
186 for (size_t i = 0, cnt = mFactoryPresets.size(); i < cnt; i++)
187 {
188 auto label = mFactoryPresets[i];
189 if (label.empty())
190 {
191 label = _("None");
192 }
193 mPresets->Append(label);
194 }
195 mPresets->Enable(true);
196 mPresets->SetSelection(selected);
197 mSelection =
198 EffectPlugin::kFactoryPresetIdent + mPresets->GetString(selected);
199 }
200 else if (type == _("Current Settings"))
201 {
202 mPresets->Clear();
203 mPresets->Enable(false);
205 }
206 else if (type == _("Factory Defaults"))
207 {
208 mPresets->Clear();
209 mPresets->Enable(false);
211 }
212}
213
214void EffectPresetsDialog::OnType(wxCommandEvent& WXUNUSED(evt))
215{
216 UpdateUI();
217}
218
219void EffectPresetsDialog::OnOk(wxCommandEvent& WXUNUSED(evt))
220{
221 UpdateUI();
222
223 EndModal(true);
224}
225
226void EffectPresetsDialog::OnCancel(wxCommandEvent& WXUNUSED(evt))
227{
228 mSelection = wxEmptyString;
229
230 EndModal(false);
231}
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
bool HasCurrentSettings(EffectPlugin &host)
bool HasFactoryDefaults(EffectPlugin &host)
RegistryPaths GetUserPresets(EffectPlugin &host)
@ ID_Type
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define _(s)
Definition: Internat.h:73
ReverbSettings preset
Definition: ReverbBase.cpp:25
@ eIsCreating
Definition: ShuttleGui.h:37
TranslatableString label
Definition: TagsEditor.cpp:165
#define S(N)
Definition: ToChars.cpp:64
Factory of instances of an effect.
Definition: EffectPlugin.h:36
static const wxString kUserPresetIdent
Definition: EffectPlugin.h:40
static const wxString kFactoryPresetIdent
Definition: EffectPlugin.h:41
static const wxString kCurrentSettingsIdent
Definition: EffectPlugin.h:42
static const wxString kFactoryDefaultsIdent
Definition: EffectPlugin.h:43
wxString GetSelected() const
void SetPrefix(const TranslatableString &type, const wxString &prefix)
RegistryPaths mFactoryPresets
void OnType(wxCommandEvent &evt)
void SetSelected(const wxString &parms)
void OnOk(wxCommandEvent &evt)
void OnCancel(wxCommandEvent &evt)
RegistryPaths mUserPresets
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const