Move keep-video-in-sequence button into the timeline dialogue.
[dcpomatic.git] / src / wx / film_editor.cc
index bbf1fc8d5f11d04683c4cf2e593e76254c8763cd..275a7ab8149e1519fadc639ab366eed70540bc70 100644 (file)
@@ -45,6 +45,7 @@
 #include "lib/playlist.h"
 #include "lib/content.h"
 #include "lib/content_factory.h"
+#include "lib/safe_stringstream.h"
 #include "timecode.h"
 #include "wx_util.h"
 #include "film_editor.h"
@@ -57,7 +58,6 @@
 
 using std::string;
 using std::cout;
-using std::stringstream;
 using std::pair;
 using std::fixed;
 using std::setprecision;
@@ -70,7 +70,7 @@ using boost::dynamic_pointer_cast;
 using boost::lexical_cast;
 
 /** @param f Film to edit */
-FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
+FilmEditor::FilmEditor (wxWindow* parent)
        : wxPanel (parent)
        , _menu (this)
        , _generally_sensitive (true)
@@ -86,7 +86,6 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
        make_dcp_panel ();
        _main_notebook->AddPage (_dcp_panel, _("DCP"), false);
        
-       set_film (f);
        connect_to_widgets ();
 
        JobManager::instance()->ActiveJobsChanged.connect (
@@ -94,7 +93,8 @@ FilmEditor::FilmEditor (shared_ptr<Film> f, wxWindow* parent)
                );
 
        Config::instance()->Changed.connect (boost::bind (&FilmEditor::config_changed, this));
-       
+
+       set_film (shared_ptr<Film> ());
        SetSizerAndFit (s);
 }
 
@@ -115,11 +115,6 @@ FilmEditor::make_dcp_panel ()
        grid->Add (_name, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND | wxLEFT | wxRIGHT);
        ++r;
        
-       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
-       _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
-       grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
-       ++r;
-
        int flags = wxALIGN_CENTER_VERTICAL;
 #ifdef __WXOSX__
        flags |= wxALIGN_RIGHT;
@@ -131,6 +126,11 @@ FilmEditor::make_dcp_panel ()
        grid->Add (_edit_isdcf_button, wxGBPosition (r, 1), wxDefaultSpan);
        ++r;
 
+       add_label_to_grid_bag_sizer (grid, _dcp_panel, _("DCP Name"), true, wxGBPosition (r, 0));
+       _dcp_name = new wxStaticText (_dcp_panel, wxID_ANY, wxT (""));
+       grid->Add (_dcp_name, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
+       ++r;
+
        add_label_to_grid_bag_sizer (grid, _dcp_panel, _("Container"), true, wxGBPosition (r, 0));
        _container = new wxChoice (_dcp_panel, wxID_ANY);
        grid->Add (_container, wxGBPosition (r, 1), wxDefaultSpan, wxEXPAND);
@@ -238,6 +238,7 @@ FilmEditor::connect_to_widgets ()
        _content->Bind          (wxEVT_COMMAND_LIST_ITEM_SELECTED,    boost::bind (&FilmEditor::content_selection_changed, this));
        _content->Bind          (wxEVT_COMMAND_LIST_ITEM_DESELECTED,  boost::bind (&FilmEditor::content_selection_changed, this));
        _content->Bind          (wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, boost::bind (&FilmEditor::content_right_click, this, _1));
+       _content->Bind          (wxEVT_DROP_FILES,                    boost::bind (&FilmEditor::content_files_dropped, this, _1));
        _content_add_file->Bind (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::content_add_file_clicked, this));
        _content_add_folder->Bind (wxEVT_COMMAND_BUTTON_CLICKED,      boost::bind (&FilmEditor::content_add_folder_clicked, this));
        _content_remove->Bind   (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::content_remove_clicked, this));
@@ -254,7 +255,6 @@ FilmEditor::connect_to_widgets ()
        _audio_channels->Bind   (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&FilmEditor::audio_channels_changed, this));
        _j2k_bandwidth->Bind    (wxEVT_COMMAND_SPINCTRL_UPDATED,      boost::bind (&FilmEditor::j2k_bandwidth_changed, this));
        _resolution->Bind       (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::resolution_changed, this));
-       _sequence_video->Bind   (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::sequence_video_changed, this));
        _three_d->Bind          (wxEVT_COMMAND_CHECKBOX_CLICKED,      boost::bind (&FilmEditor::three_d_changed, this));
        _standard->Bind         (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::standard_changed, this));
 }
@@ -294,9 +294,6 @@ FilmEditor::make_content_panel ()
                _content_sizer->Add (s, 0, wxEXPAND | wxALL, 6);
        }
 
-       _sequence_video = new wxCheckBox (_content_panel, wxID_ANY, _("Keep video in sequence"));
-       _content_sizer->Add (_sequence_video);
-
        _content_notebook = new wxNotebook (_content_panel, wxID_ANY);
        _content_sizer->Add (_content_notebook, 1, wxEXPAND | wxTOP, 6);
 
@@ -308,6 +305,8 @@ FilmEditor::make_content_panel ()
        _panels.push_back (_subtitle_panel);
        _timing_panel = new TimingPanel (this);
        _panels.push_back (_timing_panel);
+
+       _content->DragAcceptFiles (true);
 }
 
 /** Called when the name widget has been changed */
