X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplaylist.cc;h=85957e106803be886e4f5a85016f15cc21282282;hb=a7fa6e05bf01b7739556b1310db90326bf4b7cbc;hp=c18a438821b9a91fd0e4e23b7d629363e81216f0;hpb=d311043bf3c1e3e7f41b314f7ab7c91ed7e5aa7f;p=dcpomatic.git diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index c18a43882..85957e106 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -58,10 +58,26 @@ using namespace boost::placeholders; #endif -Playlist::Playlist () +class ContentSorter { +public: + bool operator()(shared_ptr a, shared_ptr 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 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 a, shared_ptr 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 film, shared_ptr 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 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 (i); @@ -666,7 +657,7 @@ Playlist::required_disk_space (shared_ptr 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 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 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; } }