Repository navigation
Expand file tree
/
Copy pathLayerLines.java
More file actions
280 lines (220 loc) · 7.45 KB
/
Copy pathLayerLines.java
File metadata and controls
280 lines (220 loc) · 7.45 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import java.awt.Color;
import java.util.LinkedList;
import java.util.List;
import javax.media.opengl.GL2;
import controlP5.Group;
import controlP5.Tab;
public class LayerLines extends LayerColor {
class Line{
float h;
float s;
float b;
float alpha;
float width;
float space;
float angle;
}
public FloatParameter alphaMult = new FloatParameter(this,1f,0f,1f,"alphaMult");
public FloatParameter size = new FloatParameter(this,0f,0f,100f,"size");
public FloatParameter space = new FloatParameter(this,1f,0f,100f,"space");
public FloatParameter add = new FloatParameter(this,1f,0f,10f,"add");
public FloatParameter insertPoint = new FloatParameter(this,0f,0f,1f,"insertPoint");
public FloatParameter deletePoint = new FloatParameter(this,1f,0f,1f,"deletePoint");
public ListParameter onBeatAdd = new ListParameter(this,0,ListParameter.onOff,ListParameter.onOffNames,"onBeatAdd");
public ListParameter deleteLeft = new ListParameter(this,0,ListParameter.onOff,ListParameter.onOffNames,"deleteLeft");
public ListParameter deleteMobile = new ListParameter(this,1,ListParameter.onOff,ListParameter.onOffNames,"deleteMobile");
public ListParameter deleteRight = new ListParameter(this,0,ListParameter.onOff,ListParameter.onOffNames,"deleteRight");
boolean addNow=false;
List<Line> lines=new LinkedList<Line>();
int deleteIdx=0;
public LayerLines(Application parent){
super(parent);
setParameterMap();
}
@Override
public void draw(GL2 gl){
//transform
//GL2 gl = PJOGL.gl;
gl.glPushMatrix();
gl.glTranslatef(Config.WIDTH/2,Config.HEIGHT/2,0);
float x=0;
float alphaMult = this.alphaMult.v();
for(Line line : lines){
if(line.width>0){
Color rgb = new Color(Color.HSBtoRGB(line.h,line.s,line.b));
float r = rgb.getRed()/255f;
float g = rgb.getGreen()/255f;
float b = rgb.getBlue()/255f;
gl.glBegin(GL2.GL_QUADS);
gl.glColor4f(r, g, b, line.alpha*alphaMult);
gl.glVertex2f(x-Config.WIDTH/2, -1*Config.HEIGHT);
gl.glVertex2f(x-Config.WIDTH/2+line.width, -1*Config.HEIGHT);
//gl.glColor4f(b, g, b, line.alpha);
gl.glVertex2f(x-Config.WIDTH/2+line.width, Config.HEIGHT);
gl.glVertex2f(x-Config.WIDTH/2, Config.HEIGHT);
gl.glEnd();
}
x+=line.space;
}
gl.glPopMatrix();
//System.out.println(x);
}
private float linesLength(List<Line> lines){
float l = 0;
for(Line line : lines){
l= l + line.space;
}
return(l);
}
private void processLines(){
//clean old lines
float insertPoint = this.insertPoint.v();
boolean inserted=false;
//delete
float deletePoint = this.deletePoint.v();
boolean deleteLeft = this.deleteLeft.v()==1;
boolean deleteMobile = this.deleteMobile.v()==1;
boolean deleteRight = this.deleteRight.v()==1;
//System.out.println(linesLength(lines)+ " "+lines.size());
LinkedList<Line> newLines = new LinkedList<LayerLines.Line>();
float len = linesLength(lines);
int j=0;
while(j<lines.size() && len - lines.get(j).space>Config.WIDTH && (deleteLeft || deleteRight)){
if(deleteIdx%3==0 && deleteLeft){
len -= lines.get(0).space;
lines.remove(0);
deleteIdx++;
}else if(deleteIdx%3==1 && deleteRight){
len -= lines.get(lines.size()-1).space;
lines.remove(lines.size()-1);
deleteIdx++;
}else if(j>0){
deleteIdx++;
}
j++;
}
float x = 0;
//boolean deleted=true;
for(int i=0;i<lines.size();i++){
Line line = lines.get(i);
x+=line.space;
//add
if(onBeatAdd.v()==0 || addNow){
if(x>=insertPoint*Config.WIDTH && !inserted){
addLine(newLines);
inserted=true;
addNow=false;
}
}
if(deleteMobile && len-line.space > Config.WIDTH && x>=Config.WIDTH*deletePoint){
//delete
len-=line.space;
deleteIdx++;
}else{
//keep
newLines.add(line);
}
}
//add if not added
if(onBeatAdd.v()==0 || addNow){
if(len < Config.WIDTH && !inserted){
addLine(newLines);
addNow=false;
}
}
j=0;
len = linesLength(newLines);
while(j<newLines.size() && len - newLines.get(j).space>Config.WIDTH && (deleteLeft || deleteRight)){
if(deleteIdx%3==0 && deleteLeft){
len -= newLines.get(0).space;
newLines.remove(0);
deleteIdx++;
}else if(deleteIdx%3==1 && deleteRight){
len -= newLines.get(newLines.size()-1).space;
newLines.remove(newLines.size()-1);
deleteIdx++;
}else if(j>0){
deleteIdx++;
}
j++;
}
//publish
lines = newLines;
}
private void addLine(LinkedList<Line> lines){
float add=this.add.v();
for(int j=0;j<add;j++){
Line newLine = new Line();
newLine.h=this.fgH.v();
newLine.s=this.fgS.v();
newLine.b=this.fgB.v();
newLine.alpha=this.fgAlpha.v();
newLine.width=this.size.v();
newLine.space=this.space.v();
if(! (newLine.space==0 && newLine.width==0)){
lines.add(newLine);
}
}
}
@Override
public void drawBackground(GL2 gl){
HSBtoRGB();
//GL2 gl = PJOGL.gl;
gl.glColor4f( backgroundR/255f, backgroundG/255f, backgroundB/255f, bgAlpha.v());
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(0f,0f);
gl.glVertex2f(Config.WIDTH,0f);
gl.glVertex2f(Config.WIDTH,Config.HEIGHT);
gl.glVertex2f(0f,Config.HEIGHT);
gl.glEnd();
}
@Override
public int buildUI(GUIController controller, int x, int y, Tab tab, Group group) {
y+=super.buildUI(controller, x, y, tab, group);
String layerType = this.getType();
//Bars
//x=750;
controller.addControlFloatParameter(layerType,"alphaMult",alphaMult.min,alphaMult.max, x, y, tab,group);
y+=controller.h+controller.hMargin;
controller.addControlFloatParameter(layerType,"add",add.min,add.max, x, y, tab,group);
controller.addToggle(layerType, "onBeatAdd.v", false, x+650, y+30, tab, group).setCaptionLabel("onBeatAdd");
int y2 = y;
y2+=controller.h+controller.hMargin;
y2+=controller.h+controller.hMargin;
controller.addToggle(layerType, "deleteLeft.v", false, x+650, y2+30, tab, group).setCaptionLabel("del Left");
y2+=controller.h+controller.hMargin;
y2+=controller.h+controller.hMargin;
controller.addToggle(layerType, "deleteMobile.v", false, x+650, y2+30, tab, group).setCaptionLabel("del Mobile");
y2+=controller.h+controller.hMargin;
y2+=controller.h+controller.hMargin;
controller.addToggle(layerType, "deleteRight.v", false, x+650, y2+30, tab, group).setCaptionLabel("del Right");
y+=controller.h+controller.hMargin;
controller.addControlFloatParameter(layerType,"size",size.min,size.max, x, y, tab,group);
y+=controller.h+controller.hMargin;
controller.addControlFloatParameter(layerType,"space",space.min,space.max, x, y, tab,group);
y+=controller.h+controller.hMargin;
controller.addControlFloatParameter(layerType,"insertPoint",insertPoint.min,insertPoint.max, x, y, tab,group);
y+=controller.h+controller.hMargin;
controller.addControlFloatParameter(layerType,"deletePoint",deletePoint.min,deletePoint.max, x, y, tab,group);
y+=controller.h+controller.hMargin;
return(y);
}
@Override
public void keyEvent(int key, int keyCode, char ch, boolean a, boolean c, boolean s,boolean win,boolean apl,long[] lastPressedTime) {
super.keyEvent(key, keyCode, ch, a, c, s, win, apl, lastPressedTime);
}
public void soundControl(SoundController soundController){
super.soundControl(soundController);
SoundControllerGroup group0 = soundController.getGroups().get(0);
if(group0.isOnBeat()){
if(onBeatAdd.v()==1){
addNow=true;
}
}
}
@Override
public void update() {
this.processLines();
super.update();
}
}