Olive
effect.h
Go to the documentation of this file.
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 #include <QLabel>
34 #include <QWidget>
35 #include <QGridLayout>
36 #include <QPushButton>
37 #include <QMouseEvent>
38 #include <QXmlStreamReader>
39 #include <QXmlStreamWriter>
40 
41 #include "ui/collapsiblewidget.h"
42 #include "ui/checkboxex.h"
43 
44 class Clip;
45 using ClipPtr = std::shared_ptr<Clip>;
46 
47 class Effect;
48 using EffectPtr = std::shared_ptr<Effect>;
49 
50 struct EffectMeta {
51  QString name;
52  QString category;
53  QString filename;
54  QString path;
55  QString tooltip;
56  int internal;
57  int type;
58  int subtype;
59 };
60 extern QVector<EffectMeta> effects;
61 
62 double log_volume(double linear);
64 const EffectMeta* get_internal_meta(int internal_id, int type);
65 
66 enum EffectType {
72 };
73 
78 };
79 
96 };
97 
126 };
127 
130 
143 
156 
158  float opacity;
159 };
160 
161 const EffectMeta* get_meta_from_name(const QString& input);
162 
163 qint16 mix_audio_sample(qint16 a, qint16 b);
164 
165 #include "effectfield.h"
166 #include "effectrow.h"
167 #include "effectgizmo.h"
168 
169 class Effect : public QObject {
170  Q_OBJECT
171 public:
172  Effect(ClipPtr c, const EffectMeta* em);
173  ~Effect();
175  const EffectMeta* meta;
176  int id;
177  QString name;
179 
180  EffectRow* add_row(const QString &name, bool savable = true, bool keyframable = true);
181  EffectRow* row(int i);
182  int row_count();
183 
184  EffectGizmo* add_gizmo(int type);
185  EffectGizmo* gizmo(int i);
186  int gizmo_count();
187 
188  bool is_enabled();
189  void set_enabled(bool b);
190 
191  virtual void refresh();
192 
193  virtual EffectPtr copy(ClipPtr c);
195 
196  virtual void load(QXmlStreamReader& stream);
197  virtual void custom_load(QXmlStreamReader& stream);
198  virtual void save(QXmlStreamWriter& stream);
199 
200  void load_from_string(const QByteArray &s);
201  QByteArray save_to_string();
202 
203  // glsl handling
204  bool is_open();
205  void open();
206  void close();
207  bool is_glsl_linked();
208  virtual void startEffect();
209  virtual void endEffect();
210 
215 
216  int getIterations();
217  void setIterations(int i);
218 
219  const char* ffmpeg_filter;
220 
221  virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size);
222  virtual void process_shader(double timecode, GLTextureCoords&, int iteration);
223  virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
224  virtual GLuint process_superimpose(double timecode);
225  virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
226 
227  virtual void gizmo_draw(double timecode, GLTextureCoords& coords);
228  void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode, bool done);
229  void gizmo_world_to_screen();
230  bool are_gizmos_enabled();
231 public slots:
232  void field_changed();
233 private slots:
234  void show_context_menu(const QPoint&);
235  void delete_self();
236  void move_up();
237  void move_down();
238  void save_to_file();
239  void load_from_file();
240 protected:
241  // glsl effect
242  QOpenGLShaderProgram* glslProgram;
243  QString vertPath;
244  QString fragPath;
245 
246  // superimpose effect
247  QImage img;
248  QOpenGLTexture* texture;
249 
250  // enable effect to update constantly
252 private:
253  // superimpose effect
254  QString script;
255 
256  bool isOpen;
257  QVector<EffectRow*> rows;
258  QVector<EffectGizmo*> gizmos;
259  QGridLayout* ui_layout;
260  QWidget* ui;
261  bool bound;
263 
264  // superimpose functions
265  virtual void redraw(double timecode);
266  bool valueHasChanged(double timecode);
267  QVector<QVariant> cachedValues;
268  void delete_texture();
269  int get_index_in_clip();
270  void validate_meta_path();
271 };
272 
273 class EffectInit : public QThread {
274 public:
275  EffectInit();
276 protected:
277  void run();
278 };
279 
280 #endif // EFFECT_H
virtual void gizmo_draw(double timecode, GLTextureCoords &coords)
Definition: effect.cpp:942
QVector< QVariant > cachedValues
Definition: effect.h:267
Definition: effect.h:109
float textureTopRightX
Definition: effect.h:147
Definition: effect.h:103
int vertexBottomLeftY
Definition: effect.h:138
float textureTopRightY
Definition: effect.h:148
QString name
Definition: effect.h:177
Definition: effect.h:121
void load_from_string(const QByteArray &s)
Definition: effect.cpp:687
int gizmo_count()
Definition: effect.cpp:385
virtual void process_coords(double timecode, GLTextureCoords &coords, int data)
Definition: effect.cpp:901
Definition: effect.h:86
Definition: effect.h:67
Definition: effect.h:68
bool are_gizmos_enabled()
Definition: effect.cpp:994
float textureBottomLeftX
Definition: effect.h:153
Definition: effect.h:101
Definition: effect.h:91
int getIterations()
Definition: effect.cpp:847
QImage img
Definition: effect.h:247
EffectInternal
Definition: effect.h:80
QString filename
Definition: effect.h:53
Definition: effect.h:89
Definition: effect.h:128
void validate_meta_path()
Definition: effect.cpp:755
virtual void custom_load(QXmlStreamReader &stream)
Definition: effect.cpp:653
void open()
Definition: effect.cpp:772
Definition: collapsiblewidget.h:45
bool is_enabled()
Definition: effect.cpp:526
double log_volume(double linear)
Definition: audio.cpp:244
EffectBlendMode
Definition: effect.h:98
float textureTopLeftY
Definition: effect.h:145
bool enable_superimpose
Definition: effect.h:213
Definition: effect.h:106
Definition: effect.h:118
EffectPtr create_effect(ClipPtr c, const EffectMeta *em)
Definition: effect.cpp:72
EffectRow * add_row(const QString &name, bool savable=true, bool keyframable=true)
Definition: effect.cpp:361
QString category
Definition: effect.h:52
Definition: effect.h:87
qint16 mix_audio_sample(qint16 a, qint16 b)
Definition: effect.cpp:1095
int vertexBottomRightX
Definition: effect.h:140
EffectGizmo * gizmo(int i)
Definition: effect.cpp:381
const EffectMeta * meta
Definition: effect.h:175
Definition: effect.h:112
Definition: effect.h:169
Definition: effect.h:93
bool isOpen
Definition: effect.h:256
float textureBottomRightX
Definition: effect.h:150
float opacity
Definition: effect.h:158
virtual EffectPtr copy(ClipPtr c)
Definition: effect.cpp:857
QWidget * ui
Definition: effect.h:260
Definition: effect.h:50
virtual void save(QXmlStreamWriter &stream)
Definition: effect.cpp:655
Definition: effect.h:113
ClipPtr parent_clip
Definition: effect.h:174
int id
Definition: effect.h:176
QString path
Definition: effect.h:54
Definition: effect.h:117
const EffectMeta * get_internal_meta(int internal_id, int type)
Definition: effect.cpp:106
void move_up()
Definition: effect.cpp:439
Definition: effect.h:116
QVector< EffectMeta > effects
Definition: effect.cpp:70
QString tooltip
Definition: effect.h:55
Definition: effect.h:102
QString fragPath
Definition: effect.h:244
bool bound
Definition: effect.h:261
Definition: effectrow.h:37
int blendmode
Definition: effect.h:157
float textureBottomLeftQ
Definition: effect.h:155
Definition: effect.h:122
EffectKeyframeType
Definition: effect.h:74
QByteArray save_to_string()
Definition: effect.cpp:731
QGridLayout * ui_layout
Definition: effect.h:259
bool enable_shader
Definition: effect.h:211
Definition: effect.h:94
float textureTopLeftX
Definition: effect.h:144
std::shared_ptr< Clip > ClipPtr
Definition: cacher.h:28
int vertexBottomRightY
Definition: effect.h:141
bool is_open()
Definition: effect.cpp:751
virtual void load(QXmlStreamReader &stream)
Definition: effect.cpp:562
Definition: effect.h:107
virtual void redraw(double timecode)
Definition: effect.cpp:998
bool enable_coords
Definition: effect.h:212
int iterations
Definition: effect.h:262
float textureTopLeftQ
Definition: effect.h:146
Definition: effect.h:99
const EffectMeta * get_meta_from_name(const QString &input)
Definition: effect.cpp:1077
int vertexBottomRightZ
Definition: effect.h:142
virtual void startEffect()
Definition: effect.cpp:830
float textureTopRightQ
Definition: effect.h:149
void delete_self()
Definition: effect.cpp:431
EffectRow * row(int i)
Definition: effect.cpp:367
int row_count()
Definition: effect.cpp:371
bool enable_always_update
Definition: effect.h:251
Definition: effect.h:82
Definition: effect.h:76
QVector< EffectGizmo * > gizmos
Definition: effect.h:258
void delete_texture()
Definition: effect.cpp:1070
Definition: effect.h:123
Definition: effect.h:70
QVector< EffectRow * > rows
Definition: effect.h:257
void gizmo_world_to_screen()
Definition: effect.cpp:971
Definition: effectgizmo.h:41
Effect(ClipPtr c, const EffectMeta *em)
Definition: effect.cpp:115
void gizmo_move(EffectGizmo *sender, int x_movement, int y_movement, double timecode, bool done)
Definition: effect.cpp:944
void show_context_menu(const QPoint &)
Definition: effect.cpp:396
CollapsibleWidget * container
Definition: effect.h:178
Definition: effect.h:273
Definition: effect.h:124
void field_changed()
Definition: effect.cpp:391
void set_enabled(bool b)
Definition: effect.cpp:530
Definition: effect.h:114
int vertexTopLeftZ
Definition: effect.h:133
int get_index_in_clip()
Definition: effect.cpp:515
Definition: effect.h:120
Definition: effect.h:125
float textureBottomRightY
Definition: effect.h:151
float textureBottomLeftY
Definition: effect.h:154
~Effect()
Definition: effect.cpp:332
bool valueHasChanged(double timecode)
Definition: effect.cpp:1042
virtual void process_shader(double timecode, GLTextureCoords &, int iteration)
Definition: effect.cpp:864
Definition: effect.h:92
QOpenGLTexture * texture
Definition: effect.h:248
Definition: effect.h:108
Definition: effect.h:105
Definition: effect.h:100
void close()
Definition: effect.cpp:814
Definition: effect.h:115
QString script
Definition: effect.h:254
bool enable_image
Definition: effect.h:214
Definition: effect.h:95
virtual void refresh()
Definition: effect.cpp:389
int type
Definition: effect.h:57
virtual void endEffect()
Definition: effect.cpp:842
bool is_glsl_linked()
Definition: effect.cpp:826
int subtype
Definition: effect.h:58
virtual GLuint process_superimpose(double timecode)
Definition: effect.cpp:903
int vertexTopRightX
Definition: effect.h:134
QOpenGLShaderProgram * glslProgram
Definition: effect.h:242
int vertexTopLeftX
Definition: effect.h:131
Definition: clip.h:50
void move_down()
Definition: effect.cpp:449
std::shared_ptr< Effect > EffectPtr
Definition: effect.h:48
virtual void process_audio(double timecode_start, double timecode_end, quint8 *samples, int nb_bytes, int channel_count)
Definition: effect.cpp:940
Definition: effect.h:75
Definition: effect.h:69
void copy_field_keyframes(EffectPtr e)
Definition: effect.cpp:347
Definition: effect.h:104
void save_to_file()
Definition: effect.cpp:459
Definition: effect.h:77
int vertexBottomLeftX
Definition: effect.h:137
int vertexTopRightZ
Definition: effect.h:136
Definition: effect.h:119
Definition: effect.h:71
Definition: effect.h:84
Definition: effect.h:110
float textureBottomRightQ
Definition: effect.h:152
void setIterations(int i)
Definition: effect.cpp:851
void load_from_file()
Definition: effect.cpp:489
QString name
Definition: effect.h:51
Definition: effect.h:85
QString vertPath
Definition: effect.h:243
const char * ffmpeg_filter
Definition: effect.h:219
int vertexBottomLeftZ
Definition: effect.h:139
EffectInit()
Definition: effectloaders.cpp:258
Definition: effect.h:81
Definition: effect.h:88
EffectGizmo * add_gizmo(int type)
Definition: effect.cpp:375
EffectType
Definition: effect.h:66
int vertexTopLeftY
Definition: effect.h:132
Definition: effect.h:90
void run()
Definition: effectloaders.cpp:262
Definition: effect.h:111
int grid_size
Definition: effect.h:129
virtual void process_image(double timecode, uint8_t *input, uint8_t *output, int size)
Definition: effect.cpp:855
Definition: effect.h:83
int vertexTopRightY
Definition: effect.h:135