Merge branch 'master' into 1.0
[dcpomatic.git] / src / wx / film_editor.cc
index ad028c930c52510b86036a2988a1a03128222c2f..f909a8e2e6a7d94ab52c030c8ca3986624d8b2fe 100644 (file)
@@ -60,6 +60,7 @@ using std::fixed;
 using std::setprecision;
 using std::list;
 using std::vector;
+using std::max;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -617,6 +618,7 @@ FilmEditor::film_changed (Film::Property p)
                setup_subtitle_control_sensitivity ();
                setup_streams ();
                setup_show_audio_sensitivity ();
+               setup_length ();
                break;
        case Film::TRUST_CONTENT_HEADERS:
                checked_set (_trust_content_headers, _film->trust_content_headers ());
@@ -697,15 +699,20 @@ FilmEditor::film_changed (Film::Property p)
                setup_dcp_name ();
                break;
        case Film::DCP_FRAME_RATE:
+       {
+               bool done = false;
                for (unsigned int i = 0; i < _dcp_frame_rate->GetCount(); ++i) {
                        if (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_frame_rate())) {
-                               if (_dcp_frame_rate->GetSelection() != int(i)) {
-                                       _dcp_frame_rate->SetSelection (i);
-                                       break;
-                               }
+                               checked_set (_dcp_frame_rate, i);
+                               done = true;
+                               break;
                        }
                }
 
+               if (!done) {
+                       checked_set (_dcp_frame_rate, -1);
+               }
+
                if (_film->video_frame_rate()) {
                        _best_dcp_frame_rate->Enable (best_dcp_frame_rate (_film->video_frame_rate ()) != _film->dcp_frame_rate ());
                } else {
@@ -713,6 +720,7 @@ FilmEditor::film_changed (Film::Property p)
                }
                setup_frame_rate_description ();
                break;
+       }
        case Film::AUDIO_MAPPING:
                _audio_mapping->set_mapping (_film->audio_mapping ());
                break;
@@ -735,7 +743,7 @@ FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
        } else if (property == FFmpegContentProperty::AUDIO_STREAMS) {
                setup_streams ();
                setup_show_audio_sensitivity ();
-       } else if (property == VideoContentProperty::VIDEO_LENGTH) {
+       } else if (property == VideoContentProperty::VIDEO_LENGTH || property == AudioContentProperty::AUDIO_LENGTH) {
                setup_length ();
                boost::shared_ptr<Content> c = content.lock ();
                if (c && c == selected_content()) {
@@ -779,17 +787,19 @@ void
 FilmEditor::setup_length ()
 {
        stringstream s;
-       if (_film->video_frame_rate() > 0 && _film->video_length()) {
-               s << _film->video_length() << " "
-                 << wx_to_std (_("frames")) << "; " << seconds_to_hms (_film->video_length() / _film->video_frame_rate());
-       } else if (_film->video_length()) {
-               s << _film->video_length() << " "
-                 << wx_to_std (_("frames"));
-       } 
+       ContentVideoFrame const frames = _film->content_length ();
+       
+       if (frames && _film->video_frame_rate()) {
+               s << frames << " " << wx_to_std (_("frames")) << "; " << seconds_to_hms (frames / _film->video_frame_rate());
+       } else if (frames) {
+               s << frames << " " << wx_to_std (_("frames"));
+       }
+
        _length->SetLabel (std_to_wx (s.str ()));
-       if (_film->video_length()) {
-               _trim_start->SetRange (0, _film->video_length());
-               _trim_end->SetRange (0, _film->video_length());
+       
+       if (frames) {
+               _trim_start->SetRange (0, frames);
+               _trim_end->SetRange (0, frames);
        }
 }      
 
@@ -905,6 +915,8 @@ 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);
+
+       setup_content_information ();
 }
 
 /** Updates the sensitivity of lots of widgets to a given value.
@@ -930,6 +942,7 @@ FilmEditor::set_things_sensitive (bool s)
        _scaler->Enable (s);
        _ffmpeg_audio_stream->Enable (s);
        _dcp_content_type->Enable (s);
+       _best_dcp_frame_rate->Enable (s);
        _dcp_frame_rate->Enable (s);
        _trim_start->Enable (s);
        _trim_end->Enable (s);