Add remove option; resize timeline after drags.
[dcpomatic.git] / src / lib / playlist.cc
index c70c79972f0d44891393a7f1d49fce5cc0a67a69..c9d05b0495465507210a28f462f63e0fb4804bc2 100644 (file)
@@ -42,6 +42,7 @@ using std::min;
 using std::max;
 using std::string;
 using std::stringstream;
+using std::pair;
 using boost::optional;
 using boost::shared_ptr;
 using boost::weak_ptr;
@@ -157,6 +158,23 @@ Playlist::remove (shared_ptr<Content> c)
        }
 }
 
+void
+Playlist::remove (ContentList c)
+{
+       for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
+               ContentList::iterator j = _content.begin ();
+               while (j != _content.end() && *j != *i) {
+                       ++j;
+               }
+       
+               if (j != _content.end ()) {
+                       _content.erase (j);
+               }
+       }
+
+       Changed ();
+}
+
 bool
 Playlist::has_subtitles () const
 {
@@ -284,8 +302,33 @@ ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b)
 }
 
 /** @return content in an undefined order */
-Playlist::ContentList
+ContentList
 Playlist::content () const
 {
        return _content;
 }
+
+void
+Playlist::repeat (ContentList c, int n)
+{
+       pair<Time, Time> range (TIME_MAX, 0);
+       for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
+               range.first = min (range.first, (*i)->start ());
+               range.second = max (range.second, (*i)->start ());
+               range.first = min (range.first, (*i)->end ());
+               range.second = max (range.second, (*i)->end ());
+       }
+
+       Time pos = range.second;
+       for (int i = 0; i < n; ++i) {
+               for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
+                       shared_ptr<Content> copy = (*i)->clone ();
+                       copy->set_start (pos + copy->start() - range.first);
+                       _content.push_back (copy);
+               }
+               pos += range.second - range.first;
+       }
+
+       reconnect ();
+       Changed ();
+}