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