Audacity  3.0.3
Public Member Functions | Private Attributes | List of all members
FFmpegPresets Class Reference

#include <ExportFFmpegDialogs.h>

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

Public Member Functions

 FFmpegPresets ()
 
 ~FFmpegPresets ()
 
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 wxChar *tag, const wxChar **attrs) override
 
XMLTagHandlerHandleXMLChild (const wxChar *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 void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Detailed Description

Definition at line 317 of file ExportFFmpegDialogs.h.

Constructor & Destructor Documentation

◆ FFmpegPresets()

FFmpegPresets::FFmpegPresets ( )

Definition at line 876 of file ExportFFmpegDialogs.cpp.

877 {
878  mPreset = NULL;
879  mAbortImport = false;
880 
881  XMLFileReader xmlfile;
882  wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
883  xmlfile.Parse(this,xmlFileName.GetFullPath());
884 }

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

Here is the call graph for this function:

◆ ~FFmpegPresets()

FFmpegPresets::~FFmpegPresets ( )

Definition at line 886 of file ExportFFmpegDialogs.cpp.

887 {
888  // We're in a destructor! Don't let exceptions out!
889  GuardedCall( [&] {
890  wxFileName xmlFileName{ FileNames::DataDir(), wxT("ffmpeg_presets.xml") };
891  XMLFileWriter writer{
892  xmlFileName.GetFullPath(), XO("Error Saving FFmpeg Presets") };
893  WriteXMLHeader(writer);
894  WriteXML(writer);
895  writer.Commit();
896  } );
897 }

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

Here is the call graph for this function:

Member Function Documentation

◆ DeletePreset()

void FFmpegPresets::DeletePreset ( wxString &  name)

Definition at line 935 of file ExportFFmpegDialogs.cpp.

936 {
937  FFmpegPresetMap::iterator iter = mPresets.find(name);
938  if (iter != mPresets.end())
939  {
940  mPresets.erase(iter);
941  }
942 }

References mPresets, and name.

◆ ExportPresets()

void FFmpegPresets::ExportPresets ( wxString &  filename)

Definition at line 913 of file ExportFFmpegDialogs.cpp.

914 {
915  GuardedCall( [&] {
916  XMLFileWriter writer{ filename, XO("Error Saving FFmpeg Presets") };
917  WriteXMLHeader(writer);
918  WriteXML(writer);
919  writer.Commit();
920  } );
921 }

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

Here is the call graph for this function:

◆ FindPreset()

FFmpegPreset * FFmpegPresets::FindPreset ( wxString &  name)

Definition at line 944 of file ExportFFmpegDialogs.cpp.

945 {
946  FFmpegPresetMap::iterator iter = mPresets.find(name);
947  if (iter != mPresets.end())
948  {
949  return &iter->second;
950  }
951 
952  return NULL;
953 }

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 923 of file ExportFFmpegDialogs.cpp.

924 {
925  list.clear();
926  FFmpegPresetMap::iterator iter;
927  for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
928  {
929  list.push_back(iter->second.mPresetName);
930  }
931 
932  std::sort( list.begin(), list.end() );
933 }

References mPresets.

◆ HandleXMLChild()

XMLTagHandler * FFmpegPresets::HandleXMLChild ( const wxChar *  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 1228 of file ExportFFmpegDialogs.cpp.

1229 {
1230  if (mAbortImport)
1231  {
1232  return NULL;
1233  }
1234 
1235  if (!wxStrcmp(tag, wxT("preset")))
1236  {
1237  return this;
1238  }
1239  else if (!wxStrcmp(tag, wxT("setctrlstate")))
1240  {
1241  return this;
1242  }
1243  return NULL;
1244 }

References mAbortImport.

◆ HandleXMLTag()

bool FFmpegPresets::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 1145 of file ExportFFmpegDialogs.cpp.

1146 {
1147  if (mAbortImport)
1148  {
1149  return false;
1150  }
1151 
1152  if (!wxStrcmp(tag,wxT("ffmpeg_presets")))
1153  {
1154  return true;
1155  }
1156 
1157  if (!wxStrcmp(tag,wxT("preset")))
1158  {
1159  while (*attrs)
1160  {
1161  const wxChar *attr = *attrs++;
1162  wxString value = *attrs++;
1163 
1164  if (!value)
1165  break;
1166 
1167  if (!wxStrcmp(attr,wxT("name")))
1168  {
1169  mPreset = FindPreset(value);
1170  if (mPreset)
1171  {
1172  auto query = XO("Replace preset '%s'?").Format( value );
1173  int action = AudacityMessageBox(
1174  query,
1175  XO("Confirm Overwrite"),
1176  wxYES_NO | wxCANCEL | wxCENTRE);
1177  if (action == wxCANCEL)
1178  {
1179  mAbortImport = true;
1180  return false;
1181  }
1182  if (action == wxNO)
1183  {
1184  mPreset = NULL;
1185  return false;
1186  }
1187  *mPreset = FFmpegPreset();
1188  }
1189  else
1190  {
1191  mPreset = &mPresets[value];
1192  }
1193  mPreset->mPresetName = value;
1194  }
1195  }
1196  return true;
1197  }
1198 
1199  if (!wxStrcmp(tag,wxT("setctrlstate")) && mPreset)
1200  {
1201  long id = -1;
1202  while (*attrs)
1203  {
1204  const wxChar *attr = *attrs++;
1205  const wxChar *value = *attrs++;
1206 
1207  if (!value)
1208  break;
1209 
1210  if (!wxStrcmp(attr,wxT("id")))
1211  {
1212  for (long i = FEFirstID; i < FELastID; i++)
1213  if (!wxStrcmp(FFmpegExportCtrlIDNames[i - FEFirstID],value))
1214  id = i;
1215  }
1216  else if (!wxStrcmp(attr,wxT("state")))
1217  {
1218  if (id > FEFirstID && id < FELastID)
1219  mPreset->mControlState[id - FEFirstID] = wxString(value);
1220  }
1221  }
1222  return true;
1223  }
1224 
1225  return false;
1226 }

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 899 of file ExportFFmpegDialogs.cpp.

900 {
901  mPreset = NULL;
902  mAbortImport = false;
903 
904  FFmpegPresetMap savePresets = mPresets;
905 
906  XMLFileReader xmlfile;
907  bool success = xmlfile.Parse(this,filename);
908  if (!success || mAbortImport) {
909  mPresets = savePresets;
910  }
911 }

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 1066 of file ExportFFmpegDialogs.cpp.

1067 {
1068  FFmpegPreset *preset = FindPreset(name);
1069  if (!preset)
1070  {
1071  AudacityMessageBox( XO("Preset '%s' does not exist." ).Format(name));
1072  return;
1073  }
1074 
1075  wxListBox *lb;
1076  wxSpinCtrl *sc;
1077  wxTextCtrl *tc;
1078  wxCheckBox *cb;
1079  wxChoice *ch;
1080 
1081  for (int id = FEFirstID; id < FELastID; id++)
1082  {
1083  wxWindow *wnd = parent->FindWindowById(id,parent);
1084  if (wnd != NULL)
1085  {
1086  wxString readstr;
1087  long readlong;
1088  bool readbool;
1089  switch(id)
1090  {
1091  // Listbox
1092  case FEFormatID:
1093  case FECodecID:
1094  lb = dynamic_cast<wxListBox*>(wnd);
1095  readstr = preset->mControlState[id - FEFirstID];
1096  readlong = lb->FindString(readstr);
1097  if (readlong > -1) lb->Select(readlong);
1098  break;
1099  // Spin control
1100  case FEBitrateID:
1101  case FEQualityID:
1102  case FESampleRateID:
1103  case FECutoffID:
1104  case FEFrameSizeID:
1105  case FEBufSizeID:
1106  case FECompLevelID:
1107  case FELPCCoeffsID:
1108  case FEMinPredID:
1109  case FEMaxPredID:
1110  case FEMinPartOrderID:
1111  case FEMaxPartOrderID:
1112  case FEMuxRateID:
1113  case FEPacketSizeID:
1114  sc = dynamic_cast<wxSpinCtrl*>(wnd);
1115  preset->mControlState[id - FEFirstID].ToLong(&readlong);
1116  sc->SetValue(readlong);
1117  break;
1118  // Text control
1119  case FELanguageID:
1120  case FETagID:
1121  tc = dynamic_cast<wxTextCtrl*>(wnd);
1122  tc->SetValue(preset->mControlState[id - FEFirstID]);
1123  break;
1124  // Choice
1125  case FEProfileID:
1126  case FEPredOrderID:
1127  ch = dynamic_cast<wxChoice*>(wnd);
1128  preset->mControlState[id - FEFirstID].ToLong(&readlong);
1129  if (readlong > -1) ch->Select(readlong);
1130  break;
1131  // Check box
1132  case FEUseLPCID:
1133  case FEBitReservoirID:
1134  case FEVariableBlockLenID:
1135  cb = dynamic_cast<wxCheckBox*>(wnd);
1136  preset->mControlState[id - FEFirstID].ToLong(&readlong);
1137  if (readlong) readbool = true; else readbool = false;
1138  cb->SetValue(readbool);
1139  break;
1140  }
1141  }
1142  }
1143 }

References AudacityMessageBox(), FindPreset(), FFmpegPreset::mControlState, name, and XO.

Here is the call graph for this function:

◆ OverwriteIsOk()

bool FFmpegPresets::OverwriteIsOk ( wxString &  name)

Definition at line 956 of file ExportFFmpegDialogs.cpp.

957 {
958  FFmpegPreset *preset = FindPreset(name);
959  if (preset)
960  {
961  auto query = XO("Overwrite preset '%s'?").Format(name);
962  int action = AudacityMessageBox(
963  query,
964  XO("Confirm Overwrite"),
965  wxYES_NO | wxCENTRE);
966  if (action == wxNO) return false;
967  }
968  return true;
969 }

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

Here is the call graph for this function:

◆ SavePreset()

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

Definition at line 972 of file ExportFFmpegDialogs.cpp.

973 {
974  wxString format;
975  wxString codec;
976  FFmpegPreset *preset;
977 
978  {
979  wxWindow *wnd;
980  wxListBox *lb;
981 
982  wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FEFormatID,parent);
983  lb = dynamic_cast<wxListBox*>(wnd);
984  if (lb->GetSelection() < 0)
985  {
986  AudacityMessageBox( XO("Please select format before saving a profile") );
987  return false;
988  }
989  format = lb->GetStringSelection();
990 
991  wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FECodecID,parent);
992  lb = dynamic_cast<wxListBox*>(wnd);
993  if (lb->GetSelection() < 0)
994  {
995  /* i18n-hint: "codec" is short for a "coder-decoder" algorithm */
996  AudacityMessageBox( XO("Please select codec before saving a profile") );
997  return false;
998  }
999  codec = lb->GetStringSelection();
1000  }
1001 
1002  preset = &mPresets[name];
1003  preset->mPresetName = name;
1004 
1005  wxSpinCtrl *sc;
1006  wxTextCtrl *tc;
1007  wxCheckBox *cb;
1008  wxChoice *ch;
1009 
1010  for (int id = FEFirstID; id < FELastID; id++)
1011  {
1012  wxWindow *wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(id,parent);
1013  if (wnd != NULL)
1014  {
1015  switch(id)
1016  {
1017  case FEFormatID:
1018  preset->mControlState[id - FEFirstID] = format;
1019  break;
1020  case FECodecID:
1021  preset->mControlState[id - FEFirstID] = codec;
1022  break;
1023  // Spin control
1024  case FEBitrateID:
1025  case FEQualityID:
1026  case FESampleRateID:
1027  case FECutoffID:
1028  case FEFrameSizeID:
1029  case FEBufSizeID:
1030  case FECompLevelID:
1031  case FELPCCoeffsID:
1032  case FEMinPredID:
1033  case FEMaxPredID:
1034  case FEMinPartOrderID:
1035  case FEMaxPartOrderID:
1036  case FEMuxRateID:
1037  case FEPacketSizeID:
1038  sc = dynamic_cast<wxSpinCtrl*>(wnd);
1039  preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),sc->GetValue());
1040  break;
1041  // Text control
1042  case FELanguageID:
1043  case FETagID:
1044  tc = dynamic_cast<wxTextCtrl*>(wnd);
1045  preset->mControlState[id - FEFirstID] = tc->GetValue();
1046  break;
1047  // Choice
1048  case FEProfileID:
1049  case FEPredOrderID:
1050  ch = dynamic_cast<wxChoice*>(wnd);
1051  preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),ch->GetSelection());
1052  break;
1053  // Check box
1054  case FEUseLPCID:
1055  case FEBitReservoirID:
1056  case FEVariableBlockLenID:
1057  cb = dynamic_cast<wxCheckBox*>(wnd);
1058  preset->mControlState[id - FEFirstID] = wxString::Format(wxT("%d"),cb->GetValue());
1059  break;
1060  }
1061  }
1062  }
1063  return true;
1064 }

