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