X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fmainwindow.cpp;h=025f00ba27186437c1a2a2ed2999e5a219d1fa90;hb=d02bca0f5622abd11b9697b738613f7644c33f59;hp=bbaa5a417ab8c9c636d76f324f3b396e7ef236b4;hpb=4d7015171fbd6c36c480d1d7992b76bbb45410c5;p=nageru diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index bbaa5a4..025f00b 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -186,10 +186,10 @@ MainWindow::MainWindow() live_player.reset(new Player(ui->live_display, Player::HTTPD_STREAM_OUTPUT)); live_player->set_done_callback([this] { post_to_main_thread([this] { - live_player_clip_done(); + live_player_done(); }); }); - live_player->set_progress_callback([this](const map &progress, double time_remaining) { + live_player->set_progress_callback([this](const map &progress, double time_remaining) { post_to_main_thread([this, progress, time_remaining] { live_player_clip_progress(progress, time_remaining); }); @@ -487,13 +487,13 @@ void MainWindow::play_clicked() start_row = selected->selectedRows(0)[0].row(); } - vector clips; + vector 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 } }); - playlist_clips->set_currently_playing(start_row, 0.0f); + ui->playlist->selectionModel()->clear(); playlist_selection_changed(); ui->stop_btn->setEnabled(true); @@ -504,45 +504,17 @@ void MainWindow::stop_clicked() Clip fake_clip; fake_clip.pts_in = 0; fake_clip.pts_out = 0; - size_t last_row = playlist_clips->size() - 1; - playlist_clips->set_currently_playing(last_row, 0.0f); + playlist_clips->set_progress({}); live_player->play(fake_clip); } -void MainWindow::live_player_clip_done() +void MainWindow::live_player_done() { - int row = playlist_clips->get_currently_playing(); - if (row == -1 || row == int(playlist_clips->size()) - 1) { - set_output_status("paused"); - playlist_clips->set_progress({}); - playlist_clips->set_currently_playing(-1, 0.0f); - } else { - playlist_clips->set_progress({ { row + 1, 0.0f } }); - playlist_clips->set_currently_playing(row + 1, 0.0f); - } + playlist_selection_changed(); + playlist_clips->set_progress({}); ui->stop_btn->setEnabled(false); } -pair MainWindow::live_player_get_next_clip() -{ - // playlist_clips can only be accessed on the main thread. - // Hopefully, we won't have to wait too long for this to come back. - // - // TODO: If MainWindow is in the process of being destroyed and waiting - // for Player to shut down, we could have a deadlock here. - promise> clip_promise; - future> clip = clip_promise.get_future(); - post_to_main_thread([&clip_promise] { - int row = playlist_clips->get_currently_playing(); - if (row != -1 && row < int(playlist_clips->size()) - 1) { - clip_promise.set_value(make_pair(*playlist_clips->clip(row + 1), row + 1)); - } else { - clip_promise.set_value(make_pair(Clip(), 0)); - } - }); - return clip.get(); -} - static string format_duration(double t) { int t_ms = lrint(t * 1e3); @@ -558,7 +530,7 @@ static string format_duration(double t) return buf; } -void MainWindow::live_player_clip_progress(const map &progress, double time_remaining) +void MainWindow::live_player_clip_progress(const map &progress, double time_remaining) { playlist_clips->set_progress(progress); set_output_status(format_duration(time_remaining) + " left"); @@ -843,9 +815,9 @@ void MainWindow::playlist_selection_changed() if (!any_selected) { set_output_status("paused"); } else { - vector clips; + vector 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");