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

#include <FFmpegPresets.h>

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

Public Member Functions

 FFmpegPresets ()
 
 ~FFmpegPresets () override
 
void GetPresetList (wxArrayString &list)
 
void LoadPreset (ExportFFmpegOptions *parent, wxString &name)
 
bool SavePreset (ExportFFmpegOptions *parent, wxString &name)
 
void DeletePreset (wxString &name)
 
bool OverwriteIsOk (wxString &name)
 
FFmpegPresetFindPreset (wxString &name)
 
void ImportPresets (wxString &filename)
 
void ExportPresets (wxString &filename)
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXMLHeader (XMLWriter &xmlFile) const
 
void WriteXML (XMLWriter &xmlFile) const
 

Private Attributes

FFmpegPresetMap mPresets
 
FFmpegPresetmPreset
 
bool mAbortImport
 

Additional Inherited Members

- Private Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Detailed Description

Definition at line 35 of file FFmpegPresets.h.

Constructor & Destructor Documentation

◆ FFmpegPresets()

FFmpegPresets::FFmpegPresets ( )

Definition at line 40 of file FFmpegPresets.cpp.

41{
42 mPreset = NULL;
43 mAbortImport = false;
44
45 XMLFileReader xmlfile;
46 wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
47 xmlfile.Parse(this,xmlFileName.GetFullPath());
48}
wxT("CloseDown"))
FFmpegPreset * mPreset
Definition: FFmpegPresets.h:59
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:19
bool Parse(XMLTagHandler *baseHandler, const FilePath &fname)
FILES_API FilePath DataDir()
Audacity user data directory.

References FileNames::DataDir(), mAbortImport, mPreset, XMLFileReader::Parse(), and wxT().

Here is the call graph for this function:

◆ ~FFmpegPresets()

FFmpegPresets::~FFmpegPresets ( )
override

Definition at line 50 of file FFmpegPresets.cpp.

51{
52 // We're in a destructor! Don't let exceptions out!
53 GuardedCall( [&] {
54 wxFileName xmlFileName{ FileNames::DataDir(), wxT("ffmpeg_presets.xml") };
55 XMLFileWriter writer{
56 xmlFileName.GetFullPath(), XO("Error Saving FFmpeg Presets") };
57 WriteXMLHeader(writer);
58 WriteXML(writer);
59 writer.Commit();
60 } );
61}
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), F3 delayedHandler=DefaultDelayedHandlerAction) noexcept(noexcept(handler(std::declval< AudacityException * >())) &&noexcept(handler(nullptr)) &&noexcept(std::function< void(AudacityException *)>{std::move(delayedHandler)}))
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
XO("Cut/Copy/Paste")
void WriteXMLHeader(XMLWriter &xmlFile) const
void WriteXML(XMLWriter &xmlFile) const
Wrapper to output XML data to files.
Definition: XMLWriter.h:84

References FileNames::DataDir(), GuardedCall(), WriteXML(), WriteXMLHeader(), wxT(), and XO().

Here is the call graph for this function:

Member Function Documentation

◆ DeletePreset()

void FFmpegPresets::DeletePreset ( wxString &  name)

Definition at line 99 of file FFmpegPresets.cpp.

100{
101 FFmpegPresetMap::iterator iter = mPresets.find(name);
102 if (iter != mPresets.end())
103 {
104 mPresets.erase(iter);
105 }
106}
wxString name
Definition: TagsEditor.cpp:166
FFmpegPresetMap mPresets
Definition: FFmpegPresets.h:58

References mPresets, and name.

◆ ExportPresets()

void FFmpegPresets::ExportPresets ( wxString &  filename)

Definition at line 77 of file FFmpegPresets.cpp.

78{
79 GuardedCall( [&] {
80 XMLFileWriter writer{ filename, XO("Error Saving FFmpeg Presets") };
81 WriteXMLHeader(writer);
82 WriteXML(writer);
83 writer.Commit();
84 } );
85}

References GuardedCall(), WriteXML(), WriteXMLHeader(), and XO().

Here is the call graph for this function:

◆ FindPreset()

FFmpegPreset * FFmpegPresets::FindPreset ( wxString &  name)

Definition at line 108 of file FFmpegPresets.cpp.

109{
110 FFmpegPresetMap::iterator iter = mPresets.find(name);
111 if (iter != mPresets.end())
112 {
113 return &iter->second;
114 }
115
116 return NULL;
117}

References mPresets, and name.

Referenced by HandleXMLTag(), LoadPreset(), and OverwriteIsOk().

Here is the caller graph for this function:

