]> git.sesse.net Git - nageru/blob - futatabi/mainwindow.h
Make the number of cameras dynamic as the frames come in.
[nageru] / futatabi / mainwindow.h
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3
4 #include "clip_list.h"
5 #include "db.h"
6 #include "state.pb.h"
7
8 #include <deque>
9 #include <memory>
10 #include <mutex>
11 #include <QLabel>
12 #include <QMainWindow>
13 #include <stdbool.h>
14 #include <sys/types.h>
15 #include <string>
16 #include <utility>
17
18 namespace Ui {
19 class MainWindow;
20 }  // namespace Ui
21
22 struct FrameOnDisk;
23 class JPEGFrameView;
24 class Player;
25 class QPushButton;
26 class QTableView;
27
28 class MainWindow : public QMainWindow {
29         Q_OBJECT
30
31 public:
32         MainWindow();
33         ~MainWindow();
34
35         // HTTP callback. TODO: Does perhaps not belong to MainWindow?
36         std::pair<std::string, std::string> get_queue_status() const;
37
38         void display_frame(unsigned stream_idx, const FrameOnDisk &frame);
39
40 private:
41         Ui::MainWindow *ui;
42
43         QLabel *disk_free_label;
44         std::unique_ptr<Player> preview_player, live_player;
45         DB db;
46         unsigned num_cameras;
47
48         // State when doing a scrub operation on a timestamp with the mouse.
49         bool scrubbing = false;
50         int scrub_x_origin;  // In pixels on the viewport.
51         int64_t scrub_pts_origin;
52
53         // Which element (e.g. pts_in on clip 4) we are scrubbing.
54         enum ScrubType { SCRUBBING_CLIP_LIST, SCRUBBING_PLAYLIST } scrub_type;
55         int scrub_row;
56         int scrub_column;
57
58         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
59         int last_mousewheel_camera_row = -1;
60         int leftover_angle_degrees = 0;
61
62         // Some operations, notably scrubbing and scrolling, happen in so large increments
63         // that we want to group them instead of saving to disk every single time.
64         // If they happen (ie., we get a callback from the model that it's changed) while
65         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
66         // before some other event happens, we count the event. (If the other event is of the
67         // same kind, we just fire off the timer anew instead of taking any action.)
68         QTimer *defer_timeout;
69         std::string deferred_change_id;
70         StateProto deferred_state;
71
72         // NOTE: The undo stack always has the current state on top.
73         std::deque<StateProto> undo_stack, redo_stack;
74
75         // Before a change that should be deferred (see above), currently_deferring_model_changes
76         // must be set to true, and current_change_id must be given contents describing what's
77         // changed to avoid accidental grouping.
78         bool currently_deferring_model_changes = false;
79         std::string current_change_id;
80
81         mutable std::mutex queue_status_mu;
82         std::string queue_status;  // Under queue_status_mu.
83
84         struct FrameAndDisplay {
85                 QFrame *frame;
86                 JPEGFrameView *display;
87                 QPushButton *preview_btn;
88         };
89         std::vector<FrameAndDisplay> displays;
90
91         void change_num_cameras();
92         void cue_in_clicked();
93         void cue_out_clicked();
94         void queue_clicked();
95         void preview_clicked();
96         void preview_angle_clicked(unsigned stream_idx);
97         void play_clicked();
98         void stop_clicked();
99         void live_player_clip_done();
100         std::pair<Clip, size_t> live_player_get_next_clip();
101         void live_player_clip_progress(const std::map<size_t, double> &progress);
102         void set_output_status(const std::string &status);
103         void playlist_duplicate();
104         void playlist_remove();
105         void playlist_move(int delta);
106
107         void defer_timer_expired();
108         void content_changed();  // In clip_list or play_list.
109         void state_changed(const StateProto &state);  // Called post-filtering.
110         void save_settings();
111
112         enum Rounding { FIRST_AT_OR_AFTER, LAST_BEFORE };
113         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
114
115         // Also covers when the playlist itself changes.
116         void playlist_selection_changed();
117
118         void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
119
120         void resizeEvent(QResizeEvent *event) override;
121         bool eventFilter(QObject *watched, QEvent *event) override;
122
123         void report_disk_space(off_t free_bytes, double estimated_seconds_left);
124         void exit_triggered();
125         void export_cliplist_clip_multitrack_triggered();
126         void export_playlist_clip_interpolated_triggered();
127         void manual_triggered();
128         void about_triggered();
129         void undo_triggered();
130         void redo_triggered();
131         void quality_toggled(int quality, bool checked);
132
133         void highlight_camera_input(int stream_idx);
134
135         template <class Model>
136         void replace_model(QTableView *view, Model **model, Model *new_model);
137
138 private slots:
139         void relayout();
140 };
141
142 extern MainWindow *global_mainwindow;
143
144 #endif