File: effect.h

package info (click to toggle)
olive-editor 20181223-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 2,844 kB
  • sloc: cpp: 20,147; xml: 315; ansic: 16; makefile: 11
file content (212 lines) | stat: -rw-r--r-- 5,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#ifndef EFFECT_H
#define EFFECT_H

#include <QObject>
#include <QString>
#include <QVector>
#include <QColor>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QMutex>
#include <QThread>
class QLabel;
class QWidget;
class CollapsibleWidget;
class QGridLayout;
class QPushButton;
class QMouseEvent;

struct Clip;
class QXmlStreamReader;
class QXmlStreamWriter;
class Effect;
class EffectRow;
class CheckboxEx;
class KeyframeDelete;

struct EffectMeta {
    QString name;
    QString category;
    QString filename;
	int internal;
	int type;
    int subtype;
};

extern QVector<EffectMeta> effects;

double log_volume(double linear);
void init_effects();
Effect* create_effect(Clip* c, const EffectMeta *em);
const EffectMeta* get_internal_meta(int internal_id, int type);

extern QMutex effects_loaded;

#define EFFECT_TYPE_INVALID 0
#define EFFECT_TYPE_VIDEO 1
#define EFFECT_TYPE_AUDIO 2
#define EFFECT_TYPE_EFFECT 3
#define EFFECT_TYPE_TRANSITION 4

#define EFFECT_KEYFRAME_LINEAR 0
#define EFFECT_KEYFRAME_HOLD 1
#define EFFECT_KEYFRAME_BEZIER 2

#define EFFECT_INTERNAL_TRANSFORM 0
#define EFFECT_INTERNAL_TEXT 1
#define EFFECT_INTERNAL_SOLID 2
#define EFFECT_INTERNAL_NOISE 3
#define EFFECT_INTERNAL_VOLUME 4
#define EFFECT_INTERNAL_PAN 5
#define EFFECT_INTERNAL_TONE 6
#define EFFECT_INTERNAL_SHAKE 7
#define EFFECT_INTERNAL_TIMECODE 8
#define EFFECT_INTERNAL_MASK 9


#define EFFECT_INTERNAL_CORNERPIN 12
#define EFFECT_INTERNAL_COUNT 13

#define KEYFRAME_TYPE_LINEAR 0
#define KEYFRAME_TYPE_SMOOTH 1
#define KEYFRAME_TYPE_BEZIER 2

struct GLTextureCoords {
    int grid_size;

	int vertexTopLeftX;
	int vertexTopLeftY;
    int vertexTopLeftZ;
	int vertexTopRightX;
	int vertexTopRightY;
    int vertexTopRightZ;
	int vertexBottomLeftX;
	int vertexBottomLeftY;
    int vertexBottomLeftZ;
	int vertexBottomRightX;
	int vertexBottomRightY;
    int vertexBottomRightZ;

    float textureTopLeftX;
    float textureTopLeftY;
    float textureTopLeftQ;
    float textureTopRightX;
    float textureTopRightY;
    float textureTopRightQ;
    float textureBottomRightX;
    float textureBottomRightY;
    float textureBottomRightQ;
    float textureBottomLeftX;
    float textureBottomLeftY;
    float textureBottomLeftQ;
};

qint16 mix_audio_sample(qint16 a, qint16 b);

#include "effectfield.h"
#include "effectrow.h"
#include "effectgizmo.h"

class Effect : public QObject {
	Q_OBJECT
public:
	Effect(Clip* c, const EffectMeta* em);
	~Effect();
    Clip* parent_clip;
	const EffectMeta* meta;
    int id;
	QString name;
	CollapsibleWidget* container;

    EffectRow* add_row(const QString &name, bool savable = true);
	EffectRow* row(int i);
	int row_count();

    EffectGizmo* add_gizmo(int type);
    EffectGizmo* gizmo(int i);
    int gizmo_count();

    bool is_enabled();
	void set_enabled(bool b);

	virtual void refresh();

	Effect* copy(Clip* c);
	void copy_field_keyframes(Effect *e);

	void load(QXmlStreamReader& stream);
    void save(QXmlStreamWriter& stream);

	// glsl handling
	void open();
	void close();
	virtual void startEffect();
	virtual void endEffect();

	bool enable_shader;
	bool enable_coords;
    bool enable_superimpose;
    bool enable_image;

	int getIterations();
	void setIterations(int i);

	const char* ffmpeg_filter;

    virtual void process_image(double timecode, uint8_t* data, int size);
	virtual void process_shader(double timecode, GLTextureCoords&);
    virtual void process_coords(double timecode, GLTextureCoords& coords, int data);
	virtual GLuint process_superimpose(double timecode);
	virtual void process_audio(double timecode_start, double timecode_end, quint8* samples, int nb_bytes, int channel_count);

    virtual void gizmo_draw(double timecode, GLTextureCoords& coords);
    void gizmo_move(EffectGizmo* sender, int x_movement, int y_movement, double timecode, bool done);
    void gizmo_world_to_screen();
    bool are_gizmos_enabled();
public slots:
	void field_changed();
private slots:
	void show_context_menu(const QPoint&);
	void delete_self();
	void move_up();
	void move_down();
protected:
	// glsl effect
	QOpenGLShaderProgram* glslProgram;
	QString vertPath;
	QString fragPath;

	// superimpose effect
	QImage img;
	QOpenGLTexture* texture;

    // enable effect to update constantly
    bool enable_always_update;
private:
	// superimpose effect
	QString script;

	bool isOpen;
	QVector<EffectRow*> rows;
    QVector<EffectGizmo*> gizmos;
	QGridLayout* ui_layout;
    QWidget* ui;
	bool bound;

	// superimpose functions
	virtual void redraw(double timecode);
	bool valueHasChanged(double timecode);
	QVector<QVariant> cachedValues;
	void delete_texture();
	int get_index_in_clip();
};

class EffectInit : public QThread {
public:
	EffectInit();
protected:
	void run();
};

#endif // EFFECT_H