References AudacityMessageBox(), format, FFmpegPreset::mControlState, FFmpegPreset::mPresetName, mPresets, name, and XO.

Here is the call graph for this function:

◆ WriteXML()

void FFmpegPresets::WriteXML ( XMLWriter xmlFile) const

Definition at line 1266 of file ExportFFmpegDialogs.cpp.

1268 {
1269  xmlFile.StartTag(wxT("ffmpeg_presets"));
1270  xmlFile.WriteAttr(wxT("version"),wxT("1.0"));
1271  FFmpegPresetMap::const_iterator iter;
1272  for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
1273  {
1274  auto preset = &iter->second;
1275  xmlFile.StartTag(wxT("preset"));
1276  xmlFile.WriteAttr(wxT("name"),preset->mPresetName);
1277  for (long i = FEFirstID + 1; i < FELastID; i++)
1278  {
1279  xmlFile.StartTag(wxT("setctrlstate"));
1280  xmlFile.WriteAttr(wxT("id"),wxString(FFmpegExportCtrlIDNames[i - FEFirstID]));
1281  xmlFile.WriteAttr(wxT("state"),preset->mControlState[i - FEFirstID]);
1282  xmlFile.EndTag(wxT("setctrlstate"));
1283  }
1284  xmlFile.EndTag(wxT("preset"));
1285  }
1286  xmlFile.EndTag(wxT("ffmpeg_presets"));
1287 }

