X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Faudio_plot.cc;h=0868d931a8be1d38dc7b95e0c154afce4e544a51;hb=8aeb741ccbe2edb528e98a431bf55459a6836a9b;hp=46c64c9bf4eb8337f05f71b939e5a228cb4f2fe1;hpb=996b0c06e23bcb6b300d7b8799df94993692e07d;p=dcpomatic.git diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 46c64c9bf..0868d931a 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -1,5 +1,3 @@ -/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */ - /* Copyright (C) 2013 Carl Hetherington @@ -42,8 +40,11 @@ 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); +#endif for (int i = 0; i < MAX_AUDIO_CHANNELS; ++i) { _channel_visible[i] = false; @@ -53,14 +54,14 @@ 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); + Bind (wxEVT_PAINT, boost::bind (&AudioPlot::paint, this)); SetMinSize (wxSize (640, 512)); } @@ -96,7 +97,14 @@ AudioPlot::set_type_visible (int t, bool v) } void -AudioPlot::paint (wxPaintEvent &) +AudioPlot::set_message (wxString s) +{ + _message = s; + Refresh (); +} + +void +AudioPlot::paint () { wxPaintDC dc (this); @@ -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; } @@ -137,8 +145,7 @@ AudioPlot::paint (wxPaintEvent &) gc->SetPen (*wxLIGHT_GREY_PEN); gc->StrokePath (grid); - gc->DrawText (_("Time"), data_width, _height - _y_origin + db_label_height / 2); - + gc->DrawText (_("DCPTime"), data_width, _height - _y_origin + db_label_height / 2); if (_type_visible[AudioPoint::PEAK]) { for (int c = 0; c < MAX_AUDIO_CHANNELS; ++c) { @@ -147,11 +154,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); } } @@ -163,11 +166,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); } } @@ -191,6 +190,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; @@ -211,6 +214,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 smoothing; @@ -252,7 +259,9 @@ AudioPlot::plot_rms (wxGraphicsPath& path, int channel) const p += pow (*j, 2); } - p = sqrt (p / smoothing.size ()); + if (smoothing.size() > 0) { + p = sqrt (p / smoothing.size ()); + } path.AddLineToPoint (_db_label_width + i * _x_scale, y_for_linear (p)); }