A few things missed when setting sensitivity.
[dcpomatic.git] / src / wx / film_editor.cc
index 22063256fd521aa3b5c7f2bac760234fa2b8b290..5ff3b3302561ecdae5b96cd26e4e43ce1da5b8ac 100644 (file)
@@ -32,7 +32,6 @@
 #include "lib/transcode_job.h"
 #include "lib/exceptions.h"
 #include "lib/ab_transcode_job.h"
-#include "lib/thumbs_job.h"
 #include "lib/job_manager.h"
 #include "lib/filter.h"
 #include "lib/screen.h"
 #include "gain_calculator_dialog.h"
 #include "sound_processor.h"
 #include "dci_name_dialog.h"
+#include "scaler.h"
 
-using namespace std;
-using namespace boost;
+using std::string;
+using std::stringstream;
+using std::pair;
+using std::fixed;
+using std::setprecision;
+using std::list;
+using std::vector;
+using boost::shared_ptr;
 
 /** @param f Film to edit */
-FilmEditor::FilmEditor (Film* f, wxWindow* parent)
+FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        : wxPanel (parent)
        , _ignore_changes (Film::NONE)
        , _film (f)
@@ -67,7 +73,7 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
 
        _use_dci_name = new wxCheckBox (this, wxID_ANY, wxT ("Use DCI name"));
        _sizer->Add (_use_dci_name, 1, wxEXPAND);
-       _edit_dci_button = new wxButton (this, wxID_ANY, wxT ("Edit..."));
+       _edit_dci_button = new wxButton (this, wxID_ANY, wxT ("Details..."));
        _sizer->Add (_edit_dci_button, 0);
 
        add_label_to_sizer (_sizer, this, "Content");
@@ -119,6 +125,16 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _scaler = new wxComboBox (this, wxID_ANY);
        _sizer->Add (video_control (_scaler), 1);
 
+       {
+               video_control (add_label_to_sizer (_sizer, this, "Audio Stream"));
+               wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _audio_stream = new wxComboBox (this, wxID_ANY);
+               s->Add (video_control (_audio_stream), 1);
+               _audio = new wxStaticText (this, wxID_ANY, wxT (""));
+               s->Add (video_control (_audio), 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
+               _sizer->Add (s, 1, wxEXPAND);
+       }
+
        {
                video_control (add_label_to_sizer (_sizer, this, "Audio Gain"));
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
@@ -143,7 +159,9 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _with_subtitles = new wxCheckBox (this, wxID_ANY, wxT("With Subtitles"));
        video_control (_with_subtitles);
        _sizer->Add (_with_subtitles, 1);
-       _sizer->AddSpacer (0);
+       
+       _subtitle_stream = new wxComboBox (this, wxID_ANY);
+       _sizer->Add (_subtitle_stream);
 
        video_control (add_label_to_sizer (_sizer, this, "Subtitle Offset"));
        _subtitle_offset = new wxSpinCtrl (this);
@@ -170,9 +188,6 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _length = new wxStaticText (this, wxID_ANY, wxT (""));
        _sizer->Add (video_control (_length), 1, wxALIGN_CENTER_VERTICAL);
 
-       video_control (add_label_to_sizer (_sizer, this, "Audio"));
-       _audio = new wxStaticText (this, wxID_ANY, wxT (""));
-       _sizer->Add (video_control (_audio), 1, wxALIGN_CENTER_VERTICAL);
 
        {
                video_control (add_label_to_sizer (_sizer, this, "Range"));
@@ -222,6 +237,10 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
                _scaler->Append (std_to_wx ((*i)->name()));
        }
 
+       JobManager::instance()->ActiveJobsChanged.connect (
+               bind (&FilmEditor::active_jobs_changed, this, _1)
+               );
+
        /* And set their values from the Film */
        set_film (f);
        
@@ -249,6 +268,8 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
        _with_subtitles->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::with_subtitles_toggled), 0, this);
        _subtitle_offset->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_offset_changed), 0, this);
        _subtitle_scale->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::subtitle_scale_changed), 0, this);
+       _audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::audio_stream_changed), 0, this);
+       _subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (FilmEditor::subtitle_stream_changed), 0, this);
 
        setup_visibility ();
        setup_formats ();
