Restore up/down buttons for simple content movements.
authorCarl Hetherington <cth@carlh.net>
Tue, 15 Oct 2013 21:18:00 +0000 (22:18 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 15 Oct 2013 21:18:00 +0000 (22:18 +0100)
ChangeLog
src/lib/film.cc
src/lib/film.h
src/lib/playlist.cc
src/lib/playlist.h
src/wx/film_editor.cc
src/wx/film_editor.h

index 4d9f33ece517526308ff9634599b5dd36b3ba515..72e10780ae23f88cc18afc6a95f8dff4bb2b3536 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-10-15  Carl Hetherington  <cth@carlh.net>
 
+       * Restore up/down buttons for simple content time
+       movements.
+
        * Include film title in KDM filenames.
 
        * Allow no-stretch scaling like in DVD-o-matic.
index bceaef96e98656615387e16bbab2f75dd0490da7..085675d071290561b622a7ec1f0e9c3dce657833 100644 (file)
@@ -806,6 +806,18 @@ Film::remove_content (shared_ptr<Content> c)
        _playlist->remove (c);
 }
 
+void
+Film::move_content_earlier (shared_ptr<Content> c)
+{
+       _playlist->move_earlier (c);
+}
+
+void
+Film::move_content_later (shared_ptr<Content> c)
+{
+       _playlist->move_later (c);
+}
+
 Time
 Film::length () const
 {
@@ -951,4 +963,3 @@ Film::make_kdms (
 
        return kdms;
 }
-       
index 01fccf7d177e197a344ffbf7354657c96fac54d3..71bbd3844525e2f73e910fb629c23fc9763ce01c 100644 (file)
@@ -235,6 +235,8 @@ public:
        void examine_and_add_content (boost::shared_ptr<Content>);
        void add_content (boost::shared_ptr<Content>);
        void remove_content (boost::shared_ptr<Content>);
+       void move_content_earlier (boost::shared_ptr<Content>);
+       void move_content_later (boost::shared_ptr<Content>);
        void set_dcp_content_type (DCPContentType const *);
        void set_container (Ratio const *);
        void set_resolution (Resolution);
index de48ff5f5cd0d49bb31a2691a437c4f825eddf38..1712dc8ff54dee392f5e865830aa91cea76c2cf1 100644 (file)
@@ -82,9 +82,8 @@ Playlist::maybe_sequence_video ()
        _sequencing_video = true;
        
        ContentList cl = _content;
-       sort (cl.begin(), cl.end(), ContentSorter ());
        Time last = 0;
-       for (ContentList::iterator i = cl.begin(); i != cl.end(); ++i) {
+       for (ContentList::iterator i = _content.begin(); i != _content.end(); ++i) {
                if (!dynamic_pointer_cast<VideoContent> (*i)) {
                        continue;
                }
@@ -92,6 +91,8 @@ Playlist::maybe_sequence_video ()
                (*i)->set_position (last);
                last = (*i)->end ();
        }
+
+       /* This won't change order, so it does not need a sort */
        
        _sequencing_video = false;
 }
@@ -120,6 +121,8 @@ Playlist::set_from_xml (shared_ptr<const Film> film, shared_ptr<const cxml::Node
                _content.push_back (content_factory (film, *i));
        }
 
+       sort (_content.begin(), _content.end(), ContentSorter ());
+
        reconnect ();
 }
 
@@ -136,6 +139,7 @@ void
 Playlist::add (shared_ptr<Content> c)
 {
        _content.push_back (c);
+       sort (_content.begin(), _content.end(), ContentSorter ());
        reconnect ();
        Changed ();
 }
@@ -152,6 +156,8 @@ Playlist::remove (shared_ptr<Content> c)
                _content.erase (i);
                Changed ();
        }
+
+       /* This won't change order, so it does not need a sort */
 }
 
 void
@@ -168,6 +174,8 @@ Playlist::remove (ContentList c)
                }
        }
 
+       /* This won't change order, so it does not need a sort */
+       
        Changed ();
 }
 
@@ -325,6 +333,60 @@ Playlist::repeat (ContentList c, int n)
                pos += range.second - range.first;
        }
 
+       sort (_content.begin(), _content.end(), ContentSorter ());
+       
        reconnect ();
        Changed ();
 }
