Prevent infinite loop of audio analysis if it is cancelled.
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2013 10:38:15 +0000 (11:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2013 10:38:15 +0000 (11:38 +0100)
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_plot.cc
src/wx/audio_plot.h

index d885e2d4d08148635a0e4aaf3b37825e32f7e0ce..26655631e8b3ccded05a17c700282c4033d214f1 100644 (file)
@@ -100,16 +100,14 @@ AudioDialog::set_content (shared_ptr<AudioContent> c)
 void
 AudioDialog::try_to_load_analysis ()
 {
 void
 AudioDialog::try_to_load_analysis ()
 {
-       shared_ptr<AudioAnalysis> 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<AudioAnalysis> a;
+       
+       a.reset (new AudioAnalysis (_content->audio_analysis_path ()));
        _plot->set_analysis (a);
 
        if (_channel_checkbox[0]) {
        _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)
 {
 void
 AudioDialog::channel_clicked (wxCommandEvent& ev)
 {
index c69baf282fc1f893a2a992d0b2cff717d5a6f090..62811091a8b9c14ce0c7b8eeb5295c4836cc04b9 100644 (file)
@@ -39,6 +39,7 @@ private:
        void type_clicked (wxCommandEvent &);
        void smoothing_changed (wxScrollEvent &);
        void try_to_load_analysis ();
        void type_clicked (wxCommandEvent &);
        void smoothing_changed (wxScrollEvent &);
        void try_to_load_analysis ();
+       void analysis_finished ();
 
        boost::shared_ptr<AudioContent> _content;
        AudioPlot* _plot;
 
        boost::shared_ptr<AudioContent> _content;
        AudioPlot* _plot;
index b2be40036be74d9d5e591b286d30f95b65cc69ad..2539a93d9b4d64f96500598007797107d3247146 100644 (file)
@@ -40,6 +40,7 @@ AudioPlot::AudioPlot (wxWindow* parent)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        , _gain (0)
        , _smoothing (max_smoothing / 2)
        : 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);
 {
 #ifndef __WXOSX__      
        SetDoubleBuffered (true);
@@ -95,6 +96,13 @@ AudioPlot::set_type_visible (int t, bool v)
        Refresh ();
 }
 
        Refresh ();
 }
 
+void
+AudioPlot::set_message (wxString s)
+{
+       _message = s;
+       Refresh ();
+}
+
 void
 AudioPlot::paint (wxPaintEvent &)
 {
 void
 AudioPlot::paint (wxPaintEvent &)
 {
@@ -107,7 +115,7 @@ AudioPlot::paint (wxPaintEvent &)
 
        if (!_analysis || _analysis->channels() == 0) {
                gc->SetFont (gc->CreateFont (*wxNORMAL_FONT));
 
        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;
        }
 
                return;
        }
 
index 82f589f6ffb8b3f30640cbd313e56f0e835b8fef..5605f94a53486439e9d98a39322b7057e06a7281 100644 (file)
@@ -33,6 +33,7 @@ public:
        void set_type_visible (int t, bool v);
        void set_gain (float);
        void set_smoothing (int);
        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;
 
 
        static const int max_smoothing;
 
@@ -57,5 +58,7 @@ private:
        float _x_scale;
        float _y_scale;
 
        float _x_scale;
        float _y_scale;
 
+       wxString _message;
+
        static const int _minimum;
 };
        static const int _minimum;
 };