Use plain git hash for VERSION when there is no exact tag.
[dcpomatic.git] / src / lib / playlist.cc
index e8714e9d6d4ffedac4ab9dd6fc6ae83ee1efe66b..85957e106803be886e4f5a85016f15cc21282282 100644 (file)
 */
 
 
-#include "playlist.h"
-#include "video_content.h"
-#include "text_content.h"
-#include "ffmpeg_decoder.h"
-#include "ffmpeg_content.h"
-#include "image_decoder.h"
 #include "audio_content.h"
+#include "compose.hpp"
+#include "config.h"
 #include "content_factory.h"
 #include "dcp_content.h"
+#include "digester.h"
+#include "ffmpeg_content.h"
+#include "ffmpeg_decoder.h"
+#include "image_decoder.h"
 #include "job.h"
-#include "config.h"
+#include "playlist.h"
+#include "text_content.h"
 #include "util.h"
-#include "digester.h"
-#include "compose.hpp"
+#include "video_content.h"
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <boost/bind/placeholders.hpp>
 #include "i18n.h"
 
 
-using std::list;
 using std::cout;
-using std::vector;
-using std::min;
+using std::dynamic_pointer_cast;
+using std::list;
 using std::max;
-using std::string;
+using std::min;
 using std::pair;
-using boost::optional;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using std::weak_ptr;
-using std::dynamic_pointer_cast;
+using boost::optional;
 using namespace dcpomatic;
 #if BOOST_VERSION >= 106100
 using namespace boost::placeholders;
 #endif
 
 
-Playlist::Playlist ()
+class ContentSorter
 {
+public:
+       bool operator()(shared_ptr<Content> a, shared_ptr<Content> b)
+       {
+               if (a->position() != b->position()) {
+                       return a->position() < b->position();
+               }
 
-}
+               /* Put video before audio if they start at the same time */
+               if (a->video && !b->video) {
+                       return true;
+               } else if (!a->video && b->video) {
+                       return false;
+               }
+
+               /* Last resort */
+               return a->digest() < b->digest();
+       }
+};
 
 
 Playlist::~Playlist ()
@@ -234,7 +250,7 @@ Playlist::set_from_xml (shared_ptr<const Film> film, cxml::ConstNodePtr node, in
 
                /* ...or have a start trim which is an integer number of frames */
                auto const old_trim = content->trim_start();
-               content->set_trim_start(old_trim);
+               content->set_trim_start(film, old_trim);
                if (old_trim != content->trim_start()) {
                        string note = _("Your project contains video content whose trim was not aligned to a frame boundary.");
                        note += "  ";
@@ -542,25 +558,6 @@ Playlist::set_sequence (bool s)
 }
 
 
-bool
-ContentSorter::operator() (shared_ptr<Content> a, shared_ptr<Content> b)
-{
-       if (a->position() != b->position()) {
-               return a->position() < b->position();
-       }
-
-       /* Put video before audio if they start at the same time */
-       if (a->video && !b->video) {
-               return true;
-       } else if (!a->video && b->video) {
-               return false;
-       }
-
-       /* Last resort */
-       return a->digest() < b->digest();
-}
-
-
 /** @return content in ascending order of position */
 ContentList
 Playlist::content () const
@@ -632,32 +629,26 @@ void
 Playlist::move_later (shared_ptr<const Film> film, shared_ptr<Content> c)
 {
        auto cont = content ();
-       auto i = cont.begin();
-       while (i != cont.end() && *i != c) {
-               ++i;
-       }
 
-       DCPOMATIC_ASSERT (i != cont.end());
-
-       ContentList::iterator next = i;
-       ++next;
+       auto iter = std::find(cont.begin(), cont.end(), c);
+       DCPOMATIC_ASSERT(iter != cont.end());
 
+       ContentList::iterator next = std::next(iter);
        if (next == cont.end()) {
+               /* This content is already at the end */
                return;
        }
 
-       auto next_c = *next;
-
-       next_c->set_position (film, c->position());
-       c->set_position (film, c->position() + next_c->length_after_trim(film));
+       (*next)->set_position(film, c->position());
+       c->set_position(film, c->position() + (*next)->length_after_trim(film));
 }
 
 
 int64_t
 Playlist::required_disk_space (shared_ptr<const Film> film, int j2k_bandwidth, int audio_channels, int audio_frame_rate) const
 {
-       int64_t video = uint64_t (j2k_bandwidth / 8) * length(film).seconds();
-       int64_t audio = uint64_t (audio_channels * audio_frame_rate * 3) * length(film).seconds();
+       int64_t video = uint64_t(j2k_bandwidth / 8) * length(film).seconds();
+       int64_t audio = uint64_t(audio_channels) * audio_frame_rate * 3 * length(film).seconds();
 
        for (auto i: content()) {
                auto d = dynamic_pointer_cast<DCPContent> (i);
@@ -666,7 +657,7 @@ Playlist::required_disk_space (shared_ptr<const Film> film, int j2k_bandwidth, i
                                video -= uint64_t (j2k_bandwidth / 8) * d->length_after_trim(film).seconds();
                        }
                        if (d->reference_audio()) {
-                               audio -= uint64_t (audio_channels * audio_frame_rate * 3) * d->length_after_trim(film).seconds();
+                               audio -= uint64_t(audio_channels) * audio_frame_rate * 3 * d->length_after_trim(film).seconds();
                        }
                }
        }
@@ -683,7 +674,7 @@ Playlist::content_summary (shared_ptr<const Film> film, DCPTimePeriod period) co
        int best_score = -1;
        for (auto i: content()) {
                int score = 0;
-               auto const o = DCPTimePeriod(i->position(), i->end(film)).overlap (period);
+               auto const o = i->period(film).overlap(period);
                if (o) {
                        score += 100 * o.get().duration().get() / period.duration().get();
                }
@@ -693,7 +684,7 @@ Playlist::content_summary (shared_ptr<const Film> film, DCPTimePeriod period) co
                }
 
                if (score > best_score) {
-                       best_summary = i->path(0).leaf().string();
+                       best_summary = i->path(0).filename().string();
                        best_score = score;
                }
        }