Remove film player, DVD ripping, alignment, screen configs; never finished and not...
[dcpomatic.git] / src / wx / film_editor.cc
index 34223ce0570999491b8cb967b1b3b835299df21a..67cd17d4ada9449a91acee724ef52aeae1871cbe 100644 (file)
 #include "lib/ab_transcode_job.h"
 #include "lib/job_manager.h"
 #include "lib/filter.h"
-#include "lib/screen.h"
 #include "lib/config.h"
 #include "filter_dialog.h"
 #include "wx_util.h"
 #include "film_editor.h"
-#include "dcp_range_dialog.h"
 #include "gain_calculator_dialog.h"
 #include "sound_processor.h"
 #include "dci_name_dialog.h"
@@ -57,8 +55,8 @@ using boost::shared_ptr;
 /** @param f Film to edit */
 FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        : wxPanel (parent)
-       , _ignore_changes (Film::NONE)
        , _film (f)
+       , _generally_sensitive (true)
 {
        _sizer = new wxFlexGridSizer (2, 4, 4);
        SetSizer (_sizer);
@@ -190,12 +188,15 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
 
 
        {
-               video_control (add_label_to_sizer (_sizer, this, "Range"));
+               video_control (add_label_to_sizer (_sizer, this, "Trim frames"));
                wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
-               _dcp_range = new wxStaticText (this, wxID_ANY, wxT (""));
-               s->Add (video_control (_dcp_range), 1, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM | wxRIGHT, 6);
-               _change_dcp_range_button = new wxButton (this, wxID_ANY, wxT ("Edit..."));
-               s->Add (video_control (_change_dcp_range_button), 0, 0, 6);
+               add_label_to_sizer (s, this, "Start");
+               _dcp_trim_start = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
+               s->Add (_dcp_trim_start);
+               add_label_to_sizer (s, this, "End");
+               _dcp_trim_end = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
+               s->Add (_dcp_trim_end);
+
                _sizer->Add (s);
        }
 
@@ -226,6 +227,8 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        _still_duration->SetRange (0, 60 * 60);
        _subtitle_offset->SetRange (-1024, 1024);
        _subtitle_scale->SetRange (1, 1000);
+       _dcp_trim_start->SetRange (0, 100);
+       _dcp_trim_end->SetRange (0, 100);
 
        vector<DCPContentType const *> const ct = DCPContentType::all ();
        for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
@@ -264,7 +267,8 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
                );
        _audio_delay->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::audio_delay_changed), 0, this);
        _still_duration->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::still_duration_changed), 0, this);
-       _change_dcp_range_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::change_dcp_range_clicked), 0, this);
+       _dcp_trim_start->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::dcp_trim_start_changed), 0, this);
+       _dcp_trim_end->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::dcp_trim_end_changed), 0, this);
        _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);