◆ GetPresetList()

void FFmpegPresets::GetPresetList ( wxArrayString &  list)

Definition at line 87 of file FFmpegPresets.cpp.

88{
89 list.clear();
90 FFmpegPresetMap::iterator iter;
91 for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
92 {
93 list.push_back(iter->second.mPresetName);
94 }
95
96 std::sort( list.begin(), list.end() );
97}

References mPresets.

◆ HandleXMLChild()

XMLTagHandler * FFmpegPresets::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 389 of file FFmpegPresets.cpp.

390{
391 if (mAbortImport)
392 {
393 return NULL;
394 }
395
396 if (tag == "preset")
397 {
398 return this;
399 }
400 else if (tag == "setctrlstate")
401 {
402 return this;
403 }
404 return NULL;
405}

References mAbortImport.

◆ HandleXMLTag()

bool FFmpegPresets::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 309 of file FFmpegPresets.cpp.

310{
311 if (mAbortImport)
312 {
313 return false;
314 }
315
316 if (tag == "ffmpeg_presets")
317 {
318 return true;
319 }
320
321 if (tag == "preset")
322 {
323 for (auto pair : attrs)
324 {
325 auto attr = pair.first;
326 auto value = pair.second;
327
328 if (attr == "name")
329 {
330 wxString strValue = value.ToWString();
331 mPreset = FindPreset(strValue);
332
333 if (mPreset)
334 {
335 auto query = XO("Replace preset '%s'?").Format( strValue );
336 int action = AudacityMessageBox(
337 query,
338 XO("Confirm Overwrite"),
339 wxYES_NO | wxCANCEL | wxCENTRE);
340 if (action == wxCANCEL)
341 {
342 mAbortImport = true;
343 return false;
344 }
345 if (action == wxNO)
346 {
347 mPreset = NULL;
348 return false;
349 }
351 }
352 else
353 {
354 mPreset = &mPresets[strValue];
355 }
356
357 mPreset->mPresetName = strValue;
358 }
359 }
360 return true;
361 }
362
363 if (tag == "setctrlstate" && mPreset)
364 {
365 long id = -1;
366 for (auto pair : attrs)
367 {
368 auto attr = pair.first;
369 auto value = pair.second;
370
371 if (attr == "id")
372 {
373 for (long i = FEFirstID; i < FELastID; i++)
374 if (!wxStrcmp(FFmpegExportCtrlIDNames[i - FEFirstID], value.ToWString()))
375 id = i;
376 }
377 else if (attr == "state")
378 {
379 if (id > FEFirstID && id < FELastID)
380 mPreset->mControlState[id - FEFirstID] = value.ToWString();
381 }
382 }
383 return true;
384 }
385
386 return false;
387}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const wxChar * FFmpegExportCtrlIDNames[]
Definition: FFmpegDefines.h:79
wxArrayString mControlState
Definition: FFmpegPresets.h:28
wxString mPresetName
Definition: FFmpegPresets.h:27
FFmpegPreset * FindPreset(wxString &name)

References AudacityMessageBox(), FFmpegExportCtrlIDNames, FindPreset(), mAbortImport, FFmpegPreset::mControlState, mPreset, FFmpegPreset::mPresetName, mPresets, and XO().

Here is the call graph for this function:

◆ ImportPresets()

void FFmpegPresets::ImportPresets ( wxString &  filename)

Definition at line 63 of file FFmpegPresets.cpp.

64{
65 mPreset = NULL;
66 mAbortImport = false;
67
68 FFmpegPresetMap savePresets = mPresets;
69
70 XMLFileReader xmlfile;
71 bool success = xmlfile.Parse(this,filename);
72 if (!success || mAbortImport) {
73 mPresets = savePresets;
74 }
75}
std::unordered_map< wxString, FFmpegPreset > FFmpegPresetMap
Definition: FFmpegPresets.h:31

References mAbortImport, mPreset, mPresets, and XMLFileReader::Parse().

Here is the call graph for this function:

◆ LoadPreset()

void FFmpegPresets::LoadPreset ( ExportFFmpegOptions parent,
wxString &  name 
)

Definition at line 230 of file FFmpegPresets.cpp.

