mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-31 16:09:28 +02:00
Dir manager uses std::shared_ptr
This commit is contained in:
parent
13e5788a6b
commit
46f38708ed
@ -332,7 +332,7 @@ bool RecordingRecoveryHandler::HandleXMLTag(const wxChar *tag,
|
||||
Sequence* seq = clip->GetSequence();
|
||||
|
||||
// Load the blockfile from the XML
|
||||
DirManager* dirManager = mProject->GetDirManager();
|
||||
const auto &dirManager = mProject->GetDirManager();
|
||||
dirManager->SetLoadingFormat(seq->GetSampleFormat());
|
||||
|
||||
BlockArray array;
|
||||
|
@ -343,8 +343,8 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
|
||||
HoldPrint(true);
|
||||
|
||||
ZoomInfo zoomInfo(0.0, ZoomInfo::GetDefaultZoom());
|
||||
DirManager *d = new DirManager();
|
||||
const auto t = TrackFactory{ d, &zoomInfo }.NewWaveTrack(int16Sample);
|
||||
auto dd = std::make_shared<DirManager>();
|
||||
const auto t = TrackFactory{ dd, &zoomInfo }.NewWaveTrack(int16Sample);
|
||||
|
||||
t->SetRate(1);
|
||||
|
||||
@ -533,7 +533,7 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
|
||||
delete[]small2;
|
||||
delete[]block;
|
||||
|
||||
d->Deref();
|
||||
dd.reset();
|
||||
|
||||
Sequence::SetMaxDiskBlockSize(oldBlockSize);
|
||||
Printf(wxT("Benchmark completed successfully.\n"));
|
||||
|
@ -83,7 +83,7 @@ static void GetAllSeqBlocks(AudacityProject *project,
|
||||
static void ReplaceBlockFiles(AudacityProject *project,
|
||||
ReplacedBlockFileHash &hash)
|
||||
{
|
||||
DirManager *dirManager = project->GetDirManager();
|
||||
const auto &dirManager = project->GetDirManager();
|
||||
BlockPtrArray blocks;
|
||||
GetAllSeqBlocks(project, &blocks);
|
||||
|
||||
@ -159,7 +159,7 @@ void FindDependencies(AudacityProject *project,
|
||||
static void RemoveDependencies(AudacityProject *project,
|
||||
AliasedFileArray &aliasedFiles)
|
||||
{
|
||||
DirManager *dirManager = project->GetDirManager();
|
||||
const auto &dirManager = project->GetDirManager();
|
||||
|
||||
ProgressDialog progress
|
||||
(_("Removing Dependencies"),
|
||||
|
@ -319,8 +319,6 @@ DirManager::DirManager()
|
||||
{
|
||||
wxLogDebug(wxT("DirManager: Created new instance."));
|
||||
|
||||
mRef = 1; // MM: Initial refcount is 1 by convention
|
||||
|
||||
// Seed the random number generator.
|
||||
// this need not be strictly uniform or random, but it should give
|
||||
// unclustered numbers
|
||||
@ -365,8 +363,6 @@ DirManager::DirManager()
|
||||
|
||||
DirManager::~DirManager()
|
||||
{
|
||||
wxASSERT(mRef == 0); // MM: Otherwise, we shouldn't DELETE it
|
||||
|
||||
numDirManagers--;
|
||||
if (numDirManagers == 0) {
|
||||
CleanTempDir();
|
||||
@ -1381,23 +1377,6 @@ bool DirManager::EnsureSafeFilename(const wxFileName &fName)
|
||||
return true;
|
||||
}
|
||||
|
||||
void DirManager::Ref()
|
||||
{
|
||||
wxASSERT(mRef > 0); // MM: If mRef is smaller, it should have been deleted already
|
||||
++mRef;
|
||||
}
|
||||
|
||||
void DirManager::Deref()
|
||||
{
|
||||
wxASSERT(mRef > 0); // MM: If mRef is smaller, it should have been deleted already
|
||||
|
||||
--mRef;
|
||||
|
||||
// MM: Automatically DELETE if refcount reaches zero
|
||||
if (mRef == 0)
|
||||
delete this;
|
||||
}
|
||||
|
||||
// Check the BlockFiles against the disk state.
|
||||
// Missing Blockfile data can be regenerated if possible or replaced with silence.
|
||||
// Orphan blockfiles can be deleted.
|
||||
@ -1829,7 +1808,7 @@ void DirManager::FindOrphanBlockFiles(
|
||||
TrackListIterator clipIter(clipTracks);
|
||||
Track *track = clipIter.First();
|
||||
if (track)
|
||||
clipboardDM = track->GetDirManager();
|
||||
clipboardDM = track->GetDirManager().get();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#ifndef _DIRMANAGER_
|
||||
#define _DIRMANAGER_
|
||||
|
||||
#include <MemoryX.h>
|
||||
#include <wx/list.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/filename.h>
|
||||
@ -38,18 +39,13 @@ wxMemorySize GetFreeMemory();
|
||||
class PROFILE_DLL_API DirManager final : public XMLTagHandler {
|
||||
public:
|
||||
|
||||
// MM: Construct DirManager with refcount=1
|
||||
// MM: Construct DirManager
|
||||
DirManager();
|
||||
|
||||
// MM: Only called by Deref() when refcount reaches zero.
|
||||
virtual ~DirManager();
|
||||
|
||||
static void SetTempDir(const wxString &_temp) { globaltemp = _temp; }
|
||||
|
||||
// MM: Ref count mechanism for the DirManager itself
|
||||
void Ref();
|
||||
void Deref();
|
||||
|
||||
// Returns true on success.
|
||||
// If SetProject is told NOT to create the directory
|
||||
// but it doesn't already exist, SetProject fails and returns false.
|
||||
@ -174,8 +170,6 @@ class PROFILE_DLL_API DirManager final : public XMLTagHandler {
|
||||
|
||||
bool MoveOrCopyToNewProjectDirectory(BlockFile *f, bool copy);
|
||||
|
||||
int mRef; // MM: Current refcount
|
||||
|
||||
BlockHash mBlockFileHash; // repository for blockfiles
|
||||
DirHash dirTopPool; // available toplevel dirs
|
||||
DirHash dirTopFull; // full toplevel dirs
|
||||
|
@ -96,7 +96,7 @@ LabelTrack::Holder TrackFactory::NewLabelTrack()
|
||||
return std::make_unique<LabelTrack>(mDirManager);
|
||||
}
|
||||
|
||||
LabelTrack::LabelTrack(DirManager * projDirManager):
|
||||
LabelTrack::LabelTrack(const std::shared_ptr<DirManager> &projDirManager):
|
||||
Track(projDirManager),
|
||||
mbHitCenter(false),
|
||||
mOldEdge(-1),
|
||||
|
@ -116,7 +116,7 @@ class AUDACITY_DLL_API LabelTrack final : public Track
|
||||
bool IsTextSelected();
|
||||
|
||||
void CreateCustomGlyphs();
|
||||
LabelTrack(DirManager * projDirManager);
|
||||
LabelTrack(const std::shared_ptr<DirManager> &projDirManager);
|
||||
LabelTrack(const LabelTrack &orig);
|
||||
|
||||
virtual ~ LabelTrack();
|
||||
|
@ -103,7 +103,7 @@ NoteTrack::Holder TrackFactory::NewNoteTrack()
|
||||
return std::make_unique<NoteTrack>(mDirManager);
|
||||
}
|
||||
|
||||
NoteTrack::NoteTrack(DirManager * projDirManager):
|
||||
NoteTrack::NoteTrack(const std::shared_ptr<DirManager> &projDirManager):
|
||||
Track(projDirManager)
|
||||
{
|
||||
SetDefaultName(_("Note Track"));
|
||||
@ -113,7 +113,6 @@ Track(projDirManager)
|
||||
mSerializationBuffer = NULL;
|
||||
mSerializationLength = 0;
|
||||
|
||||
mDirManager = projDirManager;
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
mGain = 0;
|
||||
#endif
|
||||
|
@ -54,7 +54,7 @@ class AUDACITY_DLL_API NoteTrack final : public Track {
|
||||
public:
|
||||
friend class TrackArtist;
|
||||
|
||||
NoteTrack(DirManager * projDirManager);
|
||||
NoteTrack(const std::shared_ptr<DirManager> &projDirManager);
|
||||
virtual ~NoteTrack();
|
||||
|
||||
using Holder = std::unique_ptr<NoteTrack>;
|
||||
@ -201,8 +201,6 @@ class AUDACITY_DLL_API NoteTrack final : public Track {
|
||||
mutable char *mSerializationBuffer; // NULL means no buffer
|
||||
long mSerializationLength;
|
||||
|
||||
DirManager *mDirManager;
|
||||
|
||||
#ifdef EXPERIMENTAL_MIDI_OUT
|
||||
float mGain; // velocity offset
|
||||
#endif
|
||||
|
@ -845,7 +845,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
|
||||
|
||||
// MM: DirManager is created dynamically, freed on demand via ref-counting
|
||||
// MM: We don't need to Ref() here because it start with refcount=1
|
||||
mDirManager = new DirManager();
|
||||
mDirManager = std::make_shared<DirManager>();
|
||||
|
||||
mLastSavedTracks = NULL;
|
||||
|
||||
@ -1270,7 +1270,7 @@ void AudacityProject::OnCapture(wxCommandEvent& evt)
|
||||
}
|
||||
|
||||
|
||||
DirManager *AudacityProject::GetDirManager()
|
||||
const std::shared_ptr<DirManager> &AudacityProject::GetDirManager()
|
||||
{
|
||||
return mDirManager;
|
||||
}
|
||||
@ -2442,7 +2442,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
|
||||
//
|
||||
// LL: All objects with references to the DirManager should
|
||||
// have been deleted before this.
|
||||
mDirManager->Deref();
|
||||
mDirManager.reset();
|
||||
|
||||
{
|
||||
ODLocker locker{ &AudacityProject::AllProjectDeleteMutex() };
|
||||
|
@ -193,7 +193,7 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
|
||||
bool Clipboard() { return (msClipT1 - msClipT0) > 0.0; }
|
||||
|
||||
wxString GetName();
|
||||
DirManager *GetDirManager();
|
||||
const std::shared_ptr<DirManager> &GetDirManager();
|
||||
TrackFactory *GetTrackFactory();
|
||||
AdornedRulerPanel *GetRulerPanel();
|
||||
const Tags *GetTags();
|
||||
@ -541,7 +541,7 @@ public:
|
||||
|
||||
// The project's name and file info
|
||||
wxString mFileName;
|
||||
DirManager *mDirManager; // MM: DirManager now created dynamically
|
||||
std::shared_ptr<DirManager> mDirManager; // MM: DirManager now created dynamically
|
||||
|
||||
double mRate;
|
||||
sampleFormat mDefaultFormat;
|
||||
|
@ -51,26 +51,23 @@
|
||||
int Sequence::sMaxDiskBlockSize = 1048576;
|
||||
|
||||
// Sequence methods
|
||||
Sequence::Sequence(DirManager * projDirManager, sampleFormat format)
|
||||
Sequence::Sequence(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format)
|
||||
: mDirManager(projDirManager)
|
||||
, mSampleFormat(format)
|
||||
, mMinSamples(sMaxDiskBlockSize / SAMPLE_SIZE(mSampleFormat) / 2)
|
||||
, mMaxSamples(mMinSamples * 2)
|
||||
{
|
||||
mDirManager->Ref();
|
||||
}
|
||||
|
||||
// essentially a copy constructor - but you must pass in the
|
||||
// current project's DirManager, because we might be copying
|
||||
// from one project to another
|
||||
Sequence::Sequence(const Sequence &orig, DirManager *projDirManager)
|
||||
Sequence::Sequence(const Sequence &orig, const std::shared_ptr<DirManager> &projDirManager)
|
||||
: mDirManager(projDirManager)
|
||||
, mSampleFormat(orig.mSampleFormat)
|
||||
, mMinSamples(orig.mMinSamples)
|
||||
, mMaxSamples(orig.mMaxSamples)
|
||||
{
|
||||
mDirManager->Ref();
|
||||
|
||||
bool bResult = Paste(0, &orig);
|
||||
wxASSERT(bResult); // TO DO: Actually handle this.
|
||||
(void)bResult;
|
||||
@ -79,7 +76,6 @@ Sequence::Sequence(const Sequence &orig, DirManager *projDirManager)
|
||||
Sequence::~Sequence()
|
||||
{
|
||||
DerefAllFiles();
|
||||
mDirManager->Deref();
|
||||
}
|
||||
|
||||
void Sequence::DerefAllFiles()
|
||||
@ -1022,7 +1018,7 @@ XMLTagHandler *Sequence::HandleXMLChild(const wxChar *tag)
|
||||
return this;
|
||||
else {
|
||||
mDirManager->SetLoadingFormat(mSampleFormat);
|
||||
return mDirManager;
|
||||
return mDirManager.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,12 +70,12 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
|
||||
// Constructor / Destructor / Duplicator
|
||||
//
|
||||
|
||||
Sequence(DirManager * projDirManager, sampleFormat format);
|
||||
Sequence(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format);
|
||||
|
||||
// The copy constructor and duplicate operators take a
|
||||
// DirManager as a parameter, because you might be copying
|
||||
// from one project to another...
|
||||
Sequence(const Sequence &orig, DirManager *projDirManager);
|
||||
Sequence(const Sequence &orig, const std::shared_ptr<DirManager> &projDirManager);
|
||||
|
||||
~Sequence();
|
||||
|
||||
@ -128,7 +128,7 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
|
||||
bool SetSilence(sampleCount s0, sampleCount len);
|
||||
bool InsertSilence(sampleCount s0, sampleCount len);
|
||||
|
||||
DirManager* GetDirManager() { return mDirManager; }
|
||||
const std::shared_ptr<DirManager> &GetDirManager() { return mDirManager; }
|
||||
|
||||
//
|
||||
// XMLTagHandler callback methods for loading and saving
|
||||
@ -218,7 +218,7 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
|
||||
// Private variables
|
||||
//
|
||||
|
||||
DirManager *mDirManager;
|
||||
std::shared_ptr<DirManager> mDirManager;
|
||||
|
||||
BlockArray mBlock;
|
||||
sampleFormat mSampleFormat;
|
||||
|
@ -34,7 +34,7 @@ std::unique_ptr<TimeTrack> TrackFactory::NewTimeTrack()
|
||||
return std::make_unique<TimeTrack>(mDirManager, mZoomInfo);
|
||||
}
|
||||
|
||||
TimeTrack::TimeTrack(DirManager *projDirManager, const ZoomInfo *zoomInfo):
|
||||
TimeTrack::TimeTrack(const std::shared_ptr<DirManager> &projDirManager, const ZoomInfo *zoomInfo):
|
||||
Track(projDirManager)
|
||||
, mZoomInfo(zoomInfo)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ class TimeTrack final : public Track {
|
||||
|
||||
public:
|
||||
|
||||
TimeTrack(DirManager * projDirManager, const ZoomInfo *zoomInfo);
|
||||
TimeTrack(const std::shared_ptr<DirManager> &projDirManager, const ZoomInfo *zoomInfo);
|
||||
/** @brief Copy-Constructor - create a NEW TimeTrack:: which is an independent copy of the original
|
||||
*
|
||||
* Calls TimeTrack::Init() to copy the track metadata, then does a bunch of manipulations on the
|
||||
|
@ -43,12 +43,10 @@ and TimeTrack.
|
||||
// #define DEBUG_TLI
|
||||
#endif
|
||||
|
||||
Track::Track(DirManager * projDirManager)
|
||||
Track::Track(const std::shared_ptr<DirManager> &projDirManager)
|
||||
: vrulerSize(36,0),
|
||||
mDirManager(projDirManager)
|
||||
{
|
||||
mDirManager->Ref();
|
||||
|
||||
mList = NULL;
|
||||
mSelected = false;
|
||||
mLinked = false;
|
||||
@ -74,8 +72,6 @@ Track::Track(DirManager * projDirManager)
|
||||
|
||||
Track::Track(const Track &orig)
|
||||
{
|
||||
mDirManager = NULL;
|
||||
|
||||
mList = NULL;
|
||||
mY = 0;
|
||||
mIndex = 0;
|
||||
@ -92,15 +88,7 @@ void Track::Init(const Track &orig)
|
||||
mDefaultName = orig.mDefaultName;
|
||||
mName = orig.mName;
|
||||
|
||||
if (mDirManager != orig.mDirManager) {
|
||||
if (mDirManager) {
|
||||
mDirManager->Deref(); // MM: unreference old DirManager
|
||||
}
|
||||
|
||||
// MM: Assign and ref NEW DirManager
|
||||
mDirManager = orig.mDirManager;
|
||||
mDirManager->Ref();
|
||||
}
|
||||
mDirManager = orig.mDirManager;
|
||||
|
||||
mSelected = orig.mSelected;
|
||||
mLinked = orig.mLinked;
|
||||
@ -130,7 +118,6 @@ void Track::Merge(const Track &orig)
|
||||
|
||||
Track::~Track()
|
||||
{
|
||||
mDirManager->Deref();
|
||||
}
|
||||
|
||||
|
||||
|
10
src/Track.h
10
src/Track.h
@ -143,7 +143,7 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler
|
||||
bool mMute;
|
||||
bool mSolo;
|
||||
|
||||
mutable DirManager *mDirManager;
|
||||
mutable std::shared_ptr<DirManager> mDirManager;
|
||||
|
||||
public:
|
||||
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
|
||||
@ -169,7 +169,7 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler
|
||||
All
|
||||
};
|
||||
|
||||
Track(DirManager * projDirManager);
|
||||
Track(const std::shared_ptr<DirManager> &projDirManager);
|
||||
Track(const Track &orig);
|
||||
|
||||
virtual ~ Track();
|
||||
@ -210,7 +210,7 @@ class AUDACITY_DLL_API Track /* not final */ : public XMLTagHandler
|
||||
// mostly to support "Duplicate" of const objects,
|
||||
// but in general, mucking with the dir manager is
|
||||
// separate from the Track.
|
||||
DirManager* GetDirManager() const { return mDirManager; }
|
||||
const std::shared_ptr<DirManager> &GetDirManager() const { return mDirManager; }
|
||||
|
||||
// Create a NEW track and modify this track (or return null for failure)
|
||||
virtual Holder Cut(double WXUNUSED(t0), double WXUNUSED(t1)) { return{}; }
|
||||
@ -529,13 +529,13 @@ private:
|
||||
class AUDACITY_DLL_API TrackFactory
|
||||
{
|
||||
private:
|
||||
TrackFactory(DirManager *dirManager, const ZoomInfo *zoomInfo):
|
||||
TrackFactory(const std::shared_ptr<DirManager> &dirManager, const ZoomInfo *zoomInfo):
|
||||
mDirManager(dirManager)
|
||||
, mZoomInfo(zoomInfo)
|
||||
{
|
||||
}
|
||||
|
||||
DirManager *const mDirManager;
|
||||
const std::shared_ptr<DirManager> mDirManager;
|
||||
const ZoomInfo *const mZoomInfo;
|
||||
friend class AudacityProject;
|
||||
friend class BenchmarkDialog;
|
||||
|
@ -288,7 +288,7 @@ static void ComputeSpectrumUsingRealFFTf
|
||||
}
|
||||
}
|
||||
|
||||
WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
|
||||
WaveClip::WaveClip(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format, int rate)
|
||||
{
|
||||
mOffset = 0;
|
||||
mRate = rate;
|
||||
@ -302,7 +302,7 @@ WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
|
||||
mIsPlaceholder = false;
|
||||
}
|
||||
|
||||
WaveClip::WaveClip(const WaveClip& orig, DirManager *projDirManager)
|
||||
WaveClip::WaveClip(const WaveClip& orig, const std::shared_ptr<DirManager> &projDirManager)
|
||||
{
|
||||
// essentially a copy constructor - but you must pass in the
|
||||
// current project's DirManager, because we might be copying
|
||||
|
@ -214,12 +214,12 @@ private:
|
||||
|
||||
public:
|
||||
// typical constructor
|
||||
WaveClip(DirManager *projDirManager, sampleFormat format, int rate);
|
||||
WaveClip(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format, int rate);
|
||||
|
||||
// essentially a copy constructor - but you must pass in the
|
||||
// current project's DirManager, because we might be copying
|
||||
// from one project to another
|
||||
WaveClip(const WaveClip& orig, DirManager *projDirManager);
|
||||
WaveClip(const WaveClip& orig, const std::shared_ptr<DirManager> &projDirManager);
|
||||
|
||||
virtual ~WaveClip();
|
||||
|
||||
|
@ -76,7 +76,7 @@ WaveTrack::Holder TrackFactory::NewWaveTrack(sampleFormat format, double rate)
|
||||
{ safenew WaveTrack(mDirManager, format, rate) };
|
||||
}
|
||||
|
||||
WaveTrack::WaveTrack(DirManager *projDirManager, sampleFormat format, double rate) :
|
||||
WaveTrack::WaveTrack(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format, double rate) :
|
||||
Track(projDirManager)
|
||||
{
|
||||
if (format == (sampleFormat)0)
|
||||
|
@ -69,7 +69,7 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
|
||||
// Private since only factories are allowed to construct WaveTracks
|
||||
//
|
||||
|
||||
WaveTrack(DirManager * projDirManager,
|
||||
WaveTrack(const std::shared_ptr<DirManager> &projDirManager,
|
||||
sampleFormat format = (sampleFormat)0,
|
||||
double rate = 0);
|
||||
WaveTrack(const WaveTrack &orig);
|
||||
|
Loading…
x
Reference in New Issue
Block a user