@@ -283,9 +287,7 @@ FilmEditor::left_crop_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::CROP;
        _film->set_left_crop (_left_crop->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 /** Called when the right crop widget has been changed */
@@ -296,9 +298,7 @@ FilmEditor::right_crop_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::CROP;
        _film->set_right_crop (_right_crop->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 /** Called when the top crop widget has been changed */
@@ -309,9 +309,7 @@ FilmEditor::top_crop_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::CROP;
        _film->set_top_crop (_top_crop->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 /** Called when the bottom crop value has been changed */
@@ -322,9 +320,7 @@ FilmEditor::bottom_crop_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::CROP;
        _film->set_bottom_crop (_bottom_crop->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 /** Called when the content filename has been changed */
@@ -335,21 +331,12 @@ FilmEditor::content_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::CONTENT;
-       
        try {
                _film->set_content (wx_to_std (_content->GetPath ()));
        } catch (std::exception& e) {
                _content->SetPath (std_to_wx (_film->directory ()));
                error_dialog (this, String::compose ("Could not set content: %1", e.what ()));
        }
-
-       _ignore_changes = Film::NONE;
-
-       setup_visibility ();
-       setup_formats ();
-       setup_subtitle_button ();
-       setup_streams ();
 }
 
 /** Called when the DCP A/B switch has been toggled */
@@ -360,9 +347,7 @@ FilmEditor::dcp_ab_toggled (wxCommandEvent &)
                return;
        }
        
-       _ignore_changes = Film::DCP_AB;
        _film->set_dcp_ab (_dcp_ab->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 /** Called when the name widget has been changed */
@@ -373,11 +358,7 @@ FilmEditor::name_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::NAME;
        _film->set_name (string (_name->GetValue().mb_str()));
-       _ignore_changes = Film::NONE;
-
-       _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
 }
 
 void
@@ -387,9 +368,7 @@ FilmEditor::subtitle_offset_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::SUBTITLE_OFFSET;
        _film->set_subtitle_offset (_subtitle_offset->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 void
@@ -399,9 +378,7 @@ FilmEditor::subtitle_scale_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::SUBTITLE_OFFSET;
        _film->set_subtitle_scale (_subtitle_scale->GetValue() / 100.0);
-       _ignore_changes = Film::NONE;
 }
 
 
@@ -414,7 +391,7 @@ FilmEditor::film_changed (Film::Property p)
 {
        ensure_ui_thread ();
        
-       if (!_film || _ignore_changes == p) {
+       if (!_film) {
                return;
        }
 
@@ -424,14 +401,14 @@ FilmEditor::film_changed (Film::Property p)
        case Film::NONE:
                break;
        case Film::CONTENT:
-               _content->SetPath (std_to_wx (_film->content ()));
+               checked_set (_content, _film->content ());
                setup_visibility ();
                setup_formats ();
-               setup_subtitle_button ();
+               setup_subtitle_control_sensitivity ();
                setup_streams ();
                break;
        case Film::HAS_SUBTITLES:
-               setup_subtitle_button ();
+               setup_subtitle_control_sensitivity ();
                setup_streams ();
                break;
        case Film::AUDIO_STREAMS:
@@ -446,15 +423,15 @@ FilmEditor::film_changed (Film::Property p)
                        ++i;
                        ++n;
                }
-               _format->SetSelection (n);
+               checked_set (_format, n);
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        }
        case Film::CROP:
-               _left_crop->SetValue (_film->crop().left);
-               _right_crop->SetValue (_film->crop().right);
-               _top_crop->SetValue (_film->crop().top);
-               _bottom_crop->SetValue (_film->crop().bottom);
+               checked_set (_left_crop, _film->crop().left);
+               checked_set (_right_crop, _film->crop().right);
+               checked_set (_top_crop, _film->crop().top);
+               checked_set (_bottom_crop, _film->crop().bottom);
                break;
        case Film::FILTERS:
        {
@@ -469,7 +446,8 @@ FilmEditor::film_changed (Film::Property p)
                break;
        }
        case Film::NAME:
-               _name->ChangeValue (std_to_wx (_film->name ()));
+               checked_set (_name, _film->name());
+               _film->set_dci_date_today ();
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::FRAMES_PER_SECOND:
@@ -494,66 +472,65 @@ FilmEditor::film_changed (Film::Property p)
                        s << _film->length().get() << " frames";
                } 
                _length->SetLabel (std_to_wx (s.str ()));
+               if (_film->length()) {
+                       _dcp_trim_start->SetRange (0, _film->length().get());
+                       _dcp_trim_end->SetRange (0, _film->length().get());
+               }
                break;
        case Film::DCP_CONTENT_TYPE:
-               _dcp_content_type->SetSelection (DCPContentType::as_index (_film->dcp_content_type ()));
+               checked_set (_dcp_content_type, DCPContentType::as_index (_film->dcp_content_type ()));
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::THUMBS:
                break;
-       case Film::DCP_FRAMES:
-               if (_film->dcp_frames() == 0) {
-                       _dcp_range->SetLabel (wxT ("Whole film"));
-               } else {
-                       stringstream s;
-                       s << "First " << _film->dcp_frames() << " frames";
-                       _dcp_range->SetLabel (std_to_wx (s.str ()));
-               }
-               _sizer->Layout ();
-               break;
-       case Film::DCP_TRIM_ACTION:
-               break;
        case Film::DCP_AB:
-               _dcp_ab->SetValue (_film->dcp_ab ());
+               checked_set (_dcp_ab, _film->dcp_ab ());
                break;
        case Film::SCALER:
-               _scaler->SetSelection (Scaler::as_index (_film->scaler ()));
+               checked_set (_scaler, Scaler::as_index (_film->scaler ()));
+               break;
+       case Film::DCP_TRIM_START:
+               checked_set (_dcp_trim_start, _film->dcp_trim_start());
+               break;
+       case Film::DCP_TRIM_END:
+               checked_set (_dcp_trim_end, _film->dcp_trim_end());
                break;
        case Film::AUDIO_GAIN:
-               _audio_gain->SetValue (_film->audio_gain ());
+               checked_set (_audio_gain, _film->audio_gain ());
                break;
        case Film::AUDIO_DELAY:
-               _audio_delay->SetValue (_film->audio_delay ());
+               checked_set (_audio_delay, _film->audio_delay ());
                break;
        case Film::STILL_DURATION:
-               _still_duration->SetValue (_film->still_duration ());
+               checked_set (_still_duration, _film->still_duration ());
                break;
        case Film::WITH_SUBTITLES:
-               _with_subtitles->SetValue (_film->with_subtitles ());
+               checked_set (_with_subtitles, _film->with_subtitles ());
+               _subtitle_stream->Enable (_film->with_subtitles ());
                _subtitle_scale->Enable (_film->with_subtitles ());
                _subtitle_offset->Enable (_film->with_subtitles ());
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::SUBTITLE_OFFSET:
-               _subtitle_offset->SetValue (_film->subtitle_offset ());
+               checked_set (_subtitle_offset, _film->subtitle_offset ());
                break;
        case Film::SUBTITLE_SCALE:
-               _subtitle_scale->SetValue (_film->subtitle_scale() * 100);
+               checked_set (_subtitle_scale, _film->subtitle_scale() * 100);
                break;
        case Film::USE_DCI_NAME:
-               _use_dci_name->SetValue (_film->use_dci_name ());
+               checked_set (_use_dci_name, _film->use_dci_name ());
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::DCI_METADATA:
                _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
                break;
        case Film::AUDIO_STREAM:
+               checked_set (_audio_stream, _film->audio_stream_index ());
                _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 ());
