]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Expose the queue status over HTTP.
[nageru] / mainwindow.cpp
index 235911017c114666c6bd31ab4bd0e8bee23352dc..2fb897bb55e6e7215d9ee825010ac61594d1d910 100644 (file)
@@ -7,16 +7,14 @@
 #include "timebase.h"
 #include "ui_mainwindow.h"
 
-#include <future>
-#include <string>
-#include <vector>
-
 #include <QMouseEvent>
-#include <QWheelEvent>
 #include <QShortcut>
 #include <QTimer>
-
+#include <QWheelEvent>
+#include <future>
 #include <sqlite3.h>
+#include <string>
+#include <vector>
 
 using namespace std;
 using namespace std::placeholders;
@@ -54,6 +52,9 @@ MainWindow::MainWindow()
        ui->playlist->setModel(playlist_clips);
        connect(playlist_clips, &PlayList::any_content_changed, this, &MainWindow::content_changed);
 
+       // For un-highlighting when we lose focus.
+       ui->clip_list->installEventFilter(this);
+
        // For scrubbing in the pts columns.
        ui->clip_list->viewport()->installEventFilter(this);
        ui->playlist->viewport()->installEventFilter(this);
@@ -133,10 +134,14 @@ MainWindow::MainWindow()
                        live_player_clip_progress(played_this_clip, total_length);
                });
        });
+       set_output_status("paused");
 
        defer_timeout = new QTimer(this);
        defer_timeout->setSingleShot(true);
        connect(defer_timeout, &QTimer::timeout, this, &MainWindow::defer_timer_expired);
+
+       connect(ui->clip_list->selectionModel(), &QItemSelectionModel::currentChanged,
+               this, &MainWindow::clip_list_selection_changed);
 }
 
 void MainWindow::cue_in_clicked()
