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