Cleanup: move some methods from util to maths_util.
[dcpomatic.git] / src / wx / audio_panel.cc
index f29704b548b197d5c82cf318275d2c85bd0bda26..af030e9156af37525aa4ef70cd6fbee23f703758 100644 (file)
 
 */
 
-#include "audio_panel.h"
-#include "audio_mapping_view.h"
-#include "wx_util.h"
-#include "gain_calculator_dialog.h"
-#include "content_panel.h"
+
 #include "audio_dialog.h"
-#include "static_text.h"
+#include "audio_mapping_view.h"
+#include "audio_panel.h"
 #include "check_box.h"
+#include "content_panel.h"
 #include "dcpomatic_button.h"
+#include "gain_calculator_dialog.h"
+#include "static_text.h"
+#include "wx_util.h"
 #include "lib/config.h"
 #include "lib/ffmpeg_audio_stream.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/job_manager.h"
 #include "lib/dcp_content.h"
 #include "lib/audio_content.h"
+#include "lib/maths_util.h"
 #include <wx/spinctrl.h>
 #include <iostream>
 
+
 using std::vector;
 using std::cout;
 using std::string;
@@ -50,9 +53,17 @@ using boost::optional;
 using namespace boost::placeholders;
 #endif
 
+
 AudioPanel::AudioPanel (ContentPanel* p)
        : ContentSubPanel (p, _("Audio"))
        , _audio_dialog (0)
+{
+
+}
+
+
+void
+AudioPanel::create ()
 {
        _reference = new CheckBox (this, _("Use this DCP's audio as OV and make VF"));
        _reference_note = new StaticText (this, wxT(""));
@@ -104,9 +115,9 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _delay->wrapped()->SetRange (-1000, 1000);
 
        content_selection_changed ();
-       film_changed (Film::AUDIO_CHANNELS);
-       film_changed (Film::VIDEO_FRAME_RATE);
-       film_changed (Film::REEL_TYPE);
+       film_changed (Film::Property::AUDIO_CHANNELS);
+       film_changed (Film::Property::VIDEO_FRAME_RATE);
+       film_changed (Film::Property::REEL_TYPE);
 
        _reference->Bind             (wxEVT_CHECKBOX, boost::bind (&AudioPanel::reference_clicked, this));
        _show->Bind                  (wxEVT_BUTTON,   boost::bind (&AudioPanel::show_clicked, this));
@@ -116,6 +127,8 @@ AudioPanel::AudioPanel (ContentPanel* p)
        _active_jobs_connection = JobManager::instance()->ActiveJobsChanged.connect (boost::bind (&AudioPanel::active_jobs_changed, this, _1, _2));
 
        add_to_grid ();
+
+       _sizer->Layout ();
 }
 
 void
@@ -136,7 +149,7 @@ AudioPanel::add_to_grid ()
        add_label_to_sizer (_grid, _gain_label, true, wxGBPosition(r, 0));
        {
                auto s = new wxBoxSizer (wxHORIZONTAL);
-               s->Add (_gain->wrapped(), 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
+               s->Add (_gain->wrapped(), 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
                s->Add (_gain_db_label, 0, wxALIGN_CENTER_VERTICAL);
                _grid->Add (s, wxGBPosition(r, 1));
        }
@@ -146,7 +159,7 @@ AudioPanel::add_to_grid ()
 
        add_label_to_sizer (_grid, _delay_label, true, wxGBPosition(r, 0));
        auto s = new wxBoxSizer (wxHORIZONTAL);
-       s->Add (_delay->wrapped(), 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
+       s->Add (_delay->wrapped(), 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
        s->Add (_delay_ms_label, 0, wxALIGN_CENTER_VERTICAL);
        _grid->Add (s, wxGBPosition(r, 1));
        ++r;
@@ -168,16 +181,16 @@ AudioPanel::film_changed (Film::Property property)
        }
 
        switch (property) {
-       case Film::AUDIO_CHANNELS:
-       case Film::AUDIO_PROCESSOR:
+       case Film::Property::AUDIO_CHANNELS:
+       case Film::Property::AUDIO_PROCESSOR:
                _mapping->set_output_channels (_parent->film()->audio_output_names ());
                setup_peak ();
                break;
-       case Film::VIDEO_FRAME_RATE:
+       case Film::Property::VIDEO_FRAME_RATE:
                setup_description ();
                break;
-       case Film::REEL_TYPE:
-       case Film::INTEROP:
+       case Film::Property::REEL_TYPE:
+       case Film::Property::INTEROP:
                setup_sensitivity ();
                break;
        default:
@@ -215,7 +228,7 @@ AudioPanel::film_content_changed (int property)
                }
                setup_description ();
                setup_peak ();
-               _sizer->Layout ();
+               layout ();
        } else if (property == AudioContentProperty::GAIN) {
                setup_peak ();
        } else if (property == DCPContentProperty::REFERENCE_AUDIO) {
@@ -319,23 +332,16 @@ AudioPanel::setup_sensitivity ()
        }
        setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
 
-       if (_reference->GetValue ()) {
-               _gain->wrapped()->Enable (false);
-               _gain_calculate_button->Enable (false);
-               _show->Enable (true);
-               _peak->Enable (false);
-               _delay->wrapped()->Enable (false);
-               _mapping->Enable (false);
-               _description->Enable (false);
-       } else {
-               _gain->wrapped()->Enable (sel.size() == 1);
-               _gain_calculate_button->Enable (sel.size() == 1);
-               _show->Enable (sel.size() == 1);
-               _peak->Enable (sel.size() == 1);
-               _delay->wrapped()->Enable (sel.size() == 1);
-               _mapping->Enable (sel.size() == 1);
-               _description->Enable (sel.size() == 1);
-       }
+       auto const ref = _reference->GetValue();
+       auto const single = sel.size() == 1;
+
+       _gain->wrapped()->Enable (!ref);
+       _gain_calculate_button->Enable (!ref && single);
+       _show->Enable (single);
+       _peak->Enable (!ref && single);
+       _delay->wrapped()->Enable (!ref);
+       _mapping->Enable (!ref && single);
+       _description->Enable (!ref && single);
 }
 
 void
@@ -440,3 +446,4 @@ AudioPanel::set_film (shared_ptr<Film>)
                _audio_dialog = nullptr;
        }
 }
+