@@ -193,7 +198,8 @@ void MainWindow::queue_clicked()
 
 void MainWindow::preview_clicked()
 {
-       if (cliplist_clips->empty()) return;
+       if (cliplist_clips->empty())
+               return;
 
        QItemSelectionModel *selected = ui->clip_list->selectionModel();
        if (!selected->hasSelection()) {
@@ -309,7 +315,8 @@ void MainWindow::state_changed(const StateProto &state)
 
 void MainWindow::play_clicked()
 {
-       if (playlist_clips->empty()) return;
+       if (playlist_clips->empty())
+               return;
 
        QItemSelectionModel *selected = ui->playlist->selectionModel();
        int row;
@@ -329,7 +336,7 @@ void MainWindow::live_player_clip_done()
 {
        int row = playlist_clips->get_currently_playing();
        if (row == -1 || row == int(playlist_clips->size()) - 1) {
-               ui->live_label->setText("Current output (paused)");
+               set_output_status("paused");
                playlist_clips->set_currently_playing(-1, 0.0f);
        } else {
                playlist_clips->set_currently_playing(row + 1, 0.0f);
@@ -360,7 +367,7 @@ void MainWindow::live_player_clip_progress(double played_this_clip, double total
        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.
+               remaining += double(clip.pts_out - clip.pts_in) / TIMEBASE / 0.5;  // FIXME: stop hardcoding speed.
        }
        int remaining_ms = lrint(remaining * 1e3);
 
@@ -371,8 +378,8 @@ void MainWindow::live_player_clip_progress(double played_this_clip, double total
        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);
+       snprintf(buf, sizeof(buf), "%d:%02d.%03d left", m, s, ms);
+       set_output_status(buf);
 }
 
 void MainWindow::resizeEvent(QResizeEvent *event)
@@ -410,6 +417,13 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
 
        unsigned stream_idx = ui->preview_display->get_stream_idx();
 
+       if (watched == ui->clip_list) {
+               if (event->type() == QEvent::FocusOut) {
+                       highlight_camera_input(-1);
+               }
+               return false;
+       }
+
        if (event->type() != QEvent::Wheel) {
                last_mousewheel_camera_row = -1;
        }
@@ -431,7 +445,8 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
                }
                int column = destination->columnAt(mouse->x());
                int row = destination->rowAt(mouse->y());
-               if (column == -1 || row == -1) return false;
+               if (column == -1 || row == -1)
+                       return false;
 
                if (type == SCRUBBING_CLIP_LIST) {
                        if (ClipList::Column(column) == ClipList::Column::IN) {
@@ -583,7 +598,8 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind
 {
        if (rounding == LAST_BEFORE) {
                lock_guard<mutex> lock(frame_mu);
-               if (frames[stream_idx].empty()) return;
+               if (frames[stream_idx].empty())
+                       return;
                auto it = lower_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts);
                if (it != frames[stream_idx].end()) {
                        pts = *it;
@@ -591,7 +607,8 @@ void MainWindow::preview_single_frame(int64_t pts, unsigned stream_idx, MainWind
        } else {
                assert(rounding == FIRST_AT_OR_AFTER);
                lock_guard<mutex> lock(frame_mu);
-               if (frames[stream_idx].empty()) return;
+               if (frames[stream_idx].empty())
+                       return;
                auto it = upper_bound(frames[stream_idx].begin(), frames[stream_idx].end(), pts - 1);
                if (it != frames[stream_idx].end()) {
                        pts = *it;
@@ -617,6 +634,16 @@ void MainWindow::playlist_selection_changed()
        ui->play_btn->setEnabled(!playlist_clips->empty());
 }
 
+void MainWindow::clip_list_selection_changed(const QModelIndex &current, const QModelIndex &)
+{
+       int camera_selected = -1;
+       if (current.column() >= int(ClipList::Column::CAMERA_1) &&
+           current.column() <= int(ClipList::Column::CAMERA_4)) {
+               camera_selected = current.column() - int(ClipList::Column::CAMERA_1);
+       }
+       highlight_camera_input(camera_selected);
+}
+
 void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_left)
 {
        char time_str[256];
@@ -644,10 +671,10 @@ void MainWindow::report_disk_space(off_t free_bytes, double estimated_seconds_le
 
        std::string label = buf;
 
-       post_to_main_thread([this, label]{
-                       disk_free_label->setText(QString::fromStdString(label));
-                       ui->menuBar->setCornerWidget(disk_free_label);  // Need to set this again for the sizing to get right.
-                       });
+       post_to_main_thread([this, label] {
+               disk_free_label->setText(QString::fromStdString(label));
+               ui->menuBar->setCornerWidget(disk_free_label);  // Need to set this again for the sizing to get right.
+       });
 }
 
 void MainWindow::exit_triggered()
@@ -655,3 +682,39 @@ void MainWindow::exit_triggered()
        close();
 }
 
+void MainWindow::highlight_camera_input(int stream_idx)
+{
+       if (stream_idx == 0) {
+               ui->input1_frame->setStyleSheet("background: rgb(0,255,0)");
+       } else {
+               ui->input1_frame->setStyleSheet("");
+       }
+       if (stream_idx == 1) {
+               ui->input2_frame->setStyleSheet("background: rgb(0,255,0)");
+       } else {
+               ui->input2_frame->setStyleSheet("");
+       }
+       if (stream_idx == 2) {
+               ui->input3_frame->setStyleSheet("background: rgb(0,255,0)");
+       } else {
+               ui->input3_frame->setStyleSheet("");
+       }
+       if (stream_idx == 3) {
+               ui->input4_frame->setStyleSheet("background: rgb(0,255,0)");
+       } else {
+               ui->input4_frame->setStyleSheet("");
+       }
+}
+
+void MainWindow::set_output_status(const string &status)
+{
+       ui->live_label->setText(QString::fromStdString("Current output (" + status + ")"));
+
+       lock_guard<mutex> lock(queue_status_mu);
+       queue_status = status;
+}
+
+pair<string, string> MainWindow::get_queue_status() const {
+       lock_guard<mutex> lock(queue_status_mu);
+       return {queue_status, "text/plain"};
+}