std::shared_ptr
[dcpomatic.git] / src / wx / audio_plot.h
1 /*
2     Copyright (C) 2012-2020 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 "lib/warnings.h"
24 DCPOMATIC_DISABLE_WARNINGS
25 #include <wx/wx.h>
26 DCPOMATIC_ENABLE_WARNINGS
27 #include <boost/signals2.hpp>
28 #include <vector>
29
30 struct Metrics;
31 class FilmViewer;
32
33 class AudioPlot : public wxPanel
34 {
35 public:
36         explicit AudioPlot (wxWindow *, std::weak_ptr<FilmViewer> viewer);
37
38         void set_analysis (std::shared_ptr<AudioAnalysis>);
39         void set_channel_visible (int c, bool v);
40         void set_type_visible (int t, bool v);
41         void set_smoothing (int);
42         void set_message (wxString);
43         void set_gain_correction (double gain);
44
45         wxColour colour (int n) const;
46
47         boost::signals2::signal<void (boost::optional<dcpomatic::DCPTime>, boost::optional<float>)> Cursor;
48
49         static const int max_smoothing;
50
51 private:
52
53         struct Point {
54                 Point ()
55                         : db(0)
56                 {}
57
58                 Point (wxPoint draw_, dcpomatic::DCPTime time_, float db_)
59                         : draw(draw_)
60                         , time(time_)
61                         , db(db_)
62                 {}
63
64                 wxPoint draw;
65                 dcpomatic::DCPTime time;
66                 float db;
67         };
68
69         typedef std::vector<Point> PointList;
70
71         void paint ();
72         void plot_peak (wxGraphicsPath &, int, Metrics const &) const;
73         void plot_rms (wxGraphicsPath &, int, Metrics const &) const;
74         float y_for_linear (float, Metrics const &) const;
75         AudioPoint get_point (int channel, int point) const;
76         void left_down ();
77         void mouse_moved (wxMouseEvent& ev);
78         void mouse_leave (wxMouseEvent& ev);
79         void search (std::map<int, PointList> const & search, wxMouseEvent const & ev, double& min_dist, Point& min_point) const;
80
81         std::weak_ptr<FilmViewer> _viewer;
82         std::shared_ptr<AudioAnalysis> _analysis;
83         bool _channel_visible[MAX_DCP_AUDIO_CHANNELS];
84         bool _type_visible[AudioPoint::COUNT];
85         int _smoothing;
86         std::vector<wxColour> _colours;
87         wxString _message;
88         float _gain_correction;
89
90         mutable std::map<int, PointList> _peak;
91         mutable std::map<int, PointList> _rms;
92
93         boost::optional<Point> _cursor;
94
95         static const int _minimum;
96         static const int _cursor_size;
97 };