Clicking on the audio graph jumps to that position in the film (#1507).
authorCarl Hetherington <cth@carlh.net>
Sun, 17 May 2020 19:13:25 +0000 (21:13 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 May 2020 19:13:25 +0000 (21:13 +0200)
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_panel.cc
src/wx/audio_plot.cc
src/wx/audio_plot.h
src/wx/dcp_panel.cc

index efc506aff9a62bdec61946882308950c84fb3259..f2377de43fefc07c3a273e95b348494a1e8e2839 100644 (file)
@@ -38,6 +38,7 @@ using std::list;
 using std::vector;
 using std::pair;
 using boost::shared_ptr;
 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;
 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.
  */
  *  @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> film, shared_ptr<Content> content)
+AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, weak_ptr<FilmViewer> viewer, shared_ptr<Content> content)
        : wxDialog (
                parent,
                wxID_ANY,
        : wxDialog (
                parent,
                wxID_ANY,
@@ -65,6 +66,7 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Co
 #endif
                )
        , _film (film)
 #endif
                )
        , _film (film)
+       , _viewer (viewer)
        , _content (content)
        , _channels (film->audio_channels ())
        , _plot (0)
        , _content (content)
        , _channels (film->audio_channels ())
        , _plot (0)
@@ -79,7 +81,7 @@ AudioDialog::AudioDialog (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Co
 
        _cursor = new StaticText (this, wxT("Cursor: none"));
        left->Add (_cursor, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
 
        _cursor = new StaticText (this, wxT("Cursor: none"));
        left->Add (_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);
        left->Add (_plot, 1, wxTOP | wxEXPAND, 12);
        _sample_peak = new StaticText (this, wxT (""));
        left->Add (_sample_peak, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
index 34c174cf46cdf711f5469a9889377dcad47c3986..93c33152aee997e5d73fca8f76e64d234f6888ba 100644 (file)
 #include <boost/signals2.hpp>
 
 class AudioPlot;
 #include <boost/signals2.hpp>
 
 class AudioPlot;
+class FilmViewer;
 class Film;
 
 class AudioDialog : public wxDialog
 {
 public:
 class Film;
 
 class AudioDialog : public wxDialog
 {
 public:
-       AudioDialog (wxWindow* parent, boost::shared_ptr<Film> film, boost::shared_ptr<Content> content = boost::shared_ptr<Content> ());
+       AudioDialog (wxWindow* parent, boost::shared_ptr<Film> film, boost::weak_ptr<FilmViewer> viewer, boost::shared_ptr<Content> content = boost::shared_ptr<Content>());
 
        bool Show (bool show = true);
 
 
        bool Show (bool show = true);
 
@@ -49,6 +50,7 @@ private:
 
        boost::shared_ptr<AudioAnalysis> _analysis;
        boost::weak_ptr<Film> _film;
 
        boost::shared_ptr<AudioAnalysis> _analysis;
        boost::weak_ptr<Film> _film;
+       boost::weak_ptr<FilmViewer> _viewer;
        /** content to analyse, or 0 to analyse all the film's content */
        boost::weak_ptr<Content> _content;
        int _channels;
        /** content to analyse, or 0 to analyse all the film's content */
        boost::weak_ptr<Content> _content;
        int _channels;
index 37d6f8bb6f410525bb6b0fb37a8c13a043afe017..8c3d6f6caa09932c1b7c311ae11c0fd1642a9881 100644 (file)
@@ -365,7 +365,7 @@ AudioPanel::show_clicked ()
                return;
        }
 
                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 ();
 }
 
        _audio_dialog->Show ();
 }
 
index 0b7b29923f45272bfb4676cff47fbd45adcce6fd..629de77672864eaf056b34310d665845dbdac267 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-    Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
     This file is part of DCP-o-matic.
 
 */
 
 #include "audio_plot.h"
 */
 
 #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 "lib/audio_decoder.h"
 #include "lib/audio_analysis.h"
 #include "lib/compose.hpp"
-#include "wx/wx_util.h"
 #include <wx/graphics.h>
 #include <boost/bind.hpp>
 #include <iostream>
 #include <wx/graphics.h>
 #include <boost/bind.hpp>
 #include <iostream>
@@ -37,14 +38,16 @@ using std::map;
 using boost::bind;
 using boost::optional;
 using boost::shared_ptr;
 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;
 
 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<FilmViewer> viewer)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
+       , _viewer (viewer)
        , _smoothing (max_smoothing / 2)
        , _gain_correction (0)
 {
        , _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_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));
 }
 
        SetMinSize (wxSize (640, 512));
 }
@@ -427,6 +431,19 @@ AudioPlot::search (map<int, PointList> const & search, wxMouseEvent const & ev,
        }
 }
 
        }
 }
 
+
+void
+AudioPlot::left_down ()
+{
+       if (_cursor) {
+               shared_ptr<FilmViewer> fv = _viewer.lock ();
+               if (fv) {
+                       fv->seek (_cursor->time, true);
+               }
+       }
+}
+
+
 void
 AudioPlot::mouse_moved (wxMouseEvent& ev)
 {
 void
 AudioPlot::mouse_moved (wxMouseEvent& ev)
 {
index edb444a2ab9047ed75b7021d7d5df2ebdea6129d..6eb853dce175349ee33f5a3c8878da15e71baac1 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
     This file is part of DCP-o-matic.
 
 #include <vector>
 
 struct Metrics;
 #include <vector>
 
 struct Metrics;
+class FilmViewer;
 
 class AudioPlot : public wxPanel
 {
 public:
 
 class AudioPlot : public wxPanel
 {
 public:
-       explicit AudioPlot (wxWindow *);
+       explicit AudioPlot (wxWindow *, boost::weak_ptr<FilmViewer> viewer);
 
        void set_analysis (boost::shared_ptr<AudioAnalysis>);
        void set_channel_visible (int c, bool v);
 
        void set_analysis (boost::shared_ptr<AudioAnalysis>);
        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 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<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_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::weak_ptr<FilmViewer> _viewer;
        boost::shared_ptr<AudioAnalysis> _analysis;
        bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
        bool _type_visible[AudioPoint::COUNT];
        boost::shared_ptr<AudioAnalysis> _analysis;
        bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
        bool _type_visible[AudioPoint::COUNT];
index c4a14a58b3a118bec1c36c4356aea4a1d1c84632..c3cfc91d4cb25564e5ccb19ccdeabd7a37f21a56 100644 (file)
@@ -1020,7 +1020,7 @@ DCPPanel::show_audio_clicked ()
                _audio_dialog = 0;
        }
 
                _audio_dialog = 0;
        }
 
-       AudioDialog* d = new AudioDialog (_panel, _film);
+       AudioDialog* d = new AudioDialog (_panel, _film, _viewer);
        d->Show ();
 }
 
        d->Show ();
 }