X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mainwindow.cpp;h=d6353844b95dd7589f3c1a0c53b08d99b9417d69;hb=c4b876d817b340482df70a6e691173bbd7ff1657;hp=f0a0341b89c0a758e0d61d325ac70a566d3b32eb;hpb=e6dd4055a226d31ecb29bc0746bb896e6ff7ff66;p=nageru diff --git a/mainwindow.cpp b/mainwindow.cpp index f0a0341..d635384 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,6 +3,7 @@ #include "clip_list.h" #include "player.h" #include "post_to_main_thread.h" +#include "timebase.h" #include "ui_mainwindow.h" #include @@ -107,12 +108,17 @@ MainWindow::MainWindow() live_player_clip_done(); }); }); + live_player->set_progress_callback([this](double played_this_clip, double total_length) { + post_to_main_thread([this, played_this_clip, total_length] { + live_player_clip_progress(played_this_clip, total_length); + }); + }); } void MainWindow::cue_in_clicked() { if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) { - cliplist_clips->back()->pts_in = current_pts; + cliplist_clips->mutable_back()->pts_in = current_pts; return; } Clip clip; @@ -124,7 +130,7 @@ void MainWindow::cue_in_clicked() void MainWindow::cue_out_clicked() { if (!cliplist_clips->empty()) { - cliplist_clips->back()->pts_out = current_pts; + cliplist_clips->mutable_back()->pts_out = current_pts; // TODO: select the row in the clip list? } } @@ -144,13 +150,16 @@ void MainWindow::queue_clicked() } QModelIndex index = selected->currentIndex(); + Clip clip = *cliplist_clips->clip(index.row()); if (index.column() >= int(ClipList::Column::CAMERA_1) && index.column() <= int(ClipList::Column::CAMERA_4)) { - Clip clip = *cliplist_clips->clip(index.row()); clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1); - playlist_clips->add_clip(clip); - playlist_selection_changed(); + } else { + clip.stream_idx = ui->preview_display->get_stream_idx(); } + + playlist_clips->add_clip(clip); + playlist_selection_changed(); } void MainWindow::preview_clicked() @@ -164,11 +173,14 @@ void MainWindow::preview_clicked() } QModelIndex index = selected->currentIndex(); + unsigned stream_idx; if (index.column() >= int(ClipList::Column::CAMERA_1) && index.column() <= int(ClipList::Column::CAMERA_4)) { - unsigned stream_idx = index.column() - int(ClipList::Column::CAMERA_1); - preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx); + stream_idx = index.column() - int(ClipList::Column::CAMERA_1); + } else { + stream_idx = ui->preview_display->get_stream_idx(); } + preview_player->play_clip(*cliplist_clips->clip(index.row()), stream_idx); } void MainWindow::preview_angle_clicked(unsigned stream_idx) @@ -263,9 +275,30 @@ void MainWindow::live_player_clip_done() playlist_clips->set_currently_playing(row); } else { playlist_clips->set_currently_playing(-1); + ui->live_label->setText("Current output (paused)"); } } +void MainWindow::live_player_clip_progress(double played_this_clip, double total_length) +{ + double remaining = total_length - played_this_clip; + for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) { + const Clip clip = *playlist_clips->clip(row); + remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed. + } + int remaining_ms = lrint(remaining * 1e3); + + int ms = remaining_ms % 1000; + remaining_ms /= 1000; + int s = remaining_ms % 60; + remaining_ms /= 60; + int m = remaining_ms; + + char buf[256]; + snprintf(buf, sizeof(buf), "Current output (%d:%02d.%03d left)", m, s, ms); + ui->live_label->setText(buf); +} + void MainWindow::resizeEvent(QResizeEvent *event) { QMainWindow::resizeEvent(event); @@ -355,7 +388,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) int64_t pts = scrub_pts_origin + adjusted_offset * scrub_sensitivity; if (scrub_type == SCRUBBING_CLIP_LIST) { - ClipProxy clip = cliplist_clips->clip(scrub_row); + ClipProxy clip = cliplist_clips->mutable_clip(scrub_row); if (scrub_column == int(ClipList::Column::IN)) { pts = std::max(pts, 0); pts = std::min(pts, clip->pts_out); @@ -368,7 +401,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) preview_single_frame(pts, stream_idx, LAST_BEFORE); } } else { - ClipProxy clip = playlist_clips->clip(scrub_row); + ClipProxy clip = playlist_clips->mutable_clip(scrub_row); if (scrub_column == int(PlayList::Column::IN)) { pts = std::max(pts, 0); pts = std::min(pts, clip->pts_out); @@ -409,7 +442,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) if (column == -1 || row == -1) return false; ClipProxy clip = (watched == ui->clip_list->viewport()) ? - cliplist_clips->clip(row) : playlist_clips->clip(row); + cliplist_clips->mutable_clip(row) : playlist_clips->mutable_clip(row); if (watched == ui->playlist->viewport()) { stream_idx = clip->stream_idx; }