Merge master and multifarious hackery.
[dcpomatic.git] / src / wx / film_editor.cc
index 0857b780a4d3f67525d1726f6054a2c19fb5eb0d..36d63b8055a4b7de144c8facdc1ac40f5d37cc8a 100644 (file)
@@ -237,11 +237,6 @@ FilmEditor::make_video_panel ()
        _video_sizer->Add (grid, 0, wxALL, 8);
 
        int r = 0;
-       add_label_to_grid_bag_sizer (grid, _video_panel, _("Format"), wxGBPosition (r, 0));
-       _format = new wxChoice (_video_panel, wxID_ANY);
-       grid->Add (_format, wxGBPosition (r, 1));
-       ++r;
-
        add_label_to_grid_bag_sizer (grid, _video_panel, _("Left crop"), wxGBPosition (r, 0));
        _left_crop = new wxSpinCtrl (_video_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
        grid->Add (_left_crop, wxGBPosition (r, 1));
@@ -262,6 +257,11 @@ FilmEditor::make_video_panel ()
        grid->Add (_bottom_crop, wxGBPosition (r, 1));
        ++r;
 
+       add_label_to_grid_bag_sizer (grid, _video_panel, _("Scale to"), wxGBPosition (r, 0));
+       _format = new wxChoice (_video_panel, wxID_ANY);
+       grid->Add (_format, wxGBPosition (r, 1));
+       ++r;
+
        _scaling_description = new wxStaticText (_video_panel, wxID_ANY, wxT ("\n \n \n \n"), wxDefaultPosition, wxDefaultSize);
        grid->Add (_scaling_description, wxGBPosition (r, 0), wxGBSpan (1, 2), wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
        wxFont font = _scaling_description->GetFont();
@@ -434,7 +434,7 @@ FilmEditor::make_subtitle_panel ()
                grid->Add (s);
        }
 
-       add_label_to_sizer (grid, _subtitle_panel, _("Subtitle stream"));
+       add_label_to_sizer (grid, _subtitle_panel, _("Subtitle Stream"));
        _subtitle_stream = new wxChoice (_subtitle_panel, wxID_ANY);
        grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
        grid->AddSpacer (0);
@@ -590,18 +590,6 @@ FilmEditor::film_changed (Film::Property p)
        case Film::CONTAINER:
                setup_container ();
                break;
-       case Film::FILTERS:
-       {
-               pair<string, string> p = Filter::ffmpeg_strings (_film->filters ());
-               if (p.first.empty () && p.second.empty ()) {
-                       _filters->SetLabel (_("None"));
-               } else {
-                       string const b = p.first + " " + p.second;
-                       _filters->SetLabel (std_to_wx (b));
-               }
-               _dcp_sizer->Layout ();
-               break;
-       }
        case Film::NAME:
                checked_set (_name, _film->name());
                setup_dcp_name ();
@@ -671,9 +659,11 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
        shared_ptr<Content> content = weak_content.lock ();
        shared_ptr<VideoContent> video_content;
        shared_ptr<AudioContent> audio_content;
+       shared_ptr<FFmpegContent> ffmpeg_content;
        if (content) {
                video_content = dynamic_pointer_cast<VideoContent> (content);
                audio_content = dynamic_pointer_cast<AudioContent> (content);
+               ffmpeg_content = dynamic_pointer_cast<FFmpegContent> (content);
        }
 
        if (property == VideoContentProperty::VIDEO_CROP) {
@@ -687,12 +677,50 @@ FilmEditor::film_content_changed (weak_ptr<Content> weak_content, int property)
        } else if (property == AudioContentProperty::AUDIO_DELAY) {
                checked_set (_audio_delay, audio_content ? audio_content->audio_delay() : 0);
        } else if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
+               _subtitle_stream->Clear ();
+               if (ffmpeg_content) {
+                       vector<shared_ptr<FFmpegSubtitleStream> > s = ffmpeg_content->subtitle_streams ();
+                       if (s.empty ()) {
+                               _subtitle_stream->Enable (false);
+                       }
+                       for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
+                               _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                       }
+                       
+                       if (ffmpeg_content->subtitle_stream()) {
+                               checked_set (_subtitle_stream, lexical_cast<string> (ffmpeg_content->subtitle_stream()->id));
+                       } else {
+                               _subtitle_stream->SetSelection (wxNOT_FOUND);
+                       }
+               }
                setup_subtitle_control_sensitivity ();
        } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
+               _audio_stream->Clear ();
+               if (ffmpeg_content) {
+                       vector<shared_ptr<FFmpegAudioStream> > a = ffmpeg_content->audio_streams ();
+                       for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
+                               _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
+                       }
+                       
+                       if (ffmpeg_content->audio_stream()) {
+                               checked_set (_audio_stream, lexical_cast<string> (ffmpeg_content->audio_stream()->id));
+                       }
+               }
                setup_show_audio_sensitivity ();
        } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
                setup_dcp_name ();
                setup_show_audio_sensitivity ();
