summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-10-15 22:18:00 +0100
committerCarl Hetherington <cth@carlh.net>2013-10-15 22:18:00 +0100
commit6b35b4764ac5446c845a1dde9a01e0401862d835 (patch)
treef8053ff11fcd290b07ffee4a41cf9ca3668514ca /src/lib
parentf3c8a0a8d45df52ec449aa1d3e02d308a2c36b42 (diff)
Restore up/down buttons for simple content movements.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/film.cc13
-rw-r--r--src/lib/film.h2
-rw-r--r--src/lib/playlist.cc66
-rw-r--r--src/lib/playlist.h3
4 files changed, 81 insertions, 3 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc
index bceaef96e..085675d07 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -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;
}
-
diff --git a/src/lib/film.h b/src/lib/film.h
index 01fccf7d1..71bbd3844 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -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);
diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc
index de48ff5f5..1712dc8ff 100644
--- a/src/lib/playlist.cc
+++ b/src/lib/playlist.cc
@@ -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 ();
+}
diff --git a/src/lib/playlist.h b/src/lib/playlist.h
index 7dbf41604..05928ee57 100644
--- a/src/lib/playlist.h
+++ b/src/lib/playlist.h
@@ -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;