@@ -420,7 +419,7 @@ FilmEditor::film_changed (Film::Property p)
                return;
        }
 
-       stringstream s;
+       SafeStringStream s;
 
        for (list<FilmEditorPanel*>::iterator i = _panels.begin(); i != _panels.end(); ++i) {
                (*i)->film_changed (p);
@@ -471,6 +470,7 @@ FilmEditor::film_changed (Film::Property p)
        case Film::USE_ISDCF_NAME:
                checked_set (_use_isdcf_name, _film->use_isdcf_name ());
                setup_dcp_name ();
+               use_isdcf_name_changed ();
                break;
        case Film::ISDCF_METADATA:
                setup_dcp_name ();
@@ -499,9 +499,6 @@ FilmEditor::film_changed (Film::Property p)
                checked_set (_audio_channels, _film->audio_channels ());
                setup_dcp_name ();
                break;
-       case Film::SEQUENCE_VIDEO:
-               checked_set (_sequence_video, _film->sequence_video ());
-               break;
        case Film::THREE_D:
                checked_set (_three_d, _film->three_d ());
                setup_dcp_name ();
@@ -509,6 +506,8 @@ FilmEditor::film_changed (Film::Property p)
        case Film::INTEROP:
                checked_set (_standard, _film->interop() ? 1 : 0);
                break;
+       default:
+               break;
        }
 }
 
@@ -534,6 +533,8 @@ FilmEditor::film_content_changed (int property)
                setup_content ();
        } else if (property == ContentProperty::POSITION) {
                setup_content ();
+       } else if (property == VideoContentProperty::VIDEO_SCALE) {
+               setup_dcp_name ();
        }
 }
 
@@ -624,7 +625,6 @@ FilmEditor::set_film (shared_ptr<Film> f)
        film_changed (Film::ISDCF_METADATA);
        film_changed (Film::VIDEO_FRAME_RATE);
        film_changed (Film::AUDIO_CHANNELS);
-       film_changed (Film::SEQUENCE_VIDEO);
        film_changed (Film::THREE_D);
        film_changed (Film::INTEROP);
 
@@ -666,7 +666,6 @@ FilmEditor::set_general_sensitivity (bool s)
        _j2k_bandwidth->Enable (s);
        _container->Enable (s);
        _best_frame_rate->Enable (s && _film && _film->best_video_frame_rate () != _film->video_frame_rate ());
-       _sequence_video->Enable (s);
        _resolution->Enable (s);
        _scaler->Enable (s);
        _three_d->Enable (s);
@@ -702,6 +701,18 @@ FilmEditor::use_isdcf_name_toggled ()
        _film->set_use_isdcf_name (_use_isdcf_name->GetValue ());
 }
 
+void
+FilmEditor::use_isdcf_name_changed ()
+{
+       bool const i = _film->use_isdcf_name ();
+
+       if (!i) {
+               _film->set_name (_film->isdcf_name (true));
+       }
+
+       _edit_isdcf_button->Enable (i);
+}
+
 void
 FilmEditor::edit_isdcf_button_clicked ()
 {
@@ -872,13 +883,24 @@ FilmEditor::setup_content_sensitivity ()
        _video_panel->Enable    (!video_selection.empty() && _generally_sensitive);
        _audio_panel->Enable    (!audio_selection.empty() && _generally_sensitive);
        _subtitle_panel->Enable (selection.size() == 1 && dynamic_pointer_cast<FFmpegContent> (selection.front()) && _generally_sensitive);
-       _timing_panel->Enable   (selection.size() == 1 && _generally_sensitive);
+       _timing_panel->Enable   (!selection.empty() && _generally_sensitive);
 }
 
 ContentList
 FilmEditor::selected_content ()
 {
        ContentList sel;
+
+       if (!_film) {
+               return sel;
+       }
+
+       /* The list was populated using a sorted content list, so we must sort it here too
+          so that we can look up by index and get the right thing.
+       */
+       ContentList content = _film->content ();
+       sort (content.begin(), content.end(), ContentSorter ());
+       
        long int s = -1;
        while (true) {
                s = _content->GetNextItem (s, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
@@ -887,7 +909,7 @@ FilmEditor::selected_content ()
                }
 
                if (s < int (_film->content().size ())) {
-                       sel.push_back (_film->content()[s]);
+                       sel.push_back (content[s]);
                }
        }
 
@@ -978,21 +1000,11 @@ FilmEditor::set_selection (weak_ptr<Content> wc)
                if (content[i] == wc.lock ()) {
                        _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
                } else {
-                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
+                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
                }
        }
 }
 
-void
-FilmEditor::sequence_video_changed ()
-{
-       if (!_film) {
-               return;
-       }
-       
-       _film->set_sequence_video (_sequence_video->GetValue ());
-}
-
 void
 FilmEditor::content_right_click (wxListEvent& ev)
 {
@@ -1049,3 +1061,16 @@ FilmEditor::setup_frame_rate_widget ()
 
        _frame_rate_sizer->Layout ();
 }
+
+void
+FilmEditor::content_files_dropped (wxDropFilesEvent& event)
+{
+       if (!_film) {
+               return;
+       }
+       
+       wxString* paths = event.GetFiles ();
+       for (int i = 0; i < event.GetNumberOfFiles(); i++) {
+               _film->examine_and_add_content (content_factory (_film, wx_to_std (paths[i])));
+       }
+}