+ return a->position() < b->position();
+}
+
+/** @return content in an undefined order */
+ContentList
+Playlist::content () const
+{
+ return _content;
+}
+
+void
+Playlist::repeat (ContentList c, int n)
+{
+ pair<DCPTime, DCPTime> range (DCPTime::max (), DCPTime ());
+ for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
+ range.first = min (range.first, (*i)->position ());
+ range.second = max (range.second, (*i)->position ());
+ range.first = min (range.first, (*i)->end ());
+ range.second = max (range.second, (*i)->end ());
+ }
+
+ DCPTime 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_position (pos + copy->position() - range.first);
+ _content.push_back (copy);
+ }
+ 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;
+ }
+
+ DCPOMATIC_ASSERT (i != _content.end ());
+ if (previous == _content.end ()) {
+ return;
+ }
+
+
+ DCPTime const p = (*previous)->position ();
+ (*previous)->set_position (p + c->length_after_trim ());
+ c->set_position (p);
+ sort (_content.begin(), _content.end(), ContentSorter ());
+}
+
+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;
+ }
+
+ DCPOMATIC_ASSERT (i != _content.end ());
+
+ ContentList::iterator next = i;
+ ++next;
+
+ if (next == _content.end ()) {
+ return;
+ }
+
+ (*next)->set_position (c->position ());
+ c->set_position (c->position() + (*next)->length_after_trim ());
+ sort (_content.begin(), _content.end(), ContentSorter ());