2018-03-26 Carl Hetherington <cth@carlh.net>
+ * Add real-time mouse cursor readout in audio analysis (rest of #1082)
+
* Add time axis to audio analysis (part of #1082).
* Note: from this point in the ChangeLog release versions
/*
- 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.
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 (""));
} else {
_playlist = film->playlist ();
}
+
+ _plot->Cursor.connect (bind (&AudioDialog::set_cursor, this, _1, _2));
}
void
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())));
+}
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 &);
boost::weak_ptr<Content> _content;
int _channels;
boost::shared_ptr<const Playlist> _playlist;
+ wxStaticText* _cursor;
AudioPlot* _plot;
wxStaticText* _sample_peak;
wxStaticText* _true_peak;
/*
- 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.
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)
#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));
}
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;
}
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)
)
);
}
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)
)
);
}
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>());
+}
/*
- 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.
*/
-#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;
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_)
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;
};