]> git.sesse.net Git - nageru/blobdiff - clip_list.h
Allow symlinked frame files. Useful for testing.
[nageru] / clip_list.h
index 076d4930ad718e34ccfd37627720ef305ca001a5..8dead831106e74783704ad5fab8ea6b9eb9eb675 100644 (file)
@@ -1,23 +1,25 @@
 #ifndef _CLIP_LIST_H
 #define _CLIP_LIST_H 1
 
-#include <QAbstractTableModel>
+#include "defs.h"
+#include "state.pb.h"
 
+#include <QAbstractTableModel>
 #include <stdint.h>
-
-#include <vector>
+#include <map>
 #include <string>
-
-#include "defs.h"
+#include <vector>
 
 struct Clip {
        int64_t pts_in = -1, pts_out = -1;  // pts_in is inclusive, pts_out is exclusive.
        std::string descriptions[NUM_CAMERAS];
        unsigned stream_idx = 0;  // For the playlist only.
+       double fade_time_seconds = 0.5;  // For the playlist only.
 };
 
 class DataChangedReceiver {
 public:
+       virtual ~DataChangedReceiver() {}
        virtual void emit_data_changed(size_t row) = 0;
 };
 
@@ -26,7 +28,8 @@ struct ClipProxy {
 public:
        ClipProxy(Clip &clip, DataChangedReceiver *clip_list, size_t row)
                : clip(clip), clip_list(clip_list), row(row) {}
-       ~ClipProxy() {
+       ~ClipProxy()
+       {
                if (clip_list != nullptr) {
                        clip_list->emit_data_changed(row);
                }
@@ -44,7 +47,7 @@ class ClipList : public QAbstractTableModel, public DataChangedReceiver {
        Q_OBJECT
 
 public:
-       ClipList() {}
+       explicit ClipList(const ClipListProto &serialized);
 
        enum class Column {
                IN,
@@ -68,14 +71,19 @@ public:
        size_t size() const { return clips.size(); }
        bool empty() const { return clips.empty(); }
 
-       ClipProxy clip(size_t index) { return ClipProxy(clips[index], this, index); }
+       ClipProxy mutable_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); }
+       ClipProxy mutable_back() { return mutable_clip(size() - 1); }
        const Clip *back() const { return clip(size() - 1); }
 
+       ClipListProto serialize() const;
+
        void emit_data_changed(size_t row) override;
 
+signals:
+       void any_content_changed();
+
 private:
        std::vector<Clip> clips;
 };
@@ -84,7 +92,7 @@ class PlayList : public QAbstractTableModel, public DataChangedReceiver {
        Q_OBJECT
 
 public:
-       PlayList() {}
+       explicit PlayList(const ClipListProto &serialized);
 
        enum class Column {
                PLAYING,
@@ -93,6 +101,7 @@ public:
                DURATION,
                CAMERA,
                DESCRIPTION,
+               FADE_TIME,
                NUM_COLUMNS
        };
 
@@ -100,25 +109,44 @@ public:
        int columnCount(const QModelIndex &parent) const override;
        QVariant data(const QModelIndex &parent, int role) const override;
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+       Qt::ItemFlags flags(const QModelIndex &index) const override;
+       bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
 
        void add_clip(const Clip &clip);
+
+       // <last> is inclusive in all of these.
+       void duplicate_clips(size_t first, size_t last);
+       void erase_clips(size_t first, size_t last);
+       // <delta> is -1 to move upwards, +1 to move downwards.
+       void move_clips(size_t first, size_t last, int delta);
+
        size_t size() const { return clips.size(); }
        bool empty() const { return clips.empty(); }
 
-       ClipProxy clip(size_t index) { return ClipProxy(clips[index], this, index); }
+       ClipProxy mutable_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); }
+       ClipProxy mutable_back() { return mutable_clip(size() - 1); }
        const Clip *back() const { return clip(size() - 1); }
 
-       void set_currently_playing(int index);  // -1 = none.
+       // TODO: Move these out of PlayList.
+       void set_currently_playing(int index, double progress);  // -1 = none.
        int get_currently_playing() const { return currently_playing_index; }
 
+       void set_progress(const std::map<size_t, double> &progress);
+
+       ClipListProto serialize() const;
+
        void emit_data_changed(size_t row) override;
 
+signals:
+       void any_content_changed();
+
 private:
        std::vector<Clip> clips;
        int currently_playing_index = -1;
+       double play_progress = 0.0;
+       std::map<size_t, double> current_progress;
 };
 
 #endif  // !defined (_CLIP_LIST_H)