using std::max;
using std::string;
using std::stringstream;
+using std::pair;
using boost::optional;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::lexical_cast;
Playlist::Playlist ()
- : _loop (1)
- , _sequence_video (true)
+ : _sequence_video (true)
, _sequencing_video (false)
{
}
}
- t += lexical_cast<string> (_loop);
-
return md5_digest (t.c_str(), t.length());
}
}
reconnect ();
- _loop = node->number_child<int> ("Loop");
_sequence_video = node->bool_child ("SequenceVideo");
}
(*i)->as_xml (node->add_child ("Content"));
}
- node->add_child("Loop")->add_child_text(lexical_cast<string> (_loop));
node->add_child("SequenceVideo")->add_child_text(_sequence_video ? "1" : "0");
}
}
void
-Playlist::set_loop (int l)
+Playlist::remove (ContentList c)
{
- _loop = l;
+ 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 ();
}
}
Time
-Playlist::length_without_loop () const
+Playlist::length () const
{
Time len = 0;
for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
return len;
}
-Time
-Playlist::length_with_loop () const
-{
- return length_without_loop() * _loop;
-}
-
void
Playlist::reconnect ()
{
return a->start() < b->start();
}
-/** @return content in an undefined order, not taking looping into account */
-Playlist::ContentList
-Playlist::content_without_loop () const
+/** @return content in an undefined order */
+ContentList
+Playlist::content () const
{
return _content;
}
-/** @return content in an undefined order, taking looping into account */
-Playlist::ContentList
-Playlist::content_with_loop () const
+void
+Playlist::repeat (ContentList c, int n)
{
- ContentList looped = _content;
- Time const length = length_without_loop ();
+ 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 offset = length;
- for (int i = 1; i < _loop; ++i) {
- for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) {
+ 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 (copy->start() + offset);
- looped.push_back (copy);
+ copy->set_start (pos + copy->start() - range.first);
+ _content.push_back (copy);
}
- offset += length;
+ pos += range.second - range.first;
}
-
- return looped;
+
+ reconnect ();
+ Changed ();
}