]> git.sesse.net Git - nageru/blob - futatabi/mainwindow.h
Log a warning when we kill a client that is not keeping up.
[nageru] / futatabi / mainwindow.h
1 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
3
4 #include "clip_list.h"
5 #include "db.h"
6 #include "midi_mapper.h"
7 #include "player.h"
8 #include "state.pb.h"
9
10 #include <QLabel>
11 #include <QMainWindow>
12 #include <QNetworkAccessManager>
13 #include <deque>
14 #include <memory>
15 #include <mutex>
16 #include <stdbool.h>
17 #include <string>
18 #include <sys/types.h>
19 #include <utility>
20
21 namespace Ui {
22 class MainWindow;
23 }  // namespace Ui
24
25 struct FrameOnDisk;
26 class JPEGFrameView;
27 class Player;
28 class QPushButton;
29 class QTableView;
30
31 class MainWindow : public QMainWindow, public ControllerReceiver {
32         Q_OBJECT
33
34 public:
35         MainWindow();
36         ~MainWindow();
37
38         // HTTP callback. TODO: Does perhaps not belong to MainWindow?
39         std::pair<std::string, std::string> get_queue_status() const;
40
41         void display_frame(unsigned stream_idx, const FrameOnDisk &frame);
42
43         // ControllerReceiver interface.
44         void preview() override;
45         void queue() override;
46         void play() override;
47         void next() override;
48         void toggle_lock() override;
49         void jog(int delta) override;
50         void switch_camera(unsigned camera_idx) override;
51         void set_master_speed(float speed) override;
52         void cue_in() override;
53         void cue_out() override;
54
55         // Raw receivers are not used.
56         void controller_changed(unsigned controller) override {}
57         void note_on(unsigned note) override {}
58
59 private:
60         Ui::MainWindow *ui;
61
62         QLabel *disk_free_label;
63         std::unique_ptr<Player> preview_player, live_player;
64         bool preview_playing = false;
65         DB db;
66         unsigned num_cameras;
67
68         // State when doing a scrub operation on a timestamp with the mouse.
69         bool scrubbing = false;
70         int scrub_x_origin;  // In pixels on the viewport.
71         int64_t scrub_pts_origin;
72
73         // Which element (e.g. pts_in on clip 4) we are scrubbing.
74         enum ScrubType { SCRUBBING_CLIP_LIST,
75                          SCRUBBING_PLAYLIST } scrub_type;
76         int scrub_row;
77         int scrub_column;
78
79         // Used to keep track of small mouse wheel motions on the camera index in the playlist.
80         int last_mousewheel_camera_row = -1;
81         int leftover_angle_degrees = 0;
82
83         // Normally, jog is only allowed if in the focus (well, selection) is
84         // on the in or out pts columns. However, changing camera (even when
85         // using a MIDI button) on the clip list changes the highlight,
86         // and we'd like to keep on jogging. Thus, as a special case, if you
87         // change to a camera column on the clip list (and don't change which
88         // clip you're looking at), the last column you were at will be stored here.
89         // If you then try to jog, we'll fetch the value from here and highlight it.
90         // Doing pretty much anything else is going to reset it back to -1, though.
91         int hidden_jog_column = -1;
92
93         // Some operations, notably scrubbing and scrolling, happen in so large increments
94         // that we want to group them instead of saving to disk every single time.
95         // If they happen (ie., we get a callback from the model that it's changed) while
96         // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
97         // before some other event happens, we count the event. (If the other event is of the
98         // same kind, we just fire off the timer anew instead of taking any action.)
99         QTimer *defer_timeout;
100         std::string deferred_change_id;
101         StateProto deferred_state;
102
103         // NOTE: The undo stack always has the current state on top.
104         std::deque<StateProto> undo_stack, redo_stack;
105
106         // If we need to blink the lock light, we do so for only a second.
107         // This timer signals that we should end it.
108         QTimer *lock_blink_timeout;
109
110         // Before a change that should be deferred (see above), currently_deferring_model_changes
111         // must be set to true, and current_change_id must be given contents describing what's
112         // changed to avoid accidental grouping.
113         bool currently_deferring_model_changes = false;
114         std::string current_change_id;
115
116         mutable std::mutex queue_status_mu;
117         std::string queue_status;  // Under queue_status_mu.
118
119         struct FrameAndDisplay {
120                 QFrame *frame;
121                 JPEGFrameView *display;
122                 QPushButton *preview_btn;
123                 bool hidden = false;
124         };
125         std::vector<FrameAndDisplay> displays;
126
127         // Used to get tally information, if a tally URL is set.
128         QNetworkAccessManager http;
129         QNetworkReply *http_reply = nullptr;
130
131         MIDIMapper midi_mapper;
132
133         void change_num_cameras();
134         void relayout_displays();
135         void cue_in_clicked();
136         void cue_out_clicked();
137         void queue_clicked();
138         void preview_clicked();
139         void preview_angle_clicked(unsigned stream_idx);
140         void play_clicked();
141         void next_clicked();
142         void stop_clicked();
143         void speed_slider_changed(int percent);
144         void speed_lock_clicked();
145         void preview_player_done();
146         void live_player_done();
147         void live_player_clip_progress(const std::map<uint64_t, double> &progress, TimeRemaining time_remaining);
148         void set_output_status(const std::string &status);
149         void playlist_duplicate();
150         void playlist_remove();
151         void playlist_move(int delta);
152
153         enum JogDestination { JOG_CLIP_LIST, JOG_PLAYLIST };
154         void jog_internal(JogDestination jog_destination, int column, int row, int stream_idx, int pts_delta);
155
156         void defer_timer_expired();
157         void content_changed();  // In clip_list or play_list.
158         void state_changed(const StateProto &state);  // Called post-filtering.
159         void save_settings();
160
161         void lock_blink_timer_expired();
162
163         enum Rounding { FIRST_AT_OR_AFTER,
164                         LAST_BEFORE };
165         void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
166
167         // Also covers when the playlist itself changes.
168         void playlist_selection_changed();
169
170         void clip_list_selection_changed(const QModelIndex &current, const QModelIndex &previous);
171         std::vector<ClipWithID> get_playlist(size_t start_row, size_t end_row);
172
173         void resizeEvent(QResizeEvent *event) override;
174         bool eventFilter(QObject *watched, QEvent *event) override;
175
176         void report_disk_space(off_t free_bytes, double estimated_seconds_left);
177         void midi_mapping_triggered();
178         void exit_triggered();
179         void export_cliplist_clip_multitrack_triggered();
180         void export_playlist_clip_interpolated_triggered();
181         void manual_triggered();
182         void about_triggered();
183         void undo_triggered();
184         void redo_triggered();
185         void quality_toggled(int quality, bool checked);
186         void in_padding_toggled(double seconds, bool checked);
187         void out_padding_toggled(double seconds, bool checked);
188         void hide_camera_toggled(unsigned camera_idx, bool checked);
189
190         void highlight_camera_input(int stream_idx);
191         void enable_or_disable_preview_button();
192         void enable_or_disable_queue_button();
193
194         template<class Model>
195         void replace_model(QTableView *view, Model **model, Model *new_model);
196
197         void start_tally();
198         void tally_received();
199
200 private slots:
201         void relayout();
202 };
203
204 extern MainWindow *global_mainwindow;
205
206 #endif