Audacity 3.2.0
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 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 318 of file ExportFFmpegDialogs.h.

Constructor & Destructor Documentation

◆ FFmpegPresets()

FFmpegPresets::FFmpegPresets ( )

Definition at line 865 of file ExportFFmpegDialogs.cpp.

866{
867 mPreset = NULL;
868 mAbortImport = false;
869
870 XMLFileReader xmlfile;
871 wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
872 xmlfile.Parse(this,xmlFileName.GetFullPath());
873}
FFmpegPreset * mPreset
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, and XMLFileReader::Parse().

Here is the call graph for this function:

◆ ~FFmpegPresets()

FFmpegPresets::~FFmpegPresets ( )

Definition at line 875 of file ExportFFmpegDialogs.cpp.

876{
877 // We're in a destructor! Don't let exceptions out!
878 GuardedCall( [&] {
879 wxFileName xmlFileName{ FileNames::DataDir(), wxT("ffmpeg_presets.xml") };
880 XMLFileWriter writer{
881 xmlFileName.GetFullPath(), XO("Error Saving FFmpeg Presets") };
882 WriteXMLHeader(writer);
883 WriteXML(writer);
884 writer.Commit();
885 } );
886}
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...
#define XO(s)
Definition: Internat.h:31
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(), and XO.

Here is the call graph for this function:

Member Function Documentation

◆ DeletePreset()

void FFmpegPresets::DeletePreset ( wxString &  name)

Definition at line 924 of file ExportFFmpegDialogs.cpp.

925{
926 FFmpegPresetMap::iterator iter = mPresets.find(name);
927 if (iter != mPresets.end())
928 {
929 mPresets.erase(iter);
930 }
931}
const TranslatableString name
Definition: Distortion.cpp:82
FFmpegPresetMap mPresets

References mPresets, and name.

◆ ExportPresets()

void FFmpegPresets::ExportPresets ( wxString &  filename)

Definition at line 902 of file ExportFFmpegDialogs.cpp.

903{
904 GuardedCall( [&] {
905 XMLFileWriter writer{ filename, XO("Error Saving FFmpeg Presets") };
906 WriteXMLHeader(writer);
907 WriteXML(writer);
908 writer.Commit();
909 } );
910}

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

Here is the call graph for this function:

◆ FindPreset()

FFmpegPreset * FFmpegPresets::FindPreset ( wxString &  name)

Definition at line 933 of file ExportFFmpegDialogs.cpp.

934{
935 FFmpegPresetMap::iterator iter = mPresets.find(name);
936 if (iter != mPresets.end())
937 {
938 return &iter->second;
939 }
940
941 return NULL;
942}

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

913{
914 list.clear();
915 FFmpegPresetMap::iterator iter;
916 for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
917 {
918 list.push_back(iter->second.mPresetName);
919 }
920
921 std::sort( list.begin(), list.end() );
922}

References mPresets.

◆ HandleXMLChild()

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

Implements XMLTagHandler.

Definition at line 1214 of file ExportFFmpegDialogs.cpp.

1215{
1216 if (mAbortImport)
1217 {
1218 return NULL;
1219 }
1220
1221 if (tag == "preset")
1222 {
1223 return this;
1224 }
1225 else if (tag == "setctrlstate")
1226 {
1227 return this;
1228 }
1229 return NULL;
1230}

References mAbortImport.

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 1134 of file ExportFFmpegDialogs.cpp.

1135{
1136 if (mAbortImport)
1137 {
1138 return false;
1139 }
1140
1141 if (tag == "ffmpeg_presets")
1142 {
1143 return true;
1144 }
1145
1146 if (tag == "preset")
1147 {
1148 for (auto pair : attrs)
1149 {
1150 auto attr = pair.first;
1151 auto value = pair.second;
1152
1153 if (attr == "name")
1154 {
1155 wxString strValue = value.ToWString();
1156 mPreset = FindPreset(strValue);
1157
1158 if (mPreset)
1159 {
1160 auto query = XO("Replace preset '%s'?").Format( strValue );
1161 int action = AudacityMessageBox(
1162 query,
1163 XO("Confirm Overwrite"),
1164 wxYES_NO | wxCANCEL | wxCENTRE);
1165 if (action == wxCANCEL)
1166 {
1167 mAbortImport = true;
1168 return false;
1169 }
1170 if (action == wxNO)
1171 {
1172 mPreset = NULL;
1173 return false;
1174 }
1175 *mPreset = FFmpegPreset();
1176 }
1177 else
1178 {
1179 mPreset = &mPresets[strValue];
1180 }
1181
1182 mPreset->mPresetName = strValue;
1183 }
1184 }
1185 return true;
1186 }
1187
1188 if (tag == "setctrlstate" && mPreset)
1189 {
1190 long id = -1;
1191 for (auto pair : attrs)
1192 {
1193 auto attr = pair.first;
1194 auto value = pair.second;
1195
1196 if (attr == "id")
1197 {
1198 for (long i = FEFirstID; i < FELastID; i++)
1199 if (!wxStrcmp(FFmpegExportCtrlIDNames[i - FEFirstID], value.ToWString()))
1200 id = i;
1201 }
1202 else if (attr == "state")
1203 {
1204 if (id > FEFirstID && id < FELastID)
1205 mPreset->mControlState[id - FEFirstID] = value.ToWString();
1206 }
1207 }
1208 return true;
1209 }
1210
1211 return false;
1212}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static const wxChar * FFmpegExportCtrlIDNames[]
wxArrayString mControlState
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 888 of file ExportFFmpegDialogs.cpp.

