Merge master.
[dcpomatic.git] / src / wx / film_editor.cc
index 894e2ae2bb4d3048c97b31552a829c4783fe77c9..177202d25264cf2dec6700c1484c7017780720ec 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
 /*
     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
 
@@ -51,7 +53,6 @@
 #include "audio_dialog.h"
 #include "imagemagick_content_dialog.h"
 #include "ffmpeg_content_dialog.h"
-#include "audio_mapping_view.h"
 #include "timeline_dialog.h"
 
 using std::string;
@@ -130,7 +131,7 @@ FilmEditor::make_film_panel ()
        grid->Add (_edit_dci_button, wxGBPosition (r, 1), wxDefaultSpan);
        ++r;
 
-       _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content's header"));
+       _trust_content_headers = new wxCheckBox (_film_panel, wxID_ANY, _("Trust content headers"));
        grid->Add (_trust_content_headers, wxGBPosition (r, 0), wxGBSpan(1, 2));
        ++r;
 
@@ -163,21 +164,6 @@ FilmEditor::make_film_panel ()
        grid->Add (_length, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        ++r;
 
-
-       {
-               add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim frames"), wxGBPosition (r, 0));
-               wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
-               add_label_to_sizer (s, _film_panel, _("Start"));
-               _trim_start = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
-               s->Add (_trim_start);
-               add_label_to_sizer (s, _film_panel, _("End"));
-               _trim_end = new wxSpinCtrl (_film_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (64, -1));
-               s->Add (_trim_end);
-
-               grid->Add (s, wxGBPosition (r, 1));
-       }
-       ++r;
-
        add_label_to_grid_bag_sizer (grid, _film_panel, _("Trim method"), wxGBPosition (r, 0));
        _trim_type = new wxChoice (_film_panel, wxID_ANY);
        grid->Add (_trim_type, wxGBPosition (r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
@@ -214,10 +200,8 @@ FilmEditor::connect_to_widgets ()
        _content->Connect                (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_ACTIVATED,  wxListEventHandler    (FilmEditor::content_activated), 0, this);
        _content_add->Connect            (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
        _content_remove->Connect         (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_remove_clicked), 0, this);
-       _content_edit->Connect           (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_edit_clicked), 0, this);
-       _content_earlier->Connect        (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_earlier_clicked), 0, this);
-       _content_later->Connect          (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_later_clicked), 0, this);
-       _timeline_button->Connect        (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::timeline_clicked), 0, this);
+       _content_properties->Connect     (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_properties_clicked), 0, this);
+       _content_timeline->Connect       (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::content_timeline_clicked), 0, this);
        _loop_content->Connect           (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,     wxCommandEventHandler (FilmEditor::loop_content_toggled), 0, this);
        _loop_count->Connect             (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::loop_count_changed), 0, this);
        _left_crop->Connect              (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
@@ -230,8 +214,6 @@ FilmEditor::connect_to_widgets ()
        _dcp_frame_rate->Connect         (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::dcp_frame_rate_changed), 0, this);
        _best_dcp_frame_rate->Connect    (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,       wxCommandEventHandler (FilmEditor::best_dcp_frame_rate_clicked), 0, this);
        _ab->Connect                     (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,     wxCommandEventHandler (FilmEditor::ab_toggled), 0, this);
-       _trim_start->Connect             (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::trim_start_changed), 0, this);
-       _trim_end->Connect               (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED,     wxCommandEventHandler (FilmEditor::trim_end_changed), 0, this);
        _trim_type->Connect              (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED,      wxCommandEventHandler (FilmEditor::trim_type_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);
@@ -335,8 +317,6 @@ FilmEditor::make_video_panel ()
        _top_crop->SetRange (0, 1024);
        _right_crop->SetRange (0, 1024);
        _bottom_crop->SetRange (0, 1024);
-       _trim_start->SetRange (0, 100);
-       _trim_end->SetRange (0, 100);
        _j2k_bandwidth->SetRange (50, 250);
 }
 
@@ -358,15 +338,13 @@ FilmEditor::make_content_panel ()
 
                 wxBoxSizer* b = new wxBoxSizer (wxVERTICAL);
                 _content_add = new wxButton (_content_panel, wxID_ANY, _("Add..."));
-                b->Add (_content_add);
+                b->Add (_content_add, 1, wxEXPAND | wxLEFT | wxRIGHT);
                 _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
-                b->Add (_content_remove);
-                _content_edit = new wxButton (_content_panel, wxID_ANY, _("Edit..."));
-                b->Add (_content_edit);
-                _content_earlier = new wxButton (_content_panel, wxID_ANY, _("Earlier"));
-                b->Add (_content_earlier);
-                _content_later = new wxButton (_content_panel, wxID_ANY, _("Later"));
-                b->Add (_content_later);
+                b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
+                _content_properties = new wxButton (_content_panel, wxID_ANY, _("Properties..."));
+                b->Add (_content_properties);
+               _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
+               b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
 
                 s->Add (b, 0, wxALL, 4);
 
@@ -384,9 +362,6 @@ FilmEditor::make_content_panel ()
        add_label_to_sizer (h, _content_panel, _("times"));
        _content_sizer->Add (h, 0, wxALL, 6);
 
-       _timeline_button = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
-       _content_sizer->Add (_timeline_button, 0, wxALL, 6);
-
        _loop_count->SetRange (2, 1024);
 }
 
@@ -425,9 +400,6 @@ FilmEditor::make_audio_panel ()
                grid->Add (s);
        }
 
-       _audio_mapping = new AudioMappingView (_audio_panel);
-       _audio_sizer->Add (_audio_mapping, 1, wxEXPAND | wxALL, 6);
-       
        _audio_gain->SetRange (-60, 60);
        _audio_delay->SetRange (-1000, 1000);
 }
@@ -590,7 +562,7 @@ FilmEditor::dcp_frame_rate_changed (wxCommandEvent &)
                return;
        }
 
-       _film->set_dcp_frame_rate (
+       _film->set_dcp_video_frame_rate (
                boost::lexical_cast<int> (
                        wx_to_std (_dcp_frame_rate->GetString (_dcp_frame_rate->GetSelection ()))
                        )
@@ -668,12 +640,6 @@ FilmEditor::film_changed (Film::Property p)
        case Film::SCALER:
                checked_set (_scaler, Scaler::as_index (_film->scaler ()));
                break;
-       case Film::TRIM_START:
-               checked_set (_trim_start, _film->trim_start());
-               break;
-       case Film::TRIM_END:
-               checked_set (_trim_end, _film->trim_end());
-               break;
        case Film::TRIM_TYPE:
                checked_set (_trim_type, _film->trim_type() == Film::CPL ? 0 : 1);
                break;
@@ -707,11 +673,11 @@ FilmEditor::film_changed (Film::Property p)
        case Film::DCI_METADATA:
                setup_dcp_name ();
                break;
-       case Film::DCP_FRAME_RATE:
+       case Film::DCP_VIDEO_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 (wx_to_std (_dcp_frame_rate->GetString(i)) == boost::lexical_cast<string> (_film->dcp_video_frame_rate())) {
                                checked_set (_dcp_frame_rate, i);
                                done = true;
                                break;
@@ -722,17 +688,10 @@ FilmEditor::film_changed (Film::Property p)
                        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 {
-                       _best_dcp_frame_rate->Disable ();
-               }
+               _best_dcp_frame_rate->Enable (_film->best_dcp_video_frame_rate () != _film->dcp_video_frame_rate ());
                setup_frame_rate_description ();
                break;
        }
-       case Film::AUDIO_MAPPING:
-               _audio_mapping->set_mapping (_film->audio_mapping ());
-               break;
        }
 }
 
@@ -753,7 +712,7 @@ FilmEditor::film_content_changed (weak_ptr<Content> content, int property)
        } else if (property == VideoContentProperty::VIDEO_LENGTH || property == AudioContentProperty::AUDIO_LENGTH) {
                setup_length ();
                boost::shared_ptr<Content> c = content.lock ();
-               if (c && c == selected_content()) {
+               if (selected_content() && c == selected_content()) {
                        setup_content_information ();
                }
        } else if (property == FFmpegContentProperty::AUDIO_STREAM) {
@@ -786,20 +745,10 @@ void
 FilmEditor::setup_length ()
 {
        stringstream s;
-       ContentVideoFrame const frames = _film->content_length ();
+       Time const length = _film->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"));
-       }
-
+       s << time_to_hms (length);
        _length->SetLabel (std_to_wx (s.str ()));
-       
-       if (frames) {
-               _trim_start->SetRange (0, frames);
-               _trim_end->SetRange (0, frames);
-       }
 }      
 
 void
@@ -807,11 +756,13 @@ FilmEditor::setup_frame_rate_description ()
 {
        wxString d;
        int lines = 0;
-       
+
+#if 0
+       XXX
+               
        if (_film->video_frame_rate()) {
                d << std_to_wx (FrameRateConversion (_film->video_frame_rate(), _film->dcp_frame_rate()).description);
                ++lines;
-#ifdef HAVE_SWRESAMPLE
                if (_film->audio_frame_rate() && _film->audio_frame_rate() != _film->target_audio_sample_rate ()) {
                        d << wxString::Format (
                                _("Audio will be resampled from %dHz to %dHz\n"),
@@ -820,8 +771,8 @@ FilmEditor::setup_frame_rate_description ()
                                );
                        ++lines;
                }
-#endif         
        }
+#endif 
 
        for (int i = lines; i < 2; ++i) {
                d << wxT ("\n ");
@@ -908,8 +859,7 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::COLOUR_LUT);
        film_changed (Film::J2K_BANDWIDTH);
        film_changed (Film::DCI_METADATA);
-       film_changed (Film::DCP_FRAME_RATE);
-       film_changed (Film::AUDIO_MAPPING);
+       film_changed (Film::DCP_VIDEO_FRAME_RATE);
 
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAMS);
        film_content_changed (boost::shared_ptr<Content> (), FFmpegContentProperty::SUBTITLE_STREAM);
@@ -943,8 +893,6 @@ FilmEditor::set_things_sensitive (bool 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);
        _ab->Enable (s);
        _trim_type->Enable (s);
        _colour_lut->Enable (s);
@@ -1021,26 +969,6 @@ FilmEditor::setup_notebook_size ()
        Fit ();
 }
 
-void
-FilmEditor::trim_start_changed (wxCommandEvent &)
-{
-       if (!_film) {
-               return;
-       }
-
-       _film->set_trim_start (_trim_start->GetValue ());
-}
-
-void
-FilmEditor::trim_end_changed (wxCommandEvent &)
-{
-       if (!_film) {
-               return;
-       }
-
-       _film->set_trim_end (_trim_end->GetValue ());
-}
-
 void
 FilmEditor::audio_gain_calculate_button_clicked (wxCommandEvent &)
 {
@@ -1096,7 +1024,7 @@ FilmEditor::setup_subtitle_control_sensitivity ()
 {
        bool h = false;
        if (_generally_sensitive && _film) {
-               h = !_film->has_subtitles ();
+               h = _film->has_subtitles ();
        }
        
        _with_subtitles->Enable (h);
@@ -1171,13 +1099,13 @@ FilmEditor::best_dcp_frame_rate_clicked (wxCommandEvent &)
                return;
        }
        
-       _film->set_dcp_frame_rate (best_dcp_frame_rate (_film->video_frame_rate ()));
+       _film->set_dcp_video_frame_rate (_film->best_dcp_video_frame_rate ());
 }
 
 void
 FilmEditor::setup_show_audio_sensitivity ()
 {
-       _show_audio->Enable (_film && _film->has_audio ());
+       _show_audio->Enable (_film);
 }
 
 void
@@ -1191,8 +1119,8 @@ FilmEditor::setup_content ()
        
        _content->DeleteAllItems ();
 
-       ContentList content = _film->content ();
-       for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
+       Playlist::ContentList content = _film->content ();
+       for (Playlist::ContentList::iterator i = content.begin(); i != content.end(); ++i) {
                int const t = _content->GetItemCount ();
                _content->InsertItem (t, std_to_wx ((*i)->summary ()));
                if ((*i)->summary() == selected_summary) {
@@ -1201,7 +1129,7 @@ FilmEditor::setup_content ()
        }
 
        if (selected_summary.empty () && !content.empty ()) {
-               /* Select the first item of content if non was selected before */
+               /* Select the item of content if non was selected before */
                _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
        }
 
