summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-03-26 23:51:02 +0100
committerCarl Hetherington <cth@carlh.net>2018-03-26 23:51:02 +0100
commita423c0a0a6c891d0cacd42a3ac04c110c5f2be2e (patch)
treed8634e266267edb77b78f101adc0ec98424f87e7 /src
parent37c28f4c76df89bc84d773beda1bb90be1cedd1a (diff)
Add real-time mouse cursor readout in audio analysis (rest of #1082).
Diffstat (limited to 'src')
-rw-r--r--src/wx/audio_dialog.cc19
-rw-r--r--src/wx/audio_dialog.h3
-rw-r--r--src/wx/audio_plot.cc65
-rw-r--r--src/wx/audio_plot.h48
4 files changed, 114 insertions, 21 deletions
diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc
index 938ecd1d3..b5d5634ef 100644
--- a/src/wx/audio_dialog.cc
+++ b/src/wx/audio_dialog.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -74,6 +74,8 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Co
wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
+ _cursor = new wxStaticText (this, wxID_ANY, wxT("Cursor: none"));
+ left->Add (_cursor, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
_plot = new AudioPlot (this);
left->Add (_plot, 1, wxTOP | wxEXPAND, 12);
_sample_peak = new wxStaticText (this, wxID_ANY, wxT (""));
@@ -157,6 +159,8 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Co
} else {
_playlist = film->playlist ();
}
+
+ _plot->Cursor.connect (bind (&AudioDialog::set_cursor, this, _1, _2));
}
void
@@ -383,3 +387,16 @@ AudioDialog::Show (bool show)
try_to_load_analysis ();
return r;
}
+
+void
+AudioDialog::set_cursor (optional<DCPTime> time, optional<float> db)
+{
+ if (!time || !db) {
+ _cursor->SetLabel (_("Cursor: none"));
+ return;
+ }
+
+ shared_ptr<Film> film = _film.lock();
+ DCPOMATIC_ASSERT (film);
+ _cursor->SetLabel (wxString::Format (_("Cursor: %.1fdB at %s"), *db, time->timecode(film->video_frame_rate())));
+}
diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h
index 41be90b79..6d4428546 100644
--- a/src/wx/audio_dialog.h
+++ b/src/wx/audio_dialog.h
@@ -35,6 +35,8 @@ public:
bool Show (bool show = true);
+ void set_cursor (boost::optional<DCPTime> time, boost::optional<float> db);
+
private:
void content_changed (int);
void channel_clicked (wxCommandEvent &);
@@ -49,6 +51,7 @@ private:
boost::weak_ptr<Content> _content;
int _channels;
boost::shared_ptr<const Playlist> _playlist;
+ wxStaticText* _cursor;
AudioPlot* _plot;
wxStaticText* _sample_peak;
wxStaticText* _true_peak;
diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc
index 19e7bdac8..cabbd206a 100644
--- a/src/wx/audio_plot.cc
+++ b/src/wx/audio_plot.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -32,10 +32,13 @@ using std::vector;
using std::list;
using std::max;
using std::min;
+using std::map;
using boost::bind;
+using boost::optional;
using boost::shared_ptr;
int const AudioPlot::_minimum = -70;
+int const AudioPlot::_cursor_size = 8;
int const AudioPlot::max_smoothing = 128;
AudioPlot::AudioPlot (wxWindow* parent)
@@ -80,6 +83,8 @@ AudioPlot::AudioPlot (wxWindow* parent)
#endif
Bind (wxEVT_PAINT, boost::bind (&AudioPlot::paint, this));
+ Bind (wxEVT_MOTION, boost::bind (&AudioPlot::mouse_moved, this, _1));
+ Bind (wxEVT_LEAVE_WINDOW, boost::bind (&AudioPlot::mouse_leave, this, _1));
SetMinSize (wxSize (640, 512));
}
@@ -239,6 +244,17 @@ AudioPlot::paint ()
gc->SetPen (wxPen (wxColour (0, 0, 0)));
gc->StrokePath (axes);
+ if (_cursor) {
+ wxGraphicsPath cursor = gc->CreatePath ();
+ cursor.MoveToPoint (_cursor->draw.x - _cursor_size / 2, _cursor->draw.y - _cursor_size / 2);
+ cursor.AddLineToPoint (_cursor->draw.x + _cursor_size / 2, _cursor->draw.y + _cursor_size / 2);
+ cursor.MoveToPoint (_cursor->draw.x + _cursor_size / 2, _cursor->draw.y - _cursor_size / 2);
+ cursor.AddLineToPoint (_cursor->draw.x - _cursor_size / 2, _cursor->draw.y + _cursor_size / 2);
+ gc->StrokePath (cursor);
+
+
+ }
+
delete gc;
}
@@ -276,7 +292,7 @@ AudioPlot::plot_peak (wxGraphicsPath& path, int channel, Metrics const & metrics
Point (
wxPoint (metrics.db_label_width + i * metrics.x_scale, y_for_linear (peak, metrics)),
DCPTime::from_frames (i * _analysis->samples_per_point(), _analysis->sample_rate()),
- peak
+ 20 * log10(peak)
)
);
}
@@ -345,7 +361,7 @@ AudioPlot::plot_rms (wxGraphicsPath& path, int channel, Metrics const & metrics)
Point (
wxPoint (metrics.db_label_width + i * metrics.x_scale, y_for_linear (p, metrics)),
DCPTime::from_frames (i * _analysis->samples_per_point(), _analysis->sample_rate()),
- p
+ 20 * log10(p)
)
);
}
@@ -394,3 +410,46 @@ AudioPlot::colour (int n) const
DCPOMATIC_ASSERT (n < int(_colours.size()));
return _colours[n];
}
+
+void
+AudioPlot::search (map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const
+{
+ for (map<int, PointList>::const_iterator i = search.begin(); i != search.end(); ++i) {
+ BOOST_FOREACH (Point 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::mouse_moved (wxMouseEvent& ev)
+{
+ double min_dist = DBL_MAX;
+ Point min_point;
+
+ search (_rms, ev, min_dist, min_point);
+ search (_peak, ev, min_dist, min_point);
+
+ _cursor = optional<Point> ();
+
+ 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);
+ GetParent()->Refresh (true, &before);
+ _cursor = min_point;
+ wxRect after (min_point.draw.x - _cursor_size / 2, min_point.draw.y - _cursor_size / 2, _cursor_size, _cursor_size);
+ GetParent()->Refresh (true, &after);
+ Cursor (min_point.time, min_point.db);
+ }
+}
+
+void
+AudioPlot::mouse_leave (wxMouseEvent &)
+{
+ _cursor = optional<Point> ();
+ Refresh ();
+ Cursor (optional<DCPTime>(), optional<float>());
+}
diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h
index 203d7af8b..85306a58d 100644
--- a/src/wx/audio_plot.h
+++ b/src/wx/audio_plot.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,11 +18,12 @@
*/
-#include <vector>
-#include <boost/shared_ptr.hpp>
-#include <wx/wx.h>
#include "lib/util.h"
#include "lib/audio_analysis.h"
+#include <wx/wx.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/signals2.hpp>
+#include <vector>
struct Metrics;
@@ -40,24 +41,17 @@ public:
wxColour colour (int n) const;
+ boost::signals2::signal<void (boost::optional<DCPTime>, boost::optional<float>)> Cursor;
+
static const int max_smoothing;
private:
- void paint ();
- void plot_peak (wxGraphicsPath &, int, Metrics const &) const;
- void plot_rms (wxGraphicsPath &, int, Metrics const &) const;
- float y_for_linear (float, Metrics const &) const;
- AudioPoint get_point (int channel, int point) const;
-
- boost::shared_ptr<AudioAnalysis> _analysis;
- bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
- bool _type_visible[AudioPoint::COUNT];
- int _smoothing;
- std::vector<wxColour> _colours;
- wxString _message;
- float _gain_correction;
struct Point {
+ Point ()
+ : db(0)
+ {}
+
Point (wxPoint draw_, DCPTime time_, float db_)
: draw(draw_)
, time(time_)
@@ -71,8 +65,28 @@ private:
typedef std::vector<Point> PointList;
+ void paint ();
+ void plot_peak (wxGraphicsPath &, int, Metrics const &) const;
+ void plot_rms (wxGraphicsPath &, int, Metrics const &) const;
+ float y_for_linear (float, Metrics const &) const;
+ AudioPoint get_point (int channel, int point) const;
+ void mouse_moved (wxMouseEvent& ev);
+ void mouse_leave (wxMouseEvent& ev);
+ void search (std::map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const;
+
+ boost::shared_ptr<AudioAnalysis> _analysis;
+ bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
+ bool _type_visible[AudioPoint::COUNT];
+ int _smoothing;
+ std::vector<wxColour> _colours;
+ wxString _message;
+ float _gain_correction;
+
mutable std::map<int, PointList> _peak;
mutable std::map<int, PointList> _rms;
+ boost::optional<Point> _cursor;
+
static const int _minimum;
+ static const int _cursor_size;
};