Audacity  2.2.2
AudacityApp.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AudacityApp.h
6 
7  Dominic Mazzoni
8 
9  This is the main source file for Audacity which handles
10  initialization and termination by subclassing wxApp.
11 
12 **********************************************************************/
13 
14 #ifndef __AUDACITY_APP__
15 #define __AUDACITY_APP__
16 
17 #include "Audacity.h"
18 
19 #include "MemoryX.h"
20 #include <wx/app.h>
21 #include <wx/cmdline.h>
22 #include <wx/dir.h>
23 #include <wx/event.h>
24 #include <wx/docview.h>
25 #include <wx/intl.h>
26 #include <wx/snglinst.h>
27 #include <wx/log.h>
28 #include <wx/socket.h>
29 #include <wx/timer.h>
30 
31 #include "widgets/FileHistory.h"
32 #include "ondemand/ODTaskThread.h"
33 #include "Experimental.h"
34 
35 #if defined(EXPERIMENTAL_CRASH_REPORT)
36 #include <wx/debugrpt.h>
37 #endif
38 
39 class IPCServ;
40 class Importer;
41 class CommandHandler;
42 class AppCommandEvent;
43 class AudacityLogger;
44 class AudacityProject;
45 
46 void SaveWindowSize();
47 
48 void QuitAudacity(bool bForce);
49 void QuitAudacity();
50 
51 extern bool gIsQuitting;
52 
53 // Asynchronous open
54 DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE, -1);
55 
56 class BlockFile;
57 class AliasBlockFile;
58 
59 class AudacityApp final : public wxApp {
60  public:
61  AudacityApp();
62  ~AudacityApp();
63  bool OnInit(void) override;
64  int OnExit(void) override;
65  void OnFatalException() override;
66  bool OnExceptionInMainLoop() override;
67 
68  int FilterEvent(wxEvent & event);
69 
70  // Returns the language actually used which is not lang if lang cannot be found.
71  wxString InitLang( const wxString & lang );
72 
73  // These are currently only used on Mac OS, where it's
74  // possible to have a menu bar but no windows open. It doesn't
75  // hurt any other platforms, though.
76  void OnMenuAbout(wxCommandEvent & event);
77  void OnMenuNew(wxCommandEvent & event);
78  void OnMenuOpen(wxCommandEvent & event);
79  void OnMenuPreferences(wxCommandEvent & event);
80  void OnMenuExit(wxCommandEvent & event);
81 
82  void OnQueryEndSession(wxCloseEvent & event);
83  void OnEndSession(wxCloseEvent & event);
84 
85  // Most Recently Used File support (for all platforms).
86  void OnMRUClear(wxCommandEvent &event);
87  void OnMRUFile(wxCommandEvent &event);
88  // Backend for above - returns true for success, false for failure
89  bool MRUOpen(const wxString &fileName);
90  // A wrapper of the above that does not throw
91  bool SafeMRUOpen(const wxString &fileName);
92 
93  void OnReceiveCommand(AppCommandEvent &event);
94 
95  void OnKeyDown(wxKeyEvent &event);
96 
97  void OnTimer(wxTimerEvent & event);
98 
99  // IPC communication
100  void OnServerEvent(wxSocketEvent & evt);
101  void OnSocketEvent(wxSocketEvent & evt);
102 
110 
114 
118 
119  #ifdef __WXMAC__
120  // In response to Apple Events
121  void MacOpenFile(const wxString &fileName) override;
122  void MacPrintFile(const wxString &fileName) override;
123  void MacNewFile() override;
124  #endif
125 
126  #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) && !defined(__CYGWIN__)
127  void AssociateFileTypes();
128  #endif
129 
138  wxArrayString audacityPathList;
139 
141  wxString defaultTempDir;
142 
143  // Useful functions for working with search paths
144  static void AddUniquePathToPathList(const wxString &path,
145  wxArrayString &pathList);
146  static void AddMultiPathsToPathList(const wxString &multiPathString,
147  wxArrayString &pathList);
148  static void FindFilesInPathList(const wxString & pattern,
149  const wxArrayString & pathList,
150  wxArrayString &results,
151  int flags = wxDIR_FILES);
152  static bool IsTempDirectoryNameOK( const wxString & Name );
153 
155  void AddFileToHistory(const wxString & name);
157  void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
158 
160 
161 #if defined(EXPERIMENTAL_CRASH_REPORT)
162  void GenerateCrashReport(wxDebugReport::Context ctx);
163 #endif
164 
165 #ifdef __WXMAC__
166 
167  void MacActivateApp();
168 
169 #endif
170 
171  // Set and Get values of the version major/minor/micro keys in audacity.cfg when Audacity first opens
172  void SetVersionKeysInit( int major, int minor, int micro)
174  void GetVersionKeysInit( int& major, int& minor, int& micro) const
176 
177 
178  private:
179  std::unique_ptr<CommandHandler> mCmdHandler;
180  std::unique_ptr<FileHistory> mRecentFiles;
181 
182  std::unique_ptr<wxLocale> mLocale;
183 
184  std::unique_ptr<wxSingleInstanceChecker> mChecker;
185 
186  wxTimer mTimer;
187 
189  std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject;
191 
193 
194  void InitCommandHandler();
195 
196  bool InitTempDir();
197  bool CreateSingleInstanceChecker(const wxString &dir);
198 
199  std::unique_ptr<wxCmdLineParser> ParseCommandLine();
200 
202 
203 #if defined(__WXMSW__)
204  std::unique_ptr<IPCServ> mIPCServ;
205 #else
206  std::unique_ptr<wxSocketServer> mIPCServ;
207 #endif
208 
209  // values of the version major/minor/micro keys in audacity.cfg when Audacity first opens
213 
214  public:
215  DECLARE_EVENT_TABLE()
216 };
217 
218 extern AudacityApp & wxGetApp();
219 
220 #endif
Class which actulaly imports the auido, using functions defined in ImportPCM.cpp, ImportMP3...
Definition: Import.h:89
void OnReceiveCommand(AppCommandEvent &event)
wxTimer mTimer
Definition: AudacityApp.h:186
A BlockFile is a chunk of immutable audio data.
Definition: BlockFile.h:56
void OnQueryEndSession(wxCloseEvent &event)
bool mWindowRectAlreadySaved
Definition: AudacityApp.h:201
std::unique_ptr< wxSocketServer > mIPCServ
Definition: AudacityApp.h:206
void SetMissingAliasedFileWarningShouldShow(bool b)
Changes the behavior of missing aliased blockfiles warnings.
std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject
Definition: AudacityApp.h:189
AudacityLogger * GetLogger()
void OnEndSession(wxCloseEvent &event)
bool m_aliasMissingWarningShouldShow
Definition: AudacityApp.h:188
void SaveWindowSize()
ODLock m_LastMissingBlockFileLock
Definition: AudacityApp.h:192
bool OnExceptionInMainLoop() override
void OnMenuNew(wxCommandEvent &event)
void OnMenuOpen(wxCommandEvent &event)
void OnMRUFile(wxCommandEvent &event)
void OnMenuAbout(wxCommandEvent &event)
void OnMenuExit(wxCommandEvent &event)
void InitCommandHandler()
static void AddMultiPathsToPathList(const wxString &multiPathString, wxArrayString &pathList)
std::unique_ptr< CommandHandler > mCmdHandler
Definition: AudacityApp.h:179
void GetVersionKeysInit(int &major, int &minor, int &micro) const
Definition: AudacityApp.h:174
static void FindFilesInPathList(const wxString &pattern, const wxArrayString &pathList, wxArrayString &results, int flags=wxDIR_FILES)
AudacityLogger is a thread-safe logger class.
bool ShouldShowMissingAliasedFileWarning()
Returns true if the user should be notified of missing alias warnings.
void AddFileToHistory(const wxString &name)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
int OnExit(void) override
void SetWindowRectAlreadySaved(bool alreadySaved)
Definition: AudacityApp.h:157
wxString InitLang(const wxString &lang)
static bool IsTempDirectoryNameOK(const wxString &Name)
void OnFatalException() override
wxString m_LastMissingBlockFilePath
Definition: AudacityApp.h:190
Contains methods for applying commands that are passed to it.
bool SafeMRUOpen(const wxString &fileName)
bool CreateSingleInstanceChecker(const wxString &dir)
AudacityApp is the 'main' class for Audacity.
Definition: AudacityApp.h:59
int mVersionMajorKeyInit
Definition: AudacityApp.h:210
void OnServerEvent(wxSocketEvent &evt)
void OnMenuPreferences(wxCommandEvent &event)
void OnSocketEvent(wxSocketEvent &evt)
int mVersionMicroKeyInit
Definition: AudacityApp.h:212
void QuitAudacity(bool bForce)
bool OnInit(void) override
bool GetWindowRectAlreadySaved() const
Definition: AudacityApp.h:156
void OnKeyDown(wxKeyEvent &event)
int FilterEvent(wxEvent &event)
static void AddUniquePathToPathList(const wxString &path, wxArrayString &pathList)
bool gIsQuitting
FileHistory * GetRecentFiles()
Definition: AudacityApp.h:154
An event 'envelope' for sending Command objects through the wxwidgets event loop. ...
const wxChar * name
Definition: Distortion.cpp:94
bool InitTempDir()
void MarkAliasedFilesMissingWarning(const AliasBlockFile *b)
Mark playback as having missing aliased blockfiles.
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:259
bool MRUOpen(const wxString &fileName)
wxArrayString audacityPathList
A list of directories that should be searched for Audacity files (plug-ins, help files, etc.).
Definition: AudacityApp.h:138
void OnTimer(wxTimerEvent &event)
std::unique_ptr< wxLocale > mLocale
Definition: AudacityApp.h:182
std::unique_ptr< wxCmdLineParser > ParseCommandLine()
void SetVersionKeysInit(int major, int minor, int micro)
Definition: AudacityApp.h:172
void OnMRUClear(wxCommandEvent &event)
std::unique_ptr< FileHistory > mRecentFiles
Definition: AudacityApp.h:180
int mVersionMinorKeyInit
Definition: AudacityApp.h:211
AudacityApp & wxGetApp()
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE,-1)
wxString defaultTempDir
Default temp directory.
Definition: AudacityApp.h:141
std::unique_ptr< wxSingleInstanceChecker > mChecker
Definition: AudacityApp.h:184
Similar to FileHistory, but customized to our needs.
Definition: FileHistory.h:24