1
0
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:
Paul Licameli
2016-04-12 00:31:25 -04:00
parent 48658097d6
commit 1033095696
5 changed files with 46 additions and 46 deletions

View File

@@ -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.