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