Bug2567: Macros using cut and paste should work on multiple files

This commit is contained in:
Paul Licameli 2020-12-01 23:03:23 -05:00
parent e343bf556b
commit 105558c7bf
3 changed files with 25 additions and 1 deletions

View File

@ -37,6 +37,7 @@
#include <wx/imaglist.h>
#include <wx/settings.h>
#include "Clipboard.h"
#include "ShuttleGui.h"
#include "Menus.h"
#include "Prefs.h"
@ -433,6 +434,14 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
mMacroCommands.ReadMacro(name);
{
// Move global clipboard contents aside temporarily
Clipboard tempClipboard;
auto &globalClipboard = Clipboard::Get();
globalClipboard.Swap(tempClipboard);
auto cleanup = finally([&]{
globalClipboard.Swap(tempClipboard);
});
wxWindowDisabler wd(&activityWin);
for (i = 0; i < (int)files.size(); i++) {
if (i > 0) {
@ -457,6 +466,10 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
// Ensure project is completely reset
ProjectManager::Get(*project).ResetProjectToEmpty();
// Bug2567:
// Must also destroy the clipboard, to be sure sample blocks are
// all freed and their ids can be reused safely in the next pass
globalClipboard.Clear();
if (!success)
break;

View File

@ -18,6 +18,14 @@ Clipboard::Clipboard()
Clipboard::~Clipboard() = default;
void Clipboard::Swap( Clipboard &other )
{
std::swap( mTracks, other.mTracks );
std::swap( mProject, other.mProject );
std::swap( mT0, other.mT0 );
std::swap( mT1, other.mT1 );
}
Clipboard &Clipboard::Get()
{
static Clipboard instance;

View File

@ -43,10 +43,13 @@ public:
TrackList && newContents, double t0, double t1,
const std::weak_ptr<AudacityProject> &pProject );
private:
Clipboard();
~Clipboard();
void Swap( Clipboard &other );
private:
std::shared_ptr<TrackList> mTracks;
std::weak_ptr<AudacityProject> mProject{};
double mT0{ 0 };