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