+       } else if (property == FFmpegContentProperty::FILTERS) {
+               if (ffmpeg_content) {
+                       pair<string, string> p = Filter::ffmpeg_strings (ffmpeg_content->filters ());
+                       if (p.first.empty () && p.second.empty ()) {
+                               _filters->SetLabel (_("None"));
+                       } else {
+                               string const b = p.first + " " + p.second;
+                               _filters->SetLabel (std_to_wx (b));
+                       }
+                       _dcp_sizer->Layout ();
+               }
        }
 }
 
@@ -780,7 +808,6 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::LOOP);
        film_changed (Film::DCP_CONTENT_TYPE);
        film_changed (Film::CONTAINER);
-       film_changed (Film::FILTERS);
        film_changed (Film::SCALER);
        film_changed (Film::WITH_SUBTITLES);
        film_changed (Film::SUBTITLE_OFFSET);
@@ -797,6 +824,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAMS);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::AUDIO_STREAM);
+       film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::FILTERS);
 }
 
 /** Updates the sensitivity of lots of widgets to a given value.
@@ -838,8 +866,18 @@ FilmEditor::set_things_sensitive (bool s)
 void
 FilmEditor::edit_filters_clicked (wxCommandEvent &)
 {
-       FilterDialog* d = new FilterDialog (this, _film->filters());
-       d->ActiveChanged.connect (bind (&Film::set_filters, _film, _1));
+       shared_ptr<Content> c = selected_content ();
+       if (!c) {
+               return;
+       }
+
+       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
+       if (!fc) {
+               return;
+       }
+       
+       FilterDialog* d = new FilterDialog (this, fc->filters());
+       d->ActiveChanged.connect (bind (&FFmpegContent::set_filters, fc, _1));
        d->ShowModal ();
        d->Destroy ();
 }
@@ -1099,6 +1137,13 @@ void
 FilmEditor::content_selection_changed (wxListEvent &)
 {
         setup_content_sensitivity ();
+       shared_ptr<Content> s = selected_content ();
+       film_content_changed (s, VideoContentProperty::VIDEO_CROP);
+       film_content_changed (s, AudioContentProperty::AUDIO_GAIN);
+       film_content_changed (s, AudioContentProperty::AUDIO_DELAY);
+       film_content_changed (s, FFmpegContentProperty::AUDIO_STREAM);
+       film_content_changed (s, FFmpegContentProperty::AUDIO_STREAMS);
+       film_content_changed (s, FFmpegContentProperty::SUBTITLE_STREAM);
 }
 
 void
@@ -1111,9 +1156,9 @@ FilmEditor::setup_content_sensitivity ()
         _content_remove->Enable (selection && _generally_sensitive);
        _content_timeline->Enable (_generally_sensitive);
 
-       _video_panel->Enable (selection && _generally_sensitive);
-       _audio_panel->Enable (selection && _generally_sensitive);
-       _subtitle_panel->Enable (selection && _generally_sensitive);
+       _video_panel->Enable    (selection && dynamic_pointer_cast<VideoContent>  (selection) && _generally_sensitive);
+       _audio_panel->Enable    (selection && dynamic_pointer_cast<AudioContent>  (selection) && _generally_sensitive);
+       _subtitle_panel->Enable (selection && dynamic_pointer_cast<FFmpegContent> (selection) && _generally_sensitive);
 }
 
 shared_ptr<Content>
@@ -1249,48 +1294,6 @@ FilmEditor::content_timeline_clicked (wxCommandEvent &)
        _timeline_dialog->Show ();
 }
 
-void
-FilmEditor::setup_content_properties ()
-{
-       _audio_stream->Clear ();
-       _subtitle_stream->Clear ();
-
-       shared_ptr<Content> c = selected_content ();
-       if (!c) {
-               return;
-       }
-
-       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (c);
-       if (fc) {
-               
-               vector<shared_ptr<FFmpegAudioStream> > a = fc->audio_streams ();
-               for (vector<shared_ptr<FFmpegAudioStream> >::iterator i = a.begin(); i != a.end(); ++i) {
-                       _audio_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
-               }
-               
-               if (fc->audio_stream()) {
-                       checked_set (_audio_stream, lexical_cast<string> (fc->audio_stream()->id));
-               }
-               
-               vector<shared_ptr<FFmpegSubtitleStream> > s = fc->subtitle_streams ();
-               if (s.empty ()) {
-                       _subtitle_stream->Enable (false);
-               }
-               for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
-                       _subtitle_stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx (lexical_cast<string> ((*i)->id))));
-               }
-               
-               if (fc->subtitle_stream()) {
-                       checked_set (_subtitle_stream, lexical_cast<string> (fc->subtitle_stream()->id));
-               } else {
-                       _subtitle_stream->SetSelection (wxNOT_FOUND);
-               }
-
-               /* XXX: should be general audiocontent */
-               _audio_mapping->set_mapping (fc->audio_mapping ());
-       }
-}
-
 void
 FilmEditor::audio_stream_changed (wxCommandEvent &)
 {