]> git.sesse.net Git - nageru/blobdiff - futatabi/export.cpp
Call the done callback only when the entire playlist is done. Simplifies a fair amoun...
[nageru] / futatabi / export.cpp
index 2b9f5317a0dcfb5612edde9cbcd70889ec9f7a9c..5481007c79f055ec3c7a2835cda01008a369793f 100644 (file)
@@ -223,25 +223,22 @@ void export_interpolated_clip(const string &filename, const vector<Clip> &clips)
        progress.setMaximum(100000);
        progress.setValue(0);
 
-       double total_length = compute_time_left(clips, { { 0, 0.0 } });
        vector<Player::ClipWithRow> clips_with_row;
        for (const Clip &clip : clips) {
                clips_with_row.emplace_back(Player::ClipWithRow{ clip, 0 });
        }
+       double total_length = compute_total_time(clips_with_row);
 
        promise<void> done_promise;
        future<void> done = done_promise.get_future();
        std::atomic<double> current_value{ 0.0 };
-       size_t clip_idx = 0;
 
        Player player(/*destination=*/nullptr, Player::FILE_STREAM_OUTPUT, closer.release());
-       player.set_done_callback([&done_promise, &clip_idx, &clips] {
-               if (clip_idx >= clips.size()) {
-                       done_promise.set_value();
-               }
+       player.set_done_callback([&done_promise] {
+               done_promise.set_value();
        });
-       player.set_progress_callback([&current_value, &clips, total_length](const std::map<size_t, double> &player_progress) {
-               current_value = 1.0 - compute_time_left(clips, player_progress) / total_length;
+       player.set_progress_callback([&current_value, &clips, total_length](const std::map<size_t, double> &player_progress, double time_remaining) {
+               current_value = 1.0 - time_remaining / total_length;
        });
        player.play(clips_with_row);
        while (done.wait_for(std::chrono::milliseconds(100)) != future_status::ready && !progress.wasCanceled()) {