Audacity 3.2.0
BasicEffectUIServices.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file BasicEffectUIServices.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10 Paul Licameli split from Effect.h
11
12**********************************************************************/
14#include "EffectPlugin.h"
15#include "FileNames.h"
16
17#include <wx/dialog.h>
18#include <wx/ffile.h>
19#include <wx/filedlg.h>
20#include "SelectFile.h"
21#include "AudacityMessageBox.h"
22
24 wxWindow &parent, wxDialog &dialog, EffectEditor *, bool forceModal) const
25{
26 dialog.Layout();
27 dialog.Fit();
28 dialog.SetMinSize(dialog.GetSize());
29 if (plugin.SupportsRealtime() && !forceModal) {
30 dialog.Show();
31 // Return false to bypass effect processing
32 return 0;
33 }
34 return dialog.ShowModal();
35}
36
38 const EffectPlugin &context, EffectSettings &) const
39{
40 return true;
41}
42
44{
45 return true;
46}
47
49{
50 static const FileNames::FileTypes result {
51 { XO("Presets"), { wxT("txt") }, true },
53 };
54 return result;
55};
56
58 const EffectPlugin &plugin, const EffectSettings &settings) const
59{
60 wxString params;
62 auto commandId = plugin.GetSquashedName(plugin.GetSymbol().Internal());
63 params = commandId.GET() + ":" + params;
64
65 auto path = SelectFile(FileNames::Operation::Presets,
66 XO("Export Effect Parameters"),
67 wxEmptyString,
68 wxEmptyString,
69 wxEmptyString,
71 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
72 nullptr);
73 if (path.empty()) {
74 return;
75 }
76
77 // Create/Open the file
78 wxFFile f(path, wxT("wb"));
79 if (!f.IsOpened())
80 {
82 XO("Could not open file: \"%s\"").Format( path ),
83 XO("Error Saving Effect Presets"),
84 wxICON_EXCLAMATION,
85 NULL);
86 return;
87 }
88
89 f.Write(params);
90 if (f.Error())
91 {
93 XO("Error writing to file: \"%s\"").Format( path ),
94 XO("Error Saving Effect Presets"),
95 wxICON_EXCLAMATION,
96 NULL);
97 }
98
99 f.Close();
100
101
102 //SetWindowTitle();
103
104}
105
107 const EffectPlugin &plugin, EffectSettings &settings) const
108{
109 wxString params;
110
111 auto path = SelectFile(FileNames::Operation::Presets,
112 XO("Import Effect Parameters"),
113 wxEmptyString,
114 wxEmptyString,
115 wxEmptyString,
116 PresetTypes(),
117 wxFD_OPEN | wxRESIZE_BORDER,
118 nullptr);
119 if (path.empty()) {
120 return {};
121 }
122
123 wxFFile f(path);
124 if (!f.IsOpened())
125 return {};
126
127 OptionalMessage result{};
128
129 if (f.ReadAll(&params)) {
130 wxString ident = params.BeforeFirst(':');
131 params = params.AfterFirst(':');
132
133 auto commandId = plugin.GetSquashedName(plugin.GetSymbol().Internal());
134
135 if (ident != commandId) {
136 // effect identifiers are a sensible length!
137 // must also have some params.
138 if ((params.Length() < 2 ) || (ident.Length() < 2) ||
139 (ident.Length() > 30))
140 {
142 /* i18n-hint %s will be replaced by a file name */
143 XO("%s: is not a valid presets file.\n")
144 .Format(wxFileNameFromPath(path)));
145 }
146 else
147 {
149 /* i18n-hint %s will be replaced by a file name */
150 XO("%s: is for a different Effect, Generator or Analyzer.\n")
151 .Format(wxFileNameFromPath(path)));
152 }
153 return {};
154 }
155 result = plugin.LoadSettingsFromString(params, settings);
156 }
157
158 //SetWindowTitle();
159
160 return result;
161}
162
164{
165}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const FileNames::FileTypes & PresetTypes()
EffectDistortionSettings params
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
XO("Cut/Copy/Paste")
static CommandHandlerObject & ident(AudacityProject &project)
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
static Settings & settings()
Definition: TrackInfo.cpp:51
bool ValidateUI(const EffectPlugin &context, EffectSettings &) const override
void ExportPresets(const EffectPlugin &plugin, const EffectSettings &settings) const override
int ShowClientInterface(const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
bool CloseUI() const override
void ShowOptions(const EffectPlugin &plugin) const override
OptionalMessage ImportPresets(const EffectPlugin &plugin, EffectSettings &settings) const override
virtual ComponentInterfaceSymbol GetSymbol() const =0
const wxString & Internal() const
static Identifier GetSquashedName(const Identifier &ident)
A utility that strips spaces and CamelCases a name.
Factory of instances of an effect.
Definition: EffectPlugin.h:36
virtual bool SaveSettingsAsString(const EffectSettings &settings, wxString &parms) const =0
virtual OptionalMessage LoadSettingsFromString(const wxString &parms, EffectSettings &settings) const =0
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
std::vector< FileType > FileTypes
Definition: FileNames.h:75
FILES_API const FileType AllFiles
Definition: FileNames.h:70
Abstract base class used in importing a file.
Externalized state of a plug-in.