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<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);
});
connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
this, &MainWindow::clip_list_selection_changed);
+ enable_or_disable_queue_button();
// Find out how many cameras we have in the existing frames;
// if none, we start with two cameras.
{
if (!cliplist_clips->empty() && cliplist_clips->back()->pts_out < 0) {
cliplist_clips->mutable_back()->pts_in = current_pts;
- return;
+ } else {
+ Clip clip;
+ clip.pts_in = max<int64_t>(current_pts - lrint(global_flags.cue_point_padding_seconds * TIMEBASE), 0);
+ cliplist_clips->add_clip(clip);
+ playlist_selection_changed();
}
- Clip clip;
- clip.pts_in = max<int64_t>(current_pts - lrint(global_flags.cue_point_padding_seconds * TIMEBASE), 0);
- cliplist_clips->add_clip(clip);
- playlist_selection_changed();
+
+ // Select the item so that we can jog it.
+ ui->clip_list->setFocus();
+ QModelIndex index = cliplist_clips->index(cliplist_clips->size() - 1, int(ClipList::Column::IN));
+ ui->clip_list->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
ui->clip_list->scrollToBottom();
+ enable_or_disable_queue_button();
}
void MainWindow::cue_out_clicked()
{
- if (!cliplist_clips->empty()) {
- cliplist_clips->mutable_back()->pts_out = current_pts + lrint(global_flags.cue_point_padding_seconds * TIMEBASE);
- // TODO: select the row in the clip list?
+ if (cliplist_clips->empty()) {
+ return;
}
+
+ cliplist_clips->mutable_back()->pts_out = current_pts + lrint(global_flags.cue_point_padding_seconds * TIMEBASE);
+
+ // Select the item so that we can jog it.
+ ui->clip_list->setFocus();
+ QModelIndex index = cliplist_clips->index(cliplist_clips->size() - 1, int(ClipList::Column::OUT));
+ ui->clip_list->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
+ ui->clip_list->scrollToBottom();
+ enable_or_disable_queue_button();
}
void MainWindow::queue_clicked()
{
+ // See also enable_or_disable_queue_button().
+
if (cliplist_clips->empty()) {
return;
}
void MainWindow::preview_clicked()
{
+ // See also enable_or_disable_preview_button().
+
if (ui->playlist->hasFocus()) {
// Allow the playlist as preview iff it has focus and something is selected.
QItemSelectionModel *selected = ui->playlist->selectionModel();
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.
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 } });
- playlist_clips->set_currently_playing(start_row, 0.0f);
+ ui->playlist->selectionModel()->clear();
playlist_selection_changed();
ui->stop_btn->setEnabled(true);
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);
+ ui->stop_btn->setEnabled(false);
}
-void MainWindow::live_player_clip_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);
- ui->stop_btn->setEnabled(false);
- } else {
- playlist_clips->set_progress({ { row + 1, 0.0f } });
- playlist_clips->set_currently_playing(row + 1, 0.0f);
- }
-}
-
-static string format_duration(double t)
+void MainWindow::live_player_done()
{
- int t_ms = lrint(t * 1e3);
-
- int ms = t_ms % 1000;
- t_ms /= 1000;
- int s = t_ms % 60;
- t_ms /= 60;
- int m = t_ms;
-
- char buf[256];
- snprintf(buf, sizeof(buf), "%d:%02d.%03d", m, s, ms);
- return buf;
+ playlist_selection_changed();
+ playlist_clips->set_progress({});
+ ui->stop_btn->setEnabled(false);
}
-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");
int scrub_sensitivity = 100; // pts units per pixel.
int wheel_sensitivity = 100; // pts units per degree.
+ if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {
+ enable_or_disable_preview_button();
+ }
+
unsigned stream_idx = ui->preview_display->get_stream_idx();
if (watched == ui->clip_list) {
Clip fake_clip;
fake_clip.pts_in = pts;
fake_clip.pts_out = pts + 1;
+ fake_clip.stream_idx = stream_idx;
preview_player->play(fake_clip);
}
void MainWindow::playlist_selection_changed()
{
+ enable_or_disable_preview_button();
+
QItemSelectionModel *selected = ui->playlist->selectionModel();
bool any_selected = selected->hasSelection();
ui->playlist_duplicate_btn->setEnabled(any_selected);
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");
camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
}
highlight_camera_input(camera_selected);
+ enable_or_disable_queue_button();
}
void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
}
}
+void MainWindow::enable_or_disable_preview_button()
+{
+ // Follows the logic in preview_clicked().
+
+ if (ui->playlist->hasFocus()) {
+ // Allow the playlist as preview iff it has focus and something is selected.
+ // TODO: Is this part really relevant?
+ QItemSelectionModel *selected = ui->playlist->selectionModel();
+ if (selected->hasSelection()) {
+ ui->preview_btn->setEnabled(true);
+ return;
+ }
+ }
+
+ // TODO: Perhaps only enable this if something is actually selected.
+ ui->preview_btn->setEnabled(!cliplist_clips->empty());
+}
+
+void MainWindow::enable_or_disable_queue_button()
+{
+ // Follows the logic in queue_clicked().
+ // TODO: Perhaps only enable this if something is actually selected.
+
+ bool enabled;
+
+ if (cliplist_clips->empty()) {
+ enabled = false;
+ } else {
+ QItemSelectionModel *selected = ui->clip_list->selectionModel();
+ if (!selected->hasSelection()) {
+ Clip clip = *cliplist_clips->back();
+ enabled = clip.pts_out != -1;
+ } else {
+ QModelIndex index = selected->currentIndex();
+ Clip clip = *cliplist_clips->clip(index.row());
+ enabled = clip.pts_out != -1;
+ }
+ }
+
+ ui->queue_btn->setEnabled(enabled);
+}
+
void MainWindow::set_output_status(const string &status)
{
ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
+ if (live_player != nullptr) {
+ live_player->set_pause_status(status);
+ }
lock_guard<mutex> lock(queue_status_mu);
queue_status = status;