]> git.sesse.net Git - nageru/blobdiff - futatabi/mainwindow.cpp
Fix an issue where the stop button would get grayed out if restarting playing.
[nageru] / futatabi / mainwindow.cpp
index 3d3d8c11c908c13c53bd42a1bec5f3a9c26187e0..d73f579a9e6faee5880c6ac2447004a1df6cc99c 100644 (file)
@@ -189,7 +189,7 @@ MainWindow::MainWindow()
                        live_player_done();
                });
        });
-       live_player->set_progress_callback([this](const map<size_t, double> &progress, double time_remaining) {
+       live_player->set_progress_callback([this](const map<uint64_t, double> &progress, double time_remaining) {
                post_to_main_thread([this, progress, time_remaining] {
                        live_player_clip_progress(progress, time_remaining);
                });
@@ -431,6 +431,14 @@ void MainWindow::defer_timer_expired()
 
 void MainWindow::content_changed()
 {
+       // If we are playing, update the part of the playlist that's not playing yet.
+       vector<ClipWithID> clips;
+       for (unsigned row = 0; row < playlist_clips->size(); ++row) {
+               clips.emplace_back(*playlist_clips->clip_with_id(row));
+       }
+       live_player->splice_play(clips);
+
+       // Serialize the state.
        if (defer_timeout->isActive() &&
            (!currently_deferring_model_changes || deferred_change_id != current_change_id)) {
                // There's some deferred event waiting, but this event is unrelated.
@@ -487,12 +495,13 @@ void MainWindow::play_clicked()
                start_row = selected->selectedRows(0)[0].row();
        }
 
-       vector<Player::ClipWithRow> clips;
+       vector<ClipWithID> clips;
        for (unsigned row = start_row; row < playlist_clips->size(); ++row) {
-               clips.emplace_back(Player::ClipWithRow{ *playlist_clips->clip(row), row });
+               clips.emplace_back(*playlist_clips->clip_with_id(row));
        }
        live_player->play(clips);
        playlist_clips->set_progress({ { start_row, 0.0f } });
+       ui->playlist->selectionModel()->clear();
        playlist_selection_changed();
 
        ui->stop_btn->setEnabled(true);
@@ -503,12 +512,14 @@ void MainWindow::stop_clicked()
        Clip fake_clip;
        fake_clip.pts_in = 0;
        fake_clip.pts_out = 0;
+       playlist_clips->set_progress({});
        live_player->play(fake_clip);
+       ui->stop_btn->setEnabled(false);
 }
 
 void MainWindow::live_player_done()
 {
-       set_output_status("paused");
+       playlist_selection_changed();
        playlist_clips->set_progress({});
        ui->stop_btn->setEnabled(false);
 }
@@ -528,7 +539,7 @@ static string format_duration(double t)
        return buf;
 }
 
-void MainWindow::live_player_clip_progress(const map<size_t, double> &progress, double time_remaining)
+void MainWindow::live_player_clip_progress(const map<uint64_t, double> &progress, double time_remaining)
 {
        playlist_clips->set_progress(progress);
        set_output_status(format_duration(time_remaining) + " left");
@@ -813,9 +824,9 @@ void MainWindow::playlist_selection_changed()
        if (!any_selected) {
                set_output_status("paused");
        } else {
-               vector<Player::ClipWithRow> clips;
+               vector<ClipWithID> clips;
                for (size_t row = selected->selectedRows().front().row(); row < playlist_clips->size(); ++row) {
-                       clips.emplace_back(Player::ClipWithRow{ *playlist_clips->clip(row), row });
+                       clips.emplace_back(*playlist_clips->clip_with_id(row));
                }
                double remaining = compute_total_time(clips);
                set_output_status(format_duration(remaining) + " ready");