diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index ab80fbb98..9b496bc38 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -933,7 +933,7 @@ locations of the missing files."), missingFileName.c_str()); } } -void AudacityApp::MarkAliasedFilesMissingWarning(BlockFile *b) +void AudacityApp::MarkAliasedFilesMissingWarning(const BlockFile *b) { // the reference counting provides thread safety. if (b) diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 44694ef1c..a8148a87d 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -142,7 +142,7 @@ class AudacityApp final : public wxApp { * ShouldShowMissingAliasedFileWarning can be called to determine * if the user should be notified */ - void MarkAliasedFilesMissingWarning(BlockFile *b); + void MarkAliasedFilesMissingWarning(const BlockFile *b); /** \brief Changes the behavior of missing aliased blockfiles warnings */ @@ -209,7 +209,7 @@ class AudacityApp final : public wxApp { wxTimer mTimer; bool m_aliasMissingWarningShouldShow; - BlockFile *m_LastMissingBlockFile; + const BlockFile *m_LastMissingBlockFile; ODLock m_LastMissingBlockFileLock; diff --git a/src/BlockFile.cpp b/src/BlockFile.cpp index 9960eb73a..e5ed6a4ef 100644 --- a/src/BlockFile.cpp +++ b/src/BlockFile.cpp @@ -120,7 +120,7 @@ BlockFile::~BlockFile() /// but most BlockFiles have at least their summary data here. /// (some, i.e. SilentBlockFiles, do not correspond to a file on /// disk and have empty file names) -wxFileName BlockFile::GetFileName() +wxFileName BlockFile::GetFileName() const { return mFileName; } @@ -162,7 +162,7 @@ bool BlockFile::IsLocked() /// Increases the reference count of this block by one. Only /// DirManager should call this method. -void BlockFile::Ref() +void BlockFile::Ref() const { mRefCount++; BLOCKFILE_DEBUG_OUTPUT("Ref", mRefCount); @@ -171,7 +171,7 @@ void BlockFile::Ref() /// Decreases the reference count of this block by one. If this /// causes the count to become zero, deletes the associated disk /// file and deletes this object -bool BlockFile::Deref() +bool BlockFile::Deref() const { mRefCount--; BLOCKFILE_DEBUG_OUTPUT("Deref", mRefCount); @@ -382,7 +382,7 @@ void BlockFile::FixSummary(void *data) /// @param *outRMS A pointer to where the maximum RMS value for this /// region should be stored. void BlockFile::GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS) + float *outMin, float *outMax, float *outRMS) const { // TODO: actually use summaries SampleBuffer blockData(len, floatSample); @@ -418,7 +418,7 @@ void BlockFile::GetMinMax(sampleCount start, sampleCount len, /// should be stored /// @param *outRMS A pointer to where the maximum RMS value for this /// block should be stored. -void BlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) +void BlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) const { *outMin = mMin; *outMax = mMax; @@ -634,7 +634,7 @@ void AliasBlockFile::ChangeAliasedFileName(wxFileName newAliasedFile) mAliasedFileName = newAliasedFile; } -wxLongLong AliasBlockFile::GetSpaceUsage() +wxLongLong AliasBlockFile::GetSpaceUsage() const { wxFFile summaryFile(mFileName.GetFullPath()); return summaryFile.Length(); diff --git a/src/BlockFile.h b/src/BlockFile.h index f1a3e5fea..cca57df94 100644 --- a/src/BlockFile.h +++ b/src/BlockFile.h @@ -52,7 +52,7 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { /// Retrieves audio data from this BlockFile virtual int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) = 0; + sampleCount start, sampleCount len) const = 0; // Other Properties @@ -70,10 +70,10 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { /// Gets the filename of the disk file associated with this BlockFile /// (can be empty -- some BlockFiles, like SilentBlockFile, correspond to /// no file on disk) - virtual wxFileName GetFileName(); + virtual wxFileName GetFileName() const; virtual void SetFileName(wxFileName &name); - virtual sampleCount GetLength() { return mLen; } + virtual sampleCount GetLength() const { return mLen; } virtual void SetLength(const sampleCount newLen) { mLen = newLen; } /// Locks this BlockFile, to prevent it from being moved @@ -85,22 +85,22 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { /// Gets extreme values for the specified region virtual void GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS); + float *outMin, float *outMax, float *outRMS) const; /// Gets extreme values for the entire block - virtual void GetMinMax(float *outMin, float *outMax, float *outRMS); + virtual void GetMinMax(float *outMin, float *outMax, float *outRMS) const; /// Returns the 256 byte summary data block virtual bool Read256(float *buffer, sampleCount start, sampleCount len); /// Returns the 64K summary data block virtual bool Read64K(float *buffer, sampleCount start, sampleCount len); /// Returns TRUE if this block references another disk file - virtual bool IsAlias() { return false; } + virtual bool IsAlias() const { return false; } /// Returns TRUE if this block's complete summary has been computed and is ready (for OD) - virtual bool IsSummaryAvailable(){return true;} + virtual bool IsSummaryAvailable() const {return true;} /// Returns TRUE if this block's complete data is ready to be accessed by Read() - virtual bool IsDataAvailable(){return true;} + virtual bool IsDataAvailable() const {return true;} /// Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk virtual bool IsSummaryBeingComputed(){return false;} @@ -108,7 +108,7 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { /// Create a NEW BlockFile identical to this, using the given filename virtual BlockFile *Copy(wxFileName newFileName) = 0; - virtual wxLongLong GetSpaceUsage() = 0; + virtual wxLongLong GetSpaceUsage() const = 0; /// if the on-disk state disappeared, either recover it (if it was //summary only), write out a placeholder of silence data (missing @@ -119,16 +119,16 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { //continue and the error persists, don't keep reporting it. The //Object implements this functionality internally, but we want to //be able to tell the logging to shut up from outside too. - void SilenceLog() { mSilentLog = TRUE; } + void SilenceLog() const { mSilentLog = TRUE; } ///when the project closes, it locks the blockfiles. ///Override this in case it needs special treatment virtual void CloseLock(){Lock();} /// Prevents a read on other threads. The basic blockfile runs on only one thread, so does nothing. - virtual void LockRead(){} + virtual void LockRead() const {} /// Allows reading on other threads. - virtual void UnlockRead(){} + virtual void UnlockRead() const {} private: @@ -139,8 +139,8 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { friend class ODDecodeTask; friend class ODPCMAliasBlockFile; - virtual void Ref(); - virtual bool Deref(); + virtual void Ref() const; + virtual bool Deref() const; virtual int RefCount(){return mRefCount;} protected: @@ -158,7 +158,7 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { private: int mLockCount; - int mRefCount; + mutable int mRefCount; static ArrayOf fullSummary; @@ -167,7 +167,7 @@ class PROFILE_DLL_API BlockFile /* not final, abstract */ { sampleCount mLen; SummaryInfo mSummaryInfo; float mMin, mMax, mRMS; - bool mSilentLog; + mutable bool mSilentLog; }; /// A BlockFile that refers to data in an existing file @@ -197,18 +197,18 @@ class AliasBlockFile /* not final */ : public BlockFile // Reading - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; /// as SilentLog (which would affect Summary data access), but // applying to Alias file access - void SilenceAliasLog() { mSilentAliasLog = TRUE; } + void SilenceAliasLog() const { mSilentAliasLog = TRUE; } // // These methods are for advanced use only! // wxFileName GetAliasedFileName() { return mAliasedFileName; } void ChangeAliasedFileName(wxFileName newAliasedFile); - bool IsAlias() override { return true; } + bool IsAlias() const override { return true; } protected: // Introduce a NEW virtual. @@ -220,7 +220,7 @@ class AliasBlockFile /* not final */ : public BlockFile wxFileName mAliasedFileName; sampleCount mAliasStart; int mAliasChannel; - bool mSilentAliasLog; + mutable bool mSilentAliasLog; }; #endif diff --git a/src/DirManager.cpp b/src/DirManager.cpp index d54055db9..c0b54dccc 100644 --- a/src/DirManager.cpp +++ b/src/DirManager.cpp @@ -931,7 +931,7 @@ BlockFile *DirManager::NewODDecodeBlockFile( return newBlockFile; } -bool DirManager::ContainsBlockFile(BlockFile *b) const +bool DirManager::ContainsBlockFile(const BlockFile *b) const { if (!b) return false; diff --git a/src/DirManager.h b/src/DirManager.h index 38785c0aa..adff4bdc4 100644 --- a/src/DirManager.h +++ b/src/DirManager.h @@ -74,7 +74,7 @@ class PROFILE_DLL_API DirManager final : public XMLTagHandler { sampleCount aliasLen, int aliasChannel, int decodeType); /// Returns true if the blockfile pointed to by b is contained by the DirManager - bool ContainsBlockFile(BlockFile *b) const; + bool ContainsBlockFile(const BlockFile *b) const; /// Check for existing using filename using complete filename bool ContainsBlockFile(const wxString &filepath) const; diff --git a/src/UndoManager.cpp b/src/UndoManager.cpp index 5eca99914..2155c44ff 100644 --- a/src/UndoManager.cpp +++ b/src/UndoManager.cpp @@ -35,7 +35,7 @@ UndoManager #include "UndoManager.h" -WX_DECLARE_HASH_SET(BlockFile *, wxPointerHash, wxPointerEqual, Set ); +WX_DECLARE_HASH_SET(const BlockFile *, wxPointerHash, wxPointerEqual, Set ); struct UndoStackElem { @@ -98,9 +98,9 @@ void UndoManager::CalculateSpaceUsage() { // Scan all blockfiles within current clip BlockArray *blocks = it->GetData()->GetSequenceBlockArray(); - for (size_t b = 0, cnt = blocks->size(); b < cnt; b++) + for (const auto &block : *blocks) { - BlockFile *file = (*blocks)[b].f; + BlockFile *file = block.f; // Accumulate space used by the file if the file didn't exist // in the previous level diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 7009b620a..227282b9a 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1165,7 +1165,7 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache, } bool WaveClip::GetMinMax(float *min, float *max, - double t0, double t1) + double t0, double t1) const { *min = float(0.0); // harmless, but unused since Sequence::GetMinMax does not use these values *max = float(0.0); // harmless, but unused since Sequence::GetMinMax does not use these values diff --git a/src/WaveClip.h b/src/WaveClip.h index 14357c7ae..f670bd47e 100644 --- a/src/WaveClip.h +++ b/src/WaveClip.h @@ -278,7 +278,7 @@ public: const float *& spectrogram, const sampleCount *& where, int numPixels, double t0, double pixelsPerSecond) const; - bool GetMinMax(float *min, float *max, double t0, double t1); + bool GetMinMax(float *min, float *max, double t0, double t1) const; bool GetRMS(float *rms, double t0, double t1); // Set/clear/get rectangle that this WaveClip fills on screen. This is diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index b5f98d2a2..4e76bbc2f 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -1926,7 +1926,7 @@ double WaveTrack::GetEndTime() const // bool WaveTrack::GetMinMax(float *min, float *max, - double t0, double t1) + double t0, double t1) const { bool clipFound = false; @@ -1941,9 +1941,9 @@ bool WaveTrack::GetMinMax(float *min, float *max, bool result = true; - for (WaveClipList::compatibility_iterator it=GetClipIterator(); it; it=it->GetNext()) + for (WaveClipList::compatibility_iterator it=const_cast(this)->GetClipIterator(); it; it=it->GetNext()) { - WaveClip* clip = it->GetData(); + const WaveClip* clip = it->GetData(); if (t1 >= clip->GetStartTime() && t0 <= clip->GetEndTime()) { diff --git a/src/WaveTrack.h b/src/WaveTrack.h index db7ea818c..82a8a649b 100644 --- a/src/WaveTrack.h +++ b/src/WaveTrack.h @@ -242,7 +242,7 @@ class AUDACITY_DLL_API WaveTrack final : public Track { void GetEnvelopeValues(double *buffer, int bufferLen, double t0, double tstep) const; bool GetMinMax(float *min, float *max, - double t0, double t1); + double t0, double t1) const; bool GetRMS(float *rms, double t0, double t1); // diff --git a/src/blockfile/LegacyBlockFile.cpp b/src/blockfile/LegacyBlockFile.cpp index 5c9f77bbf..95eb845a1 100644 --- a/src/blockfile/LegacyBlockFile.cpp +++ b/src/blockfile/LegacyBlockFile.cpp @@ -186,7 +186,7 @@ bool LegacyBlockFile::ReadSummary(void *data) /// @param start The offset in this block file /// @param len The number of samples to read int LegacyBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) + sampleCount start, sampleCount len) const { SF_INFO info; @@ -342,7 +342,7 @@ BlockFile *LegacyBlockFile::Copy(wxFileName newFileName) return newBlockFile; } -wxLongLong LegacyBlockFile::GetSpaceUsage() +wxLongLong LegacyBlockFile::GetSpaceUsage() const { wxFFile dataFile(mFileName.GetFullPath()); return dataFile.Length(); diff --git a/src/blockfile/LegacyBlockFile.h b/src/blockfile/LegacyBlockFile.h index 424a648f8..f4e33a4ba 100644 --- a/src/blockfile/LegacyBlockFile.h +++ b/src/blockfile/LegacyBlockFile.h @@ -51,13 +51,13 @@ class LegacyBlockFile final : public BlockFile { bool ReadSummary(void *data) override; /// Read the data section of the disk file int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; /// Create a NEW block file identical to this one BlockFile *Copy(wxFileName newFileName) override; /// Write an XML representation of this file void SaveXML(XMLWriter &xmlFile) override; - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; void Recover() override; static BlockFile *BuildFromXML(const wxString &dir, const wxChar **attrs, diff --git a/src/blockfile/ODDecodeBlockFile.cpp b/src/blockfile/ODDecodeBlockFile.cpp index 752c5303c..662d235a9 100644 --- a/src/blockfile/ODDecodeBlockFile.cpp +++ b/src/blockfile/ODDecodeBlockFile.cpp @@ -75,7 +75,7 @@ ODDecodeBlockFile::~ODDecodeBlockFile() //Check to see if we have the file for these calls. -wxLongLong ODDecodeBlockFile::GetSpaceUsage() +wxLongLong ODDecodeBlockFile::GetSpaceUsage() const { if(IsSummaryAvailable()) { @@ -91,7 +91,7 @@ wxLongLong ODDecodeBlockFile::GetSpaceUsage() /// Gets extreme values for the specified region void ODDecodeBlockFile::GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS) + float *outMin, float *outMax, float *outRMS) const { if(IsSummaryAvailable()) { @@ -108,7 +108,7 @@ void ODDecodeBlockFile::GetMinMax(sampleCount start, sampleCount len, } /// Gets extreme values for the entire block -void ODDecodeBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) +void ODDecodeBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) const { if(IsSummaryAvailable()) { @@ -289,12 +289,12 @@ void ODDecodeBlockFile::Recover(void) } } -bool ODDecodeBlockFile::IsSummaryAvailable() +bool ODDecodeBlockFile::IsSummaryAvailable() const { return IsDataAvailable(); } -bool ODDecodeBlockFile::IsDataAvailable() +bool ODDecodeBlockFile::IsDataAvailable() const { bool retval; mDataAvailableMutex.Lock(); @@ -302,6 +302,7 @@ bool ODDecodeBlockFile::IsDataAvailable() mDataAvailableMutex.Unlock(); return retval; } + /// Write the summary to disk, using the derived ReadData() to get the data /// Here, the decoder ODTask associated with this file must fetch the samples with /// the ODDecodeTask::Decode() method. @@ -367,7 +368,7 @@ void ODDecodeBlockFile::SetFileName(wxFileName &name) } ///sets the file name the summary info will be saved in. threadsafe. -wxFileName ODDecodeBlockFile::GetFileName() +wxFileName ODDecodeBlockFile::GetFileName() const { wxFileName name; mFileNameMutex.Lock(); @@ -526,7 +527,7 @@ void *ODDecodeBlockFile::CalcSummary(samplePtr buffer, sampleCount len, /// @param start The offset within the block to begin reading /// @param len The number of samples to read int ODDecodeBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) + sampleCount start, sampleCount len) const { int ret; LockRead(); @@ -571,12 +572,12 @@ void ODDecodeBlockFile::SetODFileDecoder(ODFileDecoder* decoder) /// Prevents a read on other threads. -void ODDecodeBlockFile::LockRead() +void ODDecodeBlockFile::LockRead() const { mReadDataMutex.Lock(); } /// Allows reading of encoded file on other threads. -void ODDecodeBlockFile::UnlockRead() +void ODDecodeBlockFile::UnlockRead() const { mReadDataMutex.Unlock(); } diff --git a/src/blockfile/ODDecodeBlockFile.h b/src/blockfile/ODDecodeBlockFile.h index 3df9c7b2f..b02d3201b 100644 --- a/src/blockfile/ODDecodeBlockFile.h +++ b/src/blockfile/ODDecodeBlockFile.h @@ -51,21 +51,21 @@ class ODDecodeBlockFile final : public SimpleBlockFile virtual ~ODDecodeBlockFile(); //checks to see if summary data has been computed and written to disk yet. Thread safe. Blocks if we are writing summary data. - bool IsSummaryAvailable() override; + bool IsSummaryAvailable() const override; /// Returns TRUE if this block's complete data is ready to be accessed by Read() - bool IsDataAvailable() override; + bool IsDataAvailable() const override; /// Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk bool IsSummaryBeingComputed() override { return false; } //Calls that rely on summary files need to be overidden - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; /// Gets extreme values for the specified region void GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS) override; + float *outMin, float *outMax, float *outRMS) const override; /// Gets extreme values for the entire block - void GetMinMax(float *outMin, float *outMax, float *outRMS) override; + void GetMinMax(float *outMin, float *outMax, float *outRMS) const override; /// Returns the 256 byte summary data block bool Read256(float *buffer, sampleCount start, sampleCount len) override; /// Returns the 64K summary data block @@ -97,32 +97,32 @@ class ODDecodeBlockFile final : public SimpleBlockFile void SetStart(sampleCount startSample){mStart = startSample;} ///Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. - sampleCount GetStart(){return mStart;} + sampleCount GetStart() const {return mStart;} //returns the number of samples from the beginning of the track that this blockfile starts at - sampleCount GetGlobalStart(){return mClipOffset+mStart;} + sampleCount GetGlobalStart() const {return mClipOffset+mStart;} //returns the number of samples from the beginning of the track that this blockfile ends at - sampleCount GetGlobalEnd(){return mClipOffset+mStart+GetLength();} + sampleCount GetGlobalEnd() const {return mClipOffset+mStart+GetLength();} //Below calls are overrided just so we can take wxlog calls out, which are not threadsafe. /// Reads the specified data from the aliased file using libsndfile int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; /// Read the summary into a buffer bool ReadSummary(void *data) override; ///Returns the type of audiofile this blockfile is loaded from. - unsigned int GetDecodeType() /* not override */ { return mType; } + unsigned int GetDecodeType() /* not override */ const { return mType; } // void SetDecodeType(unsigned int type) /* not override */ { mType = type; } ///sets the amount of samples the clip associated with this blockfile is offset in the wavetrack (non effecting) void SetClipOffset(sampleCount numSamples){mClipOffset= numSamples;} ///Gets the number of samples the clip associated with this blockfile is offset by. - sampleCount GetClipOffset(){return mClipOffset;} + sampleCount GetClipOffset() const {return mClipOffset;} //OD TODO:set ISAlias to true while we have no data? @@ -133,12 +133,12 @@ class ODDecodeBlockFile final : public SimpleBlockFile ///sets the file name the summary info will be saved in. threadsafe. void SetFileName(wxFileName &name) override; - wxFileName GetFileName() override; + wxFileName GetFileName() const override; /// Prevents a read on other threads of the encoded audio file. - void LockRead() override; + void LockRead() const override; /// Allows reading of encoded file on other threads. - void UnlockRead() override; + void UnlockRead() const override; ///// Get the name of the file where the audio data for this block is /// stored. @@ -162,12 +162,12 @@ class ODDecodeBlockFile final : public SimpleBlockFile ///This lock is for the filename (string) of the blockfile that contains summary/audio data ///after decoding - ODLock mFileNameMutex; + mutable ODLock mFileNameMutex; ///The original file the audio came from. wxFileName mAudioFileName; - ODLock mDataAvailableMutex; + mutable ODLock mDataAvailableMutex; bool mDataAvailable; bool mDataBeingComputed; @@ -175,7 +175,7 @@ class ODDecodeBlockFile final : public SimpleBlockFile ODLock mDecoderMutex; ///For accessing the audio file that will be decoded. Used by dir manager; - ODLock mReadDataMutex; + mutable ODLock mReadDataMutex; ///for reporting after task is complete. Only for display use. sampleCount mStart; diff --git a/src/blockfile/ODPCMAliasBlockFile.cpp b/src/blockfile/ODPCMAliasBlockFile.cpp index 07db9d255..eadddc63d 100644 --- a/src/blockfile/ODPCMAliasBlockFile.cpp +++ b/src/blockfile/ODPCMAliasBlockFile.cpp @@ -78,7 +78,7 @@ ODPCMAliasBlockFile::~ODPCMAliasBlockFile() /// DirManager should call this method. /// This method has been overidden to be threadsafe. It is important especially /// if two blockfiles deref at the same time resulting in a double deletion of the file -void ODPCMAliasBlockFile::Ref() +void ODPCMAliasBlockFile::Ref() const { mRefMutex.Lock(); BlockFile::Ref(); @@ -88,7 +88,7 @@ void ODPCMAliasBlockFile::Ref() /// Decreases the reference count of this block by one. If this /// causes the count to become zero, deletes the associated disk /// file and deletes this object -bool ODPCMAliasBlockFile::Deref() +bool ODPCMAliasBlockFile::Deref() const { bool ret; mDerefMutex.Lock(); @@ -104,7 +104,7 @@ bool ODPCMAliasBlockFile::Deref() //Check to see if we have the file for these calls. -wxLongLong ODPCMAliasBlockFile::GetSpaceUsage() +wxLongLong ODPCMAliasBlockFile::GetSpaceUsage() const { if(IsSummaryAvailable()) { @@ -148,7 +148,7 @@ void ODPCMAliasBlockFile::Unlock() /// Gets extreme values for the specified region void ODPCMAliasBlockFile::GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS) + float *outMin, float *outMax, float *outRMS) const { if(IsSummaryAvailable()) { @@ -165,7 +165,7 @@ void ODPCMAliasBlockFile::GetMinMax(sampleCount start, sampleCount len, } /// Gets extreme values for the entire block -void ODPCMAliasBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) +void ODPCMAliasBlockFile::GetMinMax(float *outMin, float *outMax, float *outRMS) const { if(IsSummaryAvailable()) { @@ -353,7 +353,7 @@ void ODPCMAliasBlockFile::Recover(void) } } -bool ODPCMAliasBlockFile::IsSummaryAvailable() +bool ODPCMAliasBlockFile::IsSummaryAvailable() const { bool retval; mSummaryAvailableMutex.Lock(); @@ -380,7 +380,7 @@ void ODPCMAliasBlockFile::SetFileName(wxFileName &name) } ///sets the file name the summary info will be saved in. threadsafe. -wxFileName ODPCMAliasBlockFile::GetFileName() +wxFileName ODPCMAliasBlockFile::GetFileName() const { wxFileName name; mFileNameMutex.Lock(); @@ -595,7 +595,7 @@ void *ODPCMAliasBlockFile::CalcSummary(samplePtr buffer, sampleCount len, /// @param start The offset within the block to begin reading /// @param len The number of samples to read int ODPCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) + sampleCount start, sampleCount len) const { LockRead(); @@ -723,12 +723,12 @@ bool ODPCMAliasBlockFile::ReadSummary(void *data) } /// Prevents a read on other threads. -void ODPCMAliasBlockFile::LockRead() +void ODPCMAliasBlockFile::LockRead() const { mReadDataMutex.Lock(); } /// Allows reading on other threads. -void ODPCMAliasBlockFile::UnlockRead() +void ODPCMAliasBlockFile::UnlockRead() const { mReadDataMutex.Unlock(); } diff --git a/src/blockfile/ODPCMAliasBlockFile.h b/src/blockfile/ODPCMAliasBlockFile.h index d3acbddf7..432348716 100644 --- a/src/blockfile/ODPCMAliasBlockFile.h +++ b/src/blockfile/ODPCMAliasBlockFile.h @@ -57,18 +57,18 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile virtual ~ODPCMAliasBlockFile(); //checks to see if summary data has been computed and written to disk yet. Thread safe. Blocks if we are writing summary data. - bool IsSummaryAvailable() override; + bool IsSummaryAvailable() const override; /// Returns TRUE if the summary has not yet been written, but is actively being computed and written to disk bool IsSummaryBeingComputed() override { return mSummaryBeingComputed; } //Calls that rely on summary files need to be overidden - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; /// Gets extreme values for the specified region void GetMinMax(sampleCount start, sampleCount len, - float *outMin, float *outMax, float *outRMS) override; + float *outMin, float *outMax, float *outRMS) const override; /// Gets extreme values for the entire block - void GetMinMax(float *outMin, float *outMax, float *outRMS) override; + void GetMinMax(float *outMin, float *outMax, float *outRMS) const override; /// Returns the 256 byte summary data block bool Read256(float *buffer, sampleCount start, sampleCount len) override; /// Returns the 64K summary data block @@ -93,7 +93,7 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile void SetStart(sampleCount startSample){mStart = startSample;} ///Gets the value that indicates where the first sample in this block corresponds to the global sequence/clip. Only for display use. - sampleCount GetStart(){return mStart;} + sampleCount GetStart() const {return mStart;} /// Locks the blockfile only if it has a file that exists. void Lock(); @@ -105,35 +105,35 @@ class ODPCMAliasBlockFile final : public PCMAliasBlockFile void SetClipOffset(sampleCount numSamples){mClipOffset= numSamples;} ///Gets the number of samples the clip associated with this blockfile is offset by. - sampleCount GetClipOffset(){return mClipOffset;} + sampleCount GetClipOffset() const {return mClipOffset;} //returns the number of samples from the beginning of the track that this blockfile starts at - sampleCount GetGlobalStart(){return mClipOffset+mStart;} + sampleCount GetGlobalStart() const {return mClipOffset+mStart;} //returns the number of samples from the beginning of the track that this blockfile ends at - sampleCount GetGlobalEnd(){return mClipOffset+mStart+GetLength();} + sampleCount GetGlobalEnd() const {return mClipOffset+mStart+GetLength();} //Below calls are overrided just so we can take wxlog calls out, which are not threadsafe. /// Reads the specified data from the aliased file using libsndfile int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; /// Read the summary into a buffer bool ReadSummary(void *data) override; ///sets the file name the summary info will be saved in. threadsafe. void SetFileName(wxFileName &name) override; - wxFileName GetFileName() override; + wxFileName GetFileName() const override; //when the file closes, it locks the blockfiles, but it calls this so we can check if it has been saved before. void CloseLock() override; /// Prevents a read on other threads. - void LockRead() override; + void LockRead() const override; /// Allows reading on other threads. - void UnlockRead() override; + void UnlockRead() const override; protected: void WriteSummary() override; @@ -142,8 +142,8 @@ protected: private: //Thread-safe versions - void Ref() override; - bool Deref() override; + void Ref() const override; + bool Deref() const override; //needed for Ref/Deref access. friend class DirManager; friend class ODComputeSummaryTask; @@ -152,20 +152,20 @@ protected: ODLock mWriteSummaryMutex; //need to protect this since it is changed from the main thread upon save. - ODLock mFileNameMutex; + mutable ODLock mFileNameMutex; ///Also need to protect the aliased file name. ODLock mAliasedFileNameMutex; //lock the read data - libsndfile can't handle two reads at once? - ODLock mReadDataMutex; + mutable ODLock mReadDataMutex; //lock the Ref counting - ODLock mDerefMutex; - ODLock mRefMutex; + mutable ODLock mDerefMutex; + mutable ODLock mRefMutex; - ODLock mSummaryAvailableMutex; + mutable ODLock mSummaryAvailableMutex; bool mSummaryAvailable; bool mSummaryBeingComputed; bool mHasBeenSaved; diff --git a/src/blockfile/PCMAliasBlockFile.cpp b/src/blockfile/PCMAliasBlockFile.cpp index 013526dce..cf9288947 100644 --- a/src/blockfile/PCMAliasBlockFile.cpp +++ b/src/blockfile/PCMAliasBlockFile.cpp @@ -74,7 +74,7 @@ PCMAliasBlockFile::~PCMAliasBlockFile() /// @param start The offset within the block to begin reading /// @param len The number of samples to read int PCMAliasBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) + sampleCount start, sampleCount len) const { SF_INFO info; diff --git a/src/blockfile/PCMAliasBlockFile.h b/src/blockfile/PCMAliasBlockFile.h index a3801922e..0718c430d 100644 --- a/src/blockfile/PCMAliasBlockFile.h +++ b/src/blockfile/PCMAliasBlockFile.h @@ -38,7 +38,7 @@ class PCMAliasBlockFile /* not final */ : public AliasBlockFile /// Reads the specified data from the aliased file using libsndfile int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; void SaveXML(XMLWriter &xmlFile) override; BlockFile *Copy(wxFileName fileName) override; diff --git a/src/blockfile/SilentBlockFile.cpp b/src/blockfile/SilentBlockFile.cpp index 254bec991..f92449924 100644 --- a/src/blockfile/SilentBlockFile.cpp +++ b/src/blockfile/SilentBlockFile.cpp @@ -31,7 +31,7 @@ bool SilentBlockFile::ReadSummary(void *data) } int SilentBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount WXUNUSED(start), sampleCount len) + sampleCount WXUNUSED(start), sampleCount len) const { ClearSamples(data, format, 0, len); @@ -82,7 +82,7 @@ BlockFile *SilentBlockFile::Copy(wxFileName newFileName) return newBlockFile; } -wxLongLong SilentBlockFile::GetSpaceUsage() +wxLongLong SilentBlockFile::GetSpaceUsage() const { return 0; } diff --git a/src/blockfile/SilentBlockFile.h b/src/blockfile/SilentBlockFile.h index 25088b8f9..583e8da24 100644 --- a/src/blockfile/SilentBlockFile.h +++ b/src/blockfile/SilentBlockFile.h @@ -36,13 +36,13 @@ class SilentBlockFile final : public BlockFile { bool ReadSummary(void *data) override; /// Read the data section of the disk file int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; /// Create a NEW block file identical to this one BlockFile *Copy(wxFileName newFileName) override; /// Write an XML representation of this file void SaveXML(XMLWriter &xmlFile) override; - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; void Recover() override { }; static BlockFile *BuildFromXML(DirManager &dm, const wxChar **attrs); diff --git a/src/blockfile/SimpleBlockFile.cpp b/src/blockfile/SimpleBlockFile.cpp index bd774859d..3352f8de4 100644 --- a/src/blockfile/SimpleBlockFile.cpp +++ b/src/blockfile/SimpleBlockFile.cpp @@ -388,7 +388,7 @@ bool SimpleBlockFile::ReadSummary(void *data) /// @param start The offset in this block file /// @param len The number of samples to read int SimpleBlockFile::ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) + sampleCount start, sampleCount len) const { if (mCache.active) { @@ -544,7 +544,7 @@ BlockFile *SimpleBlockFile::Copy(wxFileName newFileName) return newBlockFile; } -wxLongLong SimpleBlockFile::GetSpaceUsage() +wxLongLong SimpleBlockFile::GetSpaceUsage() const { if (mCache.active && mCache.needWrite) { diff --git a/src/blockfile/SimpleBlockFile.h b/src/blockfile/SimpleBlockFile.h index 54d9c3ea4..02e0246c6 100644 --- a/src/blockfile/SimpleBlockFile.h +++ b/src/blockfile/SimpleBlockFile.h @@ -65,14 +65,14 @@ class PROFILE_DLL_API SimpleBlockFile /* not final */ : public BlockFile { bool ReadSummary(void *data) override; /// Read the data section of the disk file int ReadData(samplePtr data, sampleFormat format, - sampleCount start, sampleCount len) override; + sampleCount start, sampleCount len) const override; /// Create a NEW block file identical to this one BlockFile *Copy(wxFileName newFileName) override; /// Write an XML representation of this file void SaveXML(XMLWriter &xmlFile) override; - wxLongLong GetSpaceUsage() override; + wxLongLong GetSpaceUsage() const override; void Recover() override; static BlockFile *BuildFromXML(DirManager &dm, const wxChar **attrs); @@ -92,7 +92,8 @@ class PROFILE_DLL_API SimpleBlockFile /* not final */ : public BlockFile { SimpleBlockFileCache mCache; - sampleFormat mFormat; + private: + mutable sampleFormat mFormat; // may be found lazily }; #endif