Audacity 3.2.0
Project.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Project.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10*//*******************************************************************/
11
12#include "Project.h"
13
14#include <wx/display.h>
15#include <wx/filename.h>
16
17size_t AllProjects::size() const
18{
19 return gAudacityProjects.size();
20}
21
23{
24 return gAudacityProjects.begin();
25}
26
28{
29 return gAudacityProjects.end();
30}
31
33{
34 return gAudacityProjects.rbegin();
35}
36
38{
39 return gAudacityProjects.rend();
40}
41
43{
44 std::lock_guard<std::mutex> guard{ Mutex() };
45 auto start = begin(), finish = end(), iter = std::find_if(
46 start, finish,
47 [&]( const value_type &ptr ){ return ptr.get() == &project; }
48 );
49 if (iter == finish)
50 return nullptr;
51 auto result = *iter;
52 gAudacityProjects.erase( iter );
53 return result;
54}
55
56void AllProjects::Add( const value_type &pProject )
57{
58 if (!pProject) {
59 wxASSERT(false);
60 return;
61 }
62 std::lock_guard<std::mutex> guard{ Mutex() };
63 gAudacityProjects.push_back( pProject );
64}
65
66std::mutex &AllProjects::Mutex()
67{
68 static std::mutex theMutex;
69 return theMutex;
70}
71
72int AudacityProject::mProjectCounter=0;// global counter.
73
74/* Define Global Variables */
75//This array holds onto all of the projects currently open
77
78std::shared_ptr<AudacityProject> AudacityProject::Create()
79{
80 // Must complete make_shared before using shared_from_this() or
81 // weak_from_this()
82 auto result = std::make_shared<AudacityProject>(CreateToken{});
83 // Only now build the attached objects, which also causes the project window
84 // to be built on demand
85 result->AttachedObjects::BuildAll();
86 // But not for all the attached windows. They get built on demand only
87 // later.
88 return result;
89}
90
92{
93 mProjectNo = mProjectCounter++; // Bug 322
94}
95
97{
98}
99
100const wxString &AudacityProject::GetProjectName() const
101{
102 return mName;
103}
104
106{
107 mName = name;
108}
109
111{
112 return mInitialImportPath;
113}
114
116{
117 if (mInitialImportPath.empty())
118 {
119 mInitialImportPath = path;
120 }
121}
122
123// Generate the needed, linkable registry functions
const TranslatableString name
Definition: Distortion.cpp:82
DEFINE_XML_METHOD_REGISTRY(ProjectFileIORegistry)
wxString FilePath
Definition: Project.h:20
static std::mutex & Mutex()
Definition: Project.cpp:66
const_reverse_iterator rend() const
Definition: Project.cpp:37
static Container gAudacityProjects
Definition: Project.h:40
std::vector< AProjectHolder > Container
Definition: Project.h:39
void Add(const value_type &pProject)
This invalidates iterators.
Definition: Project.cpp:56
Container::const_reverse_iterator const_reverse_iterator
Definition: Project.h:52
Container::const_iterator const_iterator
Definition: Project.h:48
size_t size() const
Definition: Project.cpp:17
const_iterator end() const
Definition: Project.cpp:27
Container::value_type value_type
Definition: Project.h:56
value_type Remove(AudacityProject &project)
Definition: Project.cpp:42
const_iterator begin() const
Definition: Project.cpp:22
const_reverse_iterator rbegin() const
Definition: Project.cpp:32
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
virtual ~AudacityProject()
Definition: Project.cpp:96
void SetInitialImportPath(const FilePath &path)
Definition: Project.cpp:115
FilePath mInitialImportPath
Definition: Project.h:126
const wxString & GetProjectName() const
Definition: Project.cpp:100
wxString mName
Definition: Project.h:121
void SetProjectName(const wxString &name)
Definition: Project.cpp:105
static int mProjectCounter
Definition: Project.h:123
FilePath GetInitialImportPath() const
Definition: Project.cpp:110
AudacityProject(CreateToken)
Don't use this constructor directly.
Definition: Project.cpp:91
static std::shared_ptr< AudacityProject > Create()
Use this factory function.
Definition: Project.cpp:78
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150