mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-16 09:31:14 +01:00
RAII for locking of WaveTracks
This commit is contained in:
@@ -285,8 +285,29 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
|
||||
// doing a copy and paste between projects.
|
||||
//
|
||||
|
||||
bool Lock();
|
||||
bool Unlock();
|
||||
bool Lock() const;
|
||||
bool Unlock() const;
|
||||
|
||||
struct WaveTrackLockDeleter {
|
||||
inline void operator () (const WaveTrack *pTrack) { pTrack->Unlock(); }
|
||||
};
|
||||
using LockerBase = std::unique_ptr<
|
||||
const WaveTrack, WaveTrackLockDeleter
|
||||
>;
|
||||
|
||||
// RAII object for locking.
|
||||
struct Locker : private LockerBase
|
||||
{
|
||||
friend LockerBase;
|
||||
Locker (const WaveTrack *pTrack)
|
||||
: LockerBase{ pTrack }
|
||||
{ pTrack->Lock(); }
|
||||
Locker(Locker &&that) : LockerBase{std::move(that)} {}
|
||||
Locker &operator= (Locker &&that) {
|
||||
(LockerBase&)(*this) = std::move(that);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
bool CloseLock(); //similar to Lock but should be called when the project closes.
|
||||
// not balanced by unlocking calls.
|
||||
|
||||
Reference in New Issue
Block a user