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 CLIP_H 22 #define CLIP_H 23 24 #include <memory> 25 #include <QWaitCondition> 26 #include <QMutex> 27 #include <QVector> 28 #include <QOpenGLFramebufferObject> 29 #include <QOpenGLTexture> 30 31 #include "rendering/cacher.h" 32 33 #include "effects/effect.h" 34 #include "effects/transition.h" 35 #include "undo/comboaction.h" 36 #include "project/media.h" 37 #include "project/footage.h" 38 39 #include "marker.h" 40 41 extern "C" { 42 #include <libavformat/avformat.h> 43 #include <libavfilter/avfilter.h> 44 } 45 46 struct ClipSpeed { 47 ClipSpeed(); 48 double value; 49 bool maintain_audio_pitch; 50 }; 51 52 using ClipPtr = std::shared_ptr<Clip>; 53 54 class Sequence; 55 56 class Clip { 57 public: 58 Clip(Sequence *s); 59 ~Clip(); 60 ClipPtr copy(Sequence *s); 61 62 bool IsActiveAt(long timecode); 63 bool IsSelected(bool containing = true); 64 65 const QColor& color(); 66 void set_color(int r, int g, int b); 67 void set_color(const QColor& c); 68 69 Media* media(); 70 FootageStream* media_stream(); 71 int media_stream_index(); 72 int media_width(); 73 int media_height(); 74 double media_frame_rate(); 75 long media_length(); 76 void set_media(Media* m, int s); 77 78 bool enabled(); 79 void set_enabled(bool e); 80 81 void move(ComboAction* ca, 82 long iin, 83 long iout, 84 long iclip_in, 85 int itrack, 86 bool verify_transitions = true, 87 bool relative = false); 88 89 long clip_in(bool with_transition = false); 90 void set_clip_in(long c); 91 92 long timeline_in(bool with_transition = false); 93 void set_timeline_in(long t); 94 95 long timeline_out(bool with_transition = false); 96 void set_timeline_out(long t); 97 98 int track(); 99 void set_track(int t); 100 101 bool reversed(); 102 void set_reversed(bool r); 103 104 bool autoscaled(); 105 void set_autoscaled(bool b); 106 107 double cached_frame_rate(); 108 void set_cached_frame_rate(double d); 109 110 const QString& name(); 111 void set_name(const QString& s); 112 113 const ClipSpeed& speed(); 114 void set_speed(const ClipSpeed& s); 115 116 AVRational time_base(); 117 118 void reset_audio(); 119 void refresh(); 120 121 long length(); 122 123 void refactor_frame_rate(ComboAction* ca, double multiplier, bool change_timeline_points); 124 Sequence* sequence; 125 126 // markers 127 QVector<Marker>& get_markers(); 128 129 // other variables (should be deep copied/duplicated in copy()) 130 int IndexOfEffect(Effect* e); 131 QList<EffectPtr> effects; 132 QVector<int> linked; 133 TransitionPtr opening_transition; 134 TransitionPtr closing_transition; 135 136 // playback functions 137 void Open(); 138 void Cache(long playhead, bool scrubbing, QVector<Clip*> &nests, int playback_speed); 139 bool Retrieve(); 140 void Close(bool wait); 141 bool IsOpen(); 142 143 bool UsesCacher(); 144 145 // temporary variables 146 int load_id; 147 bool undeletable; 148 bool replaced; 149 150 // caching functions 151 QMutex state_change_lock; 152 QMutex cache_lock; 153 154 // video playback variables 155 QOpenGLFramebufferObject** fbo; 156 QOpenGLTexture* texture; 157 long texture_frame; 158 159 private: 160 // timeline variables (should be copied in copy()) 161 bool enabled_; 162 long clip_in_; 163 long timeline_in_; 164 long timeline_out_; 165 int track_; 166 QString name_; 167 Media* media_; 168 int media_stream_; 169 ClipSpeed speed_; 170 double cached_fr_; 171 bool reverse_; 172 bool autoscale_; 173 174 Cacher cacher; 175 long cacher_frame; 176 177 QVector<Marker> markers; 178 QColor color_; 179 bool open_; 180 }; 181 182 #endif // CLIP_H 183