References FFmpegExportCtrlIDNames.

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

Here is the caller graph for this function:

◆ WriteXMLHeader()

void FFmpegPresets::WriteXMLHeader ( XMLWriter xmlFile) const

Definition at line 1246 of file ExportFFmpegDialogs.cpp.

1248 {
1249  xmlFile.Write(wxT("<?xml "));
1250  xmlFile.Write(wxT("version=\"1.0\" "));
1251  xmlFile.Write(wxT("standalone=\"no\" "));
1252  xmlFile.Write(wxT("?>\n"));
1253 
1254  wxString dtdName = wxT("-//audacityffmpegpreset-1.0.0//DTD//EN");
1255  wxString dtdURI =
1256  wxT("http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd");
1257 
1258  xmlFile.Write(wxT("<!DOCTYPE "));
1259  xmlFile.Write(wxT("project "));
1260  xmlFile.Write(wxT("PUBLIC "));
1261  xmlFile.Write(wxT("\"-//audacityffmpegpreset-1.0.0//DTD//EN\" "));
1262  xmlFile.Write(wxT("\"http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd\" "));
1263  xmlFile.Write(wxT(">\n"));
1264 }

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

Here is the caller graph for this function:

Member Data Documentation

◆ mAbortImport

bool FFmpegPresets::mAbortImport
private

