Olive
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 <memory>
25 #include <QObject>
26 #include <QString>
27 #include <QVector>
28 #include <QColor>
29 #include <QOpenGLFunctions>
30 #include <QOpenGLShaderProgram>
31 #include <QOpenGLTexture>
32 #include <QMutex>
33 #include <QThread>
34 #include <QLabel>
35 #include <QWidget>
36 #include <QGridLayout>
37 #include <QPushButton>
38 #include <QMouseEvent>
39 #include <QXmlStreamReader>
40 #include <QXmlStreamWriter>
41 #include <random>
42 
43 #include "ui/collapsiblewidget.h"
44 #include "effectrow.h"
45 #include "effectgizmo.h"
46 
47 class Clip;
48 
49 class Effect;
50 using EffectPtr = std::shared_ptr<Effect>;
51 
52 struct EffectMeta {
53  QString name;
54  QString category;
55  QString filename;
56  QString path;
57  QString tooltip;
58  int internal;
59  int type;
60  int subtype;
61 };
62 extern QVector<EffectMeta> effects;
63 
64 double log_volume(double linear);
65 
66 enum EffectType {
72 };
73 
78 };
79 
97 };
98 
101 
114 
127 
129  float opacity;
130 };
131 
132 const EffectMeta* get_meta_from_name(const QString& input);
133 
134 qint16 mix_audio_sample(qint16 a, qint16 b);
135 
136 class Effect : public QObject {
137  Q_OBJECT
138 public:
139  Effect(Clip *c, const EffectMeta* em);
140  ~Effect();
141 
143  const EffectMeta* meta;
144  int id;
145  QString name;
146 
147  void AddRow(EffectRow* row);
148 
149  EffectRow* row(int i);
150  int row_count();
151 
152  EffectGizmo* add_gizmo(int type);
153  EffectGizmo* gizmo(int i);
154  int gizmo_count();
155 
156  bool IsEnabled();
157  bool IsExpanded();
158 
159  virtual void refresh();
160 
161  virtual EffectPtr copy(Clip* c);
163 
164  virtual void load(QXmlStreamReader& stream);
165  virtual void custom_load(QXmlStreamReader& stream);
166  virtual void save(QXmlStreamWriter& stream);
167 
168  void load_from_string(const QByteArray &s);
169  QByteArray save_to_string();
170 
171  // glsl handling
172  bool is_open();
173  void open();
174  void close();
175  bool is_glsl_linked();
176  virtual void startEffect();
177  virtual void endEffect();
178 
180  ShaderFlag = 0x1,
181  CoordsFlag = 0x2,
183  ImageFlag = 0x8
184  };
185  int Flags();
186  void SetFlags(int flags);
187 
188  int getIterations();
189  void setIterations(int i);
190 
191  const char* ffmpeg_filter;
192 
193  virtual void process_image(double timecode, uint8_t* input, uint8_t* output, int size);
194  virtual void process_shader(double timecode, GLTextureCoords&, int iteration);
195  virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
196  virtual GLuint process_superimpose(double timecode);
197  virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);
198 
199  virtual void gizmo_draw(double timecode, GLTextureCoords& coords);
200  void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode, bool done);
201  void gizmo_world_to_screen();
202  bool are_gizmos_enabled();
203 
204  template <typename T>
206  {
207  static std::random_device device;
208  static std::mt19937 generator(device());
209  static std::uniform_int_distribution<> distribution(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
210  return distribution(generator);
211  }
212 
213  static EffectPtr Create(Clip *c, const EffectMeta *em);
214  static const EffectMeta* GetInternalMeta(int internal_id, int type);
215 public slots:
216  void FieldChanged();
217  void SetEnabled(bool b);
218  void SetExpanded(bool e);
219 signals:
220  void EnabledChanged(bool);
221 private slots:
222  void delete_self();
223  void move_up();
224  void move_down();
225  void save_to_file();
226  void load_from_file();
227 protected:
228  // glsl effect
229  QOpenGLShaderProgram* glslProgram;
230  QString vertPath;
231  QString fragPath;
232 
233  // superimpose effect
234  QImage img;
235  QOpenGLTexture* texture;
236 
237  // enable effect to update constantly
238  virtual bool AlwaysUpdate();
239 
240 private:
241  bool isOpen;
242  QVector<EffectRow*> rows;
243  QVector<EffectGizmo*> gizmos;
244  bool bound;
246 
247  bool enabled_;
248  bool expanded_;
249 
250  int flags_;
251 
252  QVector<KeyframeDataChange*> gizmo_dragging_actions_;
253 
254  // superimpose functions
255  virtual void redraw(double timecode);
256  bool valueHasChanged(double timecode);
257  QVector<QVariant> cachedValues;
258  void delete_texture();
259  void validate_meta_path();
260 };
261 
262 #endif // EFFECT_H
QOpenGLShaderProgram * glslProgram
Definition: effect.h:229
static EffectPtr Create(Clip *c, const EffectMeta *em)
Definition: effect.cpp:73
void SetExpanded(bool e)
Definition: effect.cpp:515
Definition: effect.h:86
QVector< EffectMeta > effects
Definition: effect.cpp:71
bool are_gizmos_enabled()
Definition: effect.cpp:1026
Definition: effect.h:67
Definition: effect.h:68
Definition: effectgizmo.h:43
void save_to_file()
Definition: effect.cpp:445
void move_up()
Definition: effect.cpp:415
int vertexTopRightZ
Definition: effect.h:107
Definition: effect.h:91
QString filename
Definition: effect.h:55
EffectInternal
Definition: effect.h:80
QImage img
Definition: effect.h:234
Definition: effect.h:89
float textureTopLeftX
Definition: effect.h:115
QVector< EffectGizmo * > gizmos
Definition: effect.h:243
int vertexTopLeftZ
Definition: effect.h:104
int vertexBottomLeftY
Definition: effect.h:109
void load_from_string(const QByteArray &s)
Definition: effect.cpp:652
int Flags()
Definition: effect.cpp:814
qint16 mix_audio_sample(qint16 a, qint16 b)
Definition: effect.cpp:1128
float textureTopLeftY
Definition: effect.h:116
Clip * parent_clip
Definition: effect.h:142
double log_volume(double linear)
Definition: audio.cpp:246
bool valueHasChanged(double timecode)
Definition: effect.cpp:1074
virtual void process_image(double timecode, uint8_t *input, uint8_t *output, int size)
Definition: effect.cpp:832
float textureBottomRightQ
Definition: effect.h:123
static const EffectMeta * GetInternalMeta(int internal_id, int type)
Definition: effect.cpp:106
void delete_self()
Definition: effect.cpp:410
virtual void process_coords(double timecode, GLTextureCoords &coords, int data)
Definition: effect.cpp:889
virtual void save(QXmlStreamWriter &stream)
Definition: effect.cpp:617
bool isOpen
Definition: effect.h:241
Definition: effect.h:87
Definition: effect.h:93
QString name
Definition: effect.h:145
int vertexBottomRightX
Definition: effect.h:111
QVector< QVariant > cachedValues
Definition: effect.h:257
void move_down()
Definition: effect.cpp:430
bool is_open()
Definition: effect.cpp:716
void delete_texture()
Definition: effect.cpp:1105
int vertexTopLeftY
Definition: effect.h:103
QOpenGLTexture * texture
Definition: effect.h:235
const char * ffmpeg_filter
Definition: effect.h:191
float textureTopRightX
Definition: effect.h:118
int id
Definition: effect.h:144
void EnabledChanged(bool)
Definition: effect.h:95
EffectKeyframeType
Definition: effect.h:74
T randomNumber()
Definition: effect.h:205
Definition: effect.h:94
int vertexTopRightY
Definition: effect.h:106
virtual void refresh()
Definition: effect.cpp:404
virtual void startEffect()
Definition: effect.cpp:795
EffectRow * row(int i)
Definition: effect.cpp:382
EffectGizmo * add_gizmo(int type)
Definition: effect.cpp:390
QString tooltip
Definition: effect.h:57
bool expanded_
Definition: effect.h:248
int subtype
Definition: effect.h:60
virtual void redraw(double timecode)
Definition: effect.cpp:1030
Definition: clip.h:56
int type
Definition: effect.h:59
Definition: effect.h:180
Definition: effect.h:82
bool is_glsl_linked()
Definition: effect.cpp:791
Definition: effect.h:76
float textureBottomRightX
Definition: effect.h:121
Definition: effect.h:70
QVector< EffectRow * > rows
Definition: effect.h:242
Definition: effect.h:52
int vertexTopRightX
Definition: effect.h:105
bool bound
Definition: effect.h:244
void copy_field_keyframes(EffectPtr e)
Definition: effect.cpp:361
int vertexTopLeftX
Definition: effect.h:102
virtual bool AlwaysUpdate()
Definition: effect.cpp:501
float opacity
Definition: effect.h:129
float textureTopLeftQ
Definition: effect.h:117
QString vertPath
Definition: effect.h:230
const EffectMeta * get_meta_from_name(const QString &input)
Definition: effect.cpp:1110
virtual void process_audio(double timecode_start, double timecode_end, quint8 *samples, int nb_bytes, int channel_count)
Definition: effect.cpp:930
int blendmode
Definition: effect.h:128
float textureBottomLeftQ
Definition: effect.h:126
Definition: effect.h:181
Definition: effect.h:92
bool IsEnabled()
Definition: effect.cpp:506
int vertexBottomLeftX
Definition: effect.h:108
void SetEnabled(bool b)
Definition: effect.cpp:520
void close()
Definition: effect.cpp:779
void AddRow(EffectRow *row)
Definition: effect.cpp:355
virtual void gizmo_draw(double timecode, GLTextureCoords &coords)
Definition: effect.cpp:932
Definition: effect.h:183
void SetFlags(int flags)
Definition: effect.cpp:819
Definition: effect.h:99
bool enabled_
Definition: effect.h:247
void FieldChanged()
Definition: effect.cpp:406
float textureTopRightQ
Definition: effect.h:120
Definition: effect.h:96
virtual void process_shader(double timecode, GLTextureCoords &, int iteration)
Definition: effect.cpp:841
int gizmo_count()
Definition: effect.cpp:400
void setIterations(int i)
Definition: effect.cpp:828
Definition: effect.h:182
virtual void custom_load(QXmlStreamReader &stream)
Definition: effect.cpp:615
std::shared_ptr< Effect > EffectPtr
Definition: effect.h:50
Definition: effect.h:75
int iterations
Definition: effect.h:245
Definition: effect.h:69
virtual GLuint process_superimpose(double timecode)
Definition: effect.cpp:891
Definition: effect.h:77
QByteArray save_to_string()
Definition: effect.cpp:696
float textureBottomRightY
Definition: effect.h:122
QVector< KeyframeDataChange * > gizmo_dragging_actions_
Definition: effect.h:252
int getIterations()
Definition: effect.cpp:824
void validate_meta_path()
Definition: effect.cpp:720
float textureBottomLeftY
Definition: effect.h:125
Definition: effect.h:71
Definition: effect.h:84
virtual void endEffect()
Definition: effect.cpp:807
~Effect()
Definition: effect.cpp:339
int vertexBottomRightY
Definition: effect.h:112
virtual EffectPtr copy(Clip *c)
Definition: effect.cpp:834
QString fragPath
Definition: effect.h:231
const EffectMeta * meta
Definition: effect.h:143
int grid_size
Definition: effect.h:100
void open()
Definition: effect.cpp:737
Definition: effect.h:85
The EffectRow class.
Definition: effectrow.h:51
int vertexBottomRightZ
Definition: effect.h:113
Definition: effect.h:81
QString category
Definition: effect.h:54
Definition: effect.h:88
EffectType
Definition: effect.h:66
float textureBottomLeftX
Definition: effect.h:124
QString path
Definition: effect.h:56
void load_from_file()
Definition: effect.cpp:475
VideoEffectFlags
Definition: effect.h:179
float textureTopRightY
Definition: effect.h:119
Definition: effect.h:136
Definition: effect.h:90
QString name
Definition: effect.h:53
int vertexBottomLeftZ
Definition: effect.h:110
void gizmo_move(EffectGizmo *sender, int x_movement, int y_movement, double timecode, bool done)
Definition: effect.cpp:934
virtual void load(QXmlStreamReader &stream)
Definition: effect.cpp:525
Effect(Clip *c, const EffectMeta *em)
Definition: effect.cpp:115
int flags_
Definition: effect.h:250
void gizmo_world_to_screen()
Definition: effect.cpp:1003
EffectGizmo * gizmo(int i)
Definition: effect.cpp:396
int row_count()
Definition: effect.cpp:386
Definition: effect.h:83
bool IsExpanded()
Definition: effect.cpp:510