Olive
effect.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 EFFECT_H
22 #define EFFECT_H
23 
24 #include <QObject>
25 #include <QString>
26 #include <QVector>
27 #include <QColor>
28 #include <QOpenGLFunctions>
29 #include <QOpenGLShaderProgram>
30 #include <QOpenGLTexture>
31 #include <QMutex>
32 #include <QThread>
33 class QLabel;
34 class QWidget;
35 class CollapsibleWidget;
36 class QGridLayout;
37 class QPushButton;
38 class QMouseEvent;
39 
40 class Clip;
41 class QXmlStreamReader;
42 class QXmlStreamWriter;
43 class Effect;
44 class EffectRow;
45 class CheckboxEx;
46 
47 struct EffectMeta {
48  QString name;
49  QString category;
50  QString filename;
51  QString path;
52  QString tooltip;
53  int internal;
54  int type;
55  int subtype;
56 };
57 extern QVector<EffectMeta> effects;
58 
59 double log_volume(double linear);
60 Effect* create_effect(Clip* c, const EffectMeta *em);
61 const EffectMeta* get_internal_meta(int internal_id, int type);
62 
63 enum EffectType {
64  EFFECT_TYPE_INVALID,
65  EFFECT_TYPE_VIDEO,
66  EFFECT_TYPE_AUDIO,
67  EFFECT_TYPE_EFFECT,
68  EFFECT_TYPE_TRANSITION
69 };
70 
71 enum EffectKeyframeType {
72  EFFECT_KEYFRAME_LINEAR,
73  EFFECT_KEYFRAME_BEZIER,
74  EFFECT_KEYFRAME_HOLD
75 };
76 
77 enum EffectInternal {
78  EFFECT_INTERNAL_TRANSFORM,
79  EFFECT_INTERNAL_TEXT,
80  EFFECT_INTERNAL_SOLID,
81  EFFECT_INTERNAL_NOISE,
82  EFFECT_INTERNAL_VOLUME,
83  EFFECT_INTERNAL_PAN,
84  EFFECT_INTERNAL_TONE,
85  EFFECT_INTERNAL_SHAKE,
86  EFFECT_INTERNAL_TIMECODE,
87  EFFECT_INTERNAL_MASK,
88  EFFECT_INTERNAL_FILLLEFTRIGHT,
89  EFFECT_INTERNAL_VST,
90  EFFECT_INTERNAL_CORNERPIN,
91  EFFECT_INTERNAL_FREI0R,
92  EFFECT_INTERNAL_COUNT
93 };
94 
95 enum EffectBlendMode {
96  BLEND_MODE_ADD,
97  BLEND_MODE_AVERAGE,
98  BLEND_MODE_COLORBURN,
99  BLEND_MODE_COLORDODGE,
100  BLEND_MODE_DARKEN,
101  BLEND_MODE_DIFFERENCE,
102  BLEND_MODE_EXCLUSION,
103  BLEND_MODE_GLOW,
104  BLEND_MODE_HARDLIGHT,
105  BLEND_MODE_HARDMIX,
106  BLEND_MODE_LIGHTEN,
107  BLEND_MODE_LINEARBURN,
108  BLEND_MODE_LINEARDODGE,
109  BLEND_MODE_LINEARLIGHT,
110  BLEND_MODE_MULTIPLY,
111  BLEND_MODE_NEGATION,
112  BLEND_MODE_NORMAL,
113  BLEND_MODE_OVERLAY,
114  BLEND_MODE_PHOENIX,
115  BLEND_MODE_PINLIGHT,
116  BLEND_MODE_REFLECT,
117  BLEND_MODE_SCREEN,
118  BLEND_MODE_SOFTLIGHT,
119  BLEND_MODE_SUBSTRACT,
120  BLEND_MODE_SUBTRACT,
121  BLEND_MODE_VIVIDLIGHT,
122  BLEND_MODE_COUNT
123 };
124 
126  int grid_size;
127 
128  int vertexTopLeftX;
129  int vertexTopLeftY;
130  int vertexTopLeftZ;
131  int vertexTopRightX;
132  int vertexTopRightY;
133  int vertexTopRightZ;
134  int vertexBottomLeftX;
135  int vertexBottomLeftY;
136  int vertexBottomLeftZ;
137  int vertexBottomRightX;
138  int vertexBottomRightY;
139  int vertexBottomRightZ;
140 
141  float textureTopLeftX;
142  float textureTopLeftY;
143  float textureTopLeftQ;
144  float textureTopRightX;
145  float textureTopRightY;
146  float textureTopRightQ;
147  float textureBottomRightX;
148  float textureBottomRightY;
149  float textureBottomRightQ;
150  float textureBottomLeftX;
151  float textureBottomLeftY;
152  float textureBottomLeftQ;
153 
154  int blendmode;
155  float opacity;
156 };
157 
158 const EffectMeta* get_meta_from_name(const QString& input);
159 
160 qint16 mix_audio_sample(qint16 a, qint16 b);
161 
162 #include "effectfield.h"
163 #include "effectrow.h"
164 #include "effectgizmo.h"
165 
166 class Effect : public QObject {
167  Q_OBJECT
168 public:
169  Effect(Clip* c, const EffectMeta* em);
170  ~Effect();
171  Clip* parent_clip;
172  const EffectMeta* meta;
173  int id;
174  QString name;
175  CollapsibleWidget* container;
176 
177  EffectRow* add_row(const QString &name, bool savable = true, bool keyframable = true);
178  EffectRow* row(int i);
179  int row_count();
180 
181  EffectGizmo* add_gizmo(int type);
182  EffectGizmo* gizmo(int i);
183  int gizmo_count();
184 
185  bool is_enabled();
186  void set_enabled(bool b);
187 
188  virtual void refresh();
189 
190  virtual Effect* copy(Clip* c);
191  void copy_field_keyframes(Effect *e);
192 
193  virtual void load(QXmlStreamReader& stream);
194  virtual void custom_load(QXmlStreamReader& stream);
195  virtual void save(QXmlStreamWriter& stream);
196 
197  void load_from_string(const QByteArray &s);
198  QByteArray save_to_string();
199 
200  // glsl handling
201  bool is_open();
202  void open();
203  void close();
204  bool is_glsl_linked();
205  virtual void startEffect();
206  virtual void endEffect();
207 
208  bool enable_shader;
209  bool enable_coords;
210  bool enable_superimpose;
211  bool enable_image;
212 
213  int getIterations();
214  void setIterations(int i);
215 
216  const char* ffmpeg_filter;
217 
218  virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size);
219  virtual void process_shader(double timecode, GLTextureCoords&, int iteration);
220  virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
221  virtual GLuint process_superimpose(double timecode);
222  virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
223 
224  virtual void gizmo_draw(double timecode, GLTextureCoords& coords);
225  void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode, bool done);
226  void gizmo_world_to_screen();
227  bool are_gizmos_enabled();
228 public slots:
229  void field_changed();
230 private slots:
231  void show_context_menu(const QPoint&);
232  void delete_self();
233  void move_up();
234  void move_down();
235  void save_to_file();
236  void load_from_file();
237 protected:
238  // glsl effect
239  QOpenGLShaderProgram* glslProgram;
240  QString vertPath;
241  QString fragPath;
242 
243  // superimpose effect
244  QImage img;
245  QOpenGLTexture* texture;
246 
247  // enable effect to update constantly
248  bool enable_always_update;
249 private:
250  // superimpose effect
251  QString script;
252 
253  bool isOpen;
254  QVector<EffectRow*> rows;
255  QVector<EffectGizmo*> gizmos;
256  QGridLayout* ui_layout;
257  QWidget* ui;
258  bool bound;
259  int iterations;
260 
261  // superimpose functions
262  virtual void redraw(double timecode);
263  bool valueHasChanged(double timecode);
264  QVector<QVariant> cachedValues;
265  void delete_texture();
266  int get_index_in_clip();
267  void validate_meta_path();
268 };
269 
270 class EffectInit : public QThread {
271 public:
272  EffectInit();
273 protected:
274  void run();
275 };
276 
277 #endif // EFFECT_H
Definition: effect.h:125
Definition: collapsiblewidget.h:45
Definition: effect.h:166
Definition: effect.h:47
Definition: checkboxex.h:26
Definition: effectrow.h:37
Definition: effectgizmo.h:41
Definition: effect.h:270
Definition: clip.h:53