Prevent infinite loop of audio analysis if it is cancelled.
[dcpomatic.git] / src / wx / audio_plot.cc
index 2a6210164e3a23f66076fc7f1fe063d8ffda7c00..2539a93d9b4d64f96500598007797107d3247146 100644 (file)
@@ -37,11 +37,14 @@ int const AudioPlot::_minimum = -70;
 int const AudioPlot::max_smoothing = 128;
 
 AudioPlot::AudioPlot (wxWindow* parent)
-       : wxPanel (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);
+#endif 
 
        for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) {
                _channel_visible[i] = false;
@@ -51,11 +54,11 @@ AudioPlot::AudioPlot (wxWindow* parent)
                _type_visible[i] = false;
        }
 
-       _colours.push_back (wxColour (  0,   0,   0));
-       _colours.push_back (wxColour (255,   0,   0));
-       _colours.push_back (wxColour (  0, 255,   0));
+       _colours.push_back (wxColour (  0,   0,   0));
+       _colours.push_back (wxColour (255,   0,   0));
+       _colours.push_back (wxColour (  0, 255,   0));
        _colours.push_back (wxColour (139,   0, 204));
-       _colours.push_back (wxColour (  0,   0, 255));
+       _colours.push_back (wxColour (  0,   0, 255));
        _colours.push_back (wxColour (100, 100, 100));
        
        Connect (wxID_ANY, wxEVT_PAINT, wxPaintEventHandler (AudioPlot::paint), 0, this);
@@ -93,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 &)
 {
@@ -105,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;
        }
 
@@ -145,11 +155,7 @@ AudioPlot::paint (wxPaintEvent &)
                                plot_peak (p, c);
                        }
                        wxColour const col = _colours[c];
-#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
                        gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (col.Red(), col.Green(), col.Blue(), col.Alpha() / 2), 1, wxPENSTYLE_SOLID));
-#else                  
-                       gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (col.Red(), col.Green(), col.Blue(), col.Alpha() / 2), 1, wxSOLID));
-#endif
                        gc->StrokePath (p);
                }
        }
@@ -161,11 +167,7 @@ AudioPlot::paint (wxPaintEvent &)
                                plot_rms (p, c);
                        }
                        wxColour const col = _colours[c];
-#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
                        gc->SetPen (*wxThePenList->FindOrCreatePen (col, 1, wxPENSTYLE_SOLID));
-#else
-                       gc->SetPen (*wxThePenList->FindOrCreatePen (col, 1, wxSOLID));
-#endif                 
                        gc->StrokePath (p);
                }
        }
@@ -189,6 +191,10 @@ AudioPlot::y_for_linear (float p) const
 void
 AudioPlot::plot_peak (wxGraphicsPath& path, int channel) const
 {
+       if (_analysis->points (channel) == 0) {
+               return;
+       }
+       
        path.MoveToPoint (_db_label_width, y_for_linear (_analysis->get_point(channel, 0)[AudioPoint::PEAK]));
 
        float peak = 0;
@@ -209,6 +215,10 @@ AudioPlot::plot_peak (wxGraphicsPath& path, int channel) const
 void
 AudioPlot::plot_rms (wxGraphicsPath& path, int channel) const
 {
+       if (_analysis->points (channel) == 0) {
+               return;
+       }
+       
        path.MoveToPoint (_db_label_width, y_for_linear (_analysis->get_point(channel, 0)[AudioPoint::RMS]));
 
        list<float> smoothing;