231{
233 if (!preset)
234 {
235 AudacityMessageBox( XO("Preset '%s' does not exist." ).Format(name));
236 return;
237 }
238
239 wxListBox *lb;
240 wxSpinCtrl *sc;
241 wxTextCtrl *tc;
242 wxCheckBox *cb;
243 wxChoice *ch;
244
245 for (int id = FEFirstID; id < FELastID; id++)
246 {
247 wxWindow *wnd = parent->FindWindowById(id,parent);
248 if (wnd != NULL)
249 {
250 wxString readstr;
251 long readlong;
252 bool readbool;
253 switch(id)
254 {
255 // Listbox
256 case FEFormatID:
257 case FECodecID:
258 lb = dynamic_cast<wxListBox*>(wnd);
259 readstr = preset->mControlState[id - FEFirstID];
260 readlong = lb->FindString(readstr);
261 if (readlong > -1) lb->Select(readlong);
262 break;
263 // Spin control
264 case FEBitrateID:
265 case FEQualityID:
266 case FESampleRateID:
267 case FECutoffID:
268 case FEFrameSizeID:
269 case FEBufSizeID:
270 case FECompLevelID:
271 case FELPCCoeffsID:
272 case FEMinPredID:
273 case FEMaxPredID:
274 case FEMinPartOrderID:
275 case FEMaxPartOrderID:
276 case FEMuxRateID:
277 case FEPacketSizeID:
278 sc = dynamic_cast<wxSpinCtrl*>(wnd);
279 preset->mControlState[id - FEFirstID].ToLong(&readlong);
280 sc->SetValue(readlong);
281 break;
282 // Text control
283 case FELanguageID:
284 case FETagID:
285 tc = dynamic_cast<wxTextCtrl*>(wnd);
286 tc->SetValue(preset->mControlState[id - FEFirstID]);
287 break;
288 // Choice
289 case FEProfileID:
290 case FEPredOrderID:
291 ch = dynamic_cast<wxChoice*>(wnd);
292 preset->mControlState[id - FEFirstID].ToLong(&readlong);
293 if (readlong > -1) ch->Select(readlong);
294 break;
295 // Check box
296 case FEUseLPCID:
297 case FEBitReservoirID:
298 case FEVariableBlockLenID:
299 cb = dynamic_cast<wxCheckBox*>(wnd);
300 preset->mControlState[id - FEFirstID].ToLong(&readlong);
301 if (readlong) readbool = true; else readbool = false;
302 cb->SetValue(readbool);
303 break;
304 }
305 }
306 }
307}
ReverbSettings preset
Definition: ReverbBase.cpp:25
Abstract base class used in importing a file.

References AudacityMessageBox(), FindPreset(), name, preset, and XO().

Here is the call graph for this function:

◆ OverwriteIsOk()

bool FFmpegPresets::OverwriteIsOk ( wxString &  name)

Definition at line 120 of file FFmpegPresets.cpp.

121{
123 if (preset)
124 {
125 auto query = XO("Overwrite preset '%s'?").Format(name);
126 int action = AudacityMessageBox(
127 query,
128 XO("Confirm Overwrite"),
129 wxYES_NO | wxCENTRE);
130 if (action == wxNO) return false;
131 }
132 return true;
133}

References AudacityMessageBox(), FindPreset(), name, preset, and XO().

Here is the call graph for this function:

◆ SavePreset()

bool FFmpegPresets::SavePreset ( ExportFFmpegOptions parent,
wxString &  name 
)

Definition at line 136 of file FFmpegPresets.cpp.

137{
138 wxString format;
139 wxString codec;
141
142 {
143 wxWindow *wnd;
144 wxListBox *lb;
145
146 wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FEFormatID,parent);
147 lb = dynamic_cast<wxListBox*>(wnd);
148 if (lb->GetSelection() < 0)
149 {
150 AudacityMessageBox( XO("Please select format before saving a profile") );
151 return false;
152 }
153 format = lb->GetStringSelection();
154
155 wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FECodecID,parent);
156 lb = dynamic_cast<wxListBox*>(wnd);
157 if (lb->GetSelection() < 0)
158 {
159 /* i18n-hint: "codec" is short for a "coder-decoder" algorithm */
160 AudacityMessageBox( XO("Please select codec before saving a profile") );
161 return false;
162 }
163 codec = lb->GetStringSelection();
164 }
165
166 preset = &mPresets[name];
167 preset->mPresetName = name;
168
169 wxSpinCtrl *sc;
170 wxTextCtrl *tc;
171 wxCheckBox *cb;
172 wxChoice *ch;
173
174 for (int id = FEFirstID; id < FELastID; id++)
175 {
176 wxWindow *wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(id,parent);
177 if (wnd != NULL)
178 {
179 switch(id)
180 {
181 case FEFormatID:
182 preset->mControlState[id - FEFirstID] = format;
183 break;
184 case FECodecID:
185 preset->mControlState[id - FEFirstID] = codec;
186 break;
187 // Spin control
188 case FEBitrateID:
189 case FEQualityID:
190 case FESampleRateID:
191 case FECutoffID:
192 case FEFrameSizeID:
193 case FEBufSizeID:
194 case FECompLevelID:
195 case FELPCCoeffsID:
196 case FEMinPredID:
197 case FEMaxPredID:
198 case FEMinPartOrderID:
199 case FEMaxPartOrderID:
200 case FEMuxRateID:
201 case FEPacketSizeID:
202 sc = dynamic_cast<wxSpinCtrl*>(wnd);
203 preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),sc->GetValue());
204 break;
205 // Text control
206 case FELanguageID:
207 case FETagID:
208 tc = dynamic_cast<wxTextCtrl*>(wnd);
209 preset->mControlState[id - FEFirstID] = tc->GetValue();
210 break;
211 // Choice
212 case FEProfileID:
213 case FEPredOrderID:
214 ch = dynamic_cast<wxChoice*>(wnd);
215 preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),ch->GetSelection());
216 break;
217 // Check box
218 case FEUseLPCID:
219 case FEBitReservoirID:
220 case FEVariableBlockLenID:
221 cb = dynamic_cast<wxCheckBox*>(wnd);
222 preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),cb->GetValue());
223 break;
224 }
225 }
226 }
227 return true;
228}

