Olive
timeline.h
1 /***
2 
3  Olive - Non-Linear Video Editor
4  Copyright (C) 2019 Olive Team
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 ***/
20 
21 #ifndef TIMELINE_H
22 #define TIMELINE_H
23 
24 #include "ui/timelinetools.h"
25 #include "project/selection.h"
26 
27 #include <QDockWidget>
28 #include <QVector>
29 #include <QTime>
30 
31 #define TRACK_DEFAULT_HEIGHT 40
32 
33 #define ADD_OBJ_TITLE 0
34 #define ADD_OBJ_SOLID 1
35 #define ADD_OBJ_BARS 2
36 #define ADD_OBJ_TONE 3
37 #define ADD_OBJ_NOISE 4
38 #define ADD_OBJ_AUDIO 5
39 
40 class QPushButton;
41 class SourceTable;
42 class ViewerWidget;
43 class ComboAction;
44 class Effect;
45 class Media;
46 class Transition;
47 class TimelineHeader;
48 class TimelineWidget;
49 class ResizableScrollBar;
50 class AudioMonitor;
51 class QScrollBar;
52 struct EffectMeta;
53 struct Sequence;
54 class Clip;
55 struct Footage;
56 struct FootageStream;
57 
58 bool is_clip_selected(Clip* clip, bool containing);
59 int getScreenPointFromFrame(double zoom, long frame);
60 long getFrameFromScreenPoint(double zoom, int x);
61 bool selection_contains_transition(const Selection& s, Clip* c, int type);
62 void move_clip(ComboAction *ca, Clip *c, long iin, long iout, long iclip_in, int itrack, bool verify_transitions = true, bool relative = false);
63 void ripple_clips(ComboAction *ca, Sequence* s, long point, long length, const QVector<int>& ignore = QVector<int>());
64 
65 struct Ghost {
66  int clip;
67  long in;
68  long out;
69  int track;
70  long clip_in;
71 
72  long old_in;
73  long old_out;
74  int old_track;
75  long old_clip_in;
76 
77  // importing variables
78  Media* media;
79  int media_stream;
80 
81  // other variables
82  long ghost_length;
83  long media_length;
84  bool trim_in;
85  bool trimming;
86 
87  // transition trimming
88  Transition* transition;
89 };
90 
91 class Timeline : public QDockWidget
92 {
93  Q_OBJECT
94 public:
95  explicit Timeline(QWidget *parent = nullptr);
96  ~Timeline();
97 
98  bool focused();
99  void multiply_zoom(double m);
100  void copy(bool del);
101  Clip* split_clip(ComboAction* ca, bool transitions, int p, long frame);
102  Clip* split_clip(ComboAction* ca, bool transitions, int p, long frame, long post_in);
103  bool split_selection(ComboAction* ca);
104  bool split_all_clips_at_point(ComboAction *ca, long point);
105  bool split_clip_and_relink(ComboAction* ca, int clip, long frame, bool relink);
106  void clean_up_selections(QVector<Selection>& areas);
107  void deselect_area(long in, long out, int track);
108  void delete_areas_and_relink(ComboAction *ca, QVector<Selection>& areas, bool deselect_areas);
109  void relink_clips_using_ids(QVector<int>& old_clips, QVector<Clip*>& new_clips);
110  void update_sequence();
111 
112  QVector<int> get_tracks_of_linked_clips(int i);
113  bool has_clip_been_split(int c);
114  void edit_to_point_internal(bool in, bool ripple);
115  void delete_in_out_internal(bool ripple);
116 
117  void create_ghosts_from_media(Sequence *seq, long entry_point, QVector<Media *> &media_list);
118  void add_clips_from_ghosts(ComboAction *ca, Sequence *s);
119 
120  int getTimelineScreenPointFromFrame(long frame);
121  long getTimelineFrameFromScreenPoint(int x);
122  int getDisplayScreenPointFromFrame(long frame);
123  long getDisplayFrameFromScreenPoint(int x);
124 
125  int get_snap_range();
126  bool snap_to_point(long point, long* l);
127  bool snap_to_timeline(long* l, bool use_playhead, bool use_markers, bool use_workarea);
128  void set_marker();
129 
130  // shared information
131  int tool;
132  long cursor_frame;
133  int cursor_track;
134  double zoom;
135  bool zoom_just_changed;
136  long drag_frame_start;
137  int drag_track_start;
138  void update_effect_controls();
139  bool showing_all;
140  double old_zoom;
141 
142  QVector<int> video_track_heights;
143  QVector<int> audio_track_heights;
144  int get_track_height_size(bool video);
145  int calculate_track_height(int track, int height);
146 
147  // snapping
148  bool snapping;
149  bool snapped;
150  long snap_point;
151 
152  // selecting functions
153  bool selecting;
154  int selection_offset;
155  void delete_selection(QVector<Selection> &selections, bool ripple);
156  void select_all();
157  bool rect_select_init;
158  bool rect_select_proc;
159  int rect_select_x;
160  int rect_select_y;
161  int rect_select_w;
162  int rect_select_h;
163 
164  // moving
165  bool moving_init;
166  bool moving_proc;
167  QVector<Ghost> ghosts;
168  bool video_ghosts;
169  bool audio_ghosts;
170  bool move_insert;
171 
172  // trimming
173  int trim_target;
174  bool trim_in_point;
175  int transition_select;
176 
177  // splitting
178  bool splitting;
179  QVector<int> split_tracks;
180  QVector<int> split_cache;
181 
182  // importing
183  bool importing;
184  bool importing_files;
185 
186  // creating variables
187  bool creating;
188  int creating_object;
189 
190  // transition variables
191  bool transition_tool_init;
192  bool transition_tool_proc;
193  int transition_tool_pre_clip;
194  int transition_tool_post_clip;
195  int transition_tool_type;
196  const EffectMeta* transition_tool_meta;
197  int transition_tool_side;
198 
199  // hand tool variables
200  bool hand_moving;
201  int drag_x_start;
202  int drag_y_start;
203 
204  bool block_repaints;
205 
206  TimelineHeader* headers;
207  AudioMonitor* audio_monitor;
208  ResizableScrollBar* horizontalScrollBar;
209 
210  QPushButton* toolArrowButton;
211  QPushButton* toolEditButton;
212  QPushButton* toolRippleButton;
213  QPushButton* toolRazorButton;
214  QPushButton* toolSlipButton;
215  QPushButton* toolSlideButton;
216  QPushButton* toolHandButton;
217  QPushButton* toolTransitionButton;
218  QPushButton* snappingButton;
219 
220  void scroll_to_frame(long frame);
221  void select_from_playhead();
222 
223  bool can_ripple_empty_space(long frame, int track);
224 
225  void resizeEvent(QResizeEvent *event);
226 public slots:
227  void paste(bool insert = false);
228  void repaint_timeline();
229  void toggle_show_all();
230  void deselect();
231  void toggle_links();
232  void split_at_playhead();
233  void ripple_delete();
234  void ripple_delete_empty_space();
235  void toggle_enable_on_selected_clips();
236 
237  void delete_inout();
238  void ripple_delete_inout();
239 
240  void ripple_to_in_point();
241  void ripple_to_out_point();
242  void edit_to_in_point();
243  void edit_to_out_point();
244 
245  void increase_track_height();
246  void decrease_track_height();
247 
248  void previous_cut();
249  void next_cut();
250 
251  void add_transition();
252 
253  void nest();
254 
255  void zoom_in();
256  void zoom_out();
257 
258 private slots:
259  void snapping_clicked(bool checked);
260  void add_btn_click();
261  void add_menu_item(QAction*);
262  void setScroll(int);
263  void record_btn_click();
264  void transition_tool_click();
265  void transition_menu_select(QAction*);
266  void resize_move(double d);
267  void set_tool();
268 
269 private:
270  void set_zoom_value(double v);
271  QVector<QPushButton*> tool_buttons;
272  void decheck_tool_buttons(QObject* sender);
273  void set_tool(int tool);
274  int scroll;
275  void set_sb_max();
276 
277  void setup_ui();
278 
279  int default_track_height;
280 
281  // ripple delete empty space variables
282  long rc_ripple_min;
283  long rc_ripple_max;
284 
285  QWidget* timeline_area;
286  TimelineWidget* video_area;
287  TimelineWidget* audio_area;
288  QWidget* editAreas;
289  QScrollBar* videoScrollbar;
290  QScrollBar* audioScrollbar;
291  QPushButton* zoomInButton;
292  QPushButton* zoomOutButton;
293  QPushButton* recordButton;
294  QPushButton* addButton;
295  QWidget* tool_button_widget;
296 };
297 
298 #endif // TIMELINE_H
Definition: sequence.h:33
Definition: selection.h:24
Definition: sourcetable.h:31
Definition: undo.h:52
Definition: audiomonitor.h:27
Definition: effect.h:166
Definition: effect.h:47
Definition: timelinewidget.h:47
Definition: timeline.h:91
Definition: timelineheader.h:31
Definition: media.h:40
Definition: footage.h:45
Definition: viewerwidget.h:44
Definition: resizablescrollbar.h:26
Definition: timeline.h:65
Definition: clip.h:53
Definition: transition.h:39
Definition: footage.h:66