Commit | Line | Data |
---|---|---|
610db5fe | 1 | class SineSphere extends APat { |
251dcf21 | 2 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
e88f9c30 | 3 | private BasicParameter yrotspeed = new BasicParameter("yspeed", 3000, 1, 10000); |
251dcf21 | 4 | private BasicParameter yrot2speed = new BasicParameter("y2speed", 4000, 1, 15000); |
e88f9c30 | 5 | private BasicParameter yrot3speed = new BasicParameter("y3speed", 1400, 1, 15000); |
251dcf21 | 6 | private BasicParameter vibrationrate = new BasicParameter("vib", 3000, 1, 10000); |
e88f9c30 AG |
7 | private SawLFO yrot = new SawLFO(0, TWO_PI, yrotspeed); |
8 | private SawLFO yrot2 = new SawLFO(0, -TWO_PI, yrot2speed); | |
9 | private SawLFO yrot3 = new SawLFO(0, -TWO_PI, yrot3speed); | |
610db5fe | 10 | public BasicParameter huespread = new BasicParameter("Hue", 0, 180); |
251dcf21 AG |
11 | public BasicParameter widthparameter= new BasicParameter("Width", 20, 1, 60); |
12 | public BasicParameter vibration_magnitude = new BasicParameter("Vmag", 20, 2, modelrad/2); | |
13 | public BasicParameter scale = new BasicParameter("Scale", 1, .1, 5); | |
1c44211b AG |
14 | private int pitch = 0; |
15 | private int channel = 0; | |
16 | private int velocity = 0; | |
df18145f | 17 | private int cur = 0; |
9fa29818 | 18 | public final LXProjection sinespin; |
09437b3e | 19 | public final LXProjection sinespin2; |
1a92d73a | 20 | public final LXProjection sinespin3; |
251dcf21 | 21 | |
8f4e6c99 | 22 | Pick Galaxy, STime; |
09437b3e | 23 | |
09437b3e AG |
24 | public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 ); |
25 | public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1); | |
26 | public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1); | |
27 | ||
7974acd6 | 28 | public final PVector P = new PVector(); |
a9aad043 | 29 | |
0b1785e3 | 30 | class Sphery { |
a9aad043 | 31 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci |
0b1785e3 | 32 | private SinLFO vibration; |
251dcf21 AG |
33 | private SinLFO surfacewave; |
34 | ||
a9aad043 AG |
35 | private SinLFO xbounce; |
36 | public SinLFO ybounce; | |
37 | private SinLFO zbounce; | |
610db5fe | 38 | float vibration_magnitude, vperiod, radius, vibration_min, vibration_max; |
1c44211b AG |
39 | |
40 | //public BasicParameter huespread; | |
a9aad043 AG |
41 | public BasicParameter bouncerate; |
42 | public BasicParameter bounceamp; | |
a62bf8ad | 43 | public BasicParameter vibrationrate; |
8f4e6c99 | 44 | public final PVector circlecenter; |
a9aad043 | 45 | |
610db5fe | 46 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float radius, float vibration_magnitude , float vperiod) |
a9aad043 | 47 | { |
0b1785e3 AG |
48 | this.f1xcenter = f1xcenter; |
49 | this.f1ycenter = f1ycenter; | |
50 | this.f1zcenter = f1zcenter; | |
610db5fe | 51 | this.radius = radius; |
8f4e6c99 | 52 | this.circlecenter= new PVector(f1xcenter,f1ycenter,f1zcenter); |
251dcf21 AG |
53 | |
54 | this.vibration_magnitude = vibration_magnitude; | |
55 | ||
0b1785e3 | 56 | this.vperiod = vperiod; |
1d414e45 AG |
57 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); |
58 | //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate); | |
e3da2932 | 59 | //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000)); |
1c44211b | 60 | //addParameter(widthparameter = new BasicParameter("Width", .2)); |
251dcf21 | 61 | //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); |
df18145f | 62 | addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy |
a9aad043 AG |
63 | |
64 | //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate); | |
610db5fe | 65 | addModulator( vibration = new SinLFO( this.radius - vibration_magnitude , this.radius + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); |
251dcf21 | 66 | |
7974acd6 | 67 | |
a9aad043 | 68 | } |
a62bf8ad | 69 | |
251dcf21 AG |
70 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_magnitude, float vperiod) |
71 | // { | |
72 | // this.f1xcenter = f1xcenter; | |
73 | // this.f1ycenter = f1ycenter; | |
74 | // this.f1zcenter = f1zcenter; | |
75 | // this.vibration_magnitude = vibration_magnitude; | |
76 | // this.vperiod = vperiod; | |
77 | // addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy | |
78 | // addModulator( vibration = new SinLFO( modelrad/10 - vibration_magnitude , modelrad/10 + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); | |
79 | ||
80 | // } | |
81 | ||
a62bf8ad | 82 | //for an ellipse |
1c44211b AG |
83 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter, |
84 | // float vibration_min, float vibration_max, float vperiod) | |
38712136 | 85 | |
1c44211b AG |
86 | // { |
87 | // this.f1xcenter = f1xcenter; | |
88 | // this.f1ycenter = f1ycenter; | |
89 | // this.f1zcenter = f1zcenter; | |
90 | // this.f2xcenter = f2xcenter; | |
91 | // this.f2ycenter = f2ycenter; | |
92 | // this.f2zcenter = f2zcenter; | |
93 | // this.vibration_min = vibration_min; | |
94 | // this.vibration_max = vibration_max; | |
95 | // this.vperiod = vperiod; | |
96 | // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
97 | // addModulator(ybounce).trigger(); | |
98 | // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx); | |
99 | // addParameter(widthparameter = new BasicParameter("Width", .1)); | |
100 | // //addParameter(huespread = new BasicParameter("bonk", .2)); | |
a9aad043 | 101 | |
1c44211b AG |
102 | // } |
103 | ||
570ba27d | 104 | public int c1c (float a) { return round(100*constrain(a,0,1)); } |
a9aad043 | 105 | |
e3da2932 AG |
106 | void setVibrationPeriod(double period){ |
107 | // to-do: make this conditional upon time signature | |
a9aad043 | 108 | |
1a92d73a | 109 | this.vibration.setPeriod(period); |
e3da2932 | 110 | } |
a9aad043 | 111 | |
251dcf21 AG |
112 | void setVibrationMagnitude(double mag){ |
113 | //to-do: make this optionally conditional upon decibel volume, frequency spectrum) | |
114 | this.vibration.setRange(-mag,mag); | |
115 | ||
116 | } | |
117 | ||
a9aad043 AG |
118 | |
119 | float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z) | |
120 | { | |
0b1785e3 AG |
121 | return dist(px, py, pz, f1x, f1y, f1z); |
122 | } | |
c2f643bd | 123 | //void updatespherey(deltaMs, ) |
55a56424 | 124 | |
e0cfbe20 | 125 | float quadrant(PVector q) { |
7b2faded | 126 | float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) ); |
8f4e6c99 | 127 | float qphi = acos( (q.z-f1zcenter)/(PVector.dist(q,circlecenter)) ); |
7b2faded | 128 | |
a62bf8ad | 129 | |
610db5fe | 130 | return map(qtheta, -PI/2, PI/2, 200-huespread.getValuef(), 240+huespread.getValuef()); |
e0cfbe20 AG |
131 | //if (q.x > f1xcenter ) {return 140 ;} |
132 | //else {return 250;} | |
55a56424 | 133 | } |
570ba27d AG |
134 | |
135 | // float noisesat(PVector q) { | |
136 | ||
137 | ||
138 | // return noise() | |
139 | ||
140 | // } | |
1a92d73a AG |
141 | color spheryvalue (PVector p) { |
142 | circlecenter.set(this.f1xcenter, this.f1ycenter, this.f1zcenter); | |
7974acd6 | 143 | |
a62bf8ad | 144 | |
a9aad043 | 145 | //switch(sShpape.cur() ) {} |
7974acd6 | 146 | |
251dcf21 AG |
147 | float b = max(0, 100 - widthparameter.getValuef()*abs(p.dist(circlecenter) |
148 | - vibration.getValuef()) ); | |
7974acd6 MS |
149 | |
150 | if (b <= 0) { | |
151 | return 0; | |
152 | } | |
153 | ||
154 | return lx.hsb( | |
a62bf8ad | 155 | constrain(quadrant(p), 0, 360), |
251dcf21 AG |
156 | // constrain(100*noise(quadrant(p)), 0, 100), |
157 | 100, | |
158 | b | |
7974acd6 | 159 | ); |
0b1785e3 | 160 | } |
a9aad043 AG |
161 | color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc) |
162 | { | |
163 | //switch(sShpape.cur() ) {} | |
a41f334c | 164 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , |
a9aad043 AG |
165 | max(0, 100 - 100*widthparameter.getValuef() * |
166 | abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) + | |
167 | (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2 | |
168 | - 1.2*vibration.getValuef() ) ) ) ; | |
0b1785e3 | 169 | } |
a9aad043 | 170 | |
0b1785e3 | 171 | |
a9aad043 AG |
172 | } |
173 | ||
8f4e6c99 AG |
174 | boolean noteOn(Note note) { |
175 | int row = note.getPitch(), col = note.getChannel(); | |
176 | // if (row == 57) {KeyPressed = col; return true; } | |
177 | return super.noteOn(note); | |
178 | } | |
1c44211b | 179 | |
a9aad043 | 180 | |
8f4e6c99 AG |
181 | // public boolean noteOn(Note note) { |
182 | // pitch= note.getPitch(); | |
183 | // velocity=note.getVelocity(); | |
184 | // channel=note.getChannel(); | |
185 | // return true; | |
186 | // } | |
187 | ||
188 | // public boolean gridPressed(int row, int col) { | |
189 | // pitch = row; channel = col; | |
190 | // cur = NumApcCols*(pitch-53)+col; | |
191 | // //setState(row, col, 0 ? 1 : 0); | |
192 | // return true; | |
193 | // } | |
df18145f AG |
194 | |
195 | //public grid | |
0b1785e3 | 196 | final Sphery[] spherys; |
1d414e45 | 197 | |
a9aad043 AG |
198 | SineSphere(GLucose glucose) |
199 | { | |
0b1785e3 | 200 | super(glucose); |
251dcf21 | 201 | println("modelrad " + modelrad); |
9fa29818 | 202 | sinespin = new LXProjection(model); |
09437b3e | 203 | sinespin2 = new LXProjection(model); |
1a92d73a | 204 | sinespin3= new LXProjection(model); |
1c44211b | 205 | addParameter(huespread); |
1a92d73a | 206 | addParameter(vibrationrate); |
251dcf21 | 207 | addParameter(widthparameter); |
e3da2932 AG |
208 | addParameter(rotationx); |
209 | addParameter(rotationy); | |
210 | addParameter(rotationz); | |
1a92d73a AG |
211 | addParameter(yrotspeed); |
212 | addParameter(yrot2speed); | |
213 | addParameter(yrot3speed); | |
251dcf21 AG |
214 | addParameter(vibration_magnitude); |
215 | addParameter(scale); | |
d8239019 | 216 | addModulator(yrot).trigger(); |
e0cfbe20 | 217 | addModulator(yrot2).trigger(); |
1a92d73a | 218 | addModulator(yrot3).trigger(); |
8f4e6c99 AG |
219 | //Galaxy = addPick("Galaxy", 1, 3, new String[] {"home", "vertical","single","aquarium"}); |
220 | STime =addPick("Time", 1, 4, new String[]{"half", "triplet", "beat", "2x", "3x" }); | |
e3da2932 | 221 | |
a9aad043 | 222 | spherys = new Sphery[] { |
610db5fe AG |
223 | new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/12, modelrad/25, 3000), |
224 | new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/14, modelrad/28, 2000), | |
225 | new Sphery(model.cx, model.cy, model.cz, modelrad/5, modelrad/15, 2300), | |
226 | new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/11, modelrad/25, 3500), | |
227 | new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/12, modelrad/30, 2000) | |
228 | ||
251dcf21 | 229 | |
e0cfbe20 | 230 | |
251dcf21 AG |
231 | |
232 | ||
233 | // new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000), | |
234 | // new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000), | |
235 | // new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300), | |
236 | ||
237 | // new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/14, modelrad/7, 3500), | |
238 | // new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/20, modelrad/10, 2000), | |
239 | // new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300), | |
e0cfbe20 | 240 | |
7974acd6 | 241 | }; |
0b1785e3 AG |
242 | } |
243 | ||
a9aad043 AG |
244 | // public void onParameterChanged(LXParameter parameter) |
245 | // { | |
e28f168c | 246 | |
e28f168c | 247 | |
a9aad043 AG |
248 | // for (Sphery s : spherys) { |
249 | // if (s == null) continue; | |
250 | // double bampv = s.bounceamp.getValue(); | |
251 | // double brv = s.bouncerate.getValue(); | |
252 | // double tempobounce = lx.tempo.bpm(); | |
253 | // if (parameter == s.bounceamp) | |
254 | // { | |
255 | // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv); | |
256 | // } | |
257 | // else if ( parameter == s.bouncerate ) | |
258 | // { | |
259 | // s.ybounce.setDuration(120000./tempobounce); | |
260 | // } | |
261 | // } | |
262 | // } | |
e28f168c | 263 | |
1d414e45 | 264 | public void run( double deltaMs) { |
1a92d73a AG |
265 | float t = lx.tempo.rampf(); |
266 | float bpm = lx.tempo.bpmf(); | |
251dcf21 | 267 | float scalevalue = scale.getValuef(); |
8f4e6c99 AG |
268 | int spherytime= STime.Cur(); |
269 | ||
df18145f | 270 | |
8f4e6c99 | 271 | switch (spherytime) { |
1a92d73a | 272 | |
8f4e6c99 | 273 | case 0: t = map(.5*t ,0,.5, 0,1); bpm = .5*bpm; break; |
df18145f | 274 | |
8f4e6c99 | 275 | case 1: t = t; bpm = bpm; break; |
1c44211b | 276 | |
8f4e6c99 | 277 | case 2: t = map(2*t,0,2,0,1); bpm = 2*bpm; break; |
1c44211b | 278 | |
8f4e6c99 AG |
279 | default: t= t; bpm = bpm; |
280 | } | |
1c44211b | 281 | |
1a92d73a | 282 | //switch(sphery.colorscheme) |
df18145f | 283 | |
1c44211b | 284 | for ( Sphery s: spherys){ |
1a92d73a AG |
285 | |
286 | //s.vibration.setBasis(t); | |
287 | s.setVibrationPeriod(vibrationrate.getValuef()); | |
251dcf21 | 288 | // s.setVibrationMagnitude(vibration_magnitude.getValuef()); |
df18145f | 289 | |
1c44211b | 290 | } |
1a92d73a AG |
291 | |
292 | ||
293 | sinespin.reset() | |
294 | // Translate so the center of the car is the origin, offset | |
09437b3e | 295 | .center() |
251dcf21 | 296 | .scale(scalevalue, scalevalue, scalevalue) |
1d414e45 | 297 | // Rotate around the origin (now the center of the car) about an y-vector |
e3da2932 | 298 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
38712136 | 299 | .translate(model.cx, model.cy, model.cz); |
1d414e45 | 300 | |
d8239019 | 301 | |
e0cfbe20 | 302 | |
1d414e45 | 303 | |
d8239019 | 304 | |
09437b3e | 305 | for (LXVector p: sinespin) |
1a92d73a | 306 | // for (Point p: model.points) |
1d414e45 | 307 | { |
7974acd6 MS |
308 | P.set(p.x, p.y, p.z); |
309 | // PVector P = new PVector(p.x, p.y, p.z); | |
310 | color c = #000000; | |
1a92d73a AG |
311 | c = blendIfColor(c, spherys[1].spheryvalue(P), ADD); |
312 | c = blendIfColor(c, spherys[0].spheryvalue(P), ADD); | |
313 | c = blendIfColor(c, spherys[2].spheryvalue(P),ADD); | |
e0cfbe20 | 314 | |
d8239019 | 315 | |
7974acd6 | 316 | colors[p.index] = c; |
e0cfbe20 | 317 | |
d8239019 | 318 | |
e0cfbe20 | 319 | } |
09437b3e AG |
320 | sinespin2.reset() |
321 | .center() | |
251dcf21 | 322 | .scale(scalevalue,scalevalue,scalevalue) |
1a92d73a | 323 | .rotate(yrot2.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
09437b3e | 324 | .translate(model.cx,model.cy,model.cz); |
e0cfbe20 | 325 | |
09437b3e | 326 | for (LXVector p: sinespin2) |
e0cfbe20 | 327 | { color c = 0; |
7974acd6 MS |
328 | // PVector P = new PVector(p.x, p.y, p.z); |
329 | P.set(p.x, p.y, p.z); | |
1a92d73a | 330 | c = blendIfColor(c, spherys[3].spheryvalue(P),ADD); |
7b2faded | 331 | |
7974acd6 | 332 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); |
e0cfbe20 AG |
333 | |
334 | } | |
1a92d73a AG |
335 | sinespin3.reset() |
336 | .center() | |
251dcf21 | 337 | .scale(scalevalue,scalevalue,scalevalue) |
e88f9c30 | 338 | .rotate(yrot3.getValuef(),-1 + rotationx.getValuef(), rotationy.getValuef(), rotationz.getValuef()) |
1a92d73a AG |
339 | .translate(model.cx, model.cy, model.cz); |
340 | for (LXVector p: sinespin3) | |
341 | { color c = 0; | |
342 | // PVector P = new PVector(p.x, p.y, p.z); | |
343 | P.set(p.x, p.y, p.z); | |
344 | c = blendIfColor(c, spherys[4].spheryvalue(P),ADD); | |
345 | ||
346 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); | |
347 | ||
348 | } | |
349 | ||
350 | ||
e0cfbe20 | 351 | |
610db5fe AG |
352 | |
353 | ||
354 | ||
355 | ||
7974acd6 MS |
356 | } |
357 | ||
358 | color blendIfColor(color c1, color c2, int mode) { | |
359 | if (c2 != 0) { | |
360 | return blendColor(c1, c2, mode); | |
361 | } | |
362 | return c1; | |
a9aad043 | 363 | } |
e27a8652 | 364 | |
a9aad043 AG |
365 | |
366 | // color c = 0; | |
367 | // c = blendColor(c, spherys[3].ellipsevalue(Px.x, Px.y, Px.z, model.xMax/4, model.yMax/4, model.zMax/4, 3*model.xMax/4, 3*model.yMax/4, 3*model.zMax/4),ADD); | |
368 | // return c; | |
369 | // } | |
a41f334c | 370 | // return lx.hsb(0,0,0); |
a9aad043 AG |
371 | // // else if(spheremode ==2) |
372 | // { color c = 0; | |
a41f334c | 373 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
374 | |
375 | // } | |
376 | ||
377 | ||
d8239019 | 378 | // } |
a9aad043 AG |
379 | |
380 | } | |
8f4e6c99 AG |
381 | /*This just takes all of Dan Horwitz's code that I want to inherit and leaves the rest behind. |
382 | A work in progress. */ | |
a9aad043 | 383 | |
610db5fe | 384 | public class APat extends SCPattern |
8f4e6c99 AG |
385 | |
386 | ||
610db5fe AG |
387 | { |
388 | ArrayList<Pick> picks = new ArrayList<Pick> (); | |
389 | ArrayList<DBool> bools = new ArrayList<DBool> (); | |
390 | ||
391 | PVector mMax, mCtr, mHalf; | |
392 | ||
393 | MidiOutput APCOut; | |
394 | int nMaxRow = 53; | |
395 | float LastJog = -1; | |
396 | float[] xWaveNz, yWaveNz; | |
397 | int nPoint , nPoints; | |
398 | PVector xyzJog = new PVector(), modmin; | |
399 | ||
400 | float NoiseMove = random(10000); | |
401 | BasicParameter pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY; | |
402 | DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey; | |
403 | ||
404 | float lxh () { return lx.getBaseHuef(); } | |
405 | int c1c (float a) { return round(100*constrain(a,0,1)); } | |
406 | float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); } | |
407 | void setNorm (PVector vec) { vec.set(vec.x/mMax.x, vec.y/mMax.y, vec.z/mMax.z); } | |
408 | void setRand (PVector vec) { vec.set(random(mMax.x), random(mMax.y), random(mMax.z)); } | |
409 | void setVec (PVector vec, LXPoint p) { vec.set(p.x, p.y, p.z); } | |
410 | void interpolate(float i, PVector a, PVector b) { a.set(interp(i,a.x,b.x), interp(i,a.y,b.y), interp(i,a.z,b.z)); } | |
411 | //void StartRun(double deltaMs) { } | |
412 | float val (BasicParameter p) { return p.getValuef(); } | |
413 | //color CalcPoint(PVector p) { return lx.hsb(0,0,0); } | |
414 | color blend3(color c1, color c2, color c3) { return blendColor(c1,blendColor(c2,c3,ADD),ADD); } | |
415 | ||
416 | void rotateZ (PVector p, PVector o, float nSin, float nCos) { p.set( nCos*(p.x-o.x) - nSin*(p.y-o.y) + o.x , nSin*(p.x-o.x) + nCos*(p.y-o.y) + o.y,p.z); } | |
417 | void rotateX (PVector p, PVector o, float nSin, float nCos) { p.set(p.x,nCos*(p.y-o.y) - nSin*(p.z-o.z) + o.y , nSin*(p.y-o.y) + nCos*(p.z-o.z) + o.z ); } | |
418 | void rotateY (PVector p, PVector o, float nSin, float nCos) { p.set( nSin*(p.z-o.z) + nCos*(p.x-o.x) + o.x,p.y, nCos*(p.z-o.z) - nSin*(p.x-o.x) + o.z ); } | |
419 | ||
420 | BasicParameter addParam(String label, double value) { BasicParameter p = new BasicParameter(label, value); addParameter(p); return p; } | |
421 | ||
422 | PVector vT1 = new PVector(), vT2 = new PVector(); | |
423 | float calcCone (PVector v1, PVector v2, PVector c) { vT1.set(v1); vT2.set(v2); vT1.sub(c); vT2.sub(c); | |
424 | return degrees(PVector.angleBetween(vT1,vT2)); } | |
425 | ||
426 | Pick addPick(String name, int def, int _max, String[] desc) { | |
427 | Pick P = new Pick(name, def, _max+1, nMaxRow, desc); | |
428 | nMaxRow = P.EndRow + 1; | |
429 | picks.add(P); | |
430 | return P; | |
431 | } | |
432 | ||
433 | boolean noteOff(Note note) { | |
434 | int row = note.getPitch(), col = note.getChannel(); | |
435 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; } | |
436 | updateLights(); return false; | |
437 | } | |
438 | ||
439 | boolean noteOn(Note note) { | |
440 | int row = note.getPitch(), col = note.getChannel(); | |
441 | for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) { presetManager.dirty(this); return true; } | |
442 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) { presetManager.dirty(this); return true; } | |
443 | println("row: " + row + " col: " + col); return false; | |
444 | } | |
445 | ||
446 | void onInactive() { uiDebugText.setText(""); } | |
447 | void onReset() { | |
448 | for (int i=0; i<bools .size(); i++) bools.get(i).reset(); | |
449 | for (int i=0; i<picks .size(); i++) picks.get(i).reset(); | |
450 | presetManager.dirty(this); | |
451 | updateLights(); | |
452 | } | |
453 | ||
454 | APat(GLucose glucose) { | |
455 | super(glucose); | |
456 | ||
457 | ||
458 | ||
459 | nPoints = model.points.size(); | |
460 | pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym ); | |
461 | pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym ); | |
462 | pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym ); | |
463 | pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup ); | |
464 | pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog ); | |
465 | pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey ); | |
466 | ||
467 | modmin = new PVector(model.xMin, model.yMin, model.zMin); | |
468 | mMax = new PVector(model.xMax, model.yMax, model.zMax); mMax.sub(modmin); | |
469 | mCtr = new PVector(); mCtr.set(mMax); mCtr.mult(.5); | |
470 | mHalf = new PVector(.5,.5,.5); | |
471 | xWaveNz = new float[ceil(mMax.y)+1]; | |
472 | yWaveNz = new float[ceil(mMax.x)+1]; | |
473 | ||
474 | //println (model.xMin + " " + model.yMin + " " + model.zMin); | |
475 | //println (model.xMax + " " + model.yMax + " " + model.zMax); | |
476 | //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}} | |
477 | } | |
478 | ||
479 | float spin() { | |
480 | float raw = val(pSpin); | |
481 | if (raw <= 0.45) { | |
482 | return raw + 0.05; | |
483 | } else if (raw >= 0.55) { | |
484 | return raw - 0.05; | |
485 | } | |
486 | return 0.5; | |
487 | } | |
488 | ||
489 | void setAPCOutput(MidiOutput output) { | |
490 | APCOut = output; | |
491 | } | |
492 | ||
493 | void updateLights() { if (APCOut == null) return; | |
494 | for (int i = 0; i < NumApcRows; ++i) | |
495 | for (int j = 0; j < 8; ++j) APCOut.sendNoteOn(j, 53+i, 0); | |
496 | for (int i=0; i<picks .size(); i++) APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3); | |
497 | for (int i=0; i<bools .size(); i++) if (bools.get(i).b) APCOut.sendNoteOn (bools.get(i).col, bools.get(i).row, 1); | |
498 | else APCOut.sendNoteOff (bools.get(i).col, bools.get(i).row, 0); | |
499 | } | |
500 | ||
501 | void run(double deltaMs) | |
502 | { | |
503 | if (deltaMs > 100) return; | |
504 | ||
505 | if (this == midiEngine.getFocusedDeck().getActivePattern()) { | |
506 | String Text1="", Text2=""; | |
507 | for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " "; | |
508 | for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " "; | |
509 | uiDebugText.setText(Text1, Text2); | |
510 | } | |
511 | ||
512 | ||
513 | } | |
514 | } | |
515 | ||
5bc92bc2 | 516 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
517 | float CH, CW, diag; |
518 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
519 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
5bc92bc2 AG |
520 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); |
521 | ||
522 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
523 | ||
524 | CubeCurl(GLucose glucose){ | |
525 | super(glucose); | |
526 | addModulator(curl).trigger(); | |
527 | addModulator(bg).trigger(); | |
7c7625ec AG |
528 | this.CH = Cube.EDGE_HEIGHT; |
529 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 530 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 531 | |
7c7625ec | 532 | |
b30f14fd | 533 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 534 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
535 | Cube a = model.cubes.get(i); |
536 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
e0cfbe20 | 537 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); |
b30f14fd AG |
538 | |
539 | } | |
5bc92bc2 AG |
540 | |
541 | } | |
7c7625ec AG |
542 | //there is definitely a better way of doing this! |
543 | PVector centerofcube(int i) { | |
544 | Cube c = model.cubes.get(i); | |
df18145f | 545 | PVector cubecenter = new PVector(c.cx, c.cy, c.cz); |
f1370a0b | 546 | |
b30f14fd | 547 | return cubecenter; |
7c7625ec AG |
548 | } |
549 | ||
5bc92bc2 AG |
550 | |
551 | void run(double deltaMs){ | |
552 | for (int i =0; i < model.cubes.size(); i++) { | |
553 | Cube c = model.cubes.get(i); | |
554 | float cfloor = c.y; | |
555 | ||
f1370a0b | 556 | // if (i%3 == 0){ |
5bc92bc2 | 557 | |
2bb56822 | 558 | // for (LXPoint p : c.points ){ |
f1370a0b AG |
559 | // // colors[p.index]=color(0,0,0); |
560 | // //float dif = (p.y - c.y); | |
561 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
562 | // } | |
563 | // } | |
5bc92bc2 | 564 | |
f1370a0b | 565 | // else if (i%3 == 1) { |
5bc92bc2 | 566 | |
2bb56822 | 567 | // for (LXPoint p: c.points){ |
f1370a0b AG |
568 | // colors[p.index]=color(0,0,0); |
569 | // float dif = (p.y - c.y); | |
570 | // // colors[p.index] = | |
571 | // // color(bg.getValuef(), | |
572 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
573 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
574 | // } | |
575 | // } | |
576 | // else if (i%3 == 2){ | |
b30f14fd | 577 | // centerlist[i].sub(cubeorigin(i); |
2bb56822 | 578 | for (LXPoint p: c.points) { |
b30f14fd | 579 | PVector pv = new PVector(p.x, p.y, p.z); |
f1370a0b | 580 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
b30f14fd | 581 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); |
5bc92bc2 AG |
582 | |
583 | ||
b30f14fd | 584 | } |
5bc92bc2 AG |
585 | |
586 | ||
f1370a0b | 587 | //} |
5bc92bc2 AG |
588 | |
589 | } | |
590 | } | |
591 | } | |
ab65d40b | 592 | JGraphAdapterDemo graph1; |
593 | ||
594 | ||
595 | // class SpinningCube extends SCPattern{ | |
596 | // LXProjection spin1, spin2, spin3; | |
597 | // SawLFO | |
598 | ||
599 | //} | |
600 | ||
601 | ||
602 | ||
5bc92bc2 | 603 | |
a9aad043 AG |
604 | class HueTestHSB extends SCPattern{ |
605 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
606 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
607 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
608 | ||
609 | HueTestHSB(GLucose glucose) { | |
610 | super(glucose); | |
611 | addParameter(HueT); | |
612 | addParameter(SatT); | |
613 | addParameter(BriT); | |
614 | } | |
615 | void run(double deltaMs){ | |
616 | ||
2bb56822 | 617 | for (LXPoint p : model.points) { |
a9aad043 | 618 | color c = 0; |
a41f334c | 619 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
620 | colors[p.index]= c; |
621 | } | |
622 | int now= millis(); | |
623 | if (now % 1000 <= 20) | |
624 | { | |
625 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); | |
626 | } | |
627 | } | |
0b1785e3 | 628 | |
a41f334c | 629 | } |