+               checked_set (_subtitle_stream, _film->subtitle_stream_index ());
                break;
        }
 }
@@ -566,15 +543,11 @@ FilmEditor::format_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::FORMAT;
        int const n = _format->GetSelection ();
        if (n >= 0) {
                assert (n < int (_formats.size()));
                _film->set_format (_formats[n]);
        }
-       _ignore_changes = Film::NONE;
-
-       _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
 }
 
 /** Called when the DCP content type widget has been changed */
@@ -585,14 +558,10 @@ FilmEditor::dcp_content_type_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::DCP_CONTENT_TYPE;
        int const n = _dcp_content_type->GetSelection ();
        if (n >= 0) {
                _film->set_dcp_content_type (DCPContentType::from_index (n));
        }
-       _ignore_changes = Film::NONE;
-
-       _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
 }
 
 /** Sets the Film that we are editing */
@@ -619,8 +588,8 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::FORMAT);
        film_changed (Film::CROP);
        film_changed (Film::FILTERS);
-       film_changed (Film::DCP_FRAMES);
-       film_changed (Film::DCP_TRIM_ACTION);
+       film_changed (Film::DCP_TRIM_START);
+       film_changed (Film::DCP_TRIM_END);
        film_changed (Film::DCP_AB);
        film_changed (Film::SIZE);
        film_changed (Film::LENGTH);
@@ -631,6 +600,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::AUDIO_DELAY);
        film_changed (Film::STILL_DURATION);
        film_changed (Film::WITH_SUBTITLES);
+       film_changed (Film::HAS_SUBTITLES);
        film_changed (Film::SUBTITLE_OFFSET);
        film_changed (Film::SUBTITLE_SCALE);
        film_changed (Film::USE_DCI_NAME);
