Audacity 3.2.0
Clipboard.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Clipboard.cpp
6
7*//*******************************************************************/
8
9#include "Clipboard.h"
10#include "BasicUI.h"
11#include "Track.h"
12
14: mTracks { TrackList::Create( nullptr ) }
15{
16}
17
18Clipboard::~Clipboard() = default;
19
21{
22 std::swap( mTracks, other.mTracks );
23 std::swap( mProject, other.mProject );
24 std::swap( mT0, other.mT0 );
25 std::swap( mT1, other.mT1 );
26}
27
29{
30 static Clipboard instance;
31 return instance;
32}
33
34//static
36{
37 return *mTracks;
38}
39
41{
42 mT0 = 0.0;
43 mT1 = 0.0;
44 mProject.reset();
45 mTracks->Clear();
46
47 if (this == &Get())
48 // Delayed message at idle time
49 // Don't need to capture a weak pointer to the global object
50 BasicUI::CallAfter([this]{ Publish({}); });
51}
52
53void Clipboard::Assign( TrackList && newContents,
54 double t0, double t1, const std::weak_ptr<AudacityProject> &pProject )
55{
56 assert(!newContents.GetOwner());
57 newContents.Swap( *mTracks );
58 newContents.Clear();
59
60 mT0 = t0;
61 mT1 = t1;
62 mProject = pProject;
63
64 if (this == &Get())
65 // Delayed message at idle time
66 // Don't need to capture a weak pointer to the global object
67 BasicUI::CallAfter([this]{ Publish({}); });
68}
69
71{
73}
74
76{
77 Get().Swap(mTempClipboard);
78}
Toolkit-neutral facade for basic user interface services.
declares abstract base class Track, TrackList, and iterators over TrackList
void Assign(TrackList &&newContents, double t0, double t1, const std::weak_ptr< AudacityProject > &pProject)
Definition: Clipboard.cpp:53
static Clipboard & Get()
Definition: Clipboard.cpp:28
std::shared_ptr< TrackList > mTracks
Definition: Clipboard.h:63
std::weak_ptr< AudacityProject > mProject
Definition: Clipboard.h:64
void Swap(Clipboard &other)
Definition: Clipboard.cpp:20
void Clear()
Definition: Clipboard.cpp:40
const TrackList & GetTracks() const
Definition: Clipboard.cpp:35
double mT0
Definition: Clipboard.h:65
double mT1
Definition: Clipboard.h:66
CallbackReturn Publish(const ClipboardChangeMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:993
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:208
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645
Clipboard mTempClipboard
Definition: Clipboard.h:74