#include "audio_plot.h"
-#include "wx_util.h"
#include "film_viewer.h"
+#include "wx_util.h"
#include "lib/audio_decoder.h"
#include "lib/audio_analysis.h"
#include "lib/compose.hpp"
+#include "lib/constants.h"
+#include "lib/maths_util.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
#include <wx/graphics.h>
+LIBDCP_ENABLE_WARNINGS
#include <boost/bind/bind.hpp>
-#include <iostream>
#include <cfloat>
-using std::cout;
-using std::vector;
using std::list;
+using std::map;
using std::max;
using std::min;
-using std::map;
-using boost::bind;
-using boost::optional;
using std::shared_ptr;
+using std::vector;
using std::weak_ptr;
+using boost::bind;
+using boost::optional;
#if BOOST_VERSION >= 106100
using namespace boost::placeholders;
#endif
int const AudioPlot::max_smoothing = 128;
-AudioPlot::AudioPlot (wxWindow* parent, weak_ptr<FilmViewer> viewer)
+AudioPlot::AudioPlot(wxWindow* parent, FilmViewer& viewer)
: wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
, _viewer (viewer)
, _smoothing (max_smoothing / 2)
_type_visible[i] = false;
}
- _colours.push_back (wxColour ( 0, 0, 0));
+ if (gui_is_dark()) {
+ _colours.push_back(wxColour(255, 255, 255));
+ } else {
+ _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));
return;
}
+ gc->SetAntialiasMode (wxANTIALIAS_DEFAULT);
+
if (!_analysis || _analysis->channels() == 0) {
- gc->SetFont (gc->CreateFont (*wxNORMAL_FONT));
+ gc->SetFont(gc->CreateFont(*wxNORMAL_FONT, gui_is_dark() ? *wxWHITE : *wxBLACK));
gc->DrawText (_message, 32, 32);
delete gc;
return;
}
auto h_grid = gc->CreatePath ();
- gc->SetFont (gc->CreateFont (*wxSMALL_FONT));
+ gc->SetFont(gc->CreateFont(*wxSMALL_FONT, gui_is_dark() ? *wxWHITE : *wxBLACK));
wxDouble db_label_height;
wxDouble db_label_descent;
wxDouble db_label_leading;
gc->DrawText (std_to_wx (String::compose ("%1dB", i)), 0, y - (db_label_height / 2));
}
- gc->SetPen (wxPen (wxColour (200, 200, 200)));
+ wxColour const grid_colour = gui_is_dark() ? wxColour(80, 80, 80) : wxColour(200, 200, 200);
+
+ gc->SetPen(wxPen(grid_colour));
gc->StrokePath (h_grid);
/* Draw an x axis with marks */
DCPOMATIC_ASSERT (_analysis->samples_per_point() != 0.0);
double const pps = _analysis->sample_rate() * metrics.x_scale / _analysis->samples_per_point();
- gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
-
double const mark_interval = calculate_mark_interval (rint (128 / pps));
auto t = DCPTime::from_seconds (mark_interval);
t += DCPTime::from_seconds (mark_interval);
}
- gc->SetPen (wxPen (wxColour (200, 200, 200)));
+ gc->SetPen(wxPen(grid_colour));
gc->StrokePath (v_grid);
if (_type_visible[AudioPoint::PEAK]) {
axes.MoveToPoint (metrics.db_label_width, 0);
axes.AddLineToPoint (metrics.db_label_width, metrics.height - metrics.y_origin);
axes.AddLineToPoint (metrics.db_label_width + data_width, metrics.height - metrics.y_origin);
- gc->SetPen (wxPen (wxColour (0, 0, 0)));
+ gc->SetPen(wxPen(grid_colour));
gc->StrokePath (axes);
if (_cursor) {
}
-void
-AudioPlot::search (map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const
-{
- for (auto const& i: search) {
- for (auto const& j: i.second) {
- double const dist = pow(ev.GetX() - j.draw.x, 2) + pow(ev.GetY() - j.draw.y, 2);
- if (dist < min_dist) {
- min_dist = dist;
- min_point = j;
- }
- }
- }
-}
-
-
void
AudioPlot::left_down ()
{
if (_cursor) {
- if (auto fv = _viewer.lock()) {
- fv->seek (_cursor->time, true);
- }
+ _viewer.seek(_cursor->time, true);
}
}
double min_dist = DBL_MAX;
Point min_point;
- search (_rms, ev, min_dist, min_point);
- search (_peak, ev, min_dist, min_point);
+ auto search = [this](map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) {
+ for (auto const& i: search) {
+ if (_channel_visible[i.first]) {
+ for (auto const& j: i.second) {
+ double const dist = pow(ev.GetX() - j.draw.x, 2) + pow(ev.GetY() - j.draw.y, 2);
+ if (dist < min_dist) {
+ min_dist = dist;
+ min_point = j;
+ }
+ }
+ }
+ }
+ };
+
+ if (_type_visible[AudioPoint::RMS]) {
+ search (_rms, ev, min_dist, min_point);
+ }
+ if (_type_visible[AudioPoint::PEAK]) {
+ search (_peak, ev, min_dist, min_point);
+ }
- _cursor = {};
+ _cursor = boost::none;
if (min_dist < DBL_MAX) {
wxRect before (min_point.draw.x - _cursor_size / 2, min_point.draw.y - _cursor_size / 2, _cursor_size, _cursor_size);
void
AudioPlot::mouse_leave (wxMouseEvent &)
{
- _cursor = {};
+ _cursor = boost::none;
Refresh ();
Cursor (optional<DCPTime>(), optional<float>());
}