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