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