mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 17:09:26 +02:00
Exception safety in: batch processing
This commit is contained in:
parent
abbe9276f0
commit
464828d88f
@ -328,7 +328,7 @@ wxString BatchCommands::PromptForParamsFor(const wxString & command, const wxStr
|
|||||||
|
|
||||||
wxString res = params;
|
wxString res = params;
|
||||||
|
|
||||||
EffectManager::Get().SetBatchProcessing(ID, true);
|
auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
|
||||||
|
|
||||||
if (EffectManager::Get().SetEffectParameters(ID, params))
|
if (EffectManager::Get().SetEffectParameters(ID, params))
|
||||||
{
|
{
|
||||||
@ -338,8 +338,6 @@ wxString BatchCommands::PromptForParamsFor(const wxString & command, const wxStr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectManager::Get().SetBatchProcessing(ID, false);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,7 +604,7 @@ bool BatchCommands::ApplyEffectCommand(const PluginID & ID, const wxString & com
|
|||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
EffectManager::Get().SetBatchProcessing(ID, true);
|
auto cleanup = EffectManager::Get().SetBatchProcessing(ID);
|
||||||
|
|
||||||
// transfer the parameters to the effect...
|
// transfer the parameters to the effect...
|
||||||
if (EffectManager::Get().SetEffectParameters(ID, params))
|
if (EffectManager::Get().SetEffectParameters(ID, params))
|
||||||
@ -617,8 +615,6 @@ bool BatchCommands::ApplyEffectCommand(const PluginID & ID, const wxString & com
|
|||||||
AudacityProject::OnEffectFlags::kDontRepeatLast);
|
AudacityProject::OnEffectFlags::kDontRepeatLast);
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectManager::Get().SetBatchProcessing(ID, false);
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,17 +648,15 @@ bool BatchCommands::ApplyCommand(const wxString & command, const wxString & para
|
|||||||
bool BatchCommands::ApplyCommandInBatchMode(const wxString & command, const wxString ¶ms)
|
bool BatchCommands::ApplyCommandInBatchMode(const wxString & command, const wxString ¶ms)
|
||||||
{
|
{
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = GetActiveProject();
|
||||||
bool rc;
|
|
||||||
|
|
||||||
// enter batch mode...
|
// enter batch mode...
|
||||||
bool prevShowMode = project->GetShowId3Dialog();
|
bool prevShowMode = project->GetShowId3Dialog();
|
||||||
|
auto cleanup = finally( [&] {
|
||||||
|
// exit batch mode...
|
||||||
|
project->SetShowId3Dialog(prevShowMode);
|
||||||
|
} );
|
||||||
|
|
||||||
rc = ApplyCommand( command, params );
|
return ApplyCommand( command, params );
|
||||||
|
|
||||||
// exit batch mode...
|
|
||||||
project->SetShowId3Dialog(prevShowMode);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyChain returns true on success, false otherwise.
|
// ApplyChain returns true on success, false otherwise.
|
||||||
@ -670,29 +664,31 @@ bool BatchCommands::ApplyCommandInBatchMode(const wxString & command, const wxSt
|
|||||||
bool BatchCommands::ApplyChain(const wxString & filename)
|
bool BatchCommands::ApplyChain(const wxString & filename)
|
||||||
{
|
{
|
||||||
mFileName = filename;
|
mFileName = filename;
|
||||||
unsigned int i;
|
|
||||||
bool res = true;
|
AudacityProject *proj = GetActiveProject();
|
||||||
|
bool res = false;
|
||||||
|
auto cleanup = finally( [&] {
|
||||||
|
if (!res) {
|
||||||
|
if(proj) {
|
||||||
|
// Chain failed or was cancelled; revert to the previous state
|
||||||
|
proj->RollbackState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
mAbort = false;
|
mAbort = false;
|
||||||
|
|
||||||
for (i = 0; i < mCommandChain.GetCount(); i++) {
|
size_t i = 0;
|
||||||
if (!ApplyCommandInBatchMode(mCommandChain[i], mParamsChain[i]) || mAbort) {
|
for (; i < mCommandChain.GetCount(); i++) {
|
||||||
res = false;
|
if (!ApplyCommandInBatchMode(mCommandChain[i], mParamsChain[i]) || mAbort)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = (i == mCommandChain.GetCount());
|
||||||
|
if (!res)
|
||||||
|
return false;
|
||||||
|
|
||||||
mFileName.Empty();
|
mFileName.Empty();
|
||||||
AudacityProject *proj = GetActiveProject();
|
|
||||||
|
|
||||||
if (!res)
|
|
||||||
{
|
|
||||||
if(proj) {
|
|
||||||
// Chain failed or was cancelled; revert to the previous state
|
|
||||||
proj->RollbackState();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chain was successfully applied; save the NEW project state
|
// Chain was successfully applied; save the NEW project state
|
||||||
wxString longDesc, shortDesc;
|
wxString longDesc, shortDesc;
|
||||||
|
@ -91,7 +91,22 @@ public:
|
|||||||
bool HasPresets(const PluginID & ID);
|
bool HasPresets(const PluginID & ID);
|
||||||
wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
|
wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
|
||||||
wxString GetDefaultPreset(const PluginID & ID);
|
wxString GetDefaultPreset(const PluginID & ID);
|
||||||
|
|
||||||
|
private:
|
||||||
void SetBatchProcessing(const PluginID & ID, bool start);
|
void SetBatchProcessing(const PluginID & ID, bool start);
|
||||||
|
struct UnsetBatchProcessing {
|
||||||
|
PluginID mID;
|
||||||
|
void operator () (EffectManager *p) const
|
||||||
|
{ if(p) p->SetBatchProcessing(mID, false); }
|
||||||
|
};
|
||||||
|
using BatchProcessingScope =
|
||||||
|
std::unique_ptr< EffectManager, UnsetBatchProcessing >;
|
||||||
|
public:
|
||||||
|
// RAII for the function above
|
||||||
|
BatchProcessingScope SetBatchProcessing(const PluginID &ID)
|
||||||
|
{
|
||||||
|
SetBatchProcessing(ID, true); return BatchProcessingScope{ this, {ID} };
|
||||||
|
}
|
||||||
|
|
||||||
/** Allow effects to disable saving the state at run time */
|
/** Allow effects to disable saving the state at run time */
|
||||||
void SetSkipStateFlag(bool flag);
|
void SetSkipStateFlag(bool flag);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user