Remove various scalar naked news and deletes

This commit is contained in:
Paul Licameli 2016-08-10 11:06:07 -04:00
commit 062e50eca6
25 changed files with 198 additions and 184 deletions

View File

@ -1203,7 +1203,8 @@ bool AudacityApp::OnInit()
::wxInitAllImageHandlers(); ::wxInitAllImageHandlers();
wxFileSystem::AddHandler(new wxZipFSHandler); // AddHandler takes ownership
wxFileSystem::AddHandler(safenew wxZipFSHandler);
// //
// Paths: set search path and temp dir path // Paths: set search path and temp dir path
@ -1433,17 +1434,18 @@ bool AudacityApp::OnInit()
// On the Mac, users don't expect a program to quit when you close the last window. // On the Mac, users don't expect a program to quit when you close the last window.
// Create a menubar that will show when all project windows are closed. // Create a menubar that will show when all project windows are closed.
wxMenu *fileMenu = new wxMenu(); auto fileMenu = std::make_unique<wxMenu>();
wxMenu *recentMenu = new wxMenu(); auto urecentMenu = std::make_unique<wxMenu>();
auto recentMenu = urecentMenu.get();
fileMenu->Append(wxID_NEW, wxString(_("&New")) + wxT("\tCtrl+N")); fileMenu->Append(wxID_NEW, wxString(_("&New")) + wxT("\tCtrl+N"));
fileMenu->Append(wxID_OPEN, wxString(_("&Open...")) + wxT("\tCtrl+O")); fileMenu->Append(wxID_OPEN, wxString(_("&Open...")) + wxT("\tCtrl+O"));
fileMenu->AppendSubMenu(recentMenu, _("Open &Recent...")); fileMenu->AppendSubMenu(urecentMenu.release(), _("Open &Recent..."));
fileMenu->Append(wxID_ABOUT, _("&About Audacity...")); fileMenu->Append(wxID_ABOUT, _("&About Audacity..."));
fileMenu->Append(wxID_PREFERENCES, wxString(_("&Preferences...")) + wxT("\tCtrl+,")); fileMenu->Append(wxID_PREFERENCES, wxString(_("&Preferences...")) + wxT("\tCtrl+,"));
{ {
auto menuBar = std::make_unique<wxMenuBar>(); auto menuBar = std::make_unique<wxMenuBar>();
menuBar->Append(fileMenu, _("&File")); menuBar->Append(fileMenu.release(), _("&File"));
// PRL: Are we sure wxWindows will not leak this menuBar? // PRL: Are we sure wxWindows will not leak this menuBar?
// The online documentation is not explicit. // The online documentation is not explicit.
@ -1766,33 +1768,34 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
wxUNIXaddress addr; wxUNIXaddress addr;
addr.Filename(sockFile); addr.Filename(sockFile);
// Setup the socket
wxSocketClient *sock = new wxSocketClient();
sock->SetFlags(wxSOCKET_WAITALL);
// We try up to 50 times since there's a small window
// where the server may not have been fully initialized.
for (int i = 0; i < 50; i++)
{ {
// Connect to the existing Audacity // Setup the socket
sock->Connect(addr, true); // A wxSocketClient must not be deleted by us, but rather, let the
if (sock->IsConnected()) // framework do appropriate delayed deletion after Destroy()
Destroy_ptr<wxSocketClient> sock { safenew wxSocketClient() };
sock->SetFlags(wxSOCKET_WAITALL);
// We try up to 50 times since there's a small window
// where the server may not have been fully initialized.
for (int i = 0; i < 50; i++)
{ {
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++) // Connect to the existing Audacity
sock->Connect(addr, true);
if (sock->IsConnected())
{ {
// Send the filename for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
wxString param = parser->GetParam(i); {
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar)); // Send the filename
wxString param = parser->GetParam(i);
sock->WriteMsg((const wxChar *) param.c_str(), (param.Len() + 1) * sizeof(wxChar));
}
return false;
} }
sock->Destroy(); wxMilliSleep(100);
return false;
} }
wxMilliSleep(100);
} }
sock->Destroy();
#endif #endif
// There is another copy of Audacity running. Force quit. // There is another copy of Audacity running. Force quit.

View File

@ -302,14 +302,15 @@ void BatchProcessDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
{ {
S.StartStatic(_("Applying..."), 1); S.StartStatic(_("Applying..."), 1);
{ {
wxImageList *imageList = new wxImageList(9, 16); auto imageList = std::make_unique<wxImageList>(9, 16);
imageList->Add(wxIcon(empty9x16_xpm)); imageList->Add(wxIcon(empty9x16_xpm));
imageList->Add(wxIcon(arrow_xpm)); imageList->Add(wxIcon(arrow_xpm));
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_SINGLE_SEL); wxLC_SINGLE_SEL);
mList = S.Id(CommandsListID).AddListControlReportMode(); mList = S.Id(CommandsListID).AddListControlReportMode();
mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL); // AssignImageList takes ownership
mList->AssignImageList(imageList.release(), wxIMAGE_LIST_SMALL);
mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT); mList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT);
} }
S.EndStatic(); S.EndStatic();

View File

