-
Notifications
You must be signed in to change notification settings - Fork 1
/
Composition.pde
104 lines (95 loc) · 2.93 KB
/
Composition.pde
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
class Composition{
PApplet parent;
GLTexture[] tex;
boolean isPlaying = false;
float duration = 0.0;
float timelineValue = 0.0;
float timer = 0.0;
int top=999, bottom=999;
boolean firstBlend = true;
boolean initialize=true;
Composition(PApplet applet){
parent = applet;
tex = new GLTexture[nbLayers-1];
for (int i = 0; i<nbLayers-1; i++){
tex[i] = new GLTexture(parent);
}
}
void display(){
if(isPlaying){
if(initialize){
println("Start composition");
for (int i = 0; i<nbLayers; i++){
// re init layers
layers[i].timelineValue=0.0;
layers[i].currentClip=0;
// re init layers clips
for(int j = 0; j<layers[i].clips.size(); j++){
(layers[i].clips).get(j).ended = false;
}
}
initialize=false;
}
fill(20);
rect(1005,15,490,280);
for (int i = nbLayers-1; i>=0; i--){
if(timelineValue>layers[i].Delay && timelineValue<layers[i].Delay+layers[i].duration && layers[i].clips.size()>0 && layers[i].currentClip<layers[i].clips.size()){
layers[i].isPlaying=true;
layers[i].timelineValue=timelineValue-layers[i].Delay;
(layers[i].clips).get(layers[i].currentClip).movie.play();
layers[i].display();
if(top==999){
top = i;
}
else{
bottom = i;
BlendModes[layers[top].clips.get(layers[top].currentClip).blendMode].setParameterValue("Opacity", layers[top].Opacity);
if(firstBlend){
firstBlend = false;
// println("top: layers["+top+"].currentClip: "+layers[top].currentClip);
// println("bottom: layers["+bottom+"].currentClip: "+layers[bottom].currentClip);
// println("blendMode: "+layers[top].clips.get(layers[top].currentClip).blendMode);
BlendModes[layers[top].clips.get(layers[top].currentClip).blendMode].apply(new GLTexture[]{layers[top].tex, layers[bottom].tex}, tex[bottom]);
}
else{
BlendModes[layers[top].clips.get(layers[top].currentClip).blendMode].apply(new GLTexture[]{tex[top], layers[bottom].tex}, tex[bottom]);
}
top = bottom;
}
}
else{
layers[i].isPlaying=false;
layers[i].timelineValue=0;
}
}
if(top!=999 && bottom!=999){
// println("Composition.get mixed tex:"+bottom);
image(tex[bottom],1005,15,490,280);
}
else if(top!=999){
// println("Composition.get one tex:"+top);
image(layers[top].tex,1005,15,490,280);
}
top = 999;
bottom = 999;
firstBlend = true;
updateCompositionGui();
}
}
void updateCompositionGui(){
timelineValue += (millis()-timer)/1000;
timer = millis();
if(timelineValue>duration){// stop composition
isPlaying=false;
initialize = true;
timelineValue=0.0;
// stop layers
for(int i=0; i<nbLayers; i++){
layers[i].isPlaying=false;
}
}
Composition_Timeline.setRange(0.0, duration);
Composition_Timeline.setValue(timelineValue);
Composition_Timeline.getCaptionLabel().align(ControlP5.LEFT, ControlP5.BOTTOM_OUTSIDE).setPaddingX(0);
}
}