From ee9649eeb5c8a3a8847f4797882d2d3dcf3397d9 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sun, 4 Jun 2017 16:52:17 +0100 Subject: [PATCH] Simplify and extend automatic screenshotting Now includes 2 'outlier' analysis effects, and has simpler code. The tricky capture cases are now first in the list. Vocorder and Chirp are now included. Comma was missing between them. Now gives error report for an unknown command. --- src/Menus.cpp | 5 ++++ src/commands/ScreenshotCommand.cpp | 45 ++++++++++++++++++++++-------- src/commands/ScreenshotCommand.h | 3 ++ src/effects/Effect.cpp | 12 ++------ src/effects/Effect.h | 3 -- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 1eb97d153..06ba130aa 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -164,6 +164,7 @@ enum { }; #include "commands/CommandFunctors.h" +#include "commands/ScreenshotCommand.h" // // Effects menu arrays // @@ -6137,6 +6138,8 @@ void AudacityProject::OnPlotSpectrum() this, -1, _("Frequency Analysis"), where ) ); } + if( ScreenshotCommand::MayCapture( mFreqWindow.get() ) ) + return; mFreqWindow->Show(true); mFreqWindow->Raise(); mFreqWindow->SetFocus(); @@ -6156,6 +6159,8 @@ void AudacityProject::OnContrast() } mContrastDialog->CentreOnParent(); + if( ScreenshotCommand::MayCapture( mContrastDialog.get() ) ) + return; mContrastDialog->Show(); } diff --git a/src/commands/ScreenshotCommand.cpp b/src/commands/ScreenshotCommand.cpp index 13d52507f..df7b4d0f4 100644 --- a/src/commands/ScreenshotCommand.cpp +++ b/src/commands/ScreenshotCommand.cpp @@ -99,6 +99,8 @@ static wxBitmap DoGetAsBitmap(const wxRect *subrect) } #endif +// static member variable. +void (*ScreenshotCommand::mIdleHandler)(wxIdleEvent& event) = NULL; // This static variable is used to get from an idle event to the screenshot // command that caused the idle event interception to be set up. ScreenshotCommand * ScreenshotCommand::mpShooter=NULL; @@ -353,6 +355,16 @@ void ScreenshotCommand::CaptureMenus(wxMenuBar*pBar, const wxString &fileName) #endif } +// Handed a dialog, which it is given the option to capture. +bool ScreenshotCommand::MayCapture( wxDialog * pDlg ) +{ + if( mIdleHandler == NULL ) + return false; + pDlg->Bind( wxEVT_IDLE, mIdleHandler ); + mIdleHandler = NULL; + pDlg->ShowModal(); + return true; +} void ScreenshotCommand::CaptureWindowOnIdle( wxWindow * pWin ) { @@ -397,12 +409,27 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri mDirToWriteTo = fileName; mpShooter = this; +#define TRICKY_CAPTURE #define CAPTURE_NYQUIST_TOO // Commented out the effects that don't have dialogs. // Also any problematic ones, const wxString EffectNames[] = { + +#ifdef TRICKY_CAPTURE + //"Contrast...", // renamed + "ContrastAnalyser", + //"Plot Spectrum...", // renamed + "PlotSpectrum", + + "Auto Duck...", // needs a track below. + //"Spectral edit multi tool", + "Spectral edit parametric EQ...", // Needs a spectral selection. + "Spectral edit shelves...", + + //"Noise Reduction...", // Exits twice... + //"SC4...", //Has 'Close' rather than 'Cancel'. +#endif "Amplify...", - //"Auto Duck...", // needs a track below. "Bass and Treble...", "Change Pitch...", "Change Speed...", @@ -415,7 +442,6 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri //"Fade In", //"Fade Out", //"Invert", - //"Noise Reduction...", // Exits twice... "Normalize...", "Paulstretch...", "Phaser...", @@ -427,7 +453,6 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri "Truncate Silence...", "Wahwah...", // Sole LADSPA effect... - //"SC4...", //Has 'Close' rather than 'Cancel'. #ifdef CAPTURE_NYQUIST_TOO "Adjustable Fade...", "Clip Fix...", @@ -439,14 +464,11 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri "Low Pass Filter...", "Notch Filter...", "Nyquist Prompt...", - //"Spectral edit multi tool", - //"Spectral edit parametric EQ...", // Needs a spectral selection. - //"Spectral edit shelves...", //"Studio Fade Out", "Tremolo...", "Vocal Reduction and Isolation...", "Vocal Remover...", - "Vocoder..." + "Vocoder...", #endif // Generators..... "Chirp...", @@ -461,8 +483,6 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri "Sample Data Import...", #endif // Analyzers... - "Contrast...", - "Plot Spectrum...", "Find Clipping...", #ifdef CAPTURE_NYQUIST_TOO "Beat Finder...", @@ -475,9 +495,12 @@ void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxStri for( int i=0;iHandleTextualCommand( Str, AlwaysEnabledFlag, AlwaysEnabledFlag ); + if( !pMan->HandleTextualCommand( Str, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + { + wxLogDebug("Command %s not found", Str); + } // This sleep is not needed, but gives user a chance to see the // dialogs as they whizz by. wxMilliSleep( 200 ); diff --git a/src/commands/ScreenshotCommand.h b/src/commands/ScreenshotCommand.h index 4f9e6d4c0..464ac90dc 100644 --- a/src/commands/ScreenshotCommand.h +++ b/src/commands/ScreenshotCommand.h @@ -56,6 +56,9 @@ private: public: static ScreenshotCommand * mpShooter; + static void (*mIdleHandler)(wxIdleEvent& event); + static void SetIdleHandler( void (*pHandler)(wxIdleEvent& event) ){mIdleHandler=pHandler;}; + static bool MayCapture( wxDialog * pDlg ); void CaptureWindowOnIdle( wxWindow * pWin ); wxTopLevelWindow *GetFrontWindow(AudacityProject *project); diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 2164cbeb0..a3f1190b7 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -63,6 +63,7 @@ greater use in future. #endif #include "../Experimental.h" +#include "../commands/ScreenshotCommand.h" static const int kDummyID = 20000; static const int kSaveAsID = 20001; @@ -88,9 +89,6 @@ const wxString Effect::kFactoryPresetIdent = wxT("Factory Preset:"); const wxString Effect::kCurrentSettingsIdent = wxT(""); const wxString Effect::kFactoryDefaultsIdent = wxT(""); -// static member variable. -void (*Effect::mIdleHandler)(wxIdleEvent& event) = NULL; - WX_DECLARE_VOIDPTR_HASH_MAP( bool, t2bHash ); Effect::Effect() @@ -549,12 +547,8 @@ bool Effect::ShowInterface(wxWindow *parent, bool forceModal) mUIDialog->Fit(); mUIDialog->SetMinSize(mUIDialog->GetSize()); - // Idle event handler is used for example to take a screenshot. - if( mIdleHandler != NULL ){ - mUIDialog->Bind( wxEVT_IDLE, mIdleHandler ); - mIdleHandler = NULL; - forceModal = true; - } + if( ScreenshotCommand::MayCapture( mUIDialog ) ) + return false; if( SupportsRealtime() && !forceModal ) { diff --git a/src/effects/Effect.h b/src/effects/Effect.h index e58fef6dd..118e15552 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -260,8 +260,6 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler, /* not virtual */ bool IsRealtimeActive(); virtual bool IsHidden(); - static void SetIdleHandler( void (*pHandler)(wxIdleEvent& event) ){mIdleHandler=pHandler;}; - // // protected virtual methods // @@ -439,7 +437,6 @@ protected: // may be needed by any particular subclass of Effect. // protected: - static void (*mIdleHandler)(wxIdleEvent& event); ProgressDialog *mProgress; // Temporary pointer, NOT deleted in destructor. double mProjectRate; // Sample rate of the project - NEW tracks should