Audacity  3.0.3
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 "Identifier.h"
15 
16 #include "ClientData.h" // to inherit
17 
18 #include <memory>
19 #include <mutex>
20 #include <wx/weakref.h> // member variable
21 #include <wx/window.h> // MSVC wants this
22 
23 class wxFrame;
24 class wxWindow;
25 
26 class AudacityProject;
27 
28 AUDACITY_DLL_API AudacityProject *GetActiveProject();
29 // For use by ProjectManager only:
30 AUDACITY_DLL_API void SetActiveProject(AudacityProject * project);
31 
37 class AUDACITY_DLL_API AllProjects
38 {
39  // Use shared_ptr to projects, because elsewhere we need weak_ptr
40  using AProjectHolder = std::shared_ptr< AudacityProject >;
41  using Container = std::vector< AProjectHolder >;
43 
44 public:
45  AllProjects() = default;
46 
47  size_t size() const;
48  bool empty() const { return size() == 0; }
49 
50  using const_iterator = Container::const_iterator;
51  const_iterator begin() const;
52  const_iterator end() const;
53 
54  using const_reverse_iterator = Container::const_reverse_iterator;
55  const_reverse_iterator rbegin() const;
56  const_reverse_iterator rend() const;
57 
58  using value_type = Container::value_type;
59 
60  // If the project is present, remove it from the global array and return
61  // a shared pointer, else return null. This invalidates any iterators.
62  value_type Remove( AudacityProject &project );
63 
64  // This invalidates iterators
65  void Add( const value_type &pProject );
66 
69  static std::mutex &Mutex();
70 
71  // Return true if all projects do close (always so if force == true)
72  // But if return is false, that means the user cancelled close of at least
73  // one un-saved project.
74  static bool Close( bool force = false );
75 
76  static bool Closing() { return sbClosing; }
77 
78 private:
79  static bool sbClosing;
80 };
81 
82 // Container of various objects associated with the project, which is
83 // responsible for destroying them
86 >;
87 // Container of pointers to various windows associated with the project, which
88 // is not responsible for destroying them -- wxWidgets handles that instead
91 >;
92 
93 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
94  EVT_TRACK_PANEL_TIMER, wxCommandEvent);
95 
96 // This event is emitted by the application object when there is a change
97 // in the activated project
98 wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
99  EVT_PROJECT_ACTIVATION, wxCommandEvent);
100 
107 class AUDACITY_DLL_API AudacityProject final
108  : public wxEvtHandler
109  , public AttachedProjectObjects
110  , public AttachedProjectWindows
111  , public std::enable_shared_from_this<AudacityProject>
112 {
113  public:
116 
117  AudacityProject();
118  virtual ~AudacityProject();
119 
120  wxFrame *GetFrame() { return mFrame; }
121  const wxFrame *GetFrame() const { return mFrame; }
122  void SetFrame( wxFrame *pFrame );
123 
124  wxWindow *GetPanel() { return mPanel; }
125  const wxWindow *GetPanel() const { return mPanel; }
126  void SetPanel( wxWindow *pPanel );
127 
128  int GetProjectNumber(){ return mProjectNo;}
129 
130  // Project name can be either empty or have the name of the project.
131  //
132  // If empty, it signifies that the project is empty/unmodified or
133  // that the project hasn't yet been saved to a permanent project
134  // file.
135  //
136  // If a name has been assigned, it is merely used to identify
137  // the project and should not be used for any other purposes.
138  const wxString &GetProjectName() const;
139  void SetProjectName(const wxString &name);
140 
141  // Used exclusively in batch mode, this allows commands to remember
142  // and use the initial import path
143  FilePath GetInitialImportPath() const;
144  void SetInitialImportPath(const FilePath &path);
145 
146 private:
147 
148  // The project's name
149  wxString mName;
150 
151  static int mProjectCounter;// global counter.
152  int mProjectNo; // count when this project was created.
153 
155 
156  public:
157  bool mbBusyImporting{ false }; // used to fix bug 584
158  int mBatchMode{ 0 };// 0 means not, >0 means in batch mode.
159 
160  private:
161  wxWeakRef< wxFrame > mFrame{};
162  wxWeakRef< wxWindow > mPanel{};
163 };
164 
167 AUDACITY_DLL_API wxFrame &GetProjectFrame( AudacityProject &project );
168 AUDACITY_DLL_API const wxFrame &GetProjectFrame( const AudacityProject &project );
169 
172 inline wxFrame *FindProjectFrame( AudacityProject *project ) {
173  return project ? &GetProjectFrame( *project ) : nullptr;
174 }
175 inline const wxFrame *FindProjectFrame( const AudacityProject *project ) {
176  return project ? &GetProjectFrame( *project ) : nullptr;
177 }
178 
180 // (as a wxWindow only, when you do not need to use the subclass TrackPanel)
181 AUDACITY_DLL_API wxWindow &GetProjectPanel( AudacityProject &project );
182 AUDACITY_DLL_API const wxWindow &GetProjectPanel(
183  const AudacityProject &project );
184 
185 #endif
GetProjectPanel
AUDACITY_DLL_API wxWindow & GetProjectPanel(AudacityProject &project)
Get the main sub-window of the project frame that displays track data.
Definition: Project.cpp:202
FilePath
wxString FilePath
Definition: Identifier.h:227
AudacityProject::GetPanel
wxWindow * GetPanel()
Definition: Project.h:124
mFrame
ScreenshotBigDialogPtr mFrame
Definition: Screenshot.cpp:129
AttachedProjectObjects
ClientData::Site< AudacityProject, ClientData::Base, ClientData::SkipCopying, std::shared_ptr > AttachedProjectObjects
Definition: Project.h:86
AudacityProject::GetFrame
wxFrame * GetFrame()
Definition: Project.h:120
AllProjects::const_iterator
Container::const_iterator const_iterator
Definition: Project.h:50
AllProjects::Closing
static bool Closing()
Definition: Project.h:76
ClientData::BarePtr
Object * BarePtr
This template-template parameter for ClientData::Site risks dangling pointers, so be careful.
Definition: ClientData.h:37
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
AllProjects::Container
std::vector< AProjectHolder > Container
Definition: Project.h:41
GetActiveProject
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:107
ClientData::SkipCopying
@ SkipCopying
ignore the source and leave empty
Definition: ClientDataHelpers.h:34
AllProjects::empty
bool empty() const
Definition: Project.h:48
AudacityProject::mProjectNo
int mProjectNo
Definition: Project.h:152
AllProjects::AllProjects
AllProjects()=default
AudacityProject::GetFrame
const wxFrame * GetFrame() const
Definition: Project.h:121
AllProjects::gAudacityProjects
static Container gAudacityProjects
Definition: Project.h:42
FindProjectFrame
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null.
Definition: Project.h:172
AudacityProject::GetProjectNumber
int GetProjectNumber()
Definition: Project.h:128
wxDECLARE_EXPORTED_EVENT
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_TRACK_PANEL_TIMER, wxCommandEvent)
name
const TranslatableString name
Definition: Distortion.cpp:98
ClientData::Site
Utility to register hooks into a host class that attach client data.
Definition: ClientData.h:220
Identifier.h
AllProjects::AProjectHolder
std::shared_ptr< AudacityProject > AProjectHolder
Definition: Project.h:40
AllProjects::const_reverse_iterator
Container::const_reverse_iterator const_reverse_iterator
Definition: Project.h:54
AllProjects::sbClosing
static bool sbClosing
Definition: Project.h:79
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
AllProjects
an object of class AllProjects acts like a standard library container, but refers to a global array o...
Definition: Project.h:38
AudacityProject::mName
wxString mName
Definition: Project.h:149
AudacityProject::GetPanel
const wxWindow * GetPanel() const
Definition: Project.h:125
AttachedProjectWindows
ClientData::Site< AudacityProject, wxWindow, ClientData::SkipCopying, ClientData::BarePtr > AttachedProjectWindows
Definition: Project.h:91
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: Project.cpp:186
ActiveProjects::Remove
void Remove(const FilePath &path)
ActiveProjects::Add
void Add(const FilePath &path)
AudacityProject::mProjectCounter
static int mProjectCounter
Definition: Project.h:151
AllProjects::value_type
Container::value_type value_type
Definition: Project.h:58
AudacityProject::mInitialImportPath
FilePath mInitialImportPath
Definition: Project.h:154
SetActiveProject
AUDACITY_DLL_API void SetActiveProject(AudacityProject *project)
Definition: Project.cpp:112