mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-11 22:27:42 +02:00
Some more factory functions return smart pointers
* factories: MakeCursor returns smart pointer; TrackPanel stores smart pointers to cursors AudacityApp::ParseCommandLine returns smart pointer
This commit is contained in:
commit
a655545a1e
@ -57,4 +57,4 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxCursor * MakeCursor(int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY);
|
std::unique_ptr<wxCursor> MakeCursor(int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY);
|
||||||
|
@ -640,7 +640,7 @@ public:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trust wxWidgets framework to delete it
|
// Trust wxWidgets framework to DELETE it
|
||||||
return safenew IPCConn();
|
return safenew IPCConn();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -1143,6 +1143,10 @@ AudacityApp::AudacityApp()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudacityApp::~AudacityApp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// The `main program' equivalent, creating the windows and returning the
|
// The `main program' equivalent, creating the windows and returning the
|
||||||
// main frame
|
// main frame
|
||||||
bool AudacityApp::OnInit()
|
bool AudacityApp::OnInit()
|
||||||
@ -1323,19 +1327,15 @@ bool AudacityApp::OnInit()
|
|||||||
// Parse command line and handle options that might require
|
// Parse command line and handle options that might require
|
||||||
// immediate exit...no need to initialize all of the audio
|
// immediate exit...no need to initialize all of the audio
|
||||||
// stuff to display the version string.
|
// stuff to display the version string.
|
||||||
wxCmdLineParser *parser = ParseCommandLine();
|
auto parser = ParseCommandLine();
|
||||||
if (!parser)
|
if (!parser)
|
||||||
{
|
{
|
||||||
delete parser;
|
|
||||||
|
|
||||||
// Either user requested help or a parsing error occured
|
// Either user requested help or a parsing error occured
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser->Found(wxT("v")))
|
if (parser->Found(wxT("v")))
|
||||||
{
|
{
|
||||||
delete parser;
|
|
||||||
|
|
||||||
wxFprintf(stderr, wxT("Audacity v%s\n"), AUDACITY_VERSION_STRING);
|
wxFprintf(stderr, wxT("Audacity v%s\n"), AUDACITY_VERSION_STRING);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -1345,8 +1345,6 @@ bool AudacityApp::OnInit()
|
|||||||
{
|
{
|
||||||
if (lval < 256 || lval > 100000000)
|
if (lval < 256 || lval > 100000000)
|
||||||
{
|
{
|
||||||
delete parser;
|
|
||||||
|
|
||||||
wxPrintf(_("Block size must be within 256 to 100000000\n"));
|
wxPrintf(_("Block size must be within 256 to 100000000\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1463,7 +1461,6 @@ bool AudacityApp::OnInit()
|
|||||||
{
|
{
|
||||||
// Important: Prevent deleting any temporary files!
|
// Important: Prevent deleting any temporary files!
|
||||||
DirManager::SetDontDeleteTempFiles();
|
DirManager::SetDontDeleteTempFiles();
|
||||||
delete parser;
|
|
||||||
QuitAudacity(true);
|
QuitAudacity(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1475,8 +1472,6 @@ bool AudacityApp::OnInit()
|
|||||||
{
|
{
|
||||||
if (parser->Found(wxT("t")))
|
if (parser->Found(wxT("t")))
|
||||||
{
|
{
|
||||||
delete parser;
|
|
||||||
|
|
||||||
RunBenchmark(NULL);
|
RunBenchmark(NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1491,8 +1486,6 @@ bool AudacityApp::OnInit()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
delete parser;
|
|
||||||
|
|
||||||
gInited = true;
|
gInited = true;
|
||||||
|
|
||||||
ModuleManager::Get().Dispatch(AppInitialized);
|
ModuleManager::Get().Dispatch(AppInitialized);
|
||||||
@ -1664,7 +1657,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
|
|||||||
else if ( mChecker->IsAnotherRunning() ) {
|
else if ( mChecker->IsAnotherRunning() ) {
|
||||||
// Parse the command line to ensure correct syntax, but
|
// Parse the command line to ensure correct syntax, but
|
||||||
// ignore options and only use the filenames, if any.
|
// ignore options and only use the filenames, if any.
|
||||||
wxCmdLineParser *parser = ParseCommandLine();
|
auto parser = ParseCommandLine();
|
||||||
if (!parser)
|
if (!parser)
|
||||||
{
|
{
|
||||||
// Complaints have already been made
|
// Complaints have already been made
|
||||||
@ -1703,10 +1696,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
|
|||||||
delete conn;
|
delete conn;
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
|
||||||
delete parser;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMilliSleep(10);
|
wxMilliSleep(10);
|
||||||
@ -1738,7 +1728,6 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sock->Destroy();
|
sock->Destroy();
|
||||||
delete parser;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1755,7 +1744,6 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
|
|||||||
_("Use the New or Open commands in the currently running Audacity\nprocess to open multiple projects simultaneously.\n");
|
_("Use the New or Open commands in the currently running Audacity\nprocess to open multiple projects simultaneously.\n");
|
||||||
wxMessageBox(prompt, _("Audacity is already running"),
|
wxMessageBox(prompt, _("Audacity is already running"),
|
||||||
wxOK | wxICON_ERROR);
|
wxOK | wxICON_ERROR);
|
||||||
delete parser;
|
|
||||||
delete mChecker;
|
delete mChecker;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1826,9 +1814,9 @@ void AudacityApp::OnSocketEvent(wxSocketEvent & evt)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxCmdLineParser *AudacityApp::ParseCommandLine()
|
std::unique_ptr<wxCmdLineParser> AudacityApp::ParseCommandLine()
|
||||||
{
|
{
|
||||||
wxCmdLineParser *parser = new wxCmdLineParser(argc, argv);
|
auto parser = std::make_unique<wxCmdLineParser>(argc, argv);
|
||||||
if (!parser)
|
if (!parser)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1861,13 +1849,9 @@ wxCmdLineParser *AudacityApp::ParseCommandLine()
|
|||||||
|
|
||||||
// Run the parser
|
// Run the parser
|
||||||
if (parser->Parse() == 0)
|
if (parser->Parse() == 0)
|
||||||
{
|
return std::move(parser);
|
||||||
return parser;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete parser;
|
return{};
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "Audacity.h"
|
#include "Audacity.h"
|
||||||
|
|
||||||
|
#include "MemoryX.h"
|
||||||
#include <wx/app.h>
|
#include <wx/app.h>
|
||||||
#include <wx/cmdline.h>
|
#include <wx/cmdline.h>
|
||||||
#include <wx/dir.h>
|
#include <wx/dir.h>
|
||||||
@ -100,6 +101,7 @@ class BlockFile;
|
|||||||
class AudacityApp final : public wxApp {
|
class AudacityApp final : public wxApp {
|
||||||
public:
|
public:
|
||||||
AudacityApp();
|
AudacityApp();
|
||||||
|
~AudacityApp();
|
||||||
bool OnInit(void) override;
|
bool OnInit(void) override;
|
||||||
int OnExit(void) override;
|
int OnExit(void) override;
|
||||||
void OnFatalException() override;
|
void OnFatalException() override;
|
||||||
@ -217,7 +219,7 @@ class AudacityApp final : public wxApp {
|
|||||||
bool InitTempDir();
|
bool InitTempDir();
|
||||||
bool CreateSingleInstanceChecker(const wxString &dir);
|
bool CreateSingleInstanceChecker(const wxString &dir);
|
||||||
|
|
||||||
wxCmdLineParser *ParseCommandLine();
|
std::unique_ptr<wxCmdLineParser> ParseCommandLine();
|
||||||
|
|
||||||
bool mWindowRectAlreadySaved;
|
bool mWindowRectAlreadySaved;
|
||||||
|
|
||||||
|
@ -418,10 +418,8 @@ END_EVENT_TABLE()
|
|||||||
|
|
||||||
/// Makes a cursor from an XPM, uses CursorId as a fallback.
|
/// Makes a cursor from an XPM, uses CursorId as a fallback.
|
||||||
/// TODO: Move this function to some other source file for reuse elsewhere.
|
/// TODO: Move this function to some other source file for reuse elsewhere.
|
||||||
wxCursor * MakeCursor( int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY )
|
std::unique_ptr<wxCursor> MakeCursor( int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY )
|
||||||
{
|
{
|
||||||
wxCursor * pCursor;
|
|
||||||
|
|
||||||
#ifdef CURSORS_SIZE32
|
#ifdef CURSORS_SIZE32
|
||||||
const int HotAdjust =0;
|
const int HotAdjust =0;
|
||||||
#else
|
#else
|
||||||
@ -434,9 +432,7 @@ wxCursor * MakeCursor( int WXUNUSED(CursorId), const char * pXpm[36], int HotX,
|
|||||||
|
|
||||||
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, HotX-HotAdjust );
|
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, HotX-HotAdjust );
|
||||||
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, HotY-HotAdjust );
|
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, HotY-HotAdjust );
|
||||||
pCursor = new wxCursor( Image );
|
return std::make_unique<wxCursor>( Image );
|
||||||
|
|
||||||
return pCursor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -523,12 +519,12 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
|
|||||||
StretchRightCursorXpm, 16, 16);
|
StretchRightCursorXpm, 16, 16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mArrowCursor = new wxCursor(wxCURSOR_ARROW);
|
mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
|
||||||
mSmoothCursor = new wxCursor(wxCURSOR_SPRAYCAN);
|
mSmoothCursor = std::make_unique<wxCursor>(wxCURSOR_SPRAYCAN);
|
||||||
mResizeCursor = new wxCursor(wxCURSOR_SIZENS);
|
mResizeCursor = std::make_unique<wxCursor>(wxCURSOR_SIZENS);
|
||||||
mRearrangeCursor = new wxCursor(wxCURSOR_HAND);
|
mRearrangeCursor = std::make_unique<wxCursor>(wxCURSOR_HAND);
|
||||||
mAdjustLeftSelectionCursor = new wxCursor(wxCURSOR_POINT_LEFT);
|
mAdjustLeftSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_LEFT);
|
||||||
mAdjustRightSelectionCursor = new wxCursor(wxCURSOR_POINT_RIGHT);
|
mAdjustRightSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_RIGHT);
|
||||||
|
|
||||||
mWaveTrackMenu = NULL;
|
mWaveTrackMenu = NULL;
|
||||||
mChannelItemsInsertionPoint = 0;
|
mChannelItemsInsertionPoint = 0;
|
||||||
@ -651,31 +647,6 @@ TrackPanel::~TrackPanel()
|
|||||||
}
|
}
|
||||||
delete mTrackArtist;
|
delete mTrackArtist;
|
||||||
|
|
||||||
delete mArrowCursor;
|
|
||||||
delete mPencilCursor;
|
|
||||||
delete mSelectCursor;
|
|
||||||
delete mEnvelopeCursor;
|
|
||||||
delete mDisabledCursor;
|
|
||||||
delete mSlideCursor;
|
|
||||||
delete mResizeCursor;
|
|
||||||
delete mSmoothCursor;
|
|
||||||
delete mZoomInCursor;
|
|
||||||
delete mZoomOutCursor;
|
|
||||||
delete mLabelCursorLeft;
|
|
||||||
delete mLabelCursorRight;
|
|
||||||
delete mRearrangeCursor;
|
|
||||||
delete mAdjustLeftSelectionCursor;
|
|
||||||
delete mAdjustRightSelectionCursor;
|
|
||||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
|
||||||
delete mBottomFrequencyCursor;
|
|
||||||
delete mTopFrequencyCursor;
|
|
||||||
delete mBandWidthCursor;
|
|
||||||
#endif
|
|
||||||
#if USE_MIDI
|
|
||||||
delete mStretchCursor;
|
|
||||||
delete mStretchLeftCursor;
|
|
||||||
delete mStretchRightCursor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delete mSnapManager;
|
delete mSnapManager;
|
||||||
|
|
||||||
@ -1796,7 +1767,7 @@ void TrackPanel::HandleCenterFrequencyCursor
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*ppCursor = mEnvelopeCursor;
|
*ppCursor = mEnvelopeCursor.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackPanel::HandleCenterFrequencyClick
|
void TrackPanel::HandleCenterFrequencyClick
|
||||||
@ -1832,7 +1803,7 @@ void TrackPanel::SetCursorAndTipWhenSelectTool( Track * t,
|
|||||||
{
|
{
|
||||||
// Do not set the default cursor here and re-set later, that causes
|
// Do not set the default cursor here and re-set later, that causes
|
||||||
// flashing.
|
// flashing.
|
||||||
*ppCursor = mSelectCursor;
|
*ppCursor = mSelectCursor.get();
|
||||||
|
|
||||||
//In Multi-tool mode, give multitool prompt if no-special-hit.
|
//In Multi-tool mode, give multitool prompt if no-special-hit.
|
||||||
if( bMultiToolMode ) {
|
if( bMultiToolMode ) {
|
||||||
@ -1880,7 +1851,7 @@ void TrackPanel::SetCursorAndTipWhenSelectTool( Track * t,
|
|||||||
isSpectralSelectionTrack(t)) {
|
isSpectralSelectionTrack(t)) {
|
||||||
// Not shift-down, but center frequency snapping toggle is on
|
// Not shift-down, but center frequency snapping toggle is on
|
||||||
tip = _("Click and drag to set frequency bandwidth.");
|
tip = _("Click and drag to set frequency bandwidth.");
|
||||||
*ppCursor = mEnvelopeCursor;
|
*ppCursor = mEnvelopeCursor.get();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1906,7 +1877,7 @@ void TrackPanel::SetCursorAndTipWhenSelectTool( Track * t,
|
|||||||
case SBRight:
|
case SBRight:
|
||||||
if ( HitTestStretch(t, rect, event)) {
|
if ( HitTestStretch(t, rect, event)) {
|
||||||
tip = _("Click and drag to stretch within selected region.");
|
tip = _("Click and drag to stretch within selected region.");
|
||||||
*ppCursor = mStretchCursor;
|
*ppCursor = mStretchCursor.get();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1927,27 +1898,27 @@ void TrackPanel::SetCursorAndTipWhenSelectTool( Track * t,
|
|||||||
break;
|
break;
|
||||||
case SBLeft:
|
case SBLeft:
|
||||||
tip = _("Click and drag to move left selection boundary.");
|
tip = _("Click and drag to move left selection boundary.");
|
||||||
*ppCursor = mAdjustLeftSelectionCursor;
|
*ppCursor = mAdjustLeftSelectionCursor.get();
|
||||||
return;
|
return;
|
||||||
case SBRight:
|
case SBRight:
|
||||||
tip = _("Click and drag to move right selection boundary.");
|
tip = _("Click and drag to move right selection boundary.");
|
||||||
*ppCursor = mAdjustRightSelectionCursor;
|
*ppCursor = mAdjustRightSelectionCursor.get();
|
||||||
return;
|
return;
|
||||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||||
case SBBottom:
|
case SBBottom:
|
||||||
tip = _("Click and drag to move bottom selection frequency.");
|
tip = _("Click and drag to move bottom selection frequency.");
|
||||||
*ppCursor = mBottomFrequencyCursor;
|
*ppCursor = mBottomFrequencyCursor.get();
|
||||||
return;
|
return;
|
||||||
case SBTop:
|
case SBTop:
|
||||||
tip = _("Click and drag to move top selection frequency.");
|
tip = _("Click and drag to move top selection frequency.");
|
||||||
*ppCursor = mTopFrequencyCursor;
|
*ppCursor = mTopFrequencyCursor.get();
|
||||||
return;
|
return;
|
||||||
case SBCenter:
|
case SBCenter:
|
||||||
HandleCenterFrequencyCursor(bShiftDown, tip, ppCursor);
|
HandleCenterFrequencyCursor(bShiftDown, tip, ppCursor);
|
||||||
return;
|
return;
|
||||||
case SBWidth:
|
case SBWidth:
|
||||||
tip = _("Click and drag to adjust frequency bandwidth.");
|
tip = _("Click and drag to adjust frequency bandwidth.");
|
||||||
*ppCursor = mBandWidthCursor;
|
*ppCursor = mBandWidthCursor.get();
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -819,31 +819,20 @@ protected:
|
|||||||
int mLogMaxScrubSpeed;
|
int mLogMaxScrubSpeed;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxCursor *mArrowCursor;
|
std::unique_ptr<wxCursor>
|
||||||
wxCursor *mPencilCursor;
|
mArrowCursor, mPencilCursor, mSelectCursor,
|
||||||
wxCursor *mSelectCursor;
|
mResizeCursor, mSlideCursor, mEnvelopeCursor, // doubles as the center frequency cursor
|
||||||
wxCursor *mResizeCursor;
|
|
||||||
wxCursor *mSlideCursor;
|
|
||||||
wxCursor *mEnvelopeCursor; // doubles as the center frequency cursor
|
|
||||||
// for spectral selection
|
// for spectral selection
|
||||||
wxCursor *mSmoothCursor;
|
mSmoothCursor, mZoomInCursor, mZoomOutCursor,
|
||||||
wxCursor *mZoomInCursor;
|
mLabelCursorLeft, mLabelCursorRight, mRearrangeCursor,
|
||||||
wxCursor *mZoomOutCursor;
|
mDisabledCursor, mAdjustLeftSelectionCursor, mAdjustRightSelectionCursor;
|
||||||
wxCursor *mLabelCursorLeft;
|
|
||||||
wxCursor *mLabelCursorRight;
|
|
||||||
wxCursor *mRearrangeCursor;
|
|
||||||
wxCursor *mDisabledCursor;
|
|
||||||
wxCursor *mAdjustLeftSelectionCursor;
|
|
||||||
wxCursor *mAdjustRightSelectionCursor;
|
|
||||||
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
|
||||||
wxCursor *mBottomFrequencyCursor;
|
std::unique_ptr<wxCursor>
|
||||||
wxCursor *mTopFrequencyCursor;
|
mBottomFrequencyCursor, mTopFrequencyCursor, mBandWidthCursor;
|
||||||
wxCursor *mBandWidthCursor;
|
|
||||||
#endif
|
#endif
|
||||||
#if USE_MIDI
|
#if USE_MIDI
|
||||||
wxCursor *mStretchCursor;
|
std::unique_ptr<wxCursor>
|
||||||
wxCursor *mStretchLeftCursor;
|
mStretchCursor, mStretchLeftCursor, mStretchRightCursor;
|
||||||
wxCursor *mStretchRightCursor;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxMenu *mWaveTrackMenu;
|
wxMenu *mWaveTrackMenu;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user