From 9f940fe8533526b10eb9cf22a8772e122760c368 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 17 May 2020 21:13:25 +0200 Subject: [PATCH] Clicking on the audio graph jumps to that position in the film (#1507). --- src/wx/audio_dialog.cc | 6 ++++-- src/wx/audio_dialog.h | 4 +++- src/wx/audio_panel.cc | 2 +- src/wx/audio_plot.cc | 23 ++++++++++++++++++++--- src/wx/audio_plot.h | 7 +++++-- src/wx/dcp_panel.cc | 2 +- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/wx/audio_dialog.cc b/src/wx/audio_dialog.cc index efc506aff..f2377de43 100644 --- a/src/wx/audio_dialog.cc +++ b/src/wx/audio_dialog.cc @@ -38,6 +38,7 @@ using std::list; using std::vector; using std::pair; using boost::shared_ptr; +using boost::weak_ptr; using boost::bind; using boost::optional; using boost::const_pointer_cast; @@ -48,7 +49,7 @@ using namespace dcpomatic; * @param film Film we are using. * @param content Content to analyse, or 0 to analyse all of the film's audio. */ -AudioDialog::AudioDialog (wxWindow* parent, shared_ptr film, shared_ptr content) +AudioDialog::AudioDialog (wxWindow* parent, shared_ptr film, weak_ptr viewer, shared_ptr content) : wxDialog ( parent, wxID_ANY, @@ -65,6 +66,7 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr film, shared_ptraudio_channels ()) , _plot (0) @@ -79,7 +81,7 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr film, shared_ptrAdd (_cursor, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP); - _plot = new AudioPlot (this); + _plot = new AudioPlot (this, viewer); left->Add (_plot, 1, wxTOP | wxEXPAND, 12); _sample_peak = new StaticText (this, wxT ("")); left->Add (_sample_peak, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP); diff --git a/src/wx/audio_dialog.h b/src/wx/audio_dialog.h index 34c174cf4..93c33152a 100644 --- a/src/wx/audio_dialog.h +++ b/src/wx/audio_dialog.h @@ -26,12 +26,13 @@ #include class AudioPlot; +class FilmViewer; class Film; class AudioDialog : public wxDialog { public: - AudioDialog (wxWindow* parent, boost::shared_ptr film, boost::shared_ptr content = boost::shared_ptr ()); + AudioDialog (wxWindow* parent, boost::shared_ptr film, boost::weak_ptr viewer, boost::shared_ptr content = boost::shared_ptr()); bool Show (bool show = true); @@ -49,6 +50,7 @@ private: boost::shared_ptr _analysis; boost::weak_ptr _film; + boost::weak_ptr _viewer; /** content to analyse, or 0 to analyse all the film's content */ boost::weak_ptr _content; int _channels; diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index 37d6f8bb6..8c3d6f6ca 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -365,7 +365,7 @@ AudioPanel::show_clicked () return; } - _audio_dialog = new AudioDialog (this, _parent->film (), ac.front ()); + _audio_dialog = new AudioDialog (this, _parent->film(), _parent->film_viewer(), ac.front()); _audio_dialog->Show (); } diff --git a/src/wx/audio_plot.cc b/src/wx/audio_plot.cc index 0b7b29923..629de7767 100644 --- a/src/wx/audio_plot.cc +++ b/src/wx/audio_plot.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington + Copyright (C) 2013-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -19,10 +19,11 @@ */ #include "audio_plot.h" +#include "wx_util.h" +#include "film_viewer.h" #include "lib/audio_decoder.h" #include "lib/audio_analysis.h" #include "lib/compose.hpp" -#include "wx/wx_util.h" #include #include #include @@ -37,14 +38,16 @@ using std::map; using boost::bind; using boost::optional; using boost::shared_ptr; +using boost::weak_ptr; using namespace dcpomatic; int const AudioPlot::_minimum = -70; int const AudioPlot::_cursor_size = 8; int const AudioPlot::max_smoothing = 128; -AudioPlot::AudioPlot (wxWindow* parent) +AudioPlot::AudioPlot (wxWindow* parent, weak_ptr viewer) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE) + , _viewer (viewer) , _smoothing (max_smoothing / 2) , _gain_correction (0) { @@ -87,6 +90,7 @@ AudioPlot::AudioPlot (wxWindow* parent) 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)); + Bind (wxEVT_LEFT_DOWN, boost::bind(&AudioPlot::left_down, this)); SetMinSize (wxSize (640, 512)); } @@ -427,6 +431,19 @@ AudioPlot::search (map const & search, wxMouseEvent const & ev, } } + +void +AudioPlot::left_down () +{ + if (_cursor) { + shared_ptr fv = _viewer.lock (); + if (fv) { + fv->seek (_cursor->time, true); + } + } +} + + void AudioPlot::mouse_moved (wxMouseEvent& ev) { diff --git a/src/wx/audio_plot.h b/src/wx/audio_plot.h index edb444a2a..6eb853dce 100644 --- a/src/wx/audio_plot.h +++ b/src/wx/audio_plot.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of DCP-o-matic. @@ -26,11 +26,12 @@ #include struct Metrics; +class FilmViewer; class AudioPlot : public wxPanel { public: - explicit AudioPlot (wxWindow *); + explicit AudioPlot (wxWindow *, boost::weak_ptr viewer); void set_analysis (boost::shared_ptr); void set_channel_visible (int c, bool v); @@ -70,10 +71,12 @@ private: 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 left_down (); void mouse_moved (wxMouseEvent& ev); void mouse_leave (wxMouseEvent& ev); void search (std::map const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const; + boost::weak_ptr _viewer; boost::shared_ptr _analysis; bool _channel_visible[MAX_DCP_AUDIO_CHANNELS]; bool _type_visible[AudioPoint::COUNT]; diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index c4a14a58b..c3cfc91d4 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -1020,7 +1020,7 @@ DCPPanel::show_audio_clicked () _audio_dialog = 0; } - AudioDialog* d = new AudioDialog (_panel, _film); + AudioDialog* d = new AudioDialog (_panel, _film, _viewer); d->Show (); } -- 2.30.2