]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Show time remaining when playing clips live.
[nageru] / mainwindow.cpp
index febcacf950bd7d7004fab030de5ae85c675c84d8..c16861102ce4dada625002a8337ec82219ae2c62 100644 (file)
@@ -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 <string>
@@ -84,8 +85,13 @@ MainWindow::MainWindow()
 
        connect(ui->playlist_duplicate_btn, &QPushButton::clicked, this, &MainWindow::playlist_duplicate);
 
-       // TODO: support the delete key iff the widget has focus?
        connect(ui->playlist_remove_btn, &QPushButton::clicked, this, &MainWindow::playlist_remove);
+       QShortcut *delete_key = new QShortcut(QKeySequence(Qt::Key_Delete), ui->playlist);
+       connect(delete_key, &QShortcut::activated, [this] {
+               if (ui->playlist->hasFocus()) {
+                       playlist_remove();
+               }
+       });
 
        // TODO: support drag-and-drop.
        connect(ui->playlist_move_up_btn, &QPushButton::clicked, [this]{ playlist_move(-1); });
@@ -102,6 +108,11 @@ 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()
@@ -258,7 +269,28 @@ 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)