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