+
+void
+Playlist::move_earlier (shared_ptr<Content> c)
+{
+       sort (_content.begin(), _content.end(), ContentSorter ());
+       
+       ContentList::iterator previous = _content.end ();
+       ContentList::iterator i = _content.begin();
+       while (i != _content.end() && *i != c) {
+               previous = i;
+               ++i;
+       }
+
+       assert (i != _content.end ());
+       if (previous == _content.end ()) {
+               return;
+       }
+       
+       Time const p = (*previous)->position ();
+       (*previous)->set_position (p + c->length_after_trim ());
+       c->set_position (p);
+       sort (_content.begin(), _content.end(), ContentSorter ());
+       
+       Changed ();
+}
+
+void
+Playlist::move_later (shared_ptr<Content> c)
+{
+       sort (_content.begin(), _content.end(), ContentSorter ());
+       
+       ContentList::iterator i = _content.begin();
+       while (i != _content.end() && *i != c) {
+               ++i;
+       }
+
+       assert (i != _content.end ());
+
+       ContentList::iterator next = i;
+       ++next;
+
+       if (next == _content.end ()) {
+               return;
+       }
+
+       Time const p = (*next)->position ();
+       (*next)->set_position (c->position ());
+       c->set_position (p + c->length_after_trim ());
+       sort (_content.begin(), _content.end(), ContentSorter ());
+       
+       Changed ();
+}
index 7dbf416041d8bf4bfa555bf45341ee01e04af812..05928ee57c13e48aa6755a6b04e06acbc8299708 100644 (file)
@@ -61,6 +61,8 @@ public:
        void add (boost::shared_ptr<Content>);
        void remove (boost::shared_ptr<Content>);
        void remove (ContentList);
+       void move_earlier (boost::shared_ptr<Content>);
+       void move_later (boost::shared_ptr<Content>);
 
        bool has_subtitles () const;
 
@@ -86,6 +88,7 @@ private:
        void content_changed (boost::weak_ptr<Content>, int, bool);
        void reconnect ();
 
+       /** List of content.  Kept sorted in position order. */
        ContentList _content;
        bool _sequence_video;
        bool _sequencing_video;
index a85052645edb499a1265c26035508c3787f11ff0..d502162583d28084da2ebc6f53eca10bfd344d05 100644 (file)
@@ -43,6 +43,7 @@
 #include "lib/dcp_content_type.h"
 #include "lib/sound_processor.h"
 #include "lib/scaler.h"
+#include "lib/playlist.h"
 #include "timecode.h"
 #include "wx_util.h"
 #include "film_editor.h"
@@ -229,6 +230,8 @@ FilmEditor::connect_to_widgets ()
        _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));
+       _content_earlier->Bind  (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::content_earlier_clicked, this));
+       _content_later->Bind    (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::content_later_clicked, this));
        _content_timeline->Bind (wxEVT_COMMAND_BUTTON_CLICKED,        boost::bind (&FilmEditor::content_timeline_clicked, this));
        _scaler->Bind           (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::scaler_changed, this));
        _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED,       boost::bind (&FilmEditor::dcp_content_type_changed, this));
@@ -266,6 +269,10 @@ FilmEditor::make_content_panel ()
                b->Add (_content_add_folder, 1, wxEXPAND | wxLEFT | wxRIGHT);
                _content_remove = new wxButton (_content_panel, wxID_ANY, _("Remove"));
                b->Add (_content_remove, 1, wxEXPAND | wxLEFT | wxRIGHT);
+               _content_earlier = new wxButton (_content_panel, wxID_UP);
+               b->Add (_content_earlier, 1, wxEXPAND);
+               _content_later = new wxButton (_content_panel, wxID_DOWN);
+               b->Add (_content_later, 1, wxEXPAND);
                _content_timeline = new wxButton (_content_panel, wxID_ANY, _("Timeline..."));
                b->Add (_content_timeline, 1, wxEXPAND | wxLEFT | wxRIGHT);
 
@@ -597,6 +604,8 @@ FilmEditor::set_general_sensitivity (bool s)
        _content_add_file->Enable (s);
        _content_add_folder->Enable (s);
        _content_remove->Enable (s);
+       _content_earlier->Enable (s);
+       _content_later->Enable (s);
        _content_timeline->Enable (s);
        _dcp_content_type->Enable (s);
        _encrypted->Enable (s);
@@ -809,6 +818,8 @@ FilmEditor::setup_content_sensitivity ()
        shared_ptr<Content> selection = selected_content ();
 
        _content_remove->Enable (selection && _generally_sensitive);
+       _content_earlier->Enable (selection && _generally_sensitive);
+       _content_later->Enable (selection && _generally_sensitive);
        _content_timeline->Enable (_generally_sensitive);
 
        _video_panel->Enable    (selection && dynamic_pointer_cast<VideoContent>  (selection) && _generally_sensitive);
@@ -918,3 +929,17 @@ FilmEditor::three_d_changed ()
 
        _film->set_three_d (_three_d->GetValue ());
 }
+
+void
+FilmEditor::content_earlier_clicked ()
+{
+       _film->move_content_earlier (selected_content ());
+       content_selection_changed ();
+}
+
+void
+FilmEditor::content_later_clicked ()
+{
+       _film->move_content_later (selected_content ());
+       content_selection_changed ();
+}
index bb217211ca7719c0e58ba4a8cb22854726ec8961..06a65dd9f661e2716adee8ab16d7acb7de28dc27 100644 (file)
@@ -80,6 +80,8 @@ private:
        void content_add_file_clicked ();
        void content_add_folder_clicked ();
        void content_remove_clicked ();
+       void content_earlier_clicked ();
+       void content_later_clicked ();
        void container_changed ();
        void dcp_content_type_changed ();
        void scaler_changed ();