@@ -643,10 +613,11 @@ FilmEditor::set_film (shared_ptr<Film> f)
 void
 FilmEditor::set_things_sensitive (bool s)
 {
+       _generally_sensitive = 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);
@@ -655,17 +626,17 @@ 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);
+       _dcp_trim_start->Enable (s);
+       _dcp_trim_end->Enable (s);
        _dcp_ab->Enable (s);
        _audio_gain->Enable (s);
        _audio_gain_calculate_button->Enable (s);
        _audio_delay->Enable (s);
        _still_duration->Enable (s);
-       _with_subtitles->Enable (s);
-       _subtitle_offset->Enable (s);
-       _subtitle_scale->Enable (s);
+
+       setup_subtitle_control_sensitivity ();
 }
 
 /** Called when the `Edit filters' button has been clicked */
@@ -686,12 +657,10 @@ FilmEditor::scaler_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::SCALER;
        int const n = _scaler->GetSelection ();
        if (n >= 0) {
                _film->set_scaler (Scaler::from_index (n));
        }
-       _ignore_changes = Film::NONE;
 }
 
 void
@@ -701,9 +670,7 @@ FilmEditor::audio_gain_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::AUDIO_GAIN;
        _film->set_audio_gain (_audio_gain->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 void
@@ -713,9 +680,7 @@ FilmEditor::audio_delay_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::AUDIO_DELAY;
        _film->set_audio_delay (_audio_delay->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 wxControl *
@@ -759,24 +724,27 @@ FilmEditor::still_duration_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::STILL_DURATION;
        _film->set_still_duration (_still_duration->GetValue ());
-       _ignore_changes = Film::NONE;
 }
 
 void
-FilmEditor::change_dcp_range_clicked (wxCommandEvent &)
+FilmEditor::dcp_trim_start_changed (wxCommandEvent &)
 {
-       DCPRangeDialog* d = new DCPRangeDialog (this, _film);
-       d->Changed.connect (bind (&FilmEditor::dcp_range_changed, this, _1, _2));
-       d->ShowModal ();
+       if (!_film) {
+               return;
+       }
+
+       _film->set_dcp_trim_start (_dcp_trim_start->GetValue ());
 }
 
 void
-FilmEditor::dcp_range_changed (int frames, TrimAction action)
+FilmEditor::dcp_trim_end_changed (wxCommandEvent &)
 {
-       _film->set_dcp_frames (frames);
-       _film->set_dcp_trim_action (action);
+       if (!_film) {
+               return;
+       }
+
+       _film->set_dcp_trim_end (_dcp_trim_end->GetValue ());
 }
 
 void
@@ -841,21 +809,21 @@ FilmEditor::with_subtitles_toggled (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::WITH_SUBTITLES;
        _film->set_with_subtitles (_with_subtitles->GetValue ());
-       _ignore_changes = Film::NONE;
-
-       _subtitle_scale->Enable (_film->with_subtitles ());
-       _subtitle_offset->Enable (_film->with_subtitles ());
 }
 
 void
-FilmEditor::setup_subtitle_button ()
+FilmEditor::setup_subtitle_control_sensitivity ()
 {
-       _with_subtitles->Enable (_film->has_subtitles ());
-       if (!_film->has_subtitles ()) {
-               _with_subtitles->SetValue (false);
+       bool h = false;
+       if (_generally_sensitive && _film) {
+               h = _film->has_subtitles();
        }
+       
+       _with_subtitles->Enable (h);
+       _subtitle_stream->Enable (h);
+       _subtitle_offset->Enable (h);
+       _subtitle_scale->Enable (h);
 }
 
 void
@@ -865,11 +833,7 @@ FilmEditor::use_dci_name_toggled (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::USE_DCI_NAME;
        _film->set_use_dci_name (_use_dci_name->GetValue ());
-       _ignore_changes = Film::NONE;
-
-       _dcp_name->SetLabel (std_to_wx (_film->dcp_name ()));
 }
 
 void
@@ -909,12 +873,7 @@ FilmEditor::audio_stream_changed (wxCommandEvent &)
                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
@@ -924,9 +883,7 @@ FilmEditor::subtitle_stream_changed (wxCommandEvent &)
                return;
        }
 
-       _ignore_changes = Film::SUBTITLE_STREAM;
        _film->set_subtitle_stream (_subtitle_stream->GetSelection ());
-       _ignore_changes = Film::NONE;
 }
 
 void