889{
890 mPreset = NULL;
891 mAbortImport = false;
892
893 FFmpegPresetMap savePresets = mPresets;
894
895 XMLFileReader xmlfile;
896 bool success = xmlfile.Parse(this,filename);
897 if (!success || mAbortImport) {
898 mPresets = savePresets;
899 }
900}
std::unordered_map< wxString, FFmpegPreset > FFmpegPresetMap

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

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

946{
948 if (preset)
949 {
950 auto query = XO("Overwrite preset '%s'?").Format(name);
951 int action = AudacityMessageBox(
952 query,
953 XO("Confirm Overwrite"),
954 wxYES_NO | wxCENTRE);
955 if (action == wxNO) return false;
956 }
957 return true;
958}

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

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

References AudacityMessageBox(), format, mPresets, name, preset, and XO.

Here is the call graph for this function:

◆ WriteXML()

void FFmpegPresets::WriteXML ( XMLWriter xmlFile) const

Definition at line 1252 of file ExportFFmpegDialogs.cpp.

1254{
1255 xmlFile.StartTag(wxT("ffmpeg_presets"));
1256 xmlFile.WriteAttr(wxT("version"),wxT("1.0"));
1257 FFmpegPresetMap::const_iterator iter;
1258 for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
1259 {
1260 auto preset = &iter->second;
1261 xmlFile.StartTag(wxT("preset"));
1262 xmlFile.WriteAttr(wxT("name"),preset->mPresetName);
1263 for (long i = FEFirstID + 1; i < FELastID; i++)
1264 {
1265 xmlFile.StartTag(wxT("setctrlstate"));
1266 xmlFile.WriteAttr(wxT("id"),wxString(FFmpegExportCtrlIDNames[i - FEFirstID]));
1267 xmlFile.WriteAttr(wxT("state"),preset->mControlState[i - FEFirstID]);
1268 xmlFile.EndTag(wxT("setctrlstate"));
1269 }
1270 xmlFile.EndTag(wxT("preset"));
1271 }
1272 xmlFile.EndTag(wxT("ffmpeg_presets"));
1273}
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:80
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:37
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:103

References FFmpegExportCtrlIDNames, and preset.

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

Here is the caller graph for this function:

◆ WriteXMLHeader()

void FFmpegPresets::WriteXMLHeader ( XMLWriter xmlFile) const

Definition at line 1232 of file ExportFFmpegDialogs.cpp.

1234{
1235 xmlFile.Write(wxT("<?xml "));
1236 xmlFile.Write(wxT("version=\"1.0\" "));
1237 xmlFile.Write(wxT("standalone=\"no\" "));
1238 xmlFile.Write(wxT("?>\n"));
1239
1240 wxString dtdName = wxT("-//audacityffmpegpreset-1.0.0//DTD//EN");
1241 wxString dtdURI =
1242 wxT("http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd");
1243
1244 xmlFile.Write(wxT("<!DOCTYPE "));
1245 xmlFile.Write(wxT("project "));
1246 xmlFile.Write(wxT("PUBLIC "));
1247 xmlFile.Write(wxT("\"-//audacityffmpegpreset-1.0.0//DTD//EN\" "));
1248 xmlFile.Write(wxT("\"http://audacity.sourceforge.net/xml/audacityffmpegpreset-1.0.0.dtd\" "));
1249 xmlFile.Write(wxT(">\n"));
1250}
virtual void Write(const wxString &data)=0

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

Here is the caller graph for this function:

Member Data Documentation

◆ mAbortImport

bool FFmpegPresets::mAbortImport
private

Definition at line 343 of file ExportFFmpegDialogs.h.

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

◆ mPreset

FFmpegPreset* FFmpegPresets::mPreset
private

Definition at line 342 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: