]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Split ClipList and PlayList.
[nageru] / mainwindow.cpp
index 74b67e4396f221ee552a1822f8e3a334792ea102..ddb08d57e7d3454144533b09a1d5d5bd795df5e3 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "clip_list.h"
 #include "player.h"
+#include "post_to_main_thread.h"
 #include "ui_mainwindow.h"
 
 #include <string>
@@ -13,7 +14,8 @@ using namespace std;
 
 MainWindow *global_mainwindow = nullptr;
 extern int64_t current_pts;
-ClipList *cliplist_clips, *playlist_clips;
+ClipList *cliplist_clips;
+PlayList *playlist_clips;
 
 MainWindow::MainWindow()
        : ui(new Ui::MainWindow)
@@ -21,10 +23,10 @@ MainWindow::MainWindow()
        global_mainwindow = this;
        ui->setupUi(this);
 
-       cliplist_clips = new ClipList(ClipList::ListDisplay::CLIP_LIST);
+       cliplist_clips = new ClipList();
        ui->clip_list->setModel(cliplist_clips);
 
-       playlist_clips = new ClipList(ClipList::ListDisplay::PLAY_LIST);
+       playlist_clips = new PlayList();
        ui->playlist->setModel(playlist_clips);
 
        // TODO: These are too big for lambdas.
@@ -63,6 +65,11 @@ MainWindow::MainWindow()
 
        preview_player = new Player(ui->preview_display);
        live_player = new Player(ui->live_display);
+       live_player->set_done_callback([this]{
+               post_to_main_thread([this]{
+                       live_player_clip_done();
+               });
+       });
 }
 
 void MainWindow::queue_clicked()
@@ -76,16 +83,18 @@ void MainWindow::queue_clicked()
        }
 
        QModelIndex index = selected->currentIndex();
-       if (index.column() >= int(ClipList::ClipListColumn::CAMERA_1) &&
-           index.column() <= int(ClipList::ClipListColumn::CAMERA_4)) {
+       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::ClipListColumn::CAMERA_1);
+               clip.stream_idx = index.column() - int(ClipList::Column::CAMERA_1);
                playlist_clips->add_clip(clip);
        }
 }
 
 void MainWindow::preview_clicked()
 {
+       if (cliplist_clips->empty()) return;
+
        QItemSelectionModel *selected = ui->clip_list->selectionModel();
        if (!selected->hasSelection()) {
                preview_player->play_clip(*cliplist_clips->back(), 0);
@@ -93,15 +102,17 @@ void MainWindow::preview_clicked()
        }
 
        QModelIndex index = selected->currentIndex();
-       if (index.column() >= int(ClipList::ClipListColumn::CAMERA_1) &&
-           index.column() <= int(ClipList::ClipListColumn::CAMERA_4)) {
-               unsigned stream_idx = index.column() - int(ClipList::ClipListColumn::CAMERA_1);
+       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);
        }
 }
 
 void MainWindow::play_clicked()
 {
+       if (playlist_clips->empty()) return;
+
        QItemSelectionModel *selected = ui->playlist->selectionModel();
        int row;
        if (!selected->hasSelection()) {
@@ -110,7 +121,34 @@ void MainWindow::play_clicked()
                row = selected->selectedRows(0)[0].row();
        }
 
-       const Clip &clip = *cliplist_clips->clip(row);
+       const Clip &clip = *playlist_clips->clip(row);
        live_player->play_clip(clip, clip.stream_idx);
        playlist_clips->set_currently_playing(row);
 }
+
+void MainWindow::live_player_clip_done()
+{
+       int row = playlist_clips->get_currently_playing();
+       if (row != -1 && row < int(playlist_clips->size()) - 1) {
+               ++row;
+               const Clip &clip = *playlist_clips->clip(row);
+               live_player->play_clip(clip, clip.stream_idx);
+               playlist_clips->set_currently_playing(row);
+       } else {
+               playlist_clips->set_currently_playing(-1);
+       }
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+       QMainWindow::resizeEvent(event);
+
+       // Ask for a relayout, but only after the event loop is done doing relayout
+       // on everything else.
+       QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
+}
+
+void MainWindow::relayout()
+{
+       ui->live_display->setMinimumHeight(ui->live_display->width() * 9 / 16);
+}