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