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