Add FilmViewer::time_until_next_frame.
[dcpomatic.git] / src / wx / audio_plot.h
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "lib/util.h"
22 #include "lib/audio_analysis.h"
23 #include <wx/wx.h>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/signals2.hpp>
26 #include <vector>
27
28 struct Metrics;
29
30 class AudioPlot : public wxPanel
31 {
32 public:
33         explicit AudioPlot (wxWindow *);
34
35         void set_analysis (boost::shared_ptr<AudioAnalysis>);
36         void set_channel_visible (int c, bool v);
37         void set_type_visible (int t, bool v);
38         void set_smoothing (int);
39         void set_message (wxString);
40         void set_gain_correction (double gain);
41
42         wxColour colour (int n) const;
43
44         boost::signals2::signal<void (boost::optional<dcpomatic::DCPTime>, boost::optional<float>)> Cursor;
45
46         static const int max_smoothing;
47
48 private:
49
50         struct Point {
51                 Point ()
52                         : db(0)
53                 {}
54
55                 Point (wxPoint draw_, dcpomatic::DCPTime time_, float db_)
56                         : draw(draw_)
57                         , time(time_)
58                         , db(db_)
59                 {}
60
61                 wxPoint draw;
62                 dcpomatic::DCPTime time;
63                 float db;
64         };
65
66         typedef std::vector<Point> PointList;
67
68         void paint ();
69         void plot_peak (wxGraphicsPath &, int, Metrics const &) const;
70         void plot_rms (wxGraphicsPath &, int, Metrics const &) const;
71         float y_for_linear (float, Metrics const &) const;
72         AudioPoint get_point (int channel, int point) const;
73         void mouse_moved (wxMouseEvent& ev);
74         void mouse_leave (wxMouseEvent& ev);
75         void search (std::map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const;
76
77         boost::shared_ptr<AudioAnalysis> _analysis;
78         bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
79         bool _type_visible[AudioPoint::COUNT];
80         int _smoothing;
81         std::vector<wxColour> _colours;
82         wxString _message;
83         float _gain_correction;
84
85         mutable std::map<int, PointList> _peak;
86         mutable std::map<int, PointList> _rms;
87
88         boost::optional<Point> _cursor;
89
90         static const int _minimum;
91         static const int _cursor_size;
92 };