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