@@ -1247,59 +1175,41 @@ FilmEditor::content_remove_clicked (wxCommandEvent &)
 void
 FilmEditor::content_activated (wxListEvent& ev)
 {
-       ContentList c = _film->content ();
+       Playlist::ContentList c = _film->content ();
        assert (ev.GetIndex() >= 0 && size_t (ev.GetIndex()) < c.size ());
 
-       edit_content (c[ev.GetIndex()]);
+       content_properties (c[ev.GetIndex()]);
 }
 
 void
-FilmEditor::content_edit_clicked (wxCommandEvent &)
+FilmEditor::content_properties_clicked (wxCommandEvent &)
 {
        shared_ptr<Content> c = selected_content ();
        if (!c) {
                return;
        }
 
-       edit_content (c);
+       content_properties (c);
 }
 
 void
-FilmEditor::edit_content (shared_ptr<Content> c)
+FilmEditor::content_properties (shared_ptr<Content> content)
 {
-       shared_ptr<ImageMagickContent> im = dynamic_pointer_cast<ImageMagickContent> (c);
-       if (im) {
-               ImageMagickContentDialog* d = new ImageMagickContentDialog (this, im);
+       shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (content);
+       if (ic) {
+               ImageMagickContentDialog* d = new ImageMagickContentDialog (this, ic);
                d->ShowModal ();
                d->Destroy ();
        }
 
-       shared_ptr<FFmpegContent> ff = dynamic_pointer_cast<FFmpegContent> (c);
-       if (ff) {
-               FFmpegContentDialog* d = new FFmpegContentDialog (this, ff);
+       shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (content);
+       if (fc) {
+               FFmpegContentDialog* d = new FFmpegContentDialog (this, fc);
                d->ShowModal ();
                d->Destroy ();
        }
 }
 
-void
-FilmEditor::content_earlier_clicked (wxCommandEvent &)
-{
-       shared_ptr<Content> c = selected_content ();
-       if (c) {
-               _film->move_content_earlier (c);
-       }
-}
-
-void
-FilmEditor::content_later_clicked (wxCommandEvent &)
-{
-       shared_ptr<Content> c = selected_content ();
-       if (c) {
-               _film->move_content_later (c);
-       }
-}
-
 void
 FilmEditor::content_selection_changed (wxListEvent &)
 {
@@ -1326,14 +1236,13 @@ FilmEditor::setup_content_button_sensitivity ()
 
        shared_ptr<Content> selection = selected_content ();
 
-        _content_edit->Enable (
+        _content_properties->Enable (
                selection && _generally_sensitive &&
                (dynamic_pointer_cast<ImageMagickContent> (selection) || dynamic_pointer_cast<FFmpegContent> (selection))
                );
        
         _content_remove->Enable (selection && _generally_sensitive);
-        _content_earlier->Enable (selection && _generally_sensitive);
-        _content_later->Enable (selection && _generally_sensitive);
+       _content_timeline->Enable (_generally_sensitive);
 }
 
 shared_ptr<Content>
@@ -1344,7 +1253,7 @@ FilmEditor::selected_content ()
                return shared_ptr<Content> ();
        }
 
-       ContentList c = _film->content ();
+       Playlist::ContentList c = _film->content ();
        if (s < 0 || size_t (s) >= c.size ()) {
                return shared_ptr<Content> ();
        }
@@ -1357,6 +1266,8 @@ FilmEditor::setup_scaling_description ()
 {
        wxString d;
 
+#if 0  
+XXX
        int lines = 0;
 
        if (_film->video_size().width && _film->video_size().height) {
@@ -1405,6 +1316,7 @@ FilmEditor::setup_scaling_description ()
                d << wxT ("\n ");
        }
 
+#endif 
        _scaling_description->SetLabel (d);
 }
 
@@ -1439,13 +1351,13 @@ FilmEditor::setup_loop_sensitivity ()
 }
 
 void
-FilmEditor::timeline_clicked (wxCommandEvent &)
+FilmEditor::content_timeline_clicked (wxCommandEvent &)
 {
        if (_timeline_dialog) {
                _timeline_dialog->Destroy ();
                _timeline_dialog = 0;
        }
        
-       _timeline_dialog = new TimelineDialog (this, _film->playlist ());
+       _timeline_dialog = new TimelineDialog (this, _film);
        _timeline_dialog->Show ();
 }