04a468416a75cc8ede8977621b14b1cd464e5c90
[dcpomatic.git] / src / wx / audio_mapping_view.cc
1 /*
2     Copyright (C) 2013-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 /** @file  src/wx/audio_mapping_view.cc
22  *  @brief AudioMappingView class and helpers.
23  */
24
25 #include "audio_mapping_view.h"
26 #include "wx_util.h"
27 #include "audio_gain_dialog.h"
28 #include "lib/audio_mapping.h"
29 #include "lib/util.h"
30 #include "lib/warnings.h"
31 #include <dcp/locale_convert.h>
32 #include <dcp/types.h>
33 DCPOMATIC_DISABLE_WARNINGS
34 #include <wx/wx.h>
35 #include <wx/renderer.h>
36 #include <wx/grid.h>
37 #include <wx/graphics.h>
38 DCPOMATIC_ENABLE_WARNINGS
39 #include <boost/foreach.hpp>
40 #include <iostream>
41
42 using std::cout;
43 using std::list;
44 using std::string;
45 using std::min;
46 using std::max;
47 using std::vector;
48 using std::pair;
49 using std::make_pair;
50 using std::shared_ptr;
51 using boost::optional;
52 #if BOOST_VERSION >= 106100
53 using namespace boost::placeholders;
54 #endif
55 using dcp::locale_convert;
56
57 #define INDICATOR_SIZE 20
58 #define GRID_SPACING 32
59 #define LEFT_WIDTH (GRID_SPACING * 3)
60 #define TOP_HEIGHT (GRID_SPACING * 2)
61
62 enum {
63         ID_off = 1,
64         ID_minus6dB = 2,
65         ID_0dB = 3,
66         ID_plus3dB = 4,
67         ID_edit = 5
68 };
69
70 AudioMappingView::AudioMappingView (wxWindow* parent, wxString left_label, wxString from, wxString top_label, wxString to)
71         : wxPanel (parent, wxID_ANY)
72         , _menu_input (0)
73         , _menu_output (1)
74         , _left_label (left_label)
75         , _from (from)
76         , _top_label (top_label)
77         , _to (to)
78 {
79         _menu = new wxMenu;
80         _menu->Append (ID_off, _("Off"));
81         _menu->Append (ID_minus6dB, _("-6dB"));
82         _menu->Append (ID_0dB, _("0dB (unchanged)"));
83         _menu->Append (ID_plus3dB, _("+3dB"));
84         _menu->Append (ID_edit, _("Edit..."));
85
86         _body = new wxPanel (this, wxID_ANY);
87         _vertical_scroll = new wxScrollBar (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
88         _horizontal_scroll = new wxScrollBar (this, wxID_ANY);
89
90 #ifndef __WXOSX__
91         SetDoubleBuffered (true);
92 #endif
93
94         Bind (wxEVT_SIZE, boost::bind(&AudioMappingView::size, this, _1));
95         Bind (wxEVT_MENU, boost::bind(&AudioMappingView::set_gain_from_menu, this, 0), ID_off);
96         Bind (wxEVT_MENU, boost::bind(&AudioMappingView::set_gain_from_menu, this, db_to_linear(-6)), ID_minus6dB);
97         Bind (wxEVT_MENU, boost::bind(&AudioMappingView::set_gain_from_menu, this, 1), ID_0dB);
98         Bind (wxEVT_MENU, boost::bind(&AudioMappingView::set_gain_from_menu, this, db_to_linear(3)), ID_plus3dB);
99         Bind (wxEVT_MENU, boost::bind(&AudioMappingView::edit, this), ID_edit);
100         Bind (wxEVT_MOUSEWHEEL, boost::bind(&AudioMappingView::mouse_wheel, this, _1));
101         _body->Bind (wxEVT_PAINT, boost::bind(&AudioMappingView::paint, this));
102         _body->Bind (wxEVT_LEFT_DOWN, boost::bind(&AudioMappingView::left_down, this, _1));
103         _body->Bind (wxEVT_RIGHT_DOWN, boost::bind(&AudioMappingView::right_down, this, _1));
104         _body->Bind (wxEVT_MOTION, boost::bind(&AudioMappingView::motion, this, _1));
105         _vertical_scroll->Bind (wxEVT_SCROLL_TOP, boost::bind(&AudioMappingView::scroll, this));
106         _vertical_scroll->Bind (wxEVT_SCROLL_BOTTOM, boost::bind(&AudioMappingView::scroll, this));
107         _vertical_scroll->Bind (wxEVT_SCROLL_LINEUP, boost::bind(&AudioMappingView::scroll, this));
108         _vertical_scroll->Bind (wxEVT_SCROLL_LINEDOWN, boost::bind(&AudioMappingView::scroll, this));
109         _vertical_scroll->Bind (wxEVT_SCROLL_PAGEUP, boost::bind(&AudioMappingView::scroll, this));
110         _vertical_scroll->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind(&AudioMappingView::scroll, this));
111         _vertical_scroll->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&AudioMappingView::scroll, this));
112         _vertical_scroll->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind(&AudioMappingView::scroll, this));
113         _horizontal_scroll->Bind (wxEVT_SCROLL_TOP, boost::bind(&AudioMappingView::scroll, this));
114         _horizontal_scroll->Bind (wxEVT_SCROLL_BOTTOM, boost::bind(&AudioMappingView::scroll, this));
115         _horizontal_scroll->Bind (wxEVT_SCROLL_LINEUP, boost::bind(&AudioMappingView::scroll, this));
116         _horizontal_scroll->Bind (wxEVT_SCROLL_LINEDOWN, boost::bind(&AudioMappingView::scroll, this));
117         _horizontal_scroll->Bind (wxEVT_SCROLL_PAGEUP, boost::bind(&AudioMappingView::scroll, this));
118         _horizontal_scroll->Bind (wxEVT_SCROLL_PAGEDOWN, boost::bind(&AudioMappingView::scroll, this));
119         _horizontal_scroll->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&AudioMappingView::scroll, this));
120         _horizontal_scroll->Bind (wxEVT_SCROLL_THUMBRELEASE, boost::bind(&AudioMappingView::scroll, this));
121 }
122
123 void
124 AudioMappingView::size (wxSizeEvent& ev)
125 {
126         setup ();
127         ev.Skip ();
128 }
129
130 void
131 AudioMappingView::setup ()
132 {
133         wxSize const s = GetSize();
134         int const w = _vertical_scroll->GetSize().GetWidth();
135         int const h = _horizontal_scroll->GetSize().GetHeight();
136
137         _vertical_scroll->SetPosition (wxPoint(s.GetWidth() - w, 0));
138         _vertical_scroll->SetSize (wxSize(w, max(0, s.GetHeight() - h)));
139
140         _body->SetSize (wxSize(max(0, s.GetWidth() - w), max(0, s.GetHeight() - h)));
141
142         _horizontal_scroll->SetPosition (wxPoint(0, s.GetHeight() - h));
143         _horizontal_scroll->SetSize (wxSize(max(0, s.GetWidth() - w), h));
144
145         _vertical_scroll->SetScrollbar (
146                 _vertical_scroll->GetThumbPosition(),
147                 s.GetHeight() - h - 8,
148                 GRID_SPACING * (2 + _input_channels.size()),
149                 GRID_SPACING,
150                 true
151                 );
152
153         _horizontal_scroll->SetScrollbar (
154                 _horizontal_scroll->GetThumbPosition(),
155                 s.GetWidth() - w - 8,
156                 GRID_SPACING * (3 + _output_channels.size()),
157                 GRID_SPACING,
158                 true);
159 }
160
161 void
162 AudioMappingView::scroll ()
163 {
164         Refresh ();
165 }
166
167 void
168 AudioMappingView::paint_static (wxDC& dc)
169 {
170         dc.SetFont (wxSWISS_FONT->Bold());
171         wxCoord label_width;
172         wxCoord label_height;
173
174         dc.GetTextExtent (_top_label, &label_width, &label_height);
175         dc.DrawText (_top_label, LEFT_WIDTH + (_output_channels.size() * GRID_SPACING - label_width) / 2, (GRID_SPACING - label_height) / 2);
176
177         dc.GetTextExtent (_left_label, &label_width, &label_height);
178         dc.DrawRotatedText (
179                 _left_label,
180                 (GRID_SPACING - label_height) / 2,
181                 TOP_HEIGHT + (_input_channels.size() * GRID_SPACING + label_width) / 2,
182                 90
183                 );
184
185         dc.SetFont (*wxSWISS_FONT);
186 }
187
188 void
189 AudioMappingView::paint_column_labels (wxDC& dc)
190 {
191         wxCoord label_width;
192         wxCoord label_height;
193         int N = 0;
194         BOOST_FOREACH (NamedChannel const& i, _output_channels) {
195                 dc.GetTextExtent (std_to_wx(i.name), &label_width, &label_height);
196                 dc.DrawText (std_to_wx(i.name), LEFT_WIDTH + GRID_SPACING * N + (GRID_SPACING - label_width) / 2, GRID_SPACING + (GRID_SPACING - label_height) / 2);
197                 ++N;
198         }
199
200         dc.DrawLine(wxPoint(LEFT_WIDTH, GRID_SPACING), wxPoint(LEFT_WIDTH + _output_channels.size() * GRID_SPACING, GRID_SPACING));
201         dc.DrawLine(wxPoint(LEFT_WIDTH, GRID_SPACING * 2), wxPoint(LEFT_WIDTH + _output_channels.size() * GRID_SPACING, GRID_SPACING * 2));
202 }
203
204 void
205 AudioMappingView::paint_column_lines (wxDC& dc)
206 {
207         for (size_t i = 0; i < _output_channels.size(); ++i) {
208                 dc.DrawLine (
209                         wxPoint(LEFT_WIDTH + GRID_SPACING * i, GRID_SPACING),
210                         wxPoint(LEFT_WIDTH + GRID_SPACING * i, TOP_HEIGHT + _input_channels.size() * GRID_SPACING)
211                         );
212         }
213
214         dc.DrawLine (
215                 wxPoint(LEFT_WIDTH + GRID_SPACING * _output_channels.size(), GRID_SPACING),
216                 wxPoint(LEFT_WIDTH + GRID_SPACING * _output_channels.size(), TOP_HEIGHT + _input_channels.size() * GRID_SPACING)
217                 );
218 }
219
220 void
221 AudioMappingView::paint_row_labels (wxDC& dc)
222 {
223         wxCoord label_width;
224         wxCoord label_height;
225
226         /* Row channel labels */
227
228         int N = 0;
229         BOOST_FOREACH (NamedChannel const& i, _input_channels) {
230                 dc.GetTextExtent (std_to_wx(i.name), &label_width, &label_height);
231                 dc.DrawText (std_to_wx(i.name), GRID_SPACING * 2 + (GRID_SPACING - label_width) / 2, TOP_HEIGHT + GRID_SPACING * N + (GRID_SPACING - label_height) / 2);
232                 ++N;
233         }
234
235         /* Vertical lines on the left */
236
237         for (int i = 1; i < 3; ++i) {
238                 dc.DrawLine (
239                         wxPoint(GRID_SPACING * i, TOP_HEIGHT),
240                         wxPoint(GRID_SPACING * i, TOP_HEIGHT + _input_channels.size() * GRID_SPACING)
241                         );
242         }
243
244         /* Group labels and lines */
245
246         int y = TOP_HEIGHT;
247         BOOST_FOREACH (Group i, _input_groups) {
248                 int const height = (i.to - i.from + 1) * GRID_SPACING;
249                 dc.GetTextExtent (std_to_wx(i.name), &label_width, &label_height);
250                 if (label_width > height) {
251                         label_width = height - 8;
252                 }
253
254                 {
255                         wxDCClipper clip (dc, wxRect(GRID_SPACING, y, GRID_SPACING, height));
256                         int yp = y;
257                         if ((yp - 2 * GRID_SPACING) < dc.GetLogicalOrigin().y) {
258                                 yp += dc.GetLogicalOrigin().y;
259                         }
260
261                         dc.DrawRotatedText (
262                                 std_to_wx(i.name),
263                                 GRID_SPACING + (GRID_SPACING - label_height) / 2,
264                                 y + (height + label_width) / 2,
265                                 90
266                                 );
267                 }
268
269                 dc.DrawLine (wxPoint(GRID_SPACING, y), wxPoint(GRID_SPACING * 2, y));
270                 y += height;
271         }
272
273         dc.DrawLine (wxPoint(GRID_SPACING, y), wxPoint(GRID_SPACING * 2, y));
274 }
275
276 void
277 AudioMappingView::paint_row_lines (wxDC& dc)
278 {
279         for (size_t i = 0; i < _input_channels.size(); ++i) {
280                 dc.DrawLine (
281                         wxPoint(GRID_SPACING * 2, TOP_HEIGHT + GRID_SPACING * i),
282                         wxPoint(LEFT_WIDTH + _output_channels.size() * GRID_SPACING, TOP_HEIGHT + GRID_SPACING * i)
283                         );
284         }
285         dc.DrawLine (
286                 wxPoint(GRID_SPACING * 2, TOP_HEIGHT + GRID_SPACING * _input_channels.size()),
287                 wxPoint(LEFT_WIDTH + _output_channels.size() * GRID_SPACING, TOP_HEIGHT + GRID_SPACING * _input_channels.size())
288                 );
289 }
290
291 void
292 AudioMappingView::paint_indicators (wxDC& dc)
293 {
294         /* _{input,output}_channels and _map may not always be in sync, be careful here */
295         size_t const output = min(_output_channels.size(), size_t(_map.output_channels()));
296         size_t const input = min(_input_channels.size(), size_t(_map.input_channels()));
297
298         for (size_t x = 0; x < output; ++x) {
299                 for (size_t y = 0; y < input; ++y) {
300                         dc.SetBrush (*wxWHITE_BRUSH);
301                         dc.DrawRectangle (
302                                 wxRect(
303                                         LEFT_WIDTH + x * GRID_SPACING + (GRID_SPACING - INDICATOR_SIZE) / 2,
304                                         TOP_HEIGHT + y * GRID_SPACING + (GRID_SPACING - INDICATOR_SIZE) / 2,
305                                         INDICATOR_SIZE, INDICATOR_SIZE
306                                         )
307                                 );
308
309                         float const value_dB = linear_to_db(_map.get(_input_channels[y].index, _output_channels[x].index));
310                         wxColour const colour = value_dB <= 0 ? wxColour(0, 255, 0) : wxColour(255, 150, 0);
311                         int const range = 18;
312                         int height = 0;
313                         if (value_dB > -range) {
314                                 height = min(INDICATOR_SIZE, static_cast<int>(INDICATOR_SIZE * (1 + value_dB / range)));
315                         }
316
317                         dc.SetBrush (*wxTheBrushList->FindOrCreateBrush(colour, wxBRUSHSTYLE_SOLID));
318                         dc.DrawRectangle (
319                                 wxRect(
320                                         LEFT_WIDTH + x * GRID_SPACING + (GRID_SPACING - INDICATOR_SIZE) / 2,
321                                         TOP_HEIGHT + y * GRID_SPACING + (GRID_SPACING - INDICATOR_SIZE) / 2 + INDICATOR_SIZE - height,
322                                         INDICATOR_SIZE, height
323                                         )
324                                 );
325                 }
326         }
327 }
328
329 static
330 void clip (wxDC& dc, int x, int y, int w, int h)
331 {
332         dc.SetClippingRegion (x, y, w, h);
333 }
334
335 static
336 void translate (wxDC& dc, int x, int y)
337 {
338         dc.SetLogicalOrigin (x, y);
339 }
340
341 static
342 void restore (wxDC& dc)
343 {
344         dc.SetLogicalOrigin (0, 0);
345         dc.DestroyClippingRegion ();
346 }
347
348 void
349 AudioMappingView::paint ()
350 {
351         wxPaintDC dc (_body);
352
353         int const hs = _horizontal_scroll->GetThumbPosition ();
354         int const vs = _vertical_scroll->GetThumbPosition ();
355
356         paint_static (dc);
357
358         clip (
359                 dc,
360                 LEFT_WIDTH,
361                 0,
362                 GRID_SPACING * _output_channels.size(),
363                 GRID_SPACING * (2 + _input_channels.size())
364              );
365         translate (dc, hs, 0);
366         paint_column_labels (dc);
367         restore (dc);
368
369         clip (
370                 dc,
371                 0,
372                 TOP_HEIGHT,
373                 GRID_SPACING * 3,
374                 min(int(GRID_SPACING * _input_channels.size()), GetSize().GetHeight() - TOP_HEIGHT)
375              );
376         translate (dc, 0, vs);
377         paint_row_labels (dc);
378         restore (dc);
379
380         clip (
381                 dc,
382                 GRID_SPACING * 2,
383                 TOP_HEIGHT,
384                 GRID_SPACING * (1 + _output_channels.size()),
385                 min(int(GRID_SPACING * (2 + _input_channels.size())), GetSize().GetHeight() - TOP_HEIGHT)
386              );
387         translate (dc, hs, vs);
388         paint_row_lines (dc);
389         restore (dc);
390
391         clip (
392                 dc,
393                 LEFT_WIDTH,
394                 GRID_SPACING,
395                 GRID_SPACING * (1 + _output_channels.size()),
396                 min(int(GRID_SPACING * (1 + _input_channels.size())), GetSize().GetHeight() - GRID_SPACING)
397              );
398         translate (dc, hs, vs);
399         paint_column_lines (dc);
400         restore (dc);
401
402         clip (
403                 dc,
404                 LEFT_WIDTH,
405                 TOP_HEIGHT,
406                 GRID_SPACING * _output_channels.size(),
407                 min(int(GRID_SPACING * _input_channels.size()), GetSize().GetHeight() - TOP_HEIGHT)
408              );
409         translate (dc, hs, vs);
410         paint_indicators (dc);
411         restore (dc);
412 }
413
414 optional<pair<NamedChannel, NamedChannel> >
415 AudioMappingView::mouse_event_to_channels (wxMouseEvent& ev) const
416 {
417         int const x = ev.GetX() + _horizontal_scroll->GetThumbPosition();
418         int const y = ev.GetY() + _vertical_scroll->GetThumbPosition();
419
420         if (x <= LEFT_WIDTH || y < TOP_HEIGHT) {
421                 return optional<pair<NamedChannel, NamedChannel> >();
422         }
423
424         int const input = (y - TOP_HEIGHT) / GRID_SPACING;
425         int const output = (x - LEFT_WIDTH) / GRID_SPACING;
426
427         if (input >= int(_input_channels.size()) || output >= int(_output_channels.size())) {
428                 return optional<pair<NamedChannel, NamedChannel> >();
429         }
430
431         return make_pair (_input_channels[input], _output_channels[output]);
432 }
433
434 optional<string>
435 AudioMappingView::mouse_event_to_input_group_name (wxMouseEvent& ev) const
436 {
437         int const x = ev.GetX() + _horizontal_scroll->GetThumbPosition();
438         if (x < GRID_SPACING || x > (2 * GRID_SPACING)) {
439                 return optional<string>();
440         }
441
442         int y = (ev.GetY() + _vertical_scroll->GetThumbPosition() - (GRID_SPACING * 2)) / GRID_SPACING;
443         BOOST_FOREACH (Group i, _input_groups) {
444                 if (i.from <= y && y <= i.to) {
445                         return i.name;
446                 }
447         }
448
449         return optional<string>();
450 }
451
452 void
453 AudioMappingView::left_down (wxMouseEvent& ev)
454 {
455         optional<pair<NamedChannel, NamedChannel> > channels = mouse_event_to_channels (ev);
456         if (!channels) {
457                 return;
458         }
459
460         if (_map.get(channels->first.index, channels->second.index) > 0) {
461                 _map.set (channels->first.index, channels->second.index, 0);
462         } else {
463                 _map.set (channels->first.index, channels->second.index, 1);
464         }
465
466         map_values_changed ();
467 }
468
469 void
470 AudioMappingView::right_down (wxMouseEvent& ev)
471 {
472         optional<pair<NamedChannel, NamedChannel> > channels = mouse_event_to_channels (ev);
473         if (!channels) {
474                 return;
475         }
476
477         _menu_input = channels->first.index;
478         _menu_output = channels->second.index;
479         PopupMenu (_menu, ev.GetPosition());
480 }
481
482 void
483 AudioMappingView::mouse_wheel (wxMouseEvent& ev)
484 {
485         if (ev.ShiftDown()) {
486                 _horizontal_scroll->SetThumbPosition (
487                         _horizontal_scroll->GetThumbPosition() + (ev.GetWheelRotation() > 0 ? -GRID_SPACING : GRID_SPACING)
488                         );
489
490         } else {
491                 _vertical_scroll->SetThumbPosition (
492                         _vertical_scroll->GetThumbPosition() + (ev.GetWheelRotation() > 0 ? -GRID_SPACING : GRID_SPACING)
493                         );
494         }
495         Refresh ();
496 }
497
498 /** Called when any gain value has changed */
499 void
500 AudioMappingView::map_values_changed ()
501 {
502         Changed (_map);
503         _last_tooltip_channels = optional<pair<NamedChannel, NamedChannel> >();
504         Refresh ();
505 }
506
507 void
508 AudioMappingView::set_gain_from_menu (double linear)
509 {
510         _map.set (_menu_input, _menu_output, linear);
511         map_values_changed ();
512 }
513
514 void
515 AudioMappingView::edit ()
516 {
517         AudioGainDialog* dialog = new AudioGainDialog (this, _menu_input, _menu_output, _map.get(_menu_input, _menu_output));
518         if (dialog->ShowModal() == wxID_OK) {
519                 _map.set (_menu_input, _menu_output, dialog->value ());
520                 map_values_changed ();
521         }
522
523         dialog->Destroy ();
524 }
525
526 void
527 AudioMappingView::set (AudioMapping map)
528 {
529         _map = map;
530         Refresh ();
531 }
532
533 void
534 AudioMappingView::set_input_channels (vector<NamedChannel> const& channels)
535 {
536         _input_channels = channels;
537         setup ();
538         Refresh ();
539 }
540
541 void
542 AudioMappingView::set_output_channels (vector<NamedChannel> const & channels)
543 {
544         _output_channels = channels;
545         setup ();
546         Refresh ();
547 }
548
549
550 wxString
551 AudioMappingView::input_channel_name_with_group (NamedChannel const& n) const
552 {
553         optional<wxString> group;
554         BOOST_FOREACH (Group i, _input_groups) {
555                 if (i.from <= n.index && n.index <= i.to) {
556                         group = std_to_wx (i.name);
557                 }
558         }
559
560         if (group && !group->IsEmpty()) {
561                 return wxString::Format ("%s/%s", group->data(), std_to_wx(n.name).data());
562         }
563
564         return std_to_wx(n.name);
565 }
566
567
568 void
569 AudioMappingView::motion (wxMouseEvent& ev)
570 {
571         optional<pair<NamedChannel, NamedChannel> > channels = mouse_event_to_channels (ev);
572         if (channels) {
573                 if (channels != _last_tooltip_channels) {
574                         wxString s;
575                         float const gain = _map.get(channels->first.index, channels->second.index);
576                         if (gain == 0) {
577                                 s = wxString::Format (
578                                         _("No audio will be passed from %s channel '%s' to %s channel '%s'."),
579                                         _from,
580                                         input_channel_name_with_group(channels->first),
581                                         _to,
582                                         std_to_wx(channels->second.name)
583                                         );
584                         } else if (gain == 1) {
585                                 s = wxString::Format (
586                                         _("Audio will be passed from %s channel %s to %s channel %s unaltered."),
587                                         _from,
588                                         input_channel_name_with_group(channels->first),
589                                         _to,
590                                         std_to_wx(channels->second.name)
591                                         );
592                         } else {
593                                 float const dB = linear_to_db(gain);
594                                 s = wxString::Format (
595                                         _("Audio will be passed from %s channel %s to %s channel %s with gain %.1fdB."),
596                                         _from,
597                                         input_channel_name_with_group(channels->first),
598                                         _to,
599                                         std_to_wx(channels->second.name),
600                                         dB
601                                         );
602                         }
603
604                         SetToolTip (s + " " + _("Right click to change gain."));
605                 }
606         } else {
607                 optional<string> group = mouse_event_to_input_group_name (ev);
608                 if (group) {
609                         SetToolTip (std_to_wx(*group));
610                 } else {
611                         SetToolTip ("");
612                 }
613         }
614
615         _last_tooltip_channels = channels;
616         ev.Skip ();
617 }
618
619 void
620 AudioMappingView::set_input_groups (vector<Group> const & groups)
621 {
622         _input_groups = groups;
623 }