From: Carl Hetherington Date: Thu, 25 Jul 2013 10:38:15 +0000 (+0100) Subject: Prevent infinite loop of audio analysis if it is cancelled. X-Git-Tag: v2.0.48~1337^2~136 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=45a523803b72cf132b44b6feec543e3587becf3a Prevent infinite loop of audio analysis if it is cancelled. --- diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index d885e2d4d..26655631e 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -100,16 +100,14 @@ AudioDialog::set_content (shared_ptr c) void AudioDialog::try_to_load_analysis () { - shared_ptr a; - - if (boost::filesystem::exists (_content->audio_analysis_path())) { - a.reset (new AudioAnalysis (_content->audio_analysis_path ())); - } else { - if (IsShown ()) { - _content->analyse_audio (bind (&AudioDialog::try_to_load_analysis, this)); - } + if (!boost::filesystem::exists (_content->audio_analysis_path()) && IsShown ()) { + _content->analyse_audio (bind (&AudioDialog::analysis_finished, this)); + return; } - + + shared_ptr a; + + a.reset (new AudioAnalysis (_content->audio_analysis_path ())); _plot->set_analysis (a); if (_channel_checkbox[0]) { @@ -123,6 +121,20 @@ AudioDialog::try_to_load_analysis () } } +void +AudioDialog::analysis_finished () +{ + if (!boost::filesystem::exists (_content->audio_analysis_path())) { + /* We analysed and still nothing showed up, so maybe it was cancelled or it failed. + Give up. + */ + _plot->set_message (_("Could not analyse audio.")); + return; + } + + try_to_load_analysis (); +} + void AudioDialog::channel_clicked (wxCommandEvent& ev) { diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index c69baf282..62811091a 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -39,6 +39,7 @@ private: void type_clicked (wxCommandEvent &); void smoothing_changed (wxScrollEvent &); void try_to_load_analysis (); + void analysis_finished (); boost::shared_ptr _content; AudioPlot* _plot; diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index b2be40036..2539a93d9 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -40,6 +40,7 @@ AudioPlot::AudioPlot (wxWindow* parent) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) , _gain (0) , _smoothing (max_smoothing / 2) + , _message (_("Please wait; audio is being analysed...")) { #ifndef __WXOSX__ SetDoubleBuffered (true); @@ -95,6 +96,13 @@ AudioPlot::set_type_visible (int t, bool v) Refresh (); } +void +AudioPlot::set_message (wxString s) +{ + _message = s; + Refresh (); +} + void AudioPlot::paint (wxPaintEvent &) { @@ -107,7 +115,7 @@ AudioPlot::paint (wxPaintEvent &) if (!_analysis || _analysis->channels() == 0) { gc->SetFont (gc->CreateFont (*wxNORMAL_FONT)); - gc->DrawText (_("Please wait; audio is being analysed..."), 32, 32); + gc->DrawText (_message, 32, 32); return; } diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h index 82f589f6f..5605f94a5 100644 --- a/src/wx/audio_plot.h +++ b/src/wx/audio_plot.h @@ -33,6 +33,7 @@ public: void set_type_visible (int t, bool v); void set_gain (float); void set_smoothing (int); + void set_message (wxString); static const int max_smoothing; @@ -57,5 +58,7 @@ private: float _x_scale; float _y_scale; + wxString _message; + static const int _minimum; };