Audacity 3.2.0
Project.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Project.h
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11#ifndef __AUDACITY_PROJECT__
12#define __AUDACITY_PROJECT__
13
14#include "ClientData.h" // to inherit
15#include "GlobalVariable.h"
16
17#include <memory>
18#include <mutex>
19
20#include <wx/event.h>
21using FilePath = wxString;
22
23class AudacityProject;
24
27
35class PROJECT_API AllProjects
36{
37
38 // Use shared_ptr to projects, because elsewhere we need weak_ptr
39 using AProjectHolder = std::shared_ptr< AudacityProject >;
40 using Container = std::vector< AProjectHolder >;
42
43public:
44 AllProjects() = default;
45
46 size_t size() const;
47 bool empty() const { return size() == 0; }
48
49 using const_iterator = Container::const_iterator;
50 const_iterator begin() const;
51 const_iterator end() const;
52
53 using const_reverse_iterator = Container::const_reverse_iterator;
54 const_reverse_iterator rbegin() const;
55 const_reverse_iterator rend() const;
56
57 using value_type = Container::value_type;
58
59 // If the project is present, remove it from the global array and return
60 // a shared pointer, else return null. This invalidates any iterators.
62
64
67 void Add( const value_type &pProject );
68
71 static std::mutex &Mutex();
72};
73
74// Container of various objects associated with the project, which is
75// responsible for destroying them
78>;
79
86class PROJECT_API AudacityProject final
87 : public wxEvtHandler
89 , public std::enable_shared_from_this<AudacityProject>
90{
91 struct CreateToken{};
92 public:
94
96 static std::shared_ptr<AudacityProject> Create();
99 virtual ~AudacityProject();
100
101 int GetProjectNumber(){ return mProjectNo;}
102
103 // Project name can be either empty or have the name of the project.
104 //
105 // If empty, it signifies that the project is empty/unmodified or
106 // that the project hasn't yet been saved to a permanent project
107 // file.
108 //
109 // If a name has been assigned, it is merely used to identify
110 // the project and should not be used for any other purposes.
111 const wxString &GetProjectName() const;
112 void SetProjectName(const wxString &name);
113
114 // Used exclusively in batch mode, this allows commands to remember
115 // and use the initial import path
116 FilePath GetInitialImportPath() const;
117 void SetInitialImportPath(const FilePath &path);
118
119private:
120
121 // The project's name
122 wxString mName;
123
124 static int mProjectCounter;// global counter.
125 int mProjectNo; // count when this project was created.
126
128
129 public:
130 bool mbBusyImporting{ false }; // used to fix bug 584
131 int mBatchMode{ 0 };// 0 means not, >0 means in batch mode.
132};
133
134// Generate a registry for serialized data attached to the project
135#include "XMLMethodRegistry.h"
136class AudacityProject;
139
140namespace BasicUI { class WindowPlacement; }
141
144 std::unique_ptr<const BasicUI::WindowPlacement>(
146>;
147
149
150PROJECT_API std::unique_ptr<const BasicUI::WindowPlacement>
152
153#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
wxString FilePath
Definition: Project.h:21
ClientData::Site< AudacityProject, ClientData::Base, ClientData::SkipCopying, std::shared_ptr > AttachedProjectObjects
Definition: Project.h:78
DECLARE_XML_METHOD_REGISTRY(PROJECT_API, ProjectFileIORegistry)
PROJECT_API 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 name
Definition: TagsEditor.cpp:166
const auto project
static Container gAudacityProjects
Definition: Project.h:41
std::vector< AProjectHolder > Container
Definition: Project.h:40
Container::const_reverse_iterator const_reverse_iterator
Definition: Project.h:53
Container::const_iterator const_iterator
Definition: Project.h:49
AllProjects()=default
Container::value_type value_type
Definition: Project.h:57
std::shared_ptr< AudacityProject > AProjectHolder
Definition: Project.h:39
bool empty() const
Definition: Project.h:47
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
int GetProjectNumber()
Definition: Project.h:101
FilePath mInitialImportPath
Definition: Project.h:127
wxString mName
Definition: Project.h:122
static int mProjectCounter
Definition: Project.h:124
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:229
Global function-valued variable, adding a convenient Call()
PROJECT_FILE_IO_API void Remove(const FilePath &path)
PROJECT_FILE_IO_API void Add(const FilePath &path)
@ SkipCopying
ignore the source and leave empty
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
A convenient default parameter for class template Site.
Definition: ClientData.h:29