C++11 tidying.
[dcpomatic.git] / src / wx / audio_mapping_view.h
1 /*
2     Copyright (C) 2013-2021 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
22 /** @file  src/wx/audio_mapping_view.h
23  *  @brief AudioMappingView class.
24  *
25  */
26
27
28 #include "lib/audio_mapping.h"
29 #include "lib/types.h"
30 #include "lib/warnings.h"
31 DCPOMATIC_DISABLE_WARNINGS
32 #include <wx/wx.h>
33 DCPOMATIC_ENABLE_WARNINGS
34 #include <boost/signals2.hpp>
35
36
37 /** @class AudioMappingView
38  *  @brief This class displays the mapping of one set of audio channels to another,
39  *  with gain values on each node of the map.
40  *
41  *  The AudioMapping passed to set() describes the actual channel mapping,
42  *  and the names passed to set_input_channels() and set_output_channels() are
43  *  used to label the rows and columns.
44  *
45  *  The display's row count is equal to the AudioMapping's input channel count,
46  *  and the column count is equal to the number of name passed to
47  *  set_output_channels().  Any other output channels in the AudioMapping are
48  *  hidden from view.  Thus input channels are never hidden but output channels
49  *  might be.
50  */
51 class AudioMappingView : public wxPanel
52 {
53 public:
54         AudioMappingView (wxWindow *, wxString left_label, wxString from, wxString top_label, wxString to);
55
56         void set (AudioMapping);
57         void set_input_channels (std::vector<NamedChannel> const& channels);
58         void set_output_channels (std::vector<NamedChannel> const& channels);
59
60         struct Group
61         {
62                 Group (int f, int t, std::string n)
63                         : from (f)
64                         , to (t)
65                         , name (n)
66                 {}
67
68                 /** First channel index (from 0) */
69                 int from;
70                 /** Last channel index (from 0) */
71                 int to;
72                 /** Name of this group */
73                 std::string name;
74         };
75
76         void set_input_groups (std::vector<Group> const & groups);
77
78         boost::signals2::signal<void (AudioMapping)> Changed;
79
80 private:
81         void map_values_changed ();
82         void paint ();
83         void paint_static (wxDC& dc);
84         void paint_column_labels (wxDC& dc);
85         void paint_column_lines (wxDC& dc);
86         void paint_row_labels (wxDC& dc);
87         void paint_row_lines (wxDC& dc);
88         void paint_indicators (wxDC& dc);
89         void size (wxSizeEvent &);
90         void scroll ();
91         void left_down (wxMouseEvent &);
92         void right_down (wxMouseEvent &);
93         void motion (wxMouseEvent &);
94         void mouse_wheel (wxMouseEvent &);
95         boost::optional<std::pair<NamedChannel, NamedChannel>> mouse_event_to_channels (wxMouseEvent& ev) const;
96         boost::optional<std::string> mouse_event_to_input_group_name (wxMouseEvent& ev) const;
97         void setup ();
98         wxString input_channel_name_with_group (NamedChannel const& n) const;
99
100         void set_gain_from_menu (double linear);
101         void edit ();
102
103         AudioMapping _map;
104
105         wxMenu* _menu = nullptr;
106         wxPanel* _body = nullptr;
107         wxScrollBar* _vertical_scroll = nullptr;
108         wxScrollBar* _horizontal_scroll = nullptr;
109         int _menu_input;
110         int _menu_output;
111
112         wxString _left_label;
113         wxString _from;
114         wxString _top_label;
115         wxString _to;
116
117         std::vector<NamedChannel> _input_channels;
118         std::vector<NamedChannel> _output_channels;
119         std::vector<Group> _input_groups;
120         std::vector<int> _column_widths;
121         int _column_widths_total = 0;
122
123         boost::optional<std::pair<NamedChannel, NamedChannel>> _last_tooltip_channels;
124 };