Open an error dialogue on uncaught exceptions in the main loop. Check that the Image...
[dcpomatic.git] / src / wx / audio_mapping_view.cc
index 54749845d6977146313c74d94d265df43a10a72d..7fdecb8d52a8dc9d3cee8ff54e8781b68b3ca422 100644 (file)
@@ -34,7 +34,7 @@ using std::max;
 using boost::shared_ptr;
 using boost::lexical_cast;
 
-#define INDICATOR_SIZE 20
+#define INDICATOR_SIZE 16
 
 enum {
        ID_off = 1,
@@ -58,6 +58,8 @@ public:
 
        void Draw (wxGrid& grid, wxGridCellAttr &, wxDC& dc, const wxRect& rect, int row, int col, bool)
        {
+               LocaleGuard lg;
+       
                dc.SetPen (*wxThePenList->FindOrCreatePen (wxColour (255, 255, 255), 1, wxPENSTYLE_SOLID));
                dc.SetBrush (*wxTheBrushList->FindOrCreateBrush (wxColour (255, 255, 255), wxBRUSHSTYLE_SOLID));
                dc.DrawRectangle (rect);
@@ -104,6 +106,8 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
        : wxPanel (parent, wxID_ANY)
        , _menu_row (0)
        , _menu_column (1)
+       , _last_tooltip_row (0)
+       , _last_tooltip_column (0)
 {
        _grid = new wxGrid (this, wxID_ANY);
 
@@ -123,6 +127,7 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
 
        Bind (wxEVT_GRID_CELL_LEFT_CLICK, boost::bind (&AudioMappingView::left_click, this, _1));
        Bind (wxEVT_GRID_CELL_RIGHT_CLICK, boost::bind (&AudioMappingView::right_click, this, _1));
+       _grid->GetGridWindow()->Bind (wxEVT_MOTION, boost::bind (&AudioMappingView::mouse_moved, this, _1));
 
        _menu = new wxMenu;
        _menu->Append (ID_off, _("Off"));
@@ -136,6 +141,14 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
        Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&AudioMappingView::edit, this), ID_edit);
 }
 
+void
+AudioMappingView::map_changed ()
+{
+       update_cells ();
+       Changed (_map);
+       _last_tooltip_column = -1;
+}      
+
 void
 AudioMappingView::left_click (wxGridEvent& ev)
 {
@@ -151,8 +164,7 @@ AudioMappingView::left_click (wxGridEvent& ev)
                _map.set (ev.GetRow(), d, 1);
        }
 
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
@@ -171,24 +183,21 @@ void
 AudioMappingView::off ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 0);
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
 AudioMappingView::full ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 1);
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
 AudioMappingView::minus3dB ()
 {
        _map.set (_menu_row, static_cast<libdcp::Channel> (_menu_column - 1), 1 / sqrt (2));
-       update_cells ();
-       Changed (_map);
+       map_changed ();
 }
 
 void
@@ -199,8 +208,7 @@ AudioMappingView::edit ()
        AudioGainDialog* dialog = new AudioGainDialog (this, _menu_row, _menu_column - 1, _map.get (_menu_row, d));
        if (dialog->ShowModal () == wxID_OK) {
                _map.set (_menu_row, d, dialog->value ());
-               update_cells ();
-               Changed (_map);
+               map_changed ();
        }
        
        dialog->Destroy ();
@@ -216,6 +224,8 @@ AudioMappingView::set (AudioMapping map)
 void
 AudioMappingView::update_cells ()
 {
+       LocaleGuard lg;
+       
        if (_grid->GetNumberRows ()) {
                _grid->DeleteRows (0, _grid->GetNumberRows ());
        }
@@ -260,7 +270,11 @@ AudioMappingView::set_column_labels ()
 {
        int const c = _grid->GetNumberCols ();
        
-       _grid->SetColLabelValue (0, _("Content channel"));
+       _grid->SetColLabelValue (0, _("Content"));
+
+#if MAX_AUDIO_CHANNELS != 12
+#warning AudioMappingView::set_column_labels() is expecting the wrong MAX_AUDIO_CHANNELS
+#endif 
        
        if (c > 0) {
                _grid->SetColLabelValue (1, _("L"));
@@ -286,5 +300,66 @@ AudioMappingView::set_column_labels ()
                _grid->SetColLabelValue (6, _("Rs"));
        }
 
+       if (c > 6) {
+               _grid->SetColLabelValue (7, _("HI"));
+       }
+
+       if (c > 7) {
+               _grid->SetColLabelValue (8, _("VI"));
+       }
+
+       if (c > 8) {
+               _grid->SetColLabelValue (9, _("Lc"));
+       }
+
+       if (c > 9) {
+               _grid->SetColLabelValue (10, _("Rc"));
+       }
+
+       if (c > 10) {
+               _grid->SetColLabelValue (11, _("BsL"));
+       }
+
+       if (c > 11) {
+               _grid->SetColLabelValue (12, _("BsR"));
+       }
+
        _grid->AutoSize ();
 }
+
+void
+AudioMappingView::mouse_moved (wxMouseEvent& ev)
+{
+       int xx;
+       int yy;
+       _grid->CalcUnscrolledPosition (ev.GetX(), ev.GetY(), &xx, &yy);
+
+       int const row = _grid->YToRow (yy);
+       int const column = _grid->XToCol (xx);
+
+       if (row < 0 || column < 1) {
+               _grid->GetGridWindow()->SetToolTip ("");
+               _last_tooltip_row = row;
+               _last_tooltip_column = column;
+       }
+
+       if (row != _last_tooltip_row || column != _last_tooltip_column) {
+
+               wxString s;
+               float const gain = _map.get (row, static_cast<libdcp::Channel> (column - 1));
+               if (gain == 0) {
+                       s = wxString::Format (_("No audio will be passed from content channel %d to DCP channel %d."), row + 1, column);
+               } else if (gain == 1) {
+                       s = wxString::Format (_("Audio will be passed from content channel %d to DCP channel %d unaltered."), row + 1, column);
+               } else {
+                       float const dB = 20 * log10 (gain);
+                       s = wxString::Format (_("Audio will be passed from content channel %d to DCP channel %d with gain %.1fdB."), row + 1, column, dB);
+               }
+               
+               _grid->GetGridWindow()->SetToolTip (s + " " + _("Right click to change gain."));
+               _last_tooltip_row = row;
+               _last_tooltip_column = column;
+       }
+
+        ev.Skip ();
+}