-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLayerVideo.pde
More file actions
147 lines (134 loc) · 3.84 KB
/
LayerVideo.pde
File metadata and controls
147 lines (134 loc) · 3.84 KB
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
class LayerVideo{
PApplet parent;
int id;
ArrayList<Clip> clips;
int currentClip = 0;
boolean isEditLayer = false;
boolean isPlaying = false;
float duration = 0.0;
float timelineValue = 0.0;
float timer = 0.0;
float posX=0, posY=0;
float Scale=1.0;
float Opacity=0.0;
float TargetOpacity=1.0;
float Delay=0.0;
float fadeInAlpha=1.0;
float fadeInDuration=0.0;
float fadeOutAlpha=1.0;
float fadeOutDuration=0.0;
GLTexture tex;
GLTextureFilter LayerFilter;
LayerVideo(PApplet applet, int _id){
parent = applet;
id = _id;
clips = new ArrayList<Clip>();
tex = new GLTexture(parent);
LayerFilter = new GLTextureFilter(parent, "LayerFilter.xml");
}
void display(){
if(clips.size()>0 && currentClip<clips.size() && isPlaying){
// println("Layer"+id+" playing");
(clips.get(currentClip)).display();
updateGLSLParams();
(clips.get(currentClip)).texFiltered.filter(LayerFilter, tex);
// display editLayer in editor
if(isEditLayer){
// due to Layer alpha, we need to "erase" previous frame
fill(20);
rect(505,15,490,280);
image(tex,505,15,490,280);
updateLayerGui();
}
// jump to next clip or end Layer
if((clips.get(currentClip)).ended){
// println("Layer"+id+".currentClip: "+currentClip+" ended");
if(isEditLayer){
float timelineValueUp=0.0;
for (int i = 0; i<= currentClip; i++){
timelineValueUp += clips.get(i).duration;
}
timelineValue = timelineValueUp;
}
currentClip++;
if(currentClip<clips.size()){
// println("Layer"+id+".currentClip: "+currentClip);
clips.get(currentClip).movie.play();
clips.get(currentClip).timer = millis();
}
else{
// gui.getController("Layer_PlayPause"+id).setValue(0.0);// problem with controlp5
// println("Layer"+id+" ended");
isPlaying = false;
// restart clips
currentClip = 0;
for(int i = 0; i<clips.size(); i++){
clips.get(i).ended = false;
}
}
}
}
}
void updateLayerGui(){
timelineValue += (millis()-timer)/1000;
if(timelineValue>duration) timelineValue=0.0;
timer = millis();
Layer_Timeline[id].setRange(0.0, duration);
Layer_Timeline[id].setValue(timelineValue);
Layer_Timeline[id].getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
}
void updateGLSLParams(){
LayerFilter.setParameterValue("posXY", new float[] {posX, posY});
LayerFilter.setParameterValue("Scale", Scale);
if(timelineValue<fadeInDuration){
Opacity = fadeInAlpha+timelineValue*((TargetOpacity-fadeInAlpha)/fadeInDuration);
// println(Opacity);
}
else if(duration-timelineValue<fadeOutDuration){
Opacity = fadeOutAlpha+(duration-timelineValue)*((TargetOpacity-fadeOutAlpha)/fadeOutDuration);
// println(Opacity);
}
else Opacity = TargetOpacity;
LayerFilter.setParameterValue("Opacity", Opacity);
}
void resetLayer(){
isPlaying = false;
timelineValue = 0.0;
Layer_PlayPause[id].setValue(0.0);
isEditLayer = false;
currentClip = 0;
duration = 0.0;
Layer_Duration[id].setText("DURATION: 0.0");
timelineValue = 0.0;
Layer_Timeline[id].setValue(0.0);
timer = 0.0;
posX=0;
posY=0;
Layer_XY[id].setArrayValue(new float[]{100,100});
Scale=1.0;
Layer_Scale[id].setValue(1.0);
Opacity=0.0;
TargetOpacity=1.0;
Layer_Opacity[id].setValue(1.0);
Delay=0.0;
Layer_Delay[id].setValue(0.0);
fadeInAlpha=1.0;
Layer_fadeInAlpha[id].setValue(1.0);
fadeInDuration=0.1;
Layer_fadeInDuration[id].setValue(0.1);
fadeOutAlpha=1.0;
Layer_fadeOutAlpha[id].setValue(1.0);
fadeOutDuration=0.1;
Layer_fadeOutDuration[id].setValue(0.1);
for(int i = clips.size()-1; i>=0; i--){
clips.get(i).movie.stop();
clips.get(i).texFiltered.delete();
clips.get(i).tex.delete();
clips.get(i).ClipFilter.delete();
clips.remove(i);
gui.remove("Layer"+id+"Clip"+i);
}
fill(20);
rect(505,15,490,280);
}
}