References AudacityMessageBox(), anonymous_namespace{ExportPCM.cpp}::format, mPresets, name, preset, wxT(), and XO().

Here is the call graph for this function:

◆ WriteXML()

void FFmpegPresets::WriteXML ( XMLWriter xmlFile) const

Definition at line 427 of file FFmpegPresets.cpp.

429{
430 xmlFile.StartTag(wxT("ffmpeg_presets"));
431 xmlFile.WriteAttr(wxT("version"),wxT("1.0"));
432 FFmpegPresetMap::const_iterator iter;
433 for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
434 {
435 auto preset = &iter->second;
436 xmlFile.StartTag(wxT("preset"));
437 xmlFile.WriteAttr(wxT("name"),preset->mPresetName);
438 for (long i = FEFirstID + 1; i < FELastID; i++)
439 {
440 xmlFile.StartTag(wxT("setctrlstate"));
441 xmlFile.WriteAttr(wxT("id"),wxString(FFmpegExportCtrlIDNames[i - FEFirstID]));
442 xmlFile.WriteAttr(wxT("state"),preset->mControlState[i - FEFirstID]);
443 xmlFile.EndTag(wxT("setctrlstate"));
444 }
445 xmlFile.EndTag(wxT("preset"));
446 }
447 xmlFile.EndTag(wxT("ffmpeg_presets"));
448}
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References FFmpegExportCtrlIDNames, preset, and wxT().

Referenced by ExportPresets(), and ~FFmpegPresets().

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

◆ WriteXMLHeader()

void FFmpegPresets::WriteXMLHeader ( XMLWriter xmlFile) const

Definition at line 407 of file FFmpegPresets.cpp.

409{
410 xmlFile.Write(wxT("<?xml "));
411 xmlFile.Write(wxT("version=\"1.0\" "));
412 xmlFile.Write(wxT("standalone=\"no\" "));
413 xmlFile.Write(wxT("?>\n"));
414
415 wxString dtdName = wxT("-//audacityffmpegpreset-1.0.0//DTD//EN");
416 wxString dtdURI =
417 wxT("http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd");
418
419 xmlFile.Write(wxT("<!DOCTYPE "));
420 xmlFile.Write(wxT("project "));
421 xmlFile.Write(wxT("PUBLIC "));
422 xmlFile.Write(wxT("\"-//audacityffmpegpreset-1.0.0//DTD//EN\" "));
423 xmlFile.Write(wxT("\"http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd\" "));
424 xmlFile.Write(wxT(">\n"));
425}
virtual void Write(const wxString &data)=0

References wxT().

Referenced by ExportPresets(), and ~FFmpegPresets().

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

Member Data Documentation

◆ mAbortImport

bool FFmpegPresets::mAbortImport
private

Definition at line 60 of file FFmpegPresets.h.

Referenced by FFmpegPresets(), HandleXMLChild(), HandleXMLTag(), and ImportPresets().

◆ mPreset

FFmpegPreset* FFmpegPresets::mPreset
private

Definition at line 59 of file FFmpegPresets.h.

Referenced by FFmpegPresets(), HandleXMLTag(), and ImportPresets().

◆ mPresets

FFmpegPresetMap FFmpegPresets::mPresets
private

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