No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / audio_mapping_view.cc
index 8f55043befc8134eb1df2459b9db043b150df4df..8d39a40ff91c7de810f6a70854e922d0da694df2 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -31,7 +32,7 @@
 #include <wx/wx.h>
 #include <wx/renderer.h>
 #include <wx/grid.h>
-#include <boost/lexical_cast.hpp>
+#include <iostream>
 
 using std::cout;
 using std::list;
@@ -39,7 +40,6 @@ using std::string;
 using std::max;
 using std::vector;
 using boost::shared_ptr;
-using boost::lexical_cast;
 
 #define INDICATOR_SIZE 16
 
@@ -79,7 +79,7 @@ public:
                dc.SetBrush (*wxTheBrushList->FindOrCreateBrush (wxColour (255, 255, 255), wxBRUSHSTYLE_SOLID));
                dc.DrawRectangle (wxRect (rect.GetLeft() + xo, rect.GetTop() + yo, INDICATOR_SIZE, INDICATOR_SIZE));
 
-               float const value = lexical_cast<float> (wx_to_std (grid.GetCellValue (row, col)));
+               float const value = raw_convert<float> (wx_to_std (grid.GetCellValue (row, col)));
                float const value_dB = 20 * log10 (value);
                int const range = 18;
                int height = 0;
@@ -88,7 +88,7 @@ public:
                }
 
                height = max (0, height);
-               
+
                if (value > 0) {
                        /* Make sure we get a little bit of the marker if there is any gain */
                        height = max (3, height);
@@ -102,7 +102,7 @@ public:
        {
                return wxSize (INDICATOR_SIZE + 4, INDICATOR_SIZE + 4);
        }
-       
+
        wxGridCellRenderer* Clone () const
        {
                return new ValueRenderer;
@@ -135,6 +135,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));
+       Bind (wxEVT_SIZE, boost::bind (&AudioMappingView::sized, this, _1));
 
        _menu = new wxMenu;
        _menu->Append (ID_off, _("Off"));
@@ -155,7 +156,7 @@ AudioMappingView::map_values_changed ()
        update_cells ();
        Changed (_map);
        _last_tooltip_column = -1;
-}      
+}
 
 void
 AudioMappingView::left_click (wxGridEvent& ev)
@@ -165,7 +166,7 @@ AudioMappingView::left_click (wxGridEvent& ev)
        }
 
        int const d = ev.GetCol() - 1;
-       
+
        if (_map.get (ev.GetRow(), d) > 0) {
                _map.set (ev.GetRow(), d, 0);
        } else {
@@ -212,13 +213,13 @@ void
 AudioMappingView::edit ()
 {
        int const d = _menu_column - 1;
-       
+
        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 ());
                map_values_changed ();
        }
-       
+
        dialog->Destroy ();
 }
 
@@ -247,7 +248,7 @@ AudioMappingView::set_output_channels (vector<string> const & names)
                _grid->InsertCols (_grid->GetNumberCols(), o - _grid->GetNumberCols());
        }
 
-       _grid->SetColLabelValue (0, _("Content"));
+       _grid->SetColLabelValue (0, wxT (""));
 
        for (size_t i = 0; i < names.size(); ++i) {
                _grid->SetColLabelValue (i + 1, std_to_wx (names[i]));
@@ -259,6 +260,11 @@ AudioMappingView::set_output_channels (vector<string> const & names)
 void
 AudioMappingView::update_cells ()
 {
+       vector<string> row_names;
+       for (int i = 0; i < _grid->GetNumberRows (); ++i) {
+               row_names.push_back (wx_to_std (_grid->GetCellValue (i, 0)));
+       }
+
        if (_grid->GetNumberRows ()) {
                _grid->DeleteRows (0, _grid->GetNumberRows ());
        }
@@ -270,8 +276,11 @@ AudioMappingView::update_cells ()
                        _grid->SetCellRenderer (i, j + 1, new ValueRenderer);
                }
        }
-       
+
        for (int i = 0; i < _map.input_channels(); ++i) {
+               if (i < int (row_names.size ())) {
+                       _grid->SetCellValue (i, 0, std_to_wx (row_names[i]));
+               }
                for (int j = 1; j < _grid->GetNumberCols(); ++j) {
                        _grid->SetCellValue (i, j, std_to_wx (raw_convert<string> (_map.get (i, j - 1))));
                }
@@ -308,7 +317,7 @@ AudioMappingView::mouse_moved (wxMouseEvent& ev)
                        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;
@@ -316,3 +325,10 @@ AudioMappingView::mouse_moved (wxMouseEvent& ev)
 
         ev.Skip ();
 }
+
+void
+AudioMappingView::sized (wxSizeEvent& ev)
+{
+       _grid->AutoSize ();
+       ev.Skip ();
+}