@ -64,7 +64,7 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
mSelected = 0; mSelected = 0;
mAudioIOBusy = false; mAudioIOBusy = false;
wxImageList *imageList = new wxImageList(9, 16); auto imageList = std::make_unique<wxImageList>(9, 16);
imageList->Add(wxIcon(empty9x16_xpm)); imageList->Add(wxIcon(empty9x16_xpm));
imageList->Add(wxIcon(arrow_xpm)); imageList->Add(wxIcon(arrow_xpm));
@ -85,7 +85,8 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
mList->InsertColumn(1, _("Size"), wxLIST_FORMAT_LEFT, 85); mList->InsertColumn(1, _("Size"), wxLIST_FORMAT_LEFT, 85);
//Assign rather than set the image list, so that it is deleted later. //Assign rather than set the image list, so that it is deleted later.
mList->AssignImageList(imageList, wxIMAGE_LIST_SMALL); // AssignImageList takes ownership
mList->AssignImageList(imageList.release(), wxIMAGE_LIST_SMALL);
S.StartMultiColumn(3, wxCENTRE); S.StartMultiColumn(3, wxCENTRE);
{ {

View File

@ -154,7 +154,7 @@ void LabelTrack::SetOffset(double dOffset)
bool LabelTrack::Clear(double b, double e) bool LabelTrack::Clear(double b, double e)
{ {
// May delete labels, so use subscripts to iterate // May DELETE labels, so use subscripts to iterate
for (size_t i = 0; i < mLabels.size(); ++i) { for (size_t i = 0; i < mLabels.size(); ++i) {
auto &labelStruct = mLabels[i]; auto &labelStruct = mLabels[i];
LabelStruct::TimeRelations relation = LabelStruct::TimeRelations relation =
@ -182,7 +182,7 @@ bool LabelTrack::Clear(double b, double e)
//used when we want to use clear only on the labels //used when we want to use clear only on the labels
bool LabelTrack::SplitDelete(double b, double e) bool LabelTrack::SplitDelete(double b, double e)
{ {
// May delete labels, so use subscripts to iterate // May DELETE labels, so use subscripts to iterate
for (size_t i = 0, len = mLabels.size(); i < len; ++i) { for (size_t i = 0, len = mLabels.size(); i < len; ++i) {
auto &labelStruct = mLabels[i]; auto &labelStruct = mLabels[i];
LabelStruct::TimeRelations relation = LabelStruct::TimeRelations relation =
@ -2292,23 +2292,18 @@ bool LabelTrack::Load(wxTextFile * in, DirManager * dirManager)
if (!(in->GetNextLine().ToULong(&len))) if (!(in->GetNextLine().ToULong(&len)))
return false; return false;
for (auto pLabel : mLabels)
delete pLabel;
mLabels.clear(); mLabels.clear();
mLabels.reserve(len); mLabels.reserve(len);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
LabelStruct *l = new LabelStruct();
double t0; double t0;
if (!Internat::CompatibleToDouble(in->GetNextLine(), &t0)) if (!Internat::CompatibleToDouble(in->GetNextLine(), &t0))
return false; return false;
l->selectedRegion.setT0(t0, false);
// Legacy file format does not include label end-times. // Legacy file format does not include label end-times.
l->selectedRegion.collapseToT0();
// PRL: nothing NEW to do, legacy file support // PRL: nothing NEW to do, legacy file support
l->title = in->GetNextLine(); mLabels.push_back(LabelStruct {
mLabels.Add(l); SelectedRegion{ t0, t0 }, in->GetNextLine()
});
} }
if (in->GetNextLine() != wxT("MLabelsEnd")) if (in->GetNextLine() != wxT("MLabelsEnd"))

View File

@ -568,7 +568,7 @@ public:
{ {
// Lose any old value // Lose any old value
reset(); reset();
// Create new value // Create NEW value
pp = safenew(address()) X(std::forward<Args>(args)...); pp = safenew(address()) X(std::forward<Args>(args)...);
} }
@ -688,6 +688,22 @@ make_movable_with_deleter(const Deleter &d, Args&&... args)
return movable_ptr_with_deleter<T, Deleter>(safenew T(std::forward<Args>(args)...), d); return movable_ptr_with_deleter<T, Deleter>(safenew T(std::forward<Args>(args)...), d);
} }
/*
* A deleter class to supply the second template parameter of unique_ptr for
* classes like wxWindow that should be sent a message called Destroy rather
* than be deleted directly
*/
template <typename T>
struct Destroyer {
void operator () (T *p) const { if (p) p->Destroy(); }
};
/*
* a convenience for using Destroyer
*/
template <typename T>
using Destroy_ptr = std::unique_ptr<T, Destroyer<T>>;
/* /*
* "finally" as in The C++ Programming Language, 4th ed., p. 358 * "finally" as in The C++ Programming Language, 4th ed., p. 358
* Useful for defining ad-hoc RAII actions. * Useful for defining ad-hoc RAII actions.

View File

@ -33,8 +33,11 @@
#include "Experimental.h" #include "Experimental.h"
// Globals, so that we remember settings from session to session // Globals, so that we remember settings from session to session
static wxPrintData *gPrintData = NULL; wxPrintData &gPrintData()
static wxPageSetupData *gPageSetupData = NULL; {
static wxPrintData theData;
return theData;
}
class AudacityPrintout final : public wxPrintout class AudacityPrintout final : public wxPrintout
{ {
@ -139,28 +142,17 @@ void AudacityPrintout::GetPageInfo(int *minPage, int *maxPage,
void HandlePageSetup(wxWindow *parent) void HandlePageSetup(wxWindow *parent)
{ {
if (gPageSetupData == NULL) wxPageSetupData pageSetupData;
gPageSetupData = new wxPageSetupDialogData();
if (gPrintData == NULL)
gPrintData = new wxPrintData();
(*gPageSetupData) = *gPrintData; wxPageSetupDialog pageSetupDialog(parent, &pageSetupData);
wxPageSetupDialog pageSetupDialog(parent, gPageSetupData);
pageSetupDialog.ShowModal(); pageSetupDialog.ShowModal();
(*gPrintData) = pageSetupDialog.GetPageSetupData().GetPrintData(); gPrintData() = pageSetupDialog.GetPageSetupData().GetPrintData();
(*gPageSetupData) = pageSetupDialog.GetPageSetupData();
} }
void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks) void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks)
{ {
if (gPageSetupData == NULL) wxPrintDialogData printDialogData(gPrintData());
gPageSetupData = new wxPageSetupDialogData();
if (gPrintData == NULL)
gPrintData = new wxPrintData();
wxPrintDialogData printDialogData(*gPrintData);
wxPrinter printer(&printDialogData); wxPrinter printer(&printDialogData);
AudacityPrintout printout(name, tracks); AudacityPrintout printout(name, tracks);
@ -174,6 +166,6 @@ void HandlePrint(wxWindow *parent, const wxString &name, TrackList *tracks)
} }
} }
else { else {
*gPrintData = printer.GetPrintDialogData().GetPrintData(); gPrintData() = printer.GetPrintDialogData().GetPrintData();
} }
} }

View File

@ -340,7 +340,8 @@ public:
{ {
mProject = proj; mProject = proj;
SetDataObject(new FileObject()); // SetDataObject takes ownership
SetDataObject(safenew FileObject());
} }
~DropTarget() ~DropTarget()
@ -1110,9 +1111,11 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
#if wxUSE_DRAG_AND_DROP #if wxUSE_DRAG_AND_DROP
// We can import now, so become a drag target // We can import now, so become a drag target
// SetDropTarget(new AudacityDropTarget(this)); // SetDropTarget(safenew AudacityDropTarget(this));
// mTrackPanel->SetDropTarget(new AudacityDropTarget(this)); // mTrackPanel->SetDropTarget(safenew AudacityDropTarget(this));
mTrackPanel->SetDropTarget(new DropTarget(this));
// SetDropTarget takes ownership
mTrackPanel->SetDropTarget(safenew DropTarget(this));
#endif #endif
wxTheApp->Connect(EVT_AUDIOIO_CAPTURE, wxTheApp->Connect(EVT_AUDIOIO_CAPTURE,

View File

@ -111,14 +111,15 @@ class ScreenFrame final : public wxFrame
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
static ScreenFrame *mFrame = NULL; using ScreenFramePtr = Destroy_ptr<ScreenFrame>;
ScreenFramePtr mFrame;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void OpenScreenshotTools() void OpenScreenshotTools()
{ {
if (!mFrame) { if (!mFrame) {
mFrame = new ScreenFrame(NULL, -1); mFrame = ScreenFramePtr{ safenew ScreenFrame(NULL, -1) };
} }
mFrame->Show(); mFrame->Show();
mFrame->Raise(); mFrame->Raise();
@ -126,10 +127,7 @@ void OpenScreenshotTools()
void CloseScreenshotTools() void CloseScreenshotTools()
{ {
if (mFrame) { mFrame.reset();
mFrame->Destroy();
mFrame = NULL;
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -485,7 +483,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event)) void ScreenFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
{ {
mFrame = NULL; if (this == mFrame.get())
mFrame.release();
Destroy(); Destroy();
} }

View File

@ -142,7 +142,8 @@ void SplashDialog::Show2( wxWindow * pParent )
{ {
if( pSelf == NULL ) if( pSelf == NULL )
{ {
pSelf = new SplashDialog( pParent ); // pParent owns it
pSelf = safenew SplashDialog( pParent );
} }
pSelf->mpHtml->SetPage(HelpText( wxT("welcome") )); pSelf->mpHtml->SetPage(HelpText( wxT("welcome") ));
pSelf->Show( true ); pSelf->Show( true );

View File

@ -163,8 +163,10 @@ public:
// //this array is sorted by start/end points and has no overlaps. If we've passed all possible intersections, insert. The array will remain sorted. // //this array is sorted by start/end points and has no overlaps. If we've passed all possible intersections, insert. The array will remain sorted.
// if(region.end < invalStart) // if(region.end < invalStart)
// { // {
// InvalidRegion* newRegion = new InvalidRegion(invalStart,invalEnd); // mRegions.insert(
// mRegions.insert(mRegions.begin()+i,newRegion); // mRegions.begin() + i,
// InvalidRegion{ invalStart, invalEnd }
// );
// break; // break;
// } // }
} }

View File

@ -116,10 +116,13 @@ WaveTrack::WaveTrack(DirManager *projDirManager, sampleFormat format, double rat
WaveTrack::WaveTrack(const WaveTrack &orig): WaveTrack::WaveTrack(const WaveTrack &orig):
Track(orig) Track(orig)
, mpSpectrumSettings(orig.mpSpectrumSettings , mpSpectrumSettings(orig.mpSpectrumSettings
? new SpectrogramSettings(*orig.mpSpectrumSettings) : 0 ? std::make_unique<SpectrogramSettings>(*orig.mpSpectrumSettings)
) : nullptr
)
, mpWaveformSettings(orig.mpWaveformSettings , mpWaveformSettings(orig.mpWaveformSettings
? new WaveformSettings(*orig.mpWaveformSettings) : 0) ? std::make_unique<WaveformSettings>(*orig.mpWaveformSettings)
: nullptr
)
{ {
mLastScaleType = -1; mLastScaleType = -1;
mLastdBRange = -1; mLastdBRange = -1;
@ -202,7 +205,7 @@ void WaveTrack::SetOffset(double o)
WaveTrack::WaveTrackDisplay WaveTrack::FindDefaultViewMode() WaveTrack::WaveTrackDisplay WaveTrack::FindDefaultViewMode()
{ {
// PRL: Bugs 1043, 1044 // PRL: Bugs 1043, 1044
// 2.1.1 writes a NEW key for this preference, which got new values, // 2.1.1 writes a NEW key for this preference, which got NEW values,
// to avoid confusing version 2.1.0 if it reads the preference file afterwards. // to avoid confusing version 2.1.0 if it reads the preference file afterwards.
// Prefer the NEW preference key if it is present // Prefer the NEW preference key if it is present

View File

@ -779,15 +779,15 @@ void Effect::Preview()
wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client) wxDialog *Effect::CreateUI(wxWindow *parent, EffectUIClientInterface *client)
{ {
EffectUIHost *dlg = new EffectUIHost(parent, this, client); Destroy_ptr<EffectUIHost> dlg
{ safenew EffectUIHost{ parent, this, client} };
if (dlg->Initialize()) if (dlg->Initialize())
{ {
return dlg; // release() is safe because parent will own it
return dlg.release();
} }
delete dlg;
return NULL; return NULL;
} }
@ -2929,7 +2929,7 @@ int EffectUIHost::ShowModal()
sz->Replace(mCloseBtn, apply); sz->Replace(mCloseBtn, apply);
sz->Replace(mApplyBtn, mCloseBtn); sz->Replace(mApplyBtn, mCloseBtn);
sz->Layout(); sz->Layout();
delete mApplyBtn; mApplyBtn->Destroy();
mApplyBtn = apply; mApplyBtn = apply;
mApplyBtn->SetDefault(); mApplyBtn->SetDefault();
mApplyBtn->SetLabel(wxGetStockLabel(wxID_OK, 0)); mApplyBtn->SetLabel(wxGetStockLabel(wxID_OK, 0));
@ -3290,7 +3290,6 @@ void EffectUIHost::OnDebug(wxCommandEvent & evt)
void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt)) void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt))
{ {
wxMenu menu; wxMenu menu;
wxMenu *sub;
LoadUserPresets(); LoadUserPresets();
@ -3300,12 +3299,12 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt))
} }
else else
{ {
sub = new wxMenu(); auto sub = std::make_unique<wxMenu>();
for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++) for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++)
{ {
sub->Append(kUserPresetsID + i, mUserPresets[i]); sub->Append(kUserPresetsID + i, mUserPresets[i]);
} }
menu.Append(0, _("User Presets"), sub); menu.Append(0, _("User Presets"), sub.release());
} }
menu.Append(kSaveAsID, _("Save Preset...")); menu.Append(kSaveAsID, _("Save Preset..."));
@ -3316,35 +3315,37 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt))
} }
else else
{ {
sub = new wxMenu(); auto sub = std::make_unique<wxMenu>();
for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++) for (size_t i = 0, cnt = mUserPresets.GetCount(); i < cnt; i++)
{ {
sub->Append(kDeletePresetID + i, mUserPresets[i]); sub->Append(kDeletePresetID + i, mUserPresets[i]);
} }
menu.Append(0, _("Delete Preset"), sub); menu.Append(0, _("Delete Preset"), sub.release());
} }
menu.AppendSeparator(); menu.AppendSeparator();
wxArrayString factory = mEffect->GetFactoryPresets(); wxArrayString factory = mEffect->GetFactoryPresets();
sub = new wxMenu();
sub->Append(kDefaultsID, _("Defaults"));
if (factory.GetCount() > 0)
{ {
sub->AppendSeparator(); auto sub = std::make_unique<wxMenu>();
for (size_t i = 0, cnt = factory.GetCount(); i < cnt; i++) sub->Append(kDefaultsID, _("Defaults"));
if (factory.GetCount() > 0)
{ {
wxString label = factory[i]; sub->AppendSeparator();
if (label.IsEmpty()) for (size_t i = 0, cnt = factory.GetCount(); i < cnt; i++)
{ {
label = _("None"); wxString label = factory[i];
} if (label.IsEmpty())
{
label = _("None");
}
sub->Append(kFactoryPresetsID + i, label); sub->Append(kFactoryPresetsID + i, label);
}
} }
menu.Append(0, _("Factory Presets"), sub.release());
} }
menu.Append(0, _("Factory Presets"), sub);
menu.AppendSeparator(); menu.AppendSeparator();
menu.Append(kImportID, _("Import..."))->Enable(mClient->CanExportPresets()); menu.Append(kImportID, _("Import..."))->Enable(mClient->CanExportPresets());
@ -3353,15 +3354,17 @@ void EffectUIHost::OnMenu(wxCommandEvent & WXUNUSED(evt))
menu.Append(kOptionsID, _("Options..."))->Enable(mClient->HasOptions()); menu.Append(kOptionsID, _("Options..."))->Enable(mClient->HasOptions());
menu.AppendSeparator(); menu.AppendSeparator();
sub = new wxMenu(); {
auto sub = std::make_unique<wxMenu>();
sub->Append(kDummyID, wxString::Format(_("Type: %s"), mEffect->GetFamily().c_str())); sub->Append(kDummyID, wxString::Format(_("Type: %s"), mEffect->GetFamily().c_str()));
sub->Append(kDummyID, wxString::Format(_("Name: %s"), mEffect->GetName().c_str())); sub->Append(kDummyID, wxString::Format(_("Name: %s"), mEffect->GetName().c_str()));
sub->Append(kDummyID, wxString::Format(_("Version: %s"), mEffect->GetVersion().c_str())); sub->Append(kDummyID, wxString::Format(_("Version: %s"), mEffect->GetVersion().c_str()));
sub->Append(kDummyID, wxString::Format(_("Vendor: %s"), mEffect->GetVendor().c_str())); sub->Append(kDummyID, wxString::Format(_("Vendor: %s"), mEffect->GetVendor().c_str()));
sub->Append(kDummyID, wxString::Format(_("Description: %s"), mEffect->GetDescription().c_str())); sub->Append(kDummyID, wxString::Format(_("Description: %s"), mEffect->GetDescription().c_str()));
menu.Append(0, _("About"), sub); menu.Append(0, _("About"), sub.release());
}
wxWindow *btn = FindWindow(kMenuID); wxWindow *btn = FindWindow(kMenuID);
wxRect r = btn->GetRect(); wxRect r = btn->GetRect();

View File

@ -412,7 +412,7 @@ private:
}; };
EffectNoiseReduction::EffectNoiseReduction() EffectNoiseReduction::EffectNoiseReduction()
: mSettings(new EffectNoiseReduction::Settings) : mSettings(std::make_unique<EffectNoiseReduction::Settings>())
{ {
Init(); Init();
} }
@ -609,8 +609,8 @@ bool EffectNoiseReduction::Process()
// settings if reducing noise. // settings if reducing noise.
if (mSettings->mDoProfile) { if (mSettings->mDoProfile) {
int spectrumSize = 1 + mSettings->WindowSize() / 2; int spectrumSize = 1 + mSettings->WindowSize() / 2;
mStatistics.reset mStatistics = std::make_unique<Statistics>
(new Statistics(spectrumSize, track->GetRate(), mSettings->mWindowTypes)); (spectrumSize, track->GetRate(), mSettings->mWindowTypes);
} }
else if (mStatistics->mWindowSize != mSettings->WindowSize()) { else if (mStatistics->mWindowSize != mSettings->WindowSize()) {
// possible only with advanced settings // possible only with advanced settings

View File

@ -27,7 +27,7 @@ effect that uses SoundTouch to do its processing (ChangeTempo
bool EffectSoundTouch::ProcessLabelTrack(Track *track) bool EffectSoundTouch::ProcessLabelTrack(Track *track)
{ {
// SetTimeWarper(new RegionTimeWarper(mCurT0, mCurT1, // SetTimeWarper(std::make_unique<RegionTimeWarper>(mCurT0, mCurT1,
// std::make_unique<LinearTimeWarper>(mCurT0, mCurT0, // std::make_unique<LinearTimeWarper>(mCurT0, mCurT0,
// mCurT1, mCurT0 + (mCurT1-mCurT0)*mFactor))); // mCurT1, mCurT0 + (mCurT1-mCurT0)*mFactor)));
LabelTrack *lt = (LabelTrack*)track; LabelTrack *lt = (LabelTrack*)track;

View File

@ -660,9 +660,6 @@ bool EffectTruncSilence::Analyze(RegionList& silenceList,
} }
// Record the silent region // Record the silent region
Region *r = new Region;
r->start = wt->LongSamplesToTime(*index + i - *silentFrame);
r->end = wt->LongSamplesToTime(*index + i);
trackSilences.push_back(Region( trackSilences.push_back(Region(
wt->LongSamplesToTime(*index + i - *silentFrame), wt->LongSamplesToTime(*index + i - *silentFrame),
wt->LongSamplesToTime(*index + i) wt->LongSamplesToTime(*index + i)

View File

@ -2797,13 +2797,13 @@ void VSTEffect::BuildFancy()
// Turn the power on...some effects need this when the editor is open // Turn the power on...some effects need this when the editor is open
PowerOn(); PowerOn();
mControl = new VSTControl; auto control = std::make_unique<VSTControl>();
if (!mControl) if (!control)
{ {
return; return;
} }
if (!mControl->Create(mParent, this)) if (!control->Create(mParent, this))
{ {
return; return;
} }
@ -2811,7 +2811,7 @@ void VSTEffect::BuildFancy()
{ {
auto mainSizer = std::make_unique<wxBoxSizer>(wxVERTICAL); auto mainSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
mainSizer->Add(mControl, 0, wxALIGN_CENTER); mainSizer->Add((mControl = control.release()), 0, wxALIGN_CENTER);
mParent->SetMinSize(wxDefaultSize); mParent->SetMinSize(wxDefaultSize);
mParent->SetSizer(mainSizer.release()); mParent->SetSizer(mainSizer.release());

View File

@ -1778,13 +1778,13 @@ bool AudioUnitEffect::PopulateUI(wxWindow *parent)
} }
else else
{ {
mControl = new AUControl; auto pControl = std::make_unique<AUControl>();
if (!mControl) if (!pControl)
{ {
return false; return false;
} }
if (!mControl->Create(container, mComponent, mUnit, mUIType == wxT("Full"))) if (!pControl->Create(container, mComponent, mUnit, mUIType == wxT("Full")))
{ {
return false; return false;
} }
@ -1792,7 +1792,7 @@ bool AudioUnitEffect::PopulateUI(wxWindow *parent)
{ {
auto innerSizer = std::make_unique<wxBoxSizer>(wxVERTICAL); auto innerSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
innerSizer->Add(mControl, 1, wxEXPAND); innerSizer->Add(pControl.release(), 1, wxEXPAND);
container->SetSizer(innerSizer.release()); container->SetSizer(innerSizer.release());
} }

View File

@ -200,7 +200,6 @@ private:
EffectUIHostInterface *mUIHost; EffectUIHostInterface *mUIHost;
wxWindow *mParent; wxWindow *mParent;
wxDialog *mDialog; wxDialog *mDialog;
AUControl *mControl;
wxString mUIType; wxString mUIType;
bool mIsGraphical; bool mIsGraphical;

View File

@ -218,7 +218,9 @@ void ODManager::Init()
mMaxThreads = 5; mMaxThreads = 5;
// wxLogDebug(wxT("Initializing ODManager...Creating manager thread")); // wxLogDebug(wxT("Initializing ODManager...Creating manager thread"));
ODManagerHelperThread* startThread = new ODManagerHelperThread; // This is a detached thread, so it deletes itself when it finishes
// ... except on Mac where we we don't use wxThread for reasons unexplained
ODManagerHelperThread* startThread = safenew ODManagerHelperThread;
// startThread->SetPriority(0);//default of 50. // startThread->SetPriority(0);//default of 50.
startThread->Create(); startThread->Create();
@ -239,7 +241,6 @@ void ODManager::DecrementCurrentThreads()
///Main loop for managing threads and tasks. ///Main loop for managing threads and tasks.
void ODManager::Start() void ODManager::Start()
{ {
ODTaskThread* thread;
bool tasksInArray; bool tasksInArray;
bool paused; bool paused;
int numQueues=0; int numQueues=0;
@ -278,7 +279,9 @@ void ODManager::Start()
mTasksMutex.Lock(); mTasksMutex.Lock();
//detach a NEW thread. //detach a NEW thread.
thread = new ODTaskThread(mTasks[0]);//task); // This is a detached thread, so it deletes itself when it finishes
// ... except on Mac where we we don't use wxThread for reasons unexplained
auto thread = safenew ODTaskThread(mTasks[0]);//task);
//thread->SetPriority(10);//default is 50. //thread->SetPriority(10);//default is 50.
thread->Create(); thread->Create();
thread->Run(); thread->Run();

View File

@ -222,7 +222,7 @@ class ODManagerHelperThread {
class ODManagerHelperThread final : public wxThread class ODManagerHelperThread final : public wxThread
{ {
public: public:
///Constructs a ODTaskThread ///Constructs an ODManagerHelperThread
///@param task the task to be launched as an ///@param task the task to be launched as an
ODManagerHelperThread(): wxThread(){} ODManagerHelperThread(): wxThread(){}

View File

@ -62,12 +62,6 @@ ExtImportPrefs::ExtImportPrefs(wxWindow * parent)
PluginList(NULL), mCreateTable (false), mDragFocus (NULL), PluginList(NULL), mCreateTable (false), mDragFocus (NULL),
mFakeKeyEvent (false), mStopRecursiveSelection (false), last_selected (-1) mFakeKeyEvent (false), mStopRecursiveSelection (false), last_selected (-1)
{ {
dragtext1 = new wxTextDataObject(wxT(""));
dragtext2 = new wxTextDataObject(wxT(""));
dragtarget1 = new ExtImportPrefsDropTarget(dragtext1);
dragtarget2 = new ExtImportPrefsDropTarget(dragtext2);
dragtarget1->SetPrefs (this);
dragtarget2->SetPrefs (this);
Populate(); Populate();
} }
@ -121,7 +115,14 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
RuleTable->SetSelectionMode (wxGrid::wxGridSelectRows); RuleTable->SetSelectionMode (wxGrid::wxGridSelectRows);
RuleTable->AutoSizeColumns (); RuleTable->AutoSizeColumns ();
RuleTable->SetDropTarget (dragtarget1); ExtImportPrefsDropTarget *dragtarget1 {};
RuleTable->SetDropTarget (
dragtarget1 = safenew ExtImportPrefsDropTarget(
dragtext1 = safenew wxTextDataObject(wxT(""))
)
);
dragtarget1->SetPrefs (this);
RuleTable->EnableDragCell (true); RuleTable->EnableDragCell (true);
fillRuleTable = true; fillRuleTable = true;
} }
@ -134,7 +135,15 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
PluginList->SetSingleStyle (wxLC_REPORT, true); PluginList->SetSingleStyle (wxLC_REPORT, true);
PluginList->SetSingleStyle (wxLC_SINGLE_SEL, true); PluginList->SetSingleStyle (wxLC_SINGLE_SEL, true);
PluginList->InsertColumn (0, _("Importer order")); PluginList->InsertColumn (0, _("Importer order"));
PluginList->SetDropTarget (dragtarget2);
ExtImportPrefsDropTarget *dragtarget2 {};
PluginList->SetDropTarget (
dragtarget2 = safenew ExtImportPrefsDropTarget(
dragtext2 = safenew wxTextDataObject(wxT(""))
)
);
dragtarget2->SetPrefs (this);
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE_USEHEADER); PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE_USEHEADER);
ExtImportItems *items = Importer::Get().GetImportItems(); ExtImportItems *items = Importer::Get().GetImportItems();
@ -646,9 +655,9 @@ void ExtImportPrefs::OnRuleTableCellClick (wxGridEvent& event)
event.Skip(); event.Skip();
} }
ExtImportPrefsDropTarget::ExtImportPrefsDropTarget (wxDataObject *dataObject) ExtImportPrefsDropTarget::ExtImportPrefsDropTarget(wxDataObject *dataObject)
: wxDropTarget(dataObject)
{ {
SetDataObject (dataObject);
mPrefs = NULL; mPrefs = NULL;
} }
@ -779,11 +788,6 @@ void ExtImportPrefsDropTarget::OnLeave()
{ {
} }
void ExtImportPrefsDropTarget::SetDataObject(wxDataObject* data)
{
this->m_dataObject = data;
}
PrefsPanel *ExtImportPrefsFactory::Create(wxWindow *parent) PrefsPanel *ExtImportPrefsFactory::Create(wxWindow *parent)
{ {
wxASSERT(parent); // to justify safenew wxASSERT(parent); // to justify safenew

View File

@ -30,14 +30,14 @@ class ShuttleGui;
class ExtImportPrefsDropTarget final : public wxDropTarget class ExtImportPrefsDropTarget final : public wxDropTarget
{ {
public: public:
ExtImportPrefsDropTarget (wxDataObject *dataObject = 0); // Takes ownership of the argument
ExtImportPrefsDropTarget(wxDataObject* dataObject = nullptr);
~ExtImportPrefsDropTarget (); ~ExtImportPrefsDropTarget ();
wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def); wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
bool OnDrop(wxCoord x, wxCoord y); bool OnDrop(wxCoord x, wxCoord y);
wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def); wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def);
wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def); wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
void OnLeave(); void OnLeave();
void SetDataObject(wxDataObject* data);
void SetPrefs (ExtImportPrefs *prefs); void SetPrefs (ExtImportPrefs *prefs);
private: private:
ExtImportPrefs *mPrefs; ExtImportPrefs *mPrefs;
@ -86,10 +86,8 @@ class ExtImportPrefs final : public PrefsPanel
wxButton *MoveFilterUp; wxButton *MoveFilterUp;
wxButton *MoveFilterDown; wxButton *MoveFilterDown;
wxTextDataObject *dragtext1; wxTextDataObject *dragtext1 {};
wxTextDataObject *dragtext2; wxTextDataObject *dragtext2 {};
ExtImportPrefsDropTarget *dragtarget1;
ExtImportPrefsDropTarget *dragtarget2;
bool mCreateTable; bool mCreateTable;
wxWindow *mDragFocus; wxWindow *mDragFocus;

View File

@ -89,6 +89,8 @@ class ToolBar /* not final */ : public wxPanelWrapper
public: public:
using Holder = Destroy_ptr<ToolBar>;
ToolBar(int type, const wxString & label, const wxString & section, bool resizable = false); ToolBar(int type, const wxString & label, const wxString & section, bool resizable = false);
virtual ~ToolBar(); virtual ~ToolBar();

View File

@ -363,7 +363,7 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
mLeft = std::make_unique<wxRegion>( 3, &pt[0] ); mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
// Create the indicator frame // Create the indicator frame
mIndicator = new wxFrame( NULL, mIndicator = FramePtr{ safenew wxFrame( NULL,
wxID_ANY, wxID_ANY,
wxEmptyString, wxEmptyString,
wxDefaultPosition, wxDefaultPosition,
@ -372,7 +372,8 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
wxFRAME_SHAPED | wxFRAME_SHAPED |
wxNO_BORDER | wxNO_BORDER |
wxFRAME_NO_TASKBAR | wxFRAME_NO_TASKBAR |
wxSTAY_ON_TOP ); wxSTAY_ON_TOP )
};
// Hook the creation event...only needed on GTK, but doesn't hurt for all // Hook the creation event...only needed on GTK, but doesn't hurt for all
mIndicator->Connect( wxEVT_CREATE, mIndicator->Connect( wxEVT_CREATE,
@ -409,20 +410,20 @@ ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
mBotDock = safenew ToolDock( this, mParent, BotDockID ); mBotDock = safenew ToolDock( this, mParent, BotDockID );
// Create all of the toolbars // Create all of the toolbars
mBars[ ToolsBarID ] = new ToolsToolBar(); mBars[ ToolsBarID ] = ToolBar::Holder{ safenew ToolsToolBar() };
mBars[ TransportBarID ] = new ControlToolBar(); mBars[ TransportBarID ] = ToolBar::Holder{ safenew ControlToolBar() };
mBars[ RecordMeterBarID ] = new MeterToolBar( parent, RecordMeterBarID ); mBars[ RecordMeterBarID ] = ToolBar::Holder{ safenew MeterToolBar( parent, RecordMeterBarID ) };
mBars[ PlayMeterBarID ] = new MeterToolBar( parent, PlayMeterBarID ); mBars[ PlayMeterBarID ] = ToolBar::Holder{ safenew MeterToolBar( parent, PlayMeterBarID ) };
mBars[ MeterBarID ] = new MeterToolBar( parent, MeterBarID ); mBars[ MeterBarID ] = ToolBar::Holder{ safenew MeterToolBar( parent, MeterBarID ) };
mBars[ EditBarID ] = new EditToolBar(); mBars[ EditBarID ] = ToolBar::Holder{ safenew EditToolBar() };
mBars[ MixerBarID ] = new MixerToolBar(); mBars[ MixerBarID ] = ToolBar::Holder{ safenew MixerToolBar() };
mBars[ TranscriptionBarID ] = new TranscriptionToolBar(); mBars[ TranscriptionBarID ] = ToolBar::Holder{ safenew TranscriptionToolBar() };
mBars[ SelectionBarID ] = new SelectionBar(); mBars[ SelectionBarID ] = ToolBar::Holder{ safenew SelectionBar() };
mBars[ DeviceBarID ] = new DeviceToolBar(); mBars[ DeviceBarID ] = ToolBar::Holder{ safenew DeviceToolBar() };
#ifdef EXPERIMENTAL_SPECTRAL_EDITING #ifdef EXPERIMENTAL_SPECTRAL_EDITING
mBars[SpectralSelectionBarID] = new SpectralSelectionBar(); mBars[SpectralSelectionBarID] = ToolBar::Holder{ safenew SpectralSelectionBar() };
#endif #endif
mBars[ ScrubbingBarID ] = new ScrubbingToolBar(); mBars[ ScrubbingBarID ] = ToolBar::Holder{ safenew ScrubbingToolBar() };
// We own the timer // We own the timer
mTimer.SetOwner( this ); mTimer.SetOwner( this );
@ -462,9 +463,6 @@ ToolManager::~ToolManager()
wxPaintEventHandler( ToolManager::OnIndicatorPaint ), wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
NULL, NULL,
this ); this );
// Must destroy the window since it doesn't have a parent
mIndicator->Destroy();
} }
// This table describes the default configuration of the toolbars as // This table describes the default configuration of the toolbars as
@ -511,11 +509,11 @@ void ToolManager::Reset()
for ( const auto &entry : DefaultConfigTable ) for ( const auto &entry : DefaultConfigTable )
{ {
int ndx = entry.barID; int ndx = entry.barID;
ToolBar *bar = mBars[ ndx ]; ToolBar *bar = mBars[ ndx ].get();
ToolBarConfiguration::Position position { ToolBarConfiguration::Position position {
(entry.rightOf == NoBarID) ? nullptr : mBars[ entry.rightOf ], (entry.rightOf == NoBarID) ? nullptr : mBars[ entry.rightOf ].get(),
(entry.below == NoBarID) ? nullptr : mBars[ entry.below ] (entry.below == NoBarID) ? nullptr : mBars[ entry.below ].get()
}; };
wxWindow *floater; wxWindow *floater;
@ -612,7 +610,7 @@ void ToolManager::Reset()
void ToolManager::RegenerateTooltips() void ToolManager::RegenerateTooltips()
{ {
for (auto bar : mBars) { for (const auto &bar : mBars) {
if (bar) if (bar)
bar->RegenerateTooltips(); bar->RegenerateTooltips();
} }
@ -645,7 +643,7 @@ void ToolManager::ReadConfig()
// Load and apply settings for each bar // Load and apply settings for each bar
for( ndx = 0; ndx < ToolBarCount; ndx++ ) for( ndx = 0; ndx < ToolBarCount; ndx++ )
{ {
ToolBar *bar = mBars[ ndx ]; ToolBar *bar = mBars[ ndx ].get();
//wxPoint Center = mParent->GetPosition() + (mParent->GetSize() * 0.33); //wxPoint Center = mParent->GetPosition() + (mParent->GetSize() * 0.33);
//wxPoint Center( //wxPoint Center(
// wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) /2 , // wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) /2 ,
@ -808,7 +806,7 @@ void ToolManager::ReadConfig()
bool deviceWasPositioned = false; bool deviceWasPositioned = false;
for( int ord = 0; ord < (int) unordered[ dock ].GetCount(); ord++ ) for( int ord = 0; ord < (int) unordered[ dock ].GetCount(); ord++ )
{ {
ToolBar *t = mBars[ unordered[ dock ][ ord ] ]; ToolBar *t = mBars[ unordered[ dock ][ ord ] ].get();
if (deviceWasPositioned && if (deviceWasPositioned &&
t->GetType() == DeviceBarID) t->GetType() == DeviceBarID)
@ -837,7 +835,7 @@ void ToolManager::ReadConfig()
// Reposition the device toolbar, if it was docked above, // Reposition the device toolbar, if it was docked above,
// right of scrubbing // right of scrubbing
const auto deviceToolBar = mBars[ DeviceBarID ]; const auto deviceToolBar = mBars[ DeviceBarID ].get();
if (deviceToolBar->GetDock() == mTopDock) { if (deviceToolBar->GetDock() == mTopDock) {
deviceToolBar->GetDock()->Undock(deviceToolBar); deviceToolBar->GetDock()->Undock(deviceToolBar);
position = { t, nullptr }; position = { t, nullptr };
@ -889,7 +887,7 @@ void ToolManager::WriteConfig()
// Save state of each bar // Save state of each bar
for( ndx = 0; ndx < ToolBarCount; ndx++ ) for( ndx = 0; ndx < ToolBarCount; ndx++ )
{ {
ToolBar *bar = mBars[ ndx ]; ToolBar *bar = mBars[ ndx ].get();
// Change to the bar subkey // Change to the bar subkey
gPrefs->SetPath( bar->GetSection() ); gPrefs->SetPath( bar->GetSection() );
@ -920,13 +918,6 @@ void ToolManager::WriteConfig()
gPrefs->SetPath( wxT("..") ); gPrefs->SetPath( wxT("..") );
} }
// Kill the bars
for( ndx = 0; ndx < ToolBarCount; ndx++ )
{
ToolBar *bar = mBars[ ndx ];
bar->Destroy();
}
// Restore original config path // Restore original config path
gPrefs->SetPath( oldpath ); gPrefs->SetPath( oldpath );
gPrefs->Flush(); gPrefs->Flush();
@ -937,7 +928,7 @@ void ToolManager::WriteConfig()
// //
ToolBar *ToolManager::GetToolBar( int type ) const ToolBar *ToolManager::GetToolBar( int type ) const
{ {
return mBars[ type ]; return mBars[ type ].get();
} }
// //
@ -980,7 +971,7 @@ bool ToolManager::IsDocked( int type )
// //
bool ToolManager::IsVisible( int type ) bool ToolManager::IsVisible( int type )
{ {
ToolBar *t = mBars[ type ]; ToolBar *t = mBars[ type ].get();
return t->IsVisible(); return t->IsVisible();
@ -1010,7 +1001,7 @@ void ToolManager::ShowHide( int type )
// //
void ToolManager::Expose( int type, bool show ) void ToolManager::Expose( int type, bool show )
{ {
ToolBar *t = mBars[ type ]; ToolBar *t = mBars[ type ].get();
// Handle docked and floaters differently // Handle docked and floaters differently
if( t->IsDocked() ) if( t->IsDocked() )
@ -1040,7 +1031,7 @@ void ToolManager::UpdatePrefs()
{ {
for( int ndx = 0; ndx < ToolBarCount; ndx++ ) for( int ndx = 0; ndx < ToolBarCount; ndx++ )
{ {
ToolBar *bar = mBars[ ndx ]; ToolBar *bar = mBars[ ndx ].get();
if( bar ) if( bar )
{ {
bar->UpdatePrefs(); bar->UpdatePrefs();
@ -1302,7 +1293,7 @@ void ToolManager::OnGrabber( GrabberEvent & event )
return HandleEscapeKey(); return HandleEscapeKey();
// Remember which bar we're dragging // Remember which bar we're dragging
mDragBar = mBars[ event.GetId() ]; mDragBar = mBars[ event.GetId() ].get();
// Remember state, in case of ESCape key later // Remember state, in case of ESCape key later
if (mDragBar->IsDocked()) { if (mDragBar->IsDocked()) {

View File

@ -97,7 +97,8 @@ class ToolManager final : public wxEvtHandler
wxPoint mLastPos; wxPoint mLastPos;
wxRect mBarPos; wxRect mBarPos;
wxFrame *mIndicator; using FramePtr = Destroy_ptr<wxFrame>;
FramePtr mIndicator;
std::unique_ptr<wxRegion> mLeft, mDown; std::unique_ptr<wxRegion> mLeft, mDown;
wxRegion *mCurrent; wxRegion *mCurrent;
@ -111,7 +112,7 @@ class ToolManager final : public wxEvtHandler
ToolDock *mTopDock; ToolDock *mTopDock;
ToolDock *mBotDock; ToolDock *mBotDock;
ToolBar *mBars[ ToolBarCount ]; ToolBar::Holder mBars[ ToolBarCount ];
wxPoint mPrevPosition {}; wxPoint mPrevPosition {};
ToolDock *mPrevDock {}; ToolDock *mPrevDock {};