@@ -328,6 +349,7 @@ FilmEditor::content_changed (wxCommandEvent &)
        setup_visibility ();
        setup_formats ();
        setup_subtitle_button ();
+       setup_streams ();
 }
 
 /** Called when the DCP A/B switch has been toggled */
@@ -390,6 +412,8 @@ FilmEditor::subtitle_scale_changed (wxCommandEvent &)
 void
 FilmEditor::film_changed (Film::Property p)
 {
+       ensure_ui_thread ();
+       
        if (!_film || _ignore_changes == p) {
                return;
        }
@@ -404,6 +428,15 @@ FilmEditor::film_changed (Film::Property p)
                setup_visibility ();
                setup_formats ();
                setup_subtitle_button ();
+               setup_streams ();
+               break;
+       case Film::HAS_SUBTITLES:
+               setup_subtitle_button ();
+               setup_streams ();
+               break;
+       case Film::AUDIO_STREAMS:
+       case Film::SUBTITLE_STREAMS:
+               setup_streams ();
                break;
        case Film::FORMAT:
        {
@@ -440,21 +473,11 @@ FilmEditor::film_changed (Film::Property p)
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::FRAMES_PER_SECOND:
-       {
-               stringstream s;
                s << fixed << setprecision(2) << _film->frames_per_second();
                _frames_per_second->SetLabel (std_to_wx (s.str ()));
                break;
-       }
-       case Film::AUDIO_CHANNELS:
-               _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
        case Film::AUDIO_SAMPLE_RATE:
-               if (_film->audio_channels() == 0 && _film->audio_sample_rate() == 0) {
-                       _audio->SetLabel (wxT (""));
-               } else {
-                       s << _film->audio_channels () << " channels, " << _film->audio_sample_rate() << "Hz";
-                       _audio->SetLabel (std_to_wx (s.str ()));
-               }
+               setup_audio_details ();
                break;
        case Film::SIZE:
                if (_film->size().width == 0 && _film->size().height == 0) {
@@ -465,10 +488,10 @@ FilmEditor::film_changed (Film::Property p)
                }
                break;
        case Film::LENGTH:
-               if (_film->frames_per_second() > 0 && _film->length() > 0) {
-                       s << _film->length() << " frames; " << seconds_to_hms (_film->length() / _film->frames_per_second());
-               } else if (_film->length() > 0) {
-                       s << _film->length() << " frames";
+               if (_film->frames_per_second() > 0 && _film->length()) {
+                       s << _film->length().get() << " frames; " << seconds_to_hms (_film->length().get() / _film->frames_per_second());
+               } else if (_film->length()) {
+                       s << _film->length().get() << " frames";
                } 
                _length->SetLabel (std_to_wx (s.str ()));
                break;
@@ -524,6 +547,14 @@ FilmEditor::film_changed (Film::Property p)
        case Film::DCI_METADATA:
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
+       case Film::AUDIO_STREAM:
+               _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
+               _audio_stream->SetSelection (_film->audio_stream_index ());
+               setup_audio_details ();
+               break;
+       case Film::SUBTITLE_STREAM:
+               _subtitle_stream->SetSelection (_film->subtitle_stream_index ());
+               break;
        }
 }
 
@@ -566,14 +597,14 @@ FilmEditor::dcp_content_type_changed (wxCommandEvent &)
 
 /** Sets the Film that we are editing */
 void
-FilmEditor::set_film (Film* f)
+FilmEditor::set_film (shared_ptr<Film> f)
 {
        _film = f;
 
        set_things_sensitive (_film != 0);
 
        if (_film) {
-               _film->Changed.connect (sigc::mem_fun (*this, &FilmEditor::film_changed));
+               _film->Changed.connect (bind (&FilmEditor::film_changed, this, _1));
        }
 
        if (_film) {
@@ -594,7 +625,6 @@ FilmEditor::set_film (Film* f)
        film_changed (Film::SIZE);
        film_changed (Film::LENGTH);
        film_changed (Film::FRAMES_PER_SECOND);
-       film_changed (Film::AUDIO_CHANNELS);
        film_changed (Film::AUDIO_SAMPLE_RATE);
        film_changed (Film::SCALER);
        film_changed (Film::AUDIO_GAIN);
@@ -616,7 +646,6 @@ FilmEditor::set_things_sensitive (bool s)
        _name->Enable (s);
        _use_dci_name->Enable (s);
        _edit_dci_button->Enable (s);
-       _frames_per_second->Enable (s);
        _format->Enable (s);
        _content->Enable (s);
        _left_crop->Enable (s);
@@ -625,6 +654,7 @@ FilmEditor::set_things_sensitive (bool s)
        _bottom_crop->Enable (s);
        _filters_button->Enable (s);
        _scaler->Enable (s);
+       _audio_stream->Enable (s);
        _dcp_content_type->Enable (s);
        _dcp_range->Enable (s);
        _change_dcp_range_button->Enable (s);
@@ -632,18 +662,21 @@ FilmEditor::set_things_sensitive (bool s)
        _audio_gain->Enable (s);
        _audio_gain_calculate_button->Enable (s);
        _audio_delay->Enable (s);
+       _subtitle_stream->Enable (s);
        _still_duration->Enable (s);
        _with_subtitles->Enable (s);
        _subtitle_offset->Enable (s);
        _subtitle_scale->Enable (s);
+       _frames_per_second->Enable (s);
+       _original_size->Enable (s);
 }
 
 /** Called when the `Edit filters' button has been clicked */
 void
 FilmEditor::edit_filters_clicked (wxCommandEvent &)
 {
-       FilterDialog* d = new FilterDialog (this, _film->filters ());
-       d->ActiveChanged.connect (sigc::mem_fun (*_film, &Film::set_filters));
+       FilterDialog* d = new FilterDialog (this, _film->filters());
+       d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
        d->ShowModal ();
        d->Destroy ();
 }
@@ -738,7 +771,7 @@ void
 FilmEditor::change_dcp_range_clicked (wxCommandEvent &)
 {
        DCPRangeDialog* d = new DCPRangeDialog (this, _film);
-       d->Changed.connect (sigc::mem_fun (*this, &FilmEditor::dcp_range_changed));
+       d->Changed.connect (bind (&FilmEditor::dcp_range_changed, this, _1, _2));
        d->ShowModal ();
 }
 
@@ -853,3 +886,66 @@ FilmEditor::edit_dci_button_clicked (wxCommandEvent &)
        d->ShowModal ();
        d->Destroy ();
 }
+
+void
+FilmEditor::setup_streams ()
+{
+       _audio_stream->Clear ();
+       vector<AudioStream> a = _film->audio_streams ();
+       for (vector<AudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
+               _audio_stream->Append (std_to_wx (i->name()));
+       }
+       _audio_stream->SetSelection (_film->audio_stream_index ());
+
+       _subtitle_stream->Clear ();
+       vector<SubtitleStream> s = _film->subtitle_streams ();
+       for (vector<SubtitleStream>::iterator i = s.begin(); i != s.end(); ++i) {
+               _subtitle_stream->Append (std_to_wx (i->name()));
+       }
+       _subtitle_stream->SetSelection (_film->subtitle_stream_index ());
+}
+
+void
+FilmEditor::audio_stream_changed (wxCommandEvent &)
+{
+       if (!_film) {
+               return;
+       }
+
+       _ignore_changes = Film::AUDIO_STREAM;
+       _film->set_audio_stream (_audio_stream->GetSelection ());
+       _ignore_changes = Film::NONE;
+
+       _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
+       setup_audio_details ();
+}
+
+void
+FilmEditor::subtitle_stream_changed (wxCommandEvent &)
+{
+       if (!_film) {
+               return;
+       }
+
+       _ignore_changes = Film::SUBTITLE_STREAM;
+       _film->set_subtitle_stream (_subtitle_stream->GetSelection ());
+       _ignore_changes = Film::NONE;
+}
+
+void
+FilmEditor::setup_audio_details ()
+{
+       if (_film->audio_channels() == 0 && _film->audio_sample_rate() == 0) {
+               _audio->SetLabel (wxT (""));
+       } else {
+               stringstream s;
+               s << _film->audio_channels () << " channels, " << _film->audio_sample_rate() << "Hz";
+               _audio->SetLabel (std_to_wx (s.str ()));
+       }
+}
+
+void
+FilmEditor::active_jobs_changed (bool a)
+{
+       set_things_sensitive (!a);
+}