Audacity  2.2.0
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  private:
172  std::unique_ptr<CommandHandler> mCmdHandler;
173  std::unique_ptr<FileHistory> mRecentFiles;
174 
175  std::unique_ptr<wxLocale> mLocale;
176 
177  std::unique_ptr<wxSingleInstanceChecker> mChecker;
178 
179  wxTimer mTimer;
180 
182  std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject;
184 
186 
187  void InitCommandHandler();
188 
189  bool InitTempDir();
190  bool CreateSingleInstanceChecker(const wxString &dir);
191 
192  std::unique_ptr<wxCmdLineParser> ParseCommandLine();
193 
195 
196 #if defined(__WXMSW__)
197  std::unique_ptr<IPCServ> mIPCServ;
198 #else
199  std::unique_ptr<wxSocketServer> mIPCServ;
200 #endif
201 
202  public:
203  DECLARE_EVENT_TABLE()
204 };
205 
206 extern AudacityApp & wxGetApp();
207 
208 #endif
Class which actulaly imports the auido, using functions defined in ImportPCM.cpp, ImportMP3...
Definition: Import.h:89
void OnReceiveCommand(AppCommandEvent &event)
Definition: AudacityApp.cpp:1642
wxTimer mTimer
Definition: AudacityApp.h:179
A BlockFile is a chunk of immutable audio data.
Definition: BlockFile.h:56
void OnQueryEndSession(wxCloseEvent &event)
Definition: AudacityApp.cpp:2071
bool mWindowRectAlreadySaved
Definition: AudacityApp.h:194
std::unique_ptr< wxSocketServer > mIPCServ
Definition: AudacityApp.h:199
void SetMissingAliasedFileWarningShouldShow(bool b)
Changes the behavior of missing aliased blockfiles warnings.
Definition: AudacityApp.cpp:947
std::weak_ptr< AudacityProject > m_LastMissingBlockFileProject
Definition: AudacityApp.h:182
AudacityLogger * GetLogger()
Definition: AudacityApp.cpp:967
void OnEndSession(wxCloseEvent &event)
Definition: AudacityApp.cpp:2085
bool m_aliasMissingWarningShouldShow
Definition: AudacityApp.h:181
void SaveWindowSize()
Definition: AudacityApp.cpp:342
ODLock m_LastMissingBlockFileLock
Definition: AudacityApp.h:185
bool OnExceptionInMainLoop() override
Definition: AudacityApp.cpp:1059
void OnMenuNew(wxCommandEvent &event)
Definition: AudacityApp.cpp:2191
void OnMenuOpen(wxCommandEvent &event)
Definition: AudacityApp.cpp:2206
void OnMRUFile(wxCommandEvent &event)
Definition: AudacityApp.cpp:826
void OnMenuAbout(wxCommandEvent &event)
Definition: AudacityApp.cpp:2173
void OnMenuExit(wxCommandEvent &event)
Definition: AudacityApp.cpp:2240
void InitCommandHandler()
Definition: AudacityApp.cpp:1635
static void AddMultiPathsToPathList(const wxString &multiPathString, wxArrayString &pathList)
Definition: AudacityApp.cpp:2040
std::unique_ptr< CommandHandler > mCmdHandler
Definition: AudacityApp.h:172
static void FindFilesInPathList(const wxString &pattern, const wxArrayString &pathList, wxArrayString &results, int flags=wxDIR_FILES)
Definition: AudacityApp.cpp:2052
AudacityLogger is a thread-safe logger class.
Definition: AudacityLogger.h:28
bool ShouldShowMissingAliasedFileWarning()
Returns true if the user should be notified of missing alias warnings.
Definition: AudacityApp.cpp:960
void AddFileToHistory(const wxString &name)
Definition: AudacityApp.cpp:2107
AudacityApp()
Definition: AudacityApp.cpp:1193
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
int OnExit(void) override
Definition: AudacityApp.cpp:2112
void SetWindowRectAlreadySaved(bool alreadySaved)
Definition: AudacityApp.h:157
~AudacityApp()
Definition: AudacityApp.cpp:1205
wxString InitLang(const wxString &lang)
Definition: AudacityApp.cpp:987
static bool IsTempDirectoryNameOK(const wxString &Name)
Definition: AudacityApp.cpp:1673
void OnFatalException() override
Definition: AudacityApp.cpp:1050
wxString m_LastMissingBlockFilePath
Definition: AudacityApp.h:183
Contains methods for applying commands that are passed to it.
Definition: CommandHandler.h:25
bool SafeMRUOpen(const wxString &fileName)
Definition: AudacityApp.cpp:813
bool CreateSingleInstanceChecker(const wxString &dir)
Definition: AudacityApp.cpp:1797
AudacityApp is the 'main' class for Audacity.
Definition: AudacityApp.h:59
void OnServerEvent(wxSocketEvent &evt)
void OnMenuPreferences(wxCommandEvent &event)
Definition: AudacityApp.cpp:2223
void OnSocketEvent(wxSocketEvent &evt)
void QuitAudacity(bool bForce)
Definition: AudacityApp.cpp:269
bool OnInit(void) override
Definition: AudacityApp.cpp:1211
bool GetWindowRectAlreadySaved() const
Definition: AudacityApp.h:156
void OnKeyDown(wxKeyEvent &event)
Definition: AudacityApp.cpp:1648
int FilterEvent(wxEvent &event)
Definition: AudacityApp.cpp:1149
static void AddUniquePathToPathList(const wxString &path, wxArrayString &pathList)
Definition: AudacityApp.cpp:2024
bool gIsQuitting
Definition: AudacityApp.cpp:267
Definition: ODTaskThread.h:150
FileHistory * GetRecentFiles()
Definition: AudacityApp.h:154
An event 'envelope' for sending Command objects through the wxwidgets event loop. ...
Definition: AppCommandEvent.h:28
const wxChar * name
Definition: Distortion.cpp:93
bool InitTempDir()
Definition: AudacityApp.cpp:1717
void MarkAliasedFilesMissingWarning(const AliasBlockFile *b)
Mark playback as having missing aliased blockfiles.
Definition: AudacityApp.cpp:925
A BlockFile that refers to data in an existing file.
Definition: BlockFile.h:259
bool MRUOpen(const wxString &fileName)
Definition: AudacityApp.cpp:766
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)
Definition: AudacityApp.cpp:842
std::unique_ptr< wxLocale > mLocale
Definition: AudacityApp.h:175
std::unique_ptr< wxCmdLineParser > ParseCommandLine()
Definition: AudacityApp.cpp:1983
void OnMRUClear(wxCommandEvent &event)
Definition: AudacityApp.cpp:818
std::unique_ptr< FileHistory > mRecentFiles
Definition: AudacityApp.h:173
AudacityApp & wxGetApp()
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE,-1)
wxString defaultTempDir
Default temp directory.
Definition: AudacityApp.h:141
Definition: AudacityApp.cpp:629
std::unique_ptr< wxSingleInstanceChecker > mChecker
Definition: AudacityApp.h:177
Similar to FileHistory, but customized to our needs.
Definition: FileHistory.h:24