Definition at line 342 of file ExportFFmpegDialogs.h.

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

◆ mPreset

FFmpegPreset* FFmpegPresets::mPreset
private

Definition at line 341 of file ExportFFmpegDialogs.h.

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

◆ mPresets

FFmpegPresetMap FFmpegPresets::mPresets
private

The documentation for this class was generated from the following files:
XMLWriter::EndTag
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:99
FFmpegPresets::WriteXML
void WriteXML(XMLWriter &xmlFile) const
Definition: ExportFFmpegDialogs.cpp:1266
GuardedCall
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), std::function< void(AudacityException *)> delayedHandler=DefaultDelayedHandlerAction{})
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
Definition: AudacityException.h:202
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
FFmpegPresets::mPreset
FFmpegPreset * mPreset
Definition: ExportFFmpegDialogs.h:341
FFmpegPresets::mPresets
FFmpegPresetMap mPresets
Definition: ExportFFmpegDialogs.h:340
Format
Abstract base class used in importing a file.
XO
#define XO(s)
Definition: Internat.h:31
FFmpegPreset::mPresetName
wxString mPresetName
Definition: ExportFFmpegDialogs.h:310
XMLFileReader::Parse
bool Parse(XMLTagHandler *baseHandler, const FilePath &fname)
Definition: XMLFileReader.cpp:42
FileNames::DataDir
FILES_API FilePath DataDir()
Audacity user data directory.
FFmpegPresetMap
std::unordered_map< wxString, FFmpegPreset > FFmpegPresetMap
Definition: ExportFFmpegDialogs.h:315
FFmpegExportCtrlIDNames
static const wxChar * FFmpegExportCtrlIDNames[]
Definition: ExportFFmpegDialogs.cpp:130
name
const TranslatableString name
Definition: Distortion.cpp:98
format
int format
Definition: ExportPCM.cpp:56
FFmpegPresets::WriteXMLHeader
void WriteXMLHeader(XMLWriter &xmlFile) const
Definition: ExportFFmpegDialogs.cpp:1246
FFmpegPreset
Definition: ExportFFmpegDialogs.h:305
FFmpegPresets::FindPreset
FFmpegPreset * FindPreset(wxString &name)
Definition: ExportFFmpegDialogs.cpp:944
XMLFileReader
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:18
XMLWriter::Write
virtual void Write(const wxString &data)=0
XMLFileWriter
Wrapper to output XML data to files.
Definition: XMLWriter.h:81
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
FFmpegPreset::mControlState
wxArrayString mControlState
Definition: ExportFFmpegDialogs.h:311
XMLWriter::StartTag
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:76
FFmpegPresets::mAbortImport
bool mAbortImport
Definition: ExportFFmpegDialogs.h:342