From 15aa84f10b91ab64fc1d3a08c2be2ac5907193d5 Mon Sep 17 00:00:00 2001 From: Steve Daulton Date: Mon, 16 Jan 2017 12:35:07 +0000 Subject: [PATCH] Fix bug 1575 Includes fix by PRL: https://github.com/Paul-Licameli/audacity/commit/cbca44e --- src/Menus.cpp | 33 ++++++++++++++++++--------------- src/Menus.h | 5 ++++- src/widgets/ProgressDialog.cpp | 9 ++++++++- src/widgets/ProgressDialog.h | 1 + 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 03e216ab9..d63a58f2c 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1695,7 +1695,7 @@ CommandFlag AudacityProject::GetFocusedFrame() return AlwaysEnabledFlag; } -CommandFlag AudacityProject::GetUpdateFlags() +CommandFlag AudacityProject::GetUpdateFlags(bool checkActive) { // This method determines all of the flags that determine whether // certain menu items and commands should be enabled or disabled, @@ -1703,6 +1703,16 @@ CommandFlag AudacityProject::GetUpdateFlags() // have changed, it's not necessary to even check for updates. auto flags = AlwaysEnabledFlag; + if (auto focus = wxWindow::FindFocus()) { + while (focus && focus->GetParent()) + focus = focus->GetParent(); + if (focus && !static_cast(focus)->IsIconized()) + flags |= NotMinimizedFlag; + } + + if ( checkActive && !IsActive() ) + return flags; + if (!gAudioIO->IsAudioTokenActive(GetAudioIOToken())) flags |= AudioIONotBusyFlag; else @@ -1791,8 +1801,11 @@ CommandFlag AudacityProject::GetUpdateFlags() if (ZoomOutAvailable() && (flags & TracksExistFlag)) flags |= ZoomOutAvailableFlag; - if ((flags & LabelTracksExistFlag) && LabelTrack::IsTextClipSupported()) - flags |= TextClipFlag; + // TextClipFlag is currently unused (Jan 2017, 2.1.3 alpha) + // and LabelTrack::IsTextClipSupported() is quite slow on Linux, + // so disable for now (See bug 1575). + // if ((flags & LabelTracksExistFlag) && LabelTrack::IsTextClipSupported()) + // flags |= TextClipFlag; flags |= GetFocusedFrame(); @@ -1829,13 +1842,6 @@ CommandFlag AudacityProject::GetUpdateFlags() if (bar->ControlToolBar::CanStopAudioStream()) flags |= CanStopAudioStreamFlag; - if (auto focus = wxWindow::FindFocus()) { - while (focus && focus->GetParent()) - focus = focus->GetParent(); - if (focus && !static_cast(focus)->IsIconized()) - flags |= NotMinimizedFlag; - } - return flags; } @@ -1928,7 +1934,7 @@ void AudacityProject::ModifyToolbarMenus() // checkActive is a temporary hack that should be removed as soon as we // get multiple effect preview working -void AudacityProject::UpdateMenus(bool /*checkActive*/) +void AudacityProject::UpdateMenus(bool checkActive) { //ANSWER-ME: Why UpdateMenus only does active project? //JKC: Is this test fixing a bug when multiple projects are open? @@ -1936,10 +1942,7 @@ void AudacityProject::UpdateMenus(bool /*checkActive*/) if (this != GetActiveProject()) return; - //if (checkActive && !IsActive()) - // return; - - auto flags = GetUpdateFlags(); + auto flags = GetUpdateFlags(checkActive); auto flags2 = flags; // We can enable some extra items if we have select-all-on-none. diff --git a/src/Menus.h b/src/Menus.h index e6c9c098b..0a027054e 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -38,7 +38,10 @@ void ModifyToolbarMenus(); void ModifyAllProjectToolbarMenus(); CommandFlag GetFocusedFrame(); -CommandFlag GetUpdateFlags(); + +// If checkActive, do not do complete flags testing on an +// inactive project as it is needlessly expensive. +CommandFlag GetUpdateFlags(bool checkActive = false); double NearestZeroCrossing(double t0); diff --git a/src/widgets/ProgressDialog.cpp b/src/widgets/ProgressDialog.cpp index dbd7bba3b..38060df9e 100644 --- a/src/widgets/ProgressDialog.cpp +++ b/src/widgets/ProgressDialog.cpp @@ -1234,6 +1234,7 @@ bool ProgressDialog::Create(const wxString & title, mStartTime = wxGetLocalTimeMillis().GetValue(); mLastUpdate = mStartTime; + mYieldTimer = mStartTime; mCancel = false; mStop = false; @@ -1346,7 +1347,13 @@ int ProgressDialog::Update(int value, const wxString & message) // (and probably other things). I do not yet know why this happens and // I'm not too keen on having timer events processed here, but you do // what you have to do. - wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER); + + // Nyquist effects call Update on every callback, but YieldFor is + // quite slow on Linux / Mac, so don't call too frequently. (bug 1575) + if ((now - mYieldTimer > 50) || (value == 1000)) { + wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER); + mYieldTimer = now; + } return eProgressSuccess; } diff --git a/src/widgets/ProgressDialog.h b/src/widgets/ProgressDialog.h index 4341306df..6733bbd34 100644 --- a/src/widgets/ProgressDialog.h +++ b/src/widgets/ProgressDialog.h @@ -90,6 +90,7 @@ protected: wxLongLong_t mStartTime; wxLongLong_t mLastUpdate; + wxLongLong_t mYieldTimer; int mLastValue; // gauge value, range = [0,1000] bool mCancel;