]> git.sesse.net Git - nageru/commitdiff
Hook up some more clip modifications.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2018 22:18:25 +0000 (00:18 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2018 22:18:25 +0000 (00:18 +0200)
clip_list.cpp
clip_list.h
main.cpp
mainwindow.cpp
mainwindow.h

index 48d8e7bee1c2fbea127957ac3c0709bc7e0ed578..d8eada85d5eab338751738c2a863b1a7d7f84a5a 100644 (file)
@@ -37,6 +37,12 @@ QVariant ClipList::data(const QModelIndex &parent, int role) const {
                } else {
                        return QVariant();
                }
+       case 2:
+               if (clips[row].pts_out >= 0) {
+                       return qlonglong(clips[row].pts_out - clips[row].pts_in);
+               } else {
+                       return QVariant();
+               }
        default:
                return QVariant();
        }
@@ -68,12 +74,14 @@ QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role
        }
 }
 
-void ClipList::add_clip(int64_t pts_in)
+void ClipList::add_clip(const Clip &clip)
 {
-       Clip clip;
-       clip.pts_in = pts_in;
-
        beginInsertRows(QModelIndex(), clips.size(), clips.size());
        clips.push_back(clip);
        endInsertRows();
 }
+
+void ClipList::emit_data_changed(size_t row)
+{
+       emit dataChanged(index(row, 0), index(row, 6));
+}
index adf3748aec8ba96da394f92aae61fc5a0e14d7d8..cb58564b33a47ea42b818842d022f011b775ddeb 100644 (file)
@@ -22,8 +22,35 @@ public:
        QVariant data(const QModelIndex &parent, int role) const override;
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
 
-       void add_clip(int64_t pts_in);
+       void add_clip(const Clip &clip);
        size_t size() const { return clips.size(); }
+       bool empty() const { return clips.empty(); }
+
+       // Like a smart pointer to a Clip, but emits dataChanged when it goes out of scope.
+       struct ClipProxy {
+       public:
+               ClipProxy(Clip &clip, ClipList *clip_list, size_t row)
+                       : clip(clip), clip_list(clip_list), row(row) {}
+               ~ClipProxy() {
+                       if (clip_list != nullptr) {
+                               clip_list->emit_data_changed(row);
+                       }
+               }
+               Clip *operator->() { return &clip; }
+
+       private:
+               Clip &clip;
+               ClipList *clip_list;
+               size_t row;
+       };
+
+       ClipProxy clip(size_t index) { return ClipProxy(clips[index], this, index); }
+       const Clip *clip(size_t index) const { return &clips[index]; }
+
+       ClipProxy back() { return clip(size() - 1); }
+       const Clip *back() const { return clip(size() - 1); }
+
+       void emit_data_changed(size_t row);
 
 private:
        std::vector<Clip> clips;
index 526ed575e32581ba6bedee5a63abd9d0ad3e1a86..865b98b82a3883693eacac6b88dd06b5548073c0 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -25,6 +25,9 @@ extern "C" {
 using namespace std;
 using namespace std::chrono;
 
+// TODO: Replace by some sort of GUI control, I guess.
+int64_t current_pts = 0;
+
 string filename_for_frame(unsigned stream_idx, int64_t pts)
 {
        char filename[256];
@@ -100,6 +103,7 @@ int thread_func()
                        this_thread::sleep_for(microseconds((pkt.pts - last_pts) * 1000000 / 12800));
                }
                last_pts = pkt.pts;
+               current_pts = pkt.pts;
        }
 
        return 0;
index e14834502e216cac0ba61a9672f6a9dafbf223b0..9db4a9bcb8eb29284a83dd3350b1fca24b58c929 100644 (file)
@@ -11,6 +11,7 @@
 using namespace std;
 
 MainWindow *global_mainwindow = nullptr;
+extern int64_t current_pts;
 
 MainWindow::MainWindow()
        : ui(new Ui::MainWindow)
@@ -21,8 +22,32 @@ MainWindow::MainWindow()
        ClipList *clips = new ClipList;
        ui->clip_list->setModel(clips);
 
-       QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Q), this);
-       connect(shortcut, &QShortcut::activated, [clips]{
-               clips->add_clip(12345);
+       // TODO: Make these into buttons.
+       // TODO: These are too big for lambdas.
+       QShortcut *cue_in = new QShortcut(QKeySequence(Qt::Key_A), this);
+       connect(cue_in, &QShortcut::activated, [clips]{
+               if (!clips->empty() && clips->back()->pts_out < 0) {
+                       clips->back()->pts_in = current_pts;
+                       return;
+               }
+               Clip clip;
+               clip.pts_in = current_pts;
+               clips->add_clip(clip);
        });
+
+       QShortcut *cue_out = new QShortcut(QKeySequence(Qt::Key_S), this);
+       connect(cue_out, &QShortcut::activated, [clips]{
+               if (!clips->empty()) {
+                       clips->back()->pts_out = current_pts;
+                       // TODO: select the row in the clip list?
+               }
+       });
+
+       QShortcut *preview_shortcut = new QShortcut(QKeySequence(Qt::Key_W), this);
+       connect(preview_shortcut, &QShortcut::activated, this, &MainWindow::preview_clicked);
+}
+
+void MainWindow::preview_clicked()
+{
+       printf("preview\n");
 }
index f17757fe335859be1b1e49d25116c4a89f9a8614..a1254b1fdd915828fa0bd4bd016f73eb72c54a19 100644 (file)
@@ -18,6 +18,9 @@ public:
 
 //private:
        Ui::MainWindow *ui;
+
+private:
+       void preview_clicked();
 };
 
 extern MainWindow *global_mainwindow;