From 1fab1cdb21d0a7ea6ea56b3b12a522bdecdd81d2 Mon Sep 17 00:00:00 2001 From: lllucius Date: Wed, 23 Oct 2013 17:00:28 +0000 Subject: [PATCH] Bug 337 - New logger class allows log to be initialized immediately without crashing Mac empty project windows This is an older one...originally from 2011. Bug says it all, but basically it allows logging to begin immediately upon startup for all platforms. And it has multithreading protection, so it should now be safe to log from the non-GUI threads. --- mac/Audacity.xcodeproj/project.pbxproj | 6 ++++ src/AudacityApp.cpp | 40 +++++++------------------- src/AudacityApp.h | 5 ++-- src/LoadModules.cpp | 2 -- src/Makefile.in | 1 + src/Menus.cpp | 22 +++----------- src/Project.cpp | 6 ---- win/Projects/Audacity/Audacity.vcproj | 8 ++++++ 8 files changed, 33 insertions(+), 57 deletions(-) diff --git a/mac/Audacity.xcodeproj/project.pbxproj b/mac/Audacity.xcodeproj/project.pbxproj index 180dbac89..6c68b10e0 100644 --- a/mac/Audacity.xcodeproj/project.pbxproj +++ b/mac/Audacity.xcodeproj/project.pbxproj @@ -902,6 +902,7 @@ 28BD8AB2101DF4C700686679 /* CommandDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28BD8AAA101DF4C600686679 /* CommandDirectory.cpp */; }; 28BD8AB3101DF4C700686679 /* ExecMenuCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28BD8AAC101DF4C600686679 /* ExecMenuCommand.cpp */; }; 28BD8AB4101DF4C700686679 /* GetAllMenuCommands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28BD8AAE101DF4C600686679 /* GetAllMenuCommands.cpp */; }; + 28C3946D1818356800FDDAC9 /* AudacityLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28C3946B1818356800FDDAC9 /* AudacityLogger.cpp */; }; 28C816BA131255790035BB10 /* Audacity.sh in Install wrapper */ = {isa = PBXBuildFile; fileRef = 28C816B81312555B0035BB10 /* Audacity.sh */; }; 28CCDD000F939FD70081F2FC /* FileHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28CCDCFF0F939FD70081F2FC /* FileHistory.cpp */; }; 28D540050FD1912A00FA7C75 /* AppCommandEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28D53FFA0FD1912A00FA7C75 /* AppCommandEvent.cpp */; }; @@ -3607,6 +3608,8 @@ 28BD8AAE101DF4C600686679 /* GetAllMenuCommands.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = GetAllMenuCommands.cpp; sourceTree = ""; tabWidth = 3; }; 28BD8AAF101DF4C600686679 /* GetAllMenuCommands.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = GetAllMenuCommands.h; sourceTree = ""; tabWidth = 3; }; 28BD8AB0101DF4C600686679 /* Validators.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = Validators.h; sourceTree = ""; tabWidth = 3; }; + 28C3946B1818356800FDDAC9 /* AudacityLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudacityLogger.cpp; sourceTree = ""; }; + 28C3946C1818356800FDDAC9 /* AudacityLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudacityLogger.h; sourceTree = ""; }; 28C816B81312555B0035BB10 /* Audacity.sh */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.script.sh; name = Audacity.sh; path = mac/Audacity.sh; sourceTree = ""; }; 28CCDCFF0F939FD70081F2FC /* FileHistory.cpp */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.cpp.cpp; path = FileHistory.cpp; sourceTree = ""; tabWidth = 3; }; 28CCDD040F93A0B20081F2FC /* FileHistory.h */ = {isa = PBXFileReference; fileEncoding = 5; indentWidth = 3; lastKnownFileType = sourcecode.c.h; path = FileHistory.h; sourceTree = ""; tabWidth = 3; }; @@ -4866,6 +4869,8 @@ 1790AFCE09883BFD008A330A /* AudacityApp.cpp */, 1790AFCF09883BFD008A330A /* AudacityApp.h */, 1790AFD009883BFD008A330A /* AudacityHeaders.h */, + 28C3946B1818356800FDDAC9 /* AudacityLogger.cpp */, + 28C3946C1818356800FDDAC9 /* AudacityLogger.h */, 1790AFD209883BFD008A330A /* AudioIO.cpp */, 1790AFD309883BFD008A330A /* AudioIO.h */, 28560C8F0A75E40F00A3429E /* AutoRecovery.cpp */, @@ -8818,6 +8823,7 @@ 2849A42017F8BEC2005C653F /* KeyView.cpp in Sources */, 284FD04217FC72A50009A025 /* ScienFilter.cpp in Sources */, 284FD04517FC72EE0009A025 /* Biquad.cpp in Sources */, + 28C3946D1818356800FDDAC9 /* AudacityLogger.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 63fb83cd1..eff39de6d 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -58,6 +58,7 @@ It handles initialization and termination by subclassing wxApp. #include "AudacityApp.h" +#include "AudacityLogger.h" #include "AboutDialog.h" #include "AColor.h" #include "AudioIO.h" @@ -284,15 +285,6 @@ void QuitAudacity(bool bForce) ModuleManager::Dispatch(AppQuiting); - wxLogWindow *lw = wxGetApp().mLogger; - if (lw) - { - lw->EnableLogging(false); - lw->SetActiveTarget(NULL); - delete lw; - wxGetApp().mLogger = NULL; - } - if (gParentFrame) gParentFrame->Destroy(); gParentFrame = NULL; @@ -313,6 +305,9 @@ void QuitAudacity(bool bForce) //delete the static lock for audacity projects AudacityProject::DeleteAllProjectsDeleteLock(); + //remove our logger + delete wxLog::SetActiveTarget(NULL); + if (bForce) { wxExit(); @@ -936,6 +931,11 @@ bool AudacityApp::ShouldShowMissingAliasedFileWarning() return ret; } +AudacityLogger *AudacityApp::GetLogger() +{ + return wxStaticCast(wxLog::GetActiveTarget(), AudacityLogger); +} + void AudacityApp::InitLang( const wxString & lang ) { if( mLocale ) @@ -1022,6 +1022,8 @@ int AudacityApp::FilterEvent(wxEvent & event) // main frame bool AudacityApp::OnInit() { + delete wxLog::SetActiveTarget(new AudacityLogger); + m_aliasMissingWarningShouldShow = true; m_LastMissingBlockFile = NULL; @@ -1059,18 +1061,6 @@ bool AudacityApp::OnInit() } #endif - mLogger=NULL; - /* i18n-hint: We translate the title of the log window, but - * we're not translating its contents, since the contents will be read by - * English speaking engineers */ - #ifndef __WXMAC__ - mLogger = new wxLogWindow(NULL, _("Audacity Log"), false, false); - mLogger->SetActiveTarget(mLogger); - mLogger->EnableLogging(true); - mLogger->SetLogLevel(wxLOG_Max); - wxLogMessage(wxString::Format(wxT("Audacity %s"), AUDACITY_VERSION_STRING)); - #endif - // Unused strings that we want to be translated, even though // we're not using them yet... wxString future1 = _("Master Gain Control"); @@ -1276,14 +1266,6 @@ bool AudacityApp::OnInit() // So we also call StartMonitoring when STOP is called. project->MayStartMonitoring(); - #ifdef __WXMAC__ - mLogger = new wxLogWindow(NULL, _("Audacity Log"), false, false); - mLogger->SetActiveTarget(mLogger); - mLogger->EnableLogging(true); - mLogger->SetLogLevel(wxLOG_Max); - wxLogMessage(wxString::Format(wxT("Audacity %s"), AUDACITY_VERSION_STRING)); - #endif - #ifdef USE_FFMPEG FFmpegStartup(); #endif diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 5e74be502..ae769c9c3 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -33,6 +33,7 @@ class IPCServ; class Importer; class CommandHandler; class AppCommandEvent; +class AudacityLogger; void SaveWindowSize(); @@ -187,9 +188,9 @@ class AudacityApp:public wxApp { bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;} void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;} - Importer *mImporter; + AudacityLogger *GetLogger(); - wxLogWindow *mLogger; + Importer *mImporter; #if defined(__WXGTK__) /** \brief This flag is set true when in a keyboard event handler. diff --git a/src/LoadModules.cpp b/src/LoadModules.cpp index 09cfa69a0..de7b415d5 100644 --- a/src/LoadModules.cpp +++ b/src/LoadModules.cpp @@ -112,8 +112,6 @@ Module::~Module() bool Module::Load() { -// wxLogNull logNo; - if (mLib->IsLoaded()) { if (mDispatch) { return true; diff --git a/src/Makefile.in b/src/Makefile.in index 0ec5d4419..3888173a8 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -51,6 +51,7 @@ OBJS = \ AColor.o \ AboutDialog.o \ AudacityApp.o \ + AudacityLogger.o \ AudioIO.o \ AutoRecovery.o \ BatchCommandDialog.o \ diff --git a/src/Menus.cpp b/src/Menus.cpp index afd533a34..d0af9e0b3 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -52,6 +52,7 @@ simplifies construction of menu items. #include "effects/EffectManager.h" #include "AudacityApp.h" +#include "AudacityLogger.h" #include "AudioIO.h" #include "Dependencies.h" #include "float_cast.h" @@ -5736,25 +5737,10 @@ void AudacityProject::OnManual() void AudacityProject::OnShowLog() { - wxLogWindow* pLogger = wxGetApp().mLogger; - // It's possible a log window was not created. - if( !pLogger ) - return; - wxFrame* pLoggerFrame = pLogger->GetFrame(); - if (!pLoggerFrame->IsShown()) - { - // Show latest lines. - //bool bSuccess = pLoggerFrame->ScrollPages(999); //v Doesn't work! - int width, height; - pLoggerFrame->GetVirtualSize(&width, &height); - //pLoggerFrame->SetScrollPos(wxVERTICAL, height); //v Doesn't work! - pLoggerFrame->SetSize(width, 430); // Have to just hope this brings the last into view. - - pLogger->Show(); + AudacityLogger *logger = wxGetApp().GetLogger(); + if (logger) { + logger->Show(); } - pLoggerFrame->Enable(); - pLoggerFrame->Raise(); - pLoggerFrame->SetFocus(); } void AudacityProject::OnBenchmark() diff --git a/src/Project.cpp b/src/Project.cpp index bbf75a004..b84d716ff 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2051,13 +2051,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event) if (gAudacityProjects.IsEmpty() && !gIsQuitting) { - if( wxGetApp().mLogger ) - wxGetApp().mLogger->Show(false); - #if !defined(__WXMAC__) - // LL: On the Mac, we don't want the logger open after all projects - // have been closed since its menu will show instead of the - // common menu. if (quitOnClose) { QuitAudacity(); } diff --git a/win/Projects/Audacity/Audacity.vcproj b/win/Projects/Audacity/Audacity.vcproj index f912c025e..71b30b35a 100644 --- a/win/Projects/Audacity/Audacity.vcproj +++ b/win/Projects/Audacity/Audacity.vcproj @@ -431,6 +431,14 @@ /> + + + +