mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 00:58:37 +02:00
Fix for bug #1142
This commit is contained in:
parent
9c4eb4943f
commit
6c73bab41e
@ -457,9 +457,8 @@ void ExportFFmpegCustomOptions::OnOpen(wxCommandEvent & WXUNUSED(evt))
|
|||||||
od.ShowModal();
|
od.ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
FFmpegPreset::FFmpegPreset(wxString &name)
|
FFmpegPreset::FFmpegPreset()
|
||||||
{
|
{
|
||||||
mPresetName = name;
|
|
||||||
mControlState.SetCount(FELastID - FEFirstID);
|
mControlState.SetCount(FELastID - FEFirstID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,13 +466,11 @@ FFmpegPreset::~FFmpegPreset()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WX_DEFINE_LIST(FFmpegPresetList);
|
|
||||||
|
|
||||||
|
|
||||||
FFmpegPresets::FFmpegPresets()
|
FFmpegPresets::FFmpegPresets()
|
||||||
{
|
{
|
||||||
mPresets = new FFmpegPresetList();
|
mPreset = NULL;
|
||||||
mPresets->DeleteContents(true);
|
mAbortImport = false;
|
||||||
|
|
||||||
XMLFileReader xmlfile;
|
XMLFileReader xmlfile;
|
||||||
wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
|
wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
|
||||||
xmlfile.Parse(this,xmlFileName.GetFullPath());
|
xmlfile.Parse(this,xmlFileName.GetFullPath());
|
||||||
@ -487,15 +484,20 @@ FFmpegPresets::~FFmpegPresets()
|
|||||||
writer.Open(xmlFileName.GetFullPath(),wxT("wb"));
|
writer.Open(xmlFileName.GetFullPath(),wxT("wb"));
|
||||||
WriteXMLHeader(writer);
|
WriteXMLHeader(writer);
|
||||||
WriteXML(writer);
|
WriteXML(writer);
|
||||||
delete mPresets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpegPresets::ImportPresets(wxString &filename)
|
void FFmpegPresets::ImportPresets(wxString &filename)
|
||||||
{
|
{
|
||||||
mPreset = NULL;
|
mPreset = NULL;
|
||||||
|
mAbortImport = false;
|
||||||
|
|
||||||
|
FFmpegPresetMap savePresets = mPresets;
|
||||||
|
|
||||||
XMLFileReader xmlfile;
|
XMLFileReader xmlfile;
|
||||||
xmlfile.Parse(this,filename);
|
bool success = xmlfile.Parse(this,filename);
|
||||||
|
if (!success || mAbortImport) {
|
||||||
|
mPresets = savePresets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpegPresets::ExportPresets(wxString &filename)
|
void FFmpegPresets::ExportPresets(wxString &filename)
|
||||||
@ -510,40 +512,35 @@ void FFmpegPresets::ExportPresets(wxString &filename)
|
|||||||
wxArrayString *FFmpegPresets::GetPresetList()
|
wxArrayString *FFmpegPresets::GetPresetList()
|
||||||
{
|
{
|
||||||
wxArrayString *list = new wxArrayString();
|
wxArrayString *list = new wxArrayString();
|
||||||
FFmpegPresetList::iterator iter;
|
FFmpegPresetMap::iterator iter;
|
||||||
for (iter = mPresets->begin(); iter != mPresets->end(); ++iter)
|
for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
|
||||||
{
|
{
|
||||||
FFmpegPreset *preset = *iter;
|
list->Add(iter->second.mPresetName);
|
||||||
list->Add(preset->mPresetName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list->Sort();
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpegPresets::DeletePreset(wxString &name)
|
void FFmpegPresets::DeletePreset(wxString &name)
|
||||||
{
|
{
|
||||||
FFmpegPresetList::iterator iter;
|
FFmpegPresetMap::iterator iter = mPresets.find(name);
|
||||||
for (iter = mPresets->begin(); iter != mPresets->end(); ++iter)
|
if (iter != mPresets.end())
|
||||||
{
|
{
|
||||||
FFmpegPreset *preset = *iter;
|
mPresets.erase(iter);
|
||||||
if (!preset->mPresetName.CmpNoCase(name))
|
|
||||||
{
|
|
||||||
mPresets->erase(iter);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FFmpegPreset *FFmpegPresets::FindPreset(wxString &name)
|
FFmpegPreset *FFmpegPresets::FindPreset(wxString &name)
|
||||||
{
|
{
|
||||||
FFmpegPreset *preset = NULL;
|
FFmpegPresetMap::iterator iter = mPresets.find(name);
|
||||||
FFmpegPresetList::iterator iter;
|
if (iter != mPresets.end())
|
||||||
for (iter = mPresets->begin(); iter != mPresets->end(); ++iter)
|
|
||||||
{
|
{
|
||||||
FFmpegPreset *current = *iter;
|
return &iter->second;
|
||||||
if (!current->mPresetName.CmpNoCase(name))
|
|
||||||
preset = current;
|
|
||||||
}
|
}
|
||||||
return preset;
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FFmpegPresets::SavePreset(ExportFFmpegOptions *parent, wxString &name)
|
void FFmpegPresets::SavePreset(ExportFFmpegOptions *parent, wxString &name)
|
||||||
@ -557,32 +554,30 @@ void FFmpegPresets::SavePreset(ExportFFmpegOptions *parent, wxString &name)
|
|||||||
int action = wxMessageBox(query,_("Confirm Overwrite"),wxYES_NO | wxCENTRE);
|
int action = wxMessageBox(query,_("Confirm Overwrite"),wxYES_NO | wxCENTRE);
|
||||||
if (action == wxNO) return;
|
if (action == wxNO) return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
wxWindow *wnd;
|
||||||
|
wxListBox *lb;
|
||||||
|
|
||||||
|
wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FEFormatID,parent);
|
||||||
|
lb = dynamic_cast<wxListBox*>(wnd);
|
||||||
|
if (lb->GetSelection() < 0)
|
||||||
{
|
{
|
||||||
wxWindow *wnd;
|
wxMessageBox(_("Please select format before saving a profile"));
|
||||||
wxListBox *lb;
|
return;
|
||||||
|
|
||||||
wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FEFormatID,parent);
|
|
||||||
lb = dynamic_cast<wxListBox*>(wnd);
|
|
||||||
if (lb->GetSelection() < 0)
|
|
||||||
{
|
|
||||||
wxMessageBox(_("Please select format before saving a profile"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
format = lb->GetStringSelection();
|
|
||||||
|
|
||||||
wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FECodecID,parent);
|
|
||||||
lb = dynamic_cast<wxListBox*>(wnd);
|
|
||||||
if (lb->GetSelection() < 0)
|
|
||||||
{
|
|
||||||
wxMessageBox(_("Please select codec before saving a profile"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
codec = lb->GetStringSelection();
|
|
||||||
|
|
||||||
preset = new FFmpegPreset(name);
|
|
||||||
mPresets->push_front(preset);
|
|
||||||
}
|
}
|
||||||
|
format = lb->GetStringSelection();
|
||||||
|
|
||||||
|
wnd = dynamic_cast<wxWindow*>(parent)->FindWindowById(FECodecID,parent);
|
||||||
|
lb = dynamic_cast<wxListBox*>(wnd);
|
||||||
|
if (lb->GetSelection() < 0)
|
||||||
|
{
|
||||||
|
wxMessageBox(_("Please select codec before saving a profile"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
codec = lb->GetStringSelection();
|
||||||
|
|
||||||
|
preset = &mPresets[name];
|
||||||
|
preset->mPresetName = name;
|
||||||
|
|
||||||
wxSpinCtrl *sc;
|
wxSpinCtrl *sc;
|
||||||
wxTextCtrl *tc;
|
wxTextCtrl *tc;
|
||||||
@ -725,11 +720,17 @@ void FFmpegPresets::LoadPreset(ExportFFmpegOptions *parent, wxString &name)
|
|||||||
|
|
||||||
bool FFmpegPresets::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
bool FFmpegPresets::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
||||||
{
|
{
|
||||||
|
if (mAbortImport)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wxStrcmp(tag,wxT("ffmpeg_presets")))
|
if (!wxStrcmp(tag,wxT("ffmpeg_presets")))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (!wxStrcmp(tag,wxT("preset")))
|
|
||||||
|
if (!wxStrcmp(tag,wxT("preset")))
|
||||||
{
|
{
|
||||||
while (*attrs)
|
while (*attrs)
|
||||||
{
|
{
|
||||||
@ -742,16 +743,33 @@ bool FFmpegPresets::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
if (!wxStrcmp(attr,wxT("name")))
|
if (!wxStrcmp(attr,wxT("name")))
|
||||||
{
|
{
|
||||||
mPreset = FindPreset(value);
|
mPreset = FindPreset(value);
|
||||||
if (!mPreset)
|
if (mPreset)
|
||||||
{
|
{
|
||||||
mPreset = new FFmpegPreset(value);
|
wxString query = wxString::Format(_("Replace preset '%s'?"), value.c_str());
|
||||||
mPresets->push_front(mPreset);
|
int action = wxMessageBox(query, _("Confirm Overwrite"), wxYES_NO | wxCANCEL | wxCENTRE);
|
||||||
|
if (action == wxCANCEL)
|
||||||
|
{
|
||||||
|
mAbortImport = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (action == wxNO)
|
||||||
|
{
|
||||||
|
mPreset = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*mPreset = FFmpegPreset();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPreset = &mPresets[value];
|
||||||
|
}
|
||||||
|
mPreset->mPresetName = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (!wxStrcmp(tag,wxT("setctrlstate")) && mPreset)
|
|
||||||
|
if (!wxStrcmp(tag,wxT("setctrlstate")) && mPreset)
|
||||||
{
|
{
|
||||||
long id = -1;
|
long id = -1;
|
||||||
while (*attrs)
|
while (*attrs)
|
||||||
@ -776,11 +794,17 @@ bool FFmpegPresets::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLTagHandler *FFmpegPresets::HandleXMLChild(const wxChar *tag)
|
XMLTagHandler *FFmpegPresets::HandleXMLChild(const wxChar *tag)
|
||||||
{
|
{
|
||||||
|
if (mAbortImport)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wxStrcmp(tag, wxT("preset")))
|
if (!wxStrcmp(tag, wxT("preset")))
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
@ -815,10 +839,10 @@ void FFmpegPresets::WriteXML(XMLWriter &xmlFile)
|
|||||||
{
|
{
|
||||||
xmlFile.StartTag(wxT("ffmpeg_presets"));
|
xmlFile.StartTag(wxT("ffmpeg_presets"));
|
||||||
xmlFile.WriteAttr(wxT("version"),wxT("1.0"));
|
xmlFile.WriteAttr(wxT("version"),wxT("1.0"));
|
||||||
FFmpegPresetList::iterator iter;
|
FFmpegPresetMap::iterator iter;
|
||||||
for (iter = mPresets->begin(); iter != mPresets->end(); ++iter)
|
for (iter = mPresets.begin(); iter != mPresets.end(); ++iter)
|
||||||
{
|
{
|
||||||
FFmpegPreset *preset = *iter;
|
FFmpegPreset *preset = &iter->second;
|
||||||
xmlFile.StartTag(wxT("preset"));
|
xmlFile.StartTag(wxT("preset"));
|
||||||
xmlFile.WriteAttr(wxT("name"),preset->mPresetName);
|
xmlFile.WriteAttr(wxT("name"),preset->mPresetName);
|
||||||
for (long i = FEFirstID + 1; i < FELastID; i++)
|
for (long i = FEFirstID + 1; i < FELastID; i++)
|
||||||
|
@ -16,6 +16,7 @@ LRN
|
|||||||
#include "../Audacity.h" // keep ffmpeg before wx because they interact
|
#include "../Audacity.h" // keep ffmpeg before wx because they interact
|
||||||
#include "../FFmpeg.h" // and Audacity.h before FFmpeg for config*.h
|
#include "../FFmpeg.h" // and Audacity.h before FFmpeg for config*.h
|
||||||
|
|
||||||
|
#include <wx/hashmap.h>
|
||||||
#include <wx/listimpl.cpp>
|
#include <wx/listimpl.cpp>
|
||||||
#include "../xml/XMLFileReader.h"
|
#include "../xml/XMLFileReader.h"
|
||||||
#include "../FileNames.h"
|
#include "../FileNames.h"
|
||||||
@ -306,7 +307,7 @@ private:
|
|||||||
class FFmpegPreset
|
class FFmpegPreset
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FFmpegPreset(wxString &name);
|
FFmpegPreset();
|
||||||
~FFmpegPreset();
|
~FFmpegPreset();
|
||||||
|
|
||||||
wxString mPresetName;
|
wxString mPresetName;
|
||||||
@ -314,7 +315,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WX_DECLARE_LIST(FFmpegPreset,FFmpegPresetList);
|
WX_DECLARE_STRING_HASH_MAP(FFmpegPreset, FFmpegPresetMap);
|
||||||
|
|
||||||
class FFmpegPresets : XMLTagHandler
|
class FFmpegPresets : XMLTagHandler
|
||||||
{
|
{
|
||||||
@ -338,8 +339,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
FFmpegPresetList *mPresets;
|
FFmpegPresetMap mPresets;
|
||||||
FFmpegPreset *mPreset; // valid during XML parsing only
|
FFmpegPreset *mPreset; // valid during XML parsing only
|
||||||
|
bool mAbortImport; // tells importer to ignore the rest of the import
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user