1 #include "mainwindow.h"
3 #include "shared/aboutdialog.h"
5 #include "shared/disk_space_estimator.h"
7 #include "frame_on_disk.h"
9 #include "shared/post_to_main_thread.h"
10 #include "shared/timebase.h"
11 #include "ui_mainwindow.h"
13 #include <QDesktopServices>
14 #include <QMessageBox>
15 #include <QMouseEvent>
18 #include <QWheelEvent>
25 using namespace std::placeholders;
27 MainWindow *global_mainwindow = nullptr;
28 static ClipList *cliplist_clips;
29 static PlayList *playlist_clips;
31 extern int64_t current_pts;
33 MainWindow::MainWindow()
34 : ui(new Ui::MainWindow),
35 db(global_flags.working_directory + "/futatabi.db")
37 global_mainwindow = this;
41 connect(ui->exit_action, &QAction::triggered, this, &MainWindow::exit_triggered);
42 connect(ui->manual_action, &QAction::triggered, this, &MainWindow::manual_triggered);
43 connect(ui->about_action, &QAction::triggered, this, &MainWindow::about_triggered);
45 global_disk_space_estimator = new DiskSpaceEstimator(bind(&MainWindow::report_disk_space, this, _1, _2));
46 disk_free_label = new QLabel(this);
47 disk_free_label->setStyleSheet("QLabel {padding-right: 5px;}");
48 ui->menuBar->setCornerWidget(disk_free_label);
50 StateProto state = db.get_state();
52 cliplist_clips = new ClipList(state.clip_list());
53 ui->clip_list->setModel(cliplist_clips);
54 connect(cliplist_clips, &ClipList::any_content_changed, this, &MainWindow::content_changed);
56 playlist_clips = new PlayList(state.play_list());
57 ui->playlist->setModel(playlist_clips);
58 connect(playlist_clips, &PlayList::any_content_changed, this, &MainWindow::content_changed);
60 // For un-highlighting when we lose focus.
61 ui->clip_list->installEventFilter(this);
63 // For scrubbing in the pts columns.
64 ui->clip_list->viewport()->installEventFilter(this);
65 ui->playlist->viewport()->installEventFilter(this);
67 QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
68 connect(cue_in, &QShortcut::activated, ui->cue_in_btn, &QPushButton::click);
69 connect(ui->cue_in_btn, &QPushButton::clicked, this, &MainWindow::cue_in_clicked);
71 QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
72 connect(cue_out, &QShortcut::activated, ui->cue_out_btn, &QPushButton::click);
73 connect(ui->cue_out_btn, &QPushButton::clicked, this, &MainWindow::cue_out_clicked);
75 QShortcut *queue = new QShortcut(QKeySequence(Qt::Key_Q), this);
76 connect(queue, &QShortcut::activated, ui->queue_btn, &QPushButton::click);
77 connect(ui->queue_btn, &QPushButton::clicked, this, &MainWindow::queue_clicked);
79 QShortcut *preview = new QShortcut(QKeySequence(Qt::Key_W), this);
80 connect(preview, &QShortcut::activated, ui->preview_btn, &QPushButton::click);
81 connect(ui->preview_btn, &QPushButton::clicked, this, &MainWindow::preview_clicked);
83 QShortcut *play = new QShortcut(QKeySequence(Qt::Key_Space), this);
84 connect(play, &QShortcut::activated, ui->play_btn, &QPushButton::click);
85 connect(ui->play_btn, &QPushButton::clicked, this, &MainWindow::play_clicked);
87 QShortcut *preview_1 = new QShortcut(QKeySequence(Qt::Key_1), this);
88 connect(preview_1, &QShortcut::activated, ui->preview_1_btn, &QPushButton::click);
89 connect(ui->input1_display, &JPEGFrameView::clicked, ui->preview_1_btn, &QPushButton::click);
90 connect(ui->preview_1_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(0); });
91 ui->input1_display->set_overlay("1");
93 QShortcut *preview_2 = new QShortcut(QKeySequence(Qt::Key_2), this);
94 connect(preview_2, &QShortcut::activated, ui->preview_2_btn, &QPushButton::click);
95 connect(ui->input2_display, &JPEGFrameView::clicked, ui->preview_2_btn, &QPushButton::click);
96 connect(ui->preview_2_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(1); });
97 ui->input2_display->set_overlay("2");
99 QShortcut *preview_3 = new QShortcut(QKeySequence(Qt::Key_3), this);
100 connect(preview_3, &QShortcut::activated, ui->preview_3_btn, &QPushButton::click);
101 connect(ui->input3_display, &JPEGFrameView::clicked, ui->preview_3_btn, &QPushButton::click);
102 connect(ui->preview_3_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(2); });
103 ui->input3_display->set_overlay("3");
105 QShortcut *preview_4 = new QShortcut(QKeySequence(Qt::Key_4), this);
106 connect(preview_4, &QShortcut::activated, ui->preview_4_btn, &QPushButton::click);
107 connect(ui->input4_display, &JPEGFrameView::clicked, ui->preview_4_btn, &QPushButton::click);
108 connect(ui->preview_4_btn, &QPushButton::clicked, [this]{ preview_angle_clicked(3); });
109 ui->input4_display->set_overlay("4");
111 connect(ui->playlist_duplicate_btn, &QPushButton::clicked, this, &MainWindow::playlist_duplicate);
113 connect(ui->playlist_remove_btn, &QPushButton::clicked, this, &MainWindow::playlist_remove);
114 QShortcut *delete_key = new QShortcut(QKeySequence(Qt::Key_Delete), ui->playlist);
115 connect(delete_key, &QShortcut::activated, [this] {
116 if (ui->playlist->hasFocus()) {
121 // TODO: support drag-and-drop.
122 connect(ui->playlist_move_up_btn, &QPushButton::clicked, [this]{ playlist_move(-1); });
123 connect(ui->playlist_move_down_btn, &QPushButton::clicked, [this]{ playlist_move(1); });
125 connect(ui->playlist->selectionModel(), &QItemSelectionModel::selectionChanged,
126 this, &MainWindow::playlist_selection_changed);
127 playlist_selection_changed(); // First time set-up.
129 preview_player = new Player(ui->preview_display, /*also_output_to_stream=*/false);
130 live_player = new Player(ui->live_display, /*also_output_to_stream=*/true);
131 live_player->set_done_callback([this]{
132 post_to_main_thread([this]{
133 live_player_clip_done();
136 live_player->set_next_clip_callback(bind(&MainWindow::live_player_get_next_clip, this));
137 live_player->set_progress_callback([this](const map<size_t, double> &progress) {
138 post_to_main_thread([this, progress] {
139 live_player_clip_progress(progress);
142 set_output_status("paused");
144 defer_timeout = new QTimer(this);
145 defer_timeout->setSingleShot(true);
146 connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
148 connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
149 this, &MainWindow::clip_list_selection_changed);
152 void MainWindow::cue_in_clicked()
154 if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
155 cliplist_clips->mutable_back()->pts_in = current_pts;
159 clip.pts_in = current_pts;
160 cliplist_clips->add_clip(clip);
161 playlist_selection_changed();
164 void MainWindow::cue_out_clicked()
166 if (!cliplist_clips->empty()) {
167 cliplist_clips->mutable_back()->pts_out = current_pts;
168 // TODO: select the row in the clip list?
172 void MainWindow::queue_clicked()
174 if (cliplist_clips->empty()) {
178 QItemSelectionModel *selected = ui->clip_list->selectionModel();
179 if (!selected->hasSelection()) {
180 Clip clip = *cliplist_clips->back();
182 if (clip.pts_out != -1) {
183 playlist_clips->add_clip(clip);
184 playlist_selection_changed();
189 QModelIndex index = selected->currentIndex();
190 Clip clip = *cliplist_clips->clip(index.row());
191 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
192 index.column() <= int(ClipList::Column::CAMERA_4)) {
193 clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
195 clip.stream_idx = ui->preview_display->get_stream_idx();
198 if (clip.pts_out != -1) {
199 playlist_clips->add_clip(clip);
200 playlist_selection_changed();
204 void MainWindow::preview_clicked()
206 if (ui->playlist->hasFocus()) {
207 // Allow the playlist as preview iff it has focus and something is selected.
208 QItemSelectionModel *selected = ui->playlist->selectionModel();
209 if (selected->hasSelection()) {
210 QModelIndex index = selected->currentIndex();
211 const Clip &clip = *playlist_clips->clip(index.row());
212 preview_player->play_clip(clip, index.row(), clip.stream_idx);
217 if (cliplist_clips->empty())
220 QItemSelectionModel *selected = ui->clip_list->selectionModel();
221 if (!selected->hasSelection()) {
222 preview_player->play_clip(*cliplist_clips->back(), cliplist_clips->size() - 1, 0);
226 QModelIndex index = selected->currentIndex();
228 if (index.column() >= int(ClipList::Column::CAMERA_1) &&
229 index.column() <= int(ClipList::Column::CAMERA_4)) {
230 stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
232 stream_idx = ui->preview_display->get_stream_idx();
234 preview_player->play_clip(*cliplist_clips->clip(index.row()), index.row(), stream_idx);
237 void MainWindow::preview_angle_clicked(unsigned stream_idx)
239 preview_player->override_angle(stream_idx);
241 // Change the selection if we were previewing a clip from the clip list.
242 // (The only other thing we could be showing is a pts scrub, and if so,
243 // that would be selected.)
244 QItemSelectionModel *selected = ui->clip_list->selectionModel();
245 if (selected->hasSelection()) {
246 QModelIndex cell = selected->selectedIndexes()[0];
247 int column = int(ClipList::Column::CAMERA_1) + stream_idx;
248 selected->setCurrentIndex(cell.sibling(cell.row(), column), QItemSelectionModel::ClearAndSelect);
252 void MainWindow::playlist_duplicate()
254 QItemSelectionModel *selected = ui->playlist->selectionModel();
255 if (!selected->hasSelection()) {
256 // Should have been grayed out, but OK.
259 QModelIndexList rows = selected->selectedRows();
260 int first = rows.front().row(), last = rows.back().row();
261 playlist_clips->duplicate_clips(first, last);
262 playlist_selection_changed();
265 void MainWindow::playlist_remove()
267 QItemSelectionModel *selected = ui->playlist->selectionModel();
268 if (!selected->hasSelection()) {
269 // Should have been grayed out, but OK.
272 QModelIndexList rows = selected->selectedRows();
273 int first = rows.front().row(), last = rows.back().row();
274 playlist_clips->erase_clips(first, last);
276 // TODO: select the next one in the list?
278 playlist_selection_changed();
281 void MainWindow::playlist_move(int delta)
283 QItemSelectionModel *selected = ui->playlist->selectionModel();
284 if (!selected->hasSelection()) {
285 // Should have been grayed out, but OK.
289 QModelIndexList rows = selected->selectedRows();
290 int first = rows.front().row(), last = rows.back().row();
291 if ((delta == -1 && first == 0) ||
292 (delta == 1 && size_t(last) == playlist_clips->size() - 1)) {
293 // Should have been grayed out, but OK.
297 playlist_clips->move_clips(first, last, delta);
298 playlist_selection_changed();
301 void MainWindow::defer_timer_expired()
303 state_changed(deferred_state);
306 void MainWindow::content_changed()
308 if (defer_timeout->isActive() &&
309 (!currently_deferring_model_changes || deferred_change_id != current_change_id)) {
310 // There's some deferred event waiting, but this event is unrelated.
311 // So it's time to short-circuit that timer and do the work it wanted to do.
312 defer_timeout->stop();
313 state_changed(deferred_state);
316 *state.mutable_clip_list() = cliplist_clips->serialize();
317 *state.mutable_play_list() = playlist_clips->serialize();
318 if (currently_deferring_model_changes) {
319 deferred_change_id = current_change_id;
320 deferred_state = std::move(state);
321 defer_timeout->start(200);
324 state_changed(state);
327 void MainWindow::state_changed(const StateProto &state)
329 db.store_state(state);
332 void MainWindow::play_clicked()
334 if (playlist_clips->empty())
337 QItemSelectionModel *selected = ui->playlist->selectionModel();
339 if (!selected->hasSelection()) {
342 row = selected->selectedRows(0)[0].row();
345 const Clip &clip = *playlist_clips->clip(row);
346 live_player->play_clip(clip, row, clip.stream_idx);
347 playlist_clips->set_progress({{ row, 0.0f }});
348 playlist_clips->set_currently_playing(row, 0.0f);
349 playlist_selection_changed();
352 void MainWindow::live_player_clip_done()
354 int row = playlist_clips->get_currently_playing();
355 if (row == -1 || row == int(playlist_clips->size()) - 1) {
356 set_output_status("paused");
357 playlist_clips->set_progress({});
358 playlist_clips->set_currently_playing(-1, 0.0f);
360 playlist_clips->set_progress({{ row + 1, 0.0f }});
361 playlist_clips->set_currently_playing(row + 1, 0.0f);
365 pair<Clip, size_t> MainWindow::live_player_get_next_clip()
367 // playlist_clips can only be accessed on the main thread.
368 // Hopefully, we won't have to wait too long for this to come back.
369 promise<pair<Clip, size_t>> clip_promise;
370 future<pair<Clip, size_t>> clip = clip_promise.get_future();
371 post_to_main_thread([this, &clip_promise] {
372 int row = playlist_clips->get_currently_playing();
373 if (row != -1 && row < int(playlist_clips->size()) - 1) {
374 clip_promise.set_value(make_pair(*playlist_clips->clip(row + 1), row + 1));
376 clip_promise.set_value(make_pair(Clip(), 0));
382 static string format_duration(double t)
384 int t_ms = lrint(t * 1e3);
386 int ms = t_ms % 1000;
393 snprintf(buf, sizeof(buf), "%d:%02d.%03d", m, s, ms);
397 void MainWindow::live_player_clip_progress(const map<size_t, double> &progress)
399 playlist_clips->set_progress(progress);
401 // Look at the last clip and then start counting from there.
402 assert(!progress.empty());
403 auto last_it = progress.end();
405 double remaining = 0.0;
406 double last_fade_time_seconds = 0.0;
407 for (size_t row = last_it->first; row < playlist_clips->size(); ++row) {
408 const Clip clip = *playlist_clips->clip(row);
409 double clip_length = double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
410 if (row == last_it->first) {
411 // A clip we're playing: Subtract the part we've already played.
412 remaining = clip_length * (1.0 - last_it->second);
414 // A clip we haven't played yet: Subtract the part that's overlapping
415 // with a previous clip (due to fade).
416 remaining += max(clip_length - last_fade_time_seconds, 0.0);
418 last_fade_time_seconds = min(clip_length, clip.fade_time_seconds);
420 set_output_status(format_duration(remaining) + " left");
423 void MainWindow::resizeEvent(QResizeEvent *event)
425 QMainWindow::resizeEvent(event);
427 // Ask for a relayout, but only after the event loop is done doing relayout
428 // on everything else.
429 QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
432 void MainWindow::relayout()
434 ui->live_display->setMinimumWidth(ui->live_display->height() * 16 / 9);
435 ui->preview_display->setMinimumWidth(ui->preview_display->height() * 16 / 9);
438 void set_pts_in(int64_t pts, int64_t current_pts, ClipProxy &clip)
440 pts = std::max<int64_t>(pts, 0);
441 if (clip->pts_out == -1) {
442 pts = std::min(pts, current_pts);
444 pts = std::min(pts, clip->pts_out);
449 bool MainWindow::eventFilter(QObject *watched, QEvent *event)
451 constexpr int dead_zone_pixels = 3; // To avoid that simple clicks get misinterpreted.
452 constexpr int scrub_sensitivity = 100; // pts units per pixel.
453 constexpr int wheel_sensitivity = 100; // pts units per degree.
454 constexpr int camera_degrees_per_pixel = 15; // One click of most mice.
456 unsigned stream_idx = ui->preview_display->get_stream_idx();
458 if (watched == ui->clip_list) {
459 if (event->type() == QEvent::FocusOut) {
460 highlight_camera_input(-1);
465 if (event->type() != QEvent::Wheel) {
466 last_mousewheel_camera_row = -1;
469 if (event->type() == QEvent::MouseButtonPress) {
470 QMouseEvent *mouse = (QMouseEvent *)event;
472 QTableView *destination;
475 if (watched == ui->clip_list->viewport()) {
476 destination = ui->clip_list;
477 type = SCRUBBING_CLIP_LIST;
478 } else if (watched == ui->playlist->viewport()) {
479 destination = ui->playlist;
480 type = SCRUBBING_PLAYLIST;
484 int column = destination->columnAt(mouse->x());
485 int row = destination->rowAt(mouse->y());
486 if (column == -1 || row == -1)
489 if (type == SCRUBBING_CLIP_LIST) {
490 if (ClipList::Column(column) == ClipList::Column::IN) {
491 scrub_pts_origin = cliplist_clips->clip(row)->pts_in;
492 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
493 } else if (ClipList::Column(column) == ClipList::Column::OUT) {
494 scrub_pts_origin = cliplist_clips->clip(row)->pts_out;
495 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
500 if (PlayList::Column(column) == PlayList::Column::IN) {
501 scrub_pts_origin = playlist_clips->clip(row)->pts_in;
502 preview_single_frame(scrub_pts_origin, stream_idx, FIRST_AT_OR_AFTER);
503 } else if (PlayList::Column(column) == PlayList::Column::OUT) {
504 scrub_pts_origin = playlist_clips->clip(row)->pts_out;
505 preview_single_frame(scrub_pts_origin, stream_idx, LAST_BEFORE);
513 scrub_column = column;
514 scrub_x_origin = mouse->x();
516 } else if (event->type() == QEvent::MouseMove) {
518 QMouseEvent *mouse = (QMouseEvent *)event;
519 int offset = mouse->x() - scrub_x_origin;
521 if (offset >= dead_zone_pixels) {
522 adjusted_offset = offset - dead_zone_pixels;
523 } else if (offset < -dead_zone_pixels) {
524 adjusted_offset = offset + dead_zone_pixels;
529 int64_t pts = scrub_pts_origin + adjusted_offset * scrub_sensitivity;
530 currently_deferring_model_changes = true;
531 if (scrub_type == SCRUBBING_CLIP_LIST) {
532 ClipProxy clip = cliplist_clips->mutable_clip(scrub_row);
533 if (scrub_column == int(ClipList::Column::IN)) {
534 current_change_id = "cliplist:in:" + to_string(scrub_row);
535 set_pts_in(pts, current_pts, clip);
536 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
538 current_change_id = "cliplist:out" + to_string(scrub_row);
539 pts = std::max(pts, clip->pts_in);
540 pts = std::min(pts, current_pts);
542 preview_single_frame(pts, stream_idx, LAST_BEFORE);
545 ClipProxy clip = playlist_clips->mutable_clip(scrub_row);
546 if (scrub_column == int(PlayList::Column::IN)) {
547 current_change_id = "playlist:in:" + to_string(scrub_row);
548 set_pts_in(pts, current_pts, clip);
549 preview_single_frame(pts, clip->stream_idx, FIRST_AT_OR_AFTER);
551 current_change_id = "playlist:out:" + to_string(scrub_row);
552 pts = std::max(pts, clip->pts_in);
553 pts = std::min(pts, current_pts);
555 preview_single_frame(pts, clip->stream_idx, LAST_BEFORE);
558 currently_deferring_model_changes = false;
560 return true; // Don't use this mouse movement for selecting things.
562 } else if (event->type() == QEvent::Wheel) {
563 QWheelEvent *wheel = (QWheelEvent *)event;
565 QTableView *destination;
566 int in_column, out_column, camera_column;
567 if (watched == ui->clip_list->viewport()) {
568 destination = ui->clip_list;
569 in_column = int(ClipList::Column::IN);
570 out_column = int(ClipList::Column::OUT);
572 last_mousewheel_camera_row = -1;
573 } else if (watched == ui->playlist->viewport()) {
574 destination = ui->playlist;
575 in_column = int(PlayList::Column::IN);
576 out_column = int(PlayList::Column::OUT);
577 camera_column = int(PlayList::Column::CAMERA);
579 last_mousewheel_camera_row = -1;
582 int column = destination->columnAt(wheel->x());
583 int row = destination->rowAt(wheel->y());
584 if (column == -1 || row == -1) return false;
586 // Only adjust pts with the wheel if the given row is selected.
587 if (!destination->hasFocus() ||
588 row != destination->selectionModel()->currentIndex().row()) {
592 currently_deferring_model_changes = true;
594 current_change_id = (watched == ui->clip_list->viewport()) ? "cliplist:" : "playlist:";
595 ClipProxy clip = (watched == ui->clip_list->viewport()) ?
596 cliplist_clips->mutable_clip(row) : playlist_clips->mutable_clip(row);
597 if (watched == ui->playlist->viewport()) {
598 stream_idx = clip->stream_idx;
601 if (column != camera_column) {
602 last_mousewheel_camera_row = -1;
604 if (column == in_column) {
605 current_change_id += "in:" + to_string(row);
606 int64_t pts = clip->pts_in + wheel->angleDelta().y() * wheel_sensitivity;
607 set_pts_in(pts, current_pts, clip);
608 preview_single_frame(pts, stream_idx, FIRST_AT_OR_AFTER);
609 } else if (column == out_column) {
610 current_change_id += "out:" + to_string(row);
611 int64_t pts = clip->pts_out + wheel->angleDelta().y() * wheel_sensitivity;
612 pts = std::max(pts, clip->pts_in);
613 pts = std::min(pts, current_pts);
615 preview_single_frame(pts, stream_idx, LAST_BEFORE);
616 } else if (column == camera_column) {
617 current_change_id += "camera:" + to_string(row);
618 int angle_degrees = wheel->angleDelta().y();
619 if (last_mousewheel_camera_row == row) {
620 angle_degrees += leftover_angle_degrees;
623 int stream_idx = clip->stream_idx + angle_degrees / camera_degrees_per_pixel;
624 stream_idx = std::max(stream_idx, 0);
625 stream_idx = std::min(stream_idx, NUM_CAMERAS - 1);
626 clip->stream_idx = stream_idx;
628 last_mousewheel_camera_row = row;
629 leftover_angle_degrees = angle_degrees % camera_degrees_per_pixel;
631 // Don't update the live view, that's rarely what the operator wants.
634 currently_deferring_model_changes = false;
635 return true; // Don't scroll.
636 } else if (event->type() == QEvent::MouseButtonRelease) {
642 void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWindow::Rounding rounding)
644 if (rounding == LAST_BEFORE) {
645 lock_guard<mutex> lock(frame_mu);
646 if (frames[stream_idx].empty())
648 auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts,
649 [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; });
650 if (it != frames[stream_idx].end()) {
654 assert(rounding == FIRST_AT_OR_AFTER);
655 lock_guard<mutex> lock(frame_mu);
656 if (frames[stream_idx].empty())
658 auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1,
659 [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; });
660 if (it != frames[stream_idx].end()) {
666 fake_clip.pts_in = pts;
667 fake_clip.pts_out = pts + 1;
668 preview_player->play_clip(fake_clip, 0, stream_idx);
671 void MainWindow::playlist_selection_changed()
673 QItemSelectionModel *selected = ui->playlist->selectionModel();
674 bool any_selected = selected->hasSelection();
675 ui->playlist_duplicate_btn->setEnabled(any_selected);
676 ui->playlist_remove_btn->setEnabled(any_selected);
677 ui->playlist_move_up_btn->setEnabled(
678 any_selected && selected->selectedRows().front().row() > 0);
679 ui->playlist_move_down_btn->setEnabled(
680 any_selected && selected->selectedRows().back().row() < int(playlist_clips->size()) - 1);
681 ui->play_btn->setEnabled(!playlist_clips->empty());
684 set_output_status("paused");
686 double remaining = 0.0;
687 for (int row = selected->selectedRows().front().row(); row < int(playlist_clips->size()); ++row) {
688 const Clip clip = *playlist_clips->clip(row);
689 remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5; // FIXME: stop hardcoding speed.
691 set_output_status(format_duration(remaining) + " ready");
695 void MainWindow::clip_list_selection_changed(const QModelIndex ¤t, const QModelIndex &)
697 int camera_selected = -1;
698 if (current.column() >= int(ClipList::Column::CAMERA_1) &&
699 current.column() <= int(ClipList::Column::CAMERA_4)) {
700 camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
702 highlight_camera_input(camera_selected);
705 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
708 if (estimated_seconds_left < 60.0) {
709 strcpy(time_str, "<font color=\"red\">Less than a minute</font>");
710 } else if (estimated_seconds_left < 1800.0) { // Less than half an hour: Xm Ys (red).
711 int s = lrintf(estimated_seconds_left);
714 snprintf(time_str, sizeof(time_str), "<font color=\"red\">%dm %ds</font>", m, s);
715 } else if (estimated_seconds_left < 3600.0) { // Less than an hour: Xm.
716 int m = lrintf(estimated_seconds_left / 60.0);
717 snprintf(time_str, sizeof(time_str), "%dm", m);
718 } else if (estimated_seconds_left < 36000.0) { // Less than ten hours: Xh Ym.
719 int m = lrintf(estimated_seconds_left / 60.0);
722 snprintf(time_str, sizeof(time_str), "%dh %dm", h, m);
723 } else { // More than ten hours: Xh.
724 int h = lrintf(estimated_seconds_left / 3600.0);
725 snprintf(time_str, sizeof(time_str), "%dh", h);
728 snprintf(buf, sizeof(buf), "Disk free: %'.0f MB (approx. %s)", free_bytes / 1048576.0, time_str);
730 std::string label = buf;
732 post_to_main_thread([this, label] {
733 disk_free_label->setText(QString::fromStdString(label));
734 ui->menuBar->setCornerWidget(disk_free_label); // Need to set this again for the sizing to get right.
738 void MainWindow::exit_triggered()
743 void MainWindow::manual_triggered()
745 if (!QDesktopServices::openUrl(QUrl("https://nageru.sesse.net/doc/"))) {
747 msgbox.setText("Could not launch manual in web browser.\nPlease see https://nageru.sesse.net/doc/ manually.");
752 void MainWindow::about_triggered()
754 AboutDialog("Futatabi", "Multicamera slow motion video server").exec();
757 void MainWindow::highlight_camera_input(int stream_idx)
759 if (stream_idx == 0) {
760 ui->input1_frame->setStyleSheet("background: rgb(0,255,0)");
762 ui->input1_frame->setStyleSheet("");
764 if (stream_idx == 1) {
765 ui->input2_frame->setStyleSheet("background: rgb(0,255,0)");
767 ui->input2_frame->setStyleSheet("");
769 if (stream_idx == 2) {
770 ui->input3_frame->setStyleSheet("background: rgb(0,255,0)");
772 ui->input3_frame->setStyleSheet("");
774 if (stream_idx == 3) {
775 ui->input4_frame->setStyleSheet("background: rgb(0,255,0)");
777 ui->input4_frame->setStyleSheet("");
781 void MainWindow::set_output_status(const string &status)
783 ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
785 lock_guard<mutex> lock(queue_status_mu);
786 queue_status = status;
789 pair<string, string> MainWindow::get_queue_status() const {
790 lock_guard<mutex> lock(queue_status_mu);
791 return {queue_status, "text/plain"};