6 #include "midi_mapper.h"
10 #include <QMainWindow>
11 #include <QNetworkAccessManager>
17 #include <sys/types.h>
30 class MainWindow : public QMainWindow, public ControllerReceiver {
37 // HTTP callback. TODO: Does perhaps not belong to MainWindow?
38 std::pair<std::string, std::string> get_queue_status() const;
40 void display_frame(unsigned stream_idx, const FrameOnDisk &frame);
42 // ControllerReceiver interface.
43 void preview() override;
44 void queue() override;
46 void toggle_lock() override;
47 void jog(int delta) override;
48 void switch_camera(unsigned camera_idx) override;
49 void set_master_speed(float speed) override;
50 void cue_in() override;
51 void cue_out() override;
53 // Raw receivers are not used.
54 void controller_changed(unsigned controller) override {}
55 void note_on(unsigned note) override {}
60 QLabel *disk_free_label;
61 std::unique_ptr<Player> preview_player, live_player;
65 // State when doing a scrub operation on a timestamp with the mouse.
66 bool scrubbing = false;
67 int scrub_x_origin; // In pixels on the viewport.
68 int64_t scrub_pts_origin;
70 // Which element (e.g. pts_in on clip 4) we are scrubbing.
71 enum ScrubType { SCRUBBING_CLIP_LIST,
72 SCRUBBING_PLAYLIST } scrub_type;
76 // Used to keep track of small mouse wheel motions on the camera index in the playlist.
77 int last_mousewheel_camera_row = -1;
78 int leftover_angle_degrees = 0;
80 // Normally, jog is only allowed if in the focus (well, selection) is
81 // on the in or out pts columns. However, changing camera (even when
82 // using a MIDI button) on the clip list changes the highlight,
83 // and we'd like to keep on jogging. Thus, as a special case, if you
84 // change to a camera column on the clip list (and don't change which
85 // clip you're looking at), the last column you were at will be stored here.
86 // If you then try to jog, we'll fetch the value from here and highlight it.
87 // Doing pretty much anything else is going to reset it back to -1, though.
88 int hidden_jog_column = -1;
90 // Some operations, notably scrubbing and scrolling, happen in so large increments
91 // that we want to group them instead of saving to disk every single time.
92 // If they happen (ie., we get a callback from the model that it's changed) while
93 // currently_deferring_model_changes, we fire off this timer. If it manages to elapse
94 // before some other event happens, we count the event. (If the other event is of the
95 // same kind, we just fire off the timer anew instead of taking any action.)
96 QTimer *defer_timeout;
97 std::string deferred_change_id;
98 StateProto deferred_state;
100 // NOTE: The undo stack always has the current state on top.
101 std::deque<StateProto> undo_stack, redo_stack;
103 // If we need to blink the lock light, we do so for only a second.
104 // This timer signals that we should end it.
105 QTimer *lock_blink_timeout;
107 // Before a change that should be deferred (see above), currently_deferring_model_changes
108 // must be set to true, and current_change_id must be given contents describing what's
109 // changed to avoid accidental grouping.
110 bool currently_deferring_model_changes = false;
111 std::string current_change_id;
113 mutable std::mutex queue_status_mu;
114 std::string queue_status; // Under queue_status_mu.
116 struct FrameAndDisplay {
118 JPEGFrameView *display;
119 QPushButton *preview_btn;
121 std::vector<FrameAndDisplay> displays;
123 // Used to get tally information, if a tally URL is set.
124 QNetworkAccessManager http;
125 QNetworkReply *http_reply = nullptr;
127 MIDIMapper midi_mapper;
129 void change_num_cameras();
130 void cue_in_clicked();
131 void cue_out_clicked();
132 void queue_clicked();
133 void preview_clicked();
134 void preview_angle_clicked(unsigned stream_idx);
137 void speed_slider_changed(int percent);
138 void speed_lock_clicked();
139 void live_player_done();
140 void live_player_clip_progress(const std::map<uint64_t, double> &progress, double time_remaining);
141 void set_output_status(const std::string &status);
142 void playlist_duplicate();
143 void playlist_remove();
144 void playlist_move(int delta);
146 enum JogDestination { JOG_CLIP_LIST, JOG_PLAYLIST };
147 void jog_internal(JogDestination jog_destination, int column, int row, int stream_idx, int pts_delta);
149 void defer_timer_expired();
150 void content_changed(); // In clip_list or play_list.
151 void state_changed(const StateProto &state); // Called post-filtering.
152 void save_settings();
154 void lock_blink_timer_expired();
156 enum Rounding { FIRST_AT_OR_AFTER,
158 void preview_single_frame(int64_t pts, unsigned stream_idx, Rounding rounding);
160 // Also covers when the playlist itself changes.
161 void playlist_selection_changed();
163 void clip_list_selection_changed(const QModelIndex ¤t, const QModelIndex &previous);
165 void resizeEvent(QResizeEvent *event) override;
166 bool eventFilter(QObject *watched, QEvent *event) override;
168 void report_disk_space(off_t free_bytes, double estimated_seconds_left);
169 void exit_triggered();
170 void export_cliplist_clip_multitrack_triggered();
171 void export_playlist_clip_interpolated_triggered();
172 void manual_triggered();
173 void about_triggered();
174 void undo_triggered();
175 void redo_triggered();
176 void quality_toggled(int quality, bool checked);
177 void padding_toggled(double seconds, bool checked);
179 void highlight_camera_input(int stream_idx);
180 void enable_or_disable_preview_button();
181 void enable_or_disable_queue_button();
183 template<class Model>
184 void replace_model(QTableView *view, Model **model, Model *new_model);
187 void tally_received();
193 extern MainWindow *global_mainwindow;