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
125
126#include "BasicUI.h"
127
128std::unique_ptr<const BasicUI::WindowPlacement>
130{
132 std::unique_ptr<const BasicUI::WindowPlacement> result;
133 if (project && factory && (result = factory(*project)).get())
134 return result;
135 else
136 return std::make_unique<BasicUI::WindowPlacement>();
137}
static RegisteredToolbarFactory factory
Toolkit-neutral facade for basic user interface services.
const TranslatableString name
Definition: Distortion.cpp:76
DEFINE_XML_METHOD_REGISTRY(ProjectFileIORegistry)
std::unique_ptr< const BasicUI::WindowPlacement > ProjectFramePlacement(AudacityProject *project)
Make a WindowPlacement object suitable for project (which may be null)
Definition: Project.cpp:129
wxString FilePath
Definition: Project.h:21
const auto project
static std::mutex & Mutex()
Definition: Project.cpp:66
const_reverse_iterator rend() const
Definition: Project.cpp:37
static Container gAudacityProjects
Definition: Project.h:41
std::vector< AProjectHolder > Container
Definition: Project.h:40
void Add(const value_type &pProject)
This invalidates iterators.
Definition: Project.cpp:56
Container::const_reverse_iterator const_reverse_iterator
Definition: Project.h:53
Container::const_iterator const_iterator
Definition: Project.h:49
size_t size() const
Definition: Project.cpp:17
const_iterator end() const
Definition: Project.cpp:27
Container::value_type value_type
Definition: Project.h:57
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:90
virtual ~AudacityProject()
Definition: Project.cpp:96
void SetInitialImportPath(const FilePath &path)
Definition: Project.cpp:115
FilePath mInitialImportPath
Definition: Project.h:127
const wxString & GetProjectName() const
Definition: Project.cpp:100
wxString mName
Definition: Project.h:122
void SetProjectName(const wxString &name)
Definition: Project.cpp:105
static int mProjectCounter
Definition: Project.h:124
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
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101