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); | |
45717f71 | 14 | private int pitch = 0; |
15 | private int channel = 0; | |
16 | private int velocity = 0; | |
17 | private int cur = 0; | |
18 | public final LXProjection sinespin; | |
09437b3e | 19 | public final LXProjection sinespin2; |
1a92d73a | 20 | public final LXProjection sinespin3; |
251dcf21 | 21 | |
45717f71 | 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 |
45717f71 | 32 | private SinLFO vibration; |
33 | private SinLFO surfacewave; | |
251dcf21 | 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 | |
45717f71 | 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; | |
45717f71 | 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 | 57 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); |
45717f71 | 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)); |
45717f71 | 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 | |
45717f71 | 70 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_magnitude, float vperiod) |
251dcf21 | 71 | // { |
45717f71 | 72 | // this.f1xcenter = f1xcenter; |
73 | // this.f1ycenter = f1ycenter; | |
74 | // this.f1zcenter = f1zcenter; | |
75 | // this.vibration_magnitude = vibration_magnitude; | |
251dcf21 | 76 | // this.vperiod = vperiod; |
45717f71 | 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()); | |
251dcf21 AG |
79 | |
80 | // } | |
81 | ||
a62bf8ad | 82 | //for an ellipse |
45717f71 | 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 | |
45717f71 | 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 | ||
45717f71 | 104 | public int c1c (float a) { return round(100*constrain(a,0,1)); } |
a9aad043 | 105 | |
e3da2932 | 106 | void setVibrationPeriod(double period){ |
45717f71 | 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 | 118 | |
45717f71 | 119 | float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z) |
a9aad043 | 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) { |
45717f71 | 126 | float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) ); |
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 | 131 | //if (q.x > f1xcenter ) {return 140 ;} |
45717f71 | 132 | //else {return 250;} |
55a56424 | 133 | } |
570ba27d AG |
134 | |
135 | // float noisesat(PVector q) { | |
136 | ||
137 | ||
45717f71 | 138 | // return noise() |
570ba27d AG |
139 | |
140 | // } | |
1a92d73a | 141 | color spheryvalue (PVector p) { |
45717f71 | 142 | circlecenter.set(this.f1xcenter, this.f1ycenter, this.f1zcenter); |
7974acd6 | 143 | |
a62bf8ad | 144 | |
45717f71 | 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 | |
45717f71 | 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 | { | |
45717f71 | 163 | //switch(sShpape.cur() ) {} |
164 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , | |
a9aad043 | 165 | max(0, 100 - 100*widthparameter.getValuef() * |
45717f71 | 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 | |
45717f71 | 172 | } |
a9aad043 | 173 | |
8f4e6c99 AG |
174 | boolean noteOn(Note note) { |
175 | int row = note.getPitch(), col = note.getChannel(); | |
45717f71 | 176 | // if (row == 57) {KeyPressed = col; return true; } |
8f4e6c99 AG |
177 | return super.noteOn(note); |
178 | } | |
1c44211b | 179 | |
a9aad043 | 180 | |
45717f71 | 181 | // public boolean noteOn(Note note) { |
182 | // pitch= note.getPitch(); | |
8f4e6c99 AG |
183 | // velocity=note.getVelocity(); |
184 | // channel=note.getChannel(); | |
185 | // return true; | |
186 | // } | |
187 | ||
188 | // public boolean gridPressed(int row, int col) { | |
45717f71 | 189 | // pitch = row; channel = col; |
190 | // cur = NumApcCols*(pitch-53)+col; | |
191 | // //setState(row, col, 0 ? 1 : 0); | |
8f4e6c99 AG |
192 | // return true; |
193 | // } | |
df18145f AG |
194 | |
195 | //public grid | |
0b1785e3 | 196 | final Sphery[] spherys; |
1d414e45 | 197 | |
45717f71 | 198 | SineSphere(LX lx) |
a9aad043 | 199 | { |
dde75983 | 200 | super(lx); |
45717f71 | 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(); |
45717f71 | 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), | |
45717f71 | 225 | new Sphery(model.cx, model.cy, model.cz, modelrad/5, modelrad/15, 2300), |
610db5fe AG |
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 | ||
45717f71 | 229 | |
230 | }; | |
0b1785e3 AG |
231 | } |
232 | ||
a9aad043 AG |
233 | // public void onParameterChanged(LXParameter parameter) |
234 | // { | |
e28f168c | 235 | |
e28f168c | 236 | |
45717f71 | 237 | // for (Sphery s : spherys) { |
238 | // if (s == null) continue; | |
239 | // double bampv = s.bounceamp.getValue(); | |
240 | // double brv = s.bouncerate.getValue(); | |
241 | // double tempobounce = lx.tempo.bpm(); | |
242 | // if (parameter == s.bounceamp) | |
243 | // { | |
244 | // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv); | |
245 | // } | |
246 | // else if ( parameter == s.bouncerate ) | |
247 | // { | |
248 | // s.ybounce.setDuration(120000./tempobounce); | |
249 | // } | |
250 | // } | |
251 | // } | |
e28f168c | 252 | |
1d414e45 | 253 | public void run( double deltaMs) { |
45717f71 | 254 | float t = lx.tempo.rampf(); |
1a92d73a | 255 | float bpm = lx.tempo.bpmf(); |
251dcf21 | 256 | float scalevalue = scale.getValuef(); |
8f4e6c99 AG |
257 | int spherytime= STime.Cur(); |
258 | ||
df18145f | 259 | |
8f4e6c99 | 260 | switch (spherytime) { |
1a92d73a | 261 | |
45717f71 | 262 | case 0: t = map(.5*t ,0,.5, 0,1); bpm = .5*bpm; break; |
df18145f | 263 | |
45717f71 | 264 | case 1: t = t; bpm = bpm; break; |
1c44211b | 265 | |
45717f71 | 266 | case 2: t = map(2*t,0,2,0,1); bpm = 2*bpm; break; |
1c44211b | 267 | |
45717f71 | 268 | default: t= t; bpm = bpm; |
8f4e6c99 | 269 | } |
1c44211b | 270 | |
1a92d73a | 271 | //switch(sphery.colorscheme) |
df18145f | 272 | |
1c44211b | 273 | for ( Sphery s: spherys){ |
1a92d73a | 274 | s.setVibrationPeriod(vibrationrate.getValuef()); |
45717f71 | 275 | // s.setVibrationMagnitude(vibration_magnitude.getValuef()); |
df18145f | 276 | |
1c44211b | 277 | } |
1a92d73a AG |
278 | |
279 | ||
280 | sinespin.reset() | |
45717f71 | 281 | // Translate so the center of the car is the origin, offset |
09437b3e | 282 | .center() |
251dcf21 | 283 | .scale(scalevalue, scalevalue, scalevalue) |
1d414e45 | 284 | // Rotate around the origin (now the center of the car) about an y-vector |
e3da2932 | 285 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
38712136 | 286 | .translate(model.cx, model.cy, model.cz); |
1d414e45 | 287 | |
d8239019 | 288 | |
e0cfbe20 | 289 | |
1d414e45 | 290 | |
d8239019 | 291 | |
09437b3e | 292 | for (LXVector p: sinespin) |
1a92d73a | 293 | // for (Point p: model.points) |
1d414e45 | 294 | { |
7974acd6 MS |
295 | P.set(p.x, p.y, p.z); |
296 | // PVector P = new PVector(p.x, p.y, p.z); | |
297 | color c = #000000; | |
1a92d73a AG |
298 | c = blendIfColor(c, spherys[1].spheryvalue(P), ADD); |
299 | c = blendIfColor(c, spherys[0].spheryvalue(P), ADD); | |
300 | c = blendIfColor(c, spherys[2].spheryvalue(P),ADD); | |
e0cfbe20 | 301 | |
d8239019 | 302 | |
7974acd6 | 303 | colors[p.index] = c; |
e0cfbe20 | 304 | |
d8239019 | 305 | |
e0cfbe20 | 306 | } |
09437b3e AG |
307 | sinespin2.reset() |
308 | .center() | |
251dcf21 | 309 | .scale(scalevalue,scalevalue,scalevalue) |
1a92d73a | 310 | .rotate(yrot2.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
09437b3e | 311 | .translate(model.cx,model.cy,model.cz); |
e0cfbe20 | 312 | |
09437b3e | 313 | for (LXVector p: sinespin2) |
45717f71 | 314 | { color c = 0; |
7974acd6 MS |
315 | // PVector P = new PVector(p.x, p.y, p.z); |
316 | P.set(p.x, p.y, p.z); | |
1a92d73a | 317 | c = blendIfColor(c, spherys[3].spheryvalue(P),ADD); |
7b2faded | 318 | |
7974acd6 | 319 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); |
e0cfbe20 | 320 | |
45717f71 | 321 | } |
1a92d73a AG |
322 | sinespin3.reset() |
323 | .center() | |
251dcf21 | 324 | .scale(scalevalue,scalevalue,scalevalue) |
e88f9c30 | 325 | .rotate(yrot3.getValuef(),-1 + rotationx.getValuef(), rotationy.getValuef(), rotationz.getValuef()) |
1a92d73a AG |
326 | .translate(model.cx, model.cy, model.cz); |
327 | for (LXVector p: sinespin3) | |
45717f71 | 328 | { color c = 0; |
1a92d73a AG |
329 | // PVector P = new PVector(p.x, p.y, p.z); |
330 | P.set(p.x, p.y, p.z); | |
331 | c = blendIfColor(c, spherys[4].spheryvalue(P),ADD); | |
332 | ||
333 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); | |
334 | ||
335 | } | |
336 | ||
337 | ||
e0cfbe20 | 338 | |
610db5fe AG |
339 | |
340 | ||
341 | ||
342 | ||
7974acd6 MS |
343 | } |
344 | ||
345 | color blendIfColor(color c1, color c2, int mode) { | |
346 | if (c2 != 0) { | |
347 | return blendColor(c1, c2, mode); | |
348 | } | |
349 | return c1; | |
a9aad043 | 350 | } |
e27a8652 | 351 | |
a9aad043 | 352 | |
45717f71 | 353 | // color c = 0; |
354 | // 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); | |
355 | // return c; | |
a9aad043 | 356 | // } |
a41f334c | 357 | // return lx.hsb(0,0,0); |
45717f71 | 358 | // // else if(spheremode ==2) |
a9aad043 | 359 | // { color c = 0; |
45717f71 | 360 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
361 | |
362 | // } | |
363 | ||
364 | ||
45717f71 | 365 | // } |
a9aad043 AG |
366 | |
367 | } | |
8f4e6c99 | 368 | /*This just takes all of Dan Horwitz's code that I want to inherit and leaves the rest behind. |
45717f71 | 369 | A work in progress. */ |
a9aad043 | 370 | |
610db5fe | 371 | public class APat extends SCPattern |
8f4e6c99 AG |
372 | |
373 | ||
610db5fe | 374 | { |
45717f71 | 375 | ArrayList<Pick> picks = new ArrayList<Pick> (); |
376 | ArrayList<DBool> bools = new ArrayList<DBool> (); | |
377 | ||
378 | PVector mMax, mCtr, mHalf; | |
379 | ||
380 | MidiOutput APCOut; | |
381 | int nMaxRow = 53; | |
382 | float LastJog = -1; | |
383 | float[] xWaveNz, yWaveNz; | |
384 | int nPoint , nPoints; | |
385 | PVector xyzJog = new PVector(), modmin; | |
386 | ||
387 | float NoiseMove = random(10000); | |
388 | BasicParameter pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY; | |
389 | DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey; | |
390 | ||
391 | float lxh () { return lx.getBaseHuef(); } | |
392 | int c1c (float a) { return round(100*constrain(a,0,1)); } | |
393 | float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); } | |
394 | void setNorm (PVector vec) { vec.set(vec.x/mMax.x, vec.y/mMax.y, vec.z/mMax.z); } | |
395 | void setRand (PVector vec) { vec.set(random(mMax.x), random(mMax.y), random(mMax.z)); } | |
396 | void setVec (PVector vec, LXPoint p) { vec.set(p.x, p.y, p.z); } | |
397 | 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)); } | |
398 | void StartRun(double deltaMs) { } | |
399 | float val (BasicParameter p) { return p.getValuef(); } | |
400 | color CalcPoint(PVector p) { return lx.hsb(0,0,0); } | |
401 | color blend3(color c1, color c2, color c3) { return blendColor(c1,blendColor(c2,c3,ADD),ADD); } | |
402 | ||
403 | 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); } | |
404 | 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 ); } | |
405 | 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 ); } | |
406 | ||
407 | BasicParameter addParam(String label, double value) { BasicParameter p = new BasicParameter(label, value); addParameter(p); return p; } | |
408 | ||
409 | PVector vT1 = new PVector(), vT2 = new PVector(); | |
410 | float calcCone (PVector v1, PVector v2, PVector c) { vT1.set(v1); vT2.set(v2); vT1.sub(c); vT2.sub(c); | |
610db5fe AG |
411 | return degrees(PVector.angleBetween(vT1,vT2)); } |
412 | ||
45717f71 | 413 | Pick addPick(String name, int def, int _max, String[] desc) { |
414 | Pick P = new Pick(name, def, _max+1, nMaxRow, desc); | |
415 | nMaxRow = P.EndRow + 1; | |
610db5fe AG |
416 | picks.add(P); |
417 | return P; | |
418 | } | |
419 | ||
45717f71 | 420 | boolean noteOff(Note note) { |
610db5fe AG |
421 | int row = note.getPitch(), col = note.getChannel(); |
422 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; } | |
423 | updateLights(); return false; | |
424 | } | |
425 | ||
45717f71 | 426 | boolean noteOn(Note note) { |
610db5fe | 427 | int row = note.getPitch(), col = note.getChannel(); |
45717f71 | 428 | for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) { presetManager.dirty(this); return true; } |
429 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) { presetManager.dirty(this); return true; } | |
430 | println("row: " + row + " col: " + col); return false; | |
610db5fe AG |
431 | } |
432 | ||
45717f71 | 433 | void onInactive() { uiDebugText.setText(""); } |
434 | void onReset() { | |
610db5fe AG |
435 | for (int i=0; i<bools .size(); i++) bools.get(i).reset(); |
436 | for (int i=0; i<picks .size(); i++) picks.get(i).reset(); | |
45717f71 | 437 | presetManager.dirty(this); |
438 | updateLights(); | |
610db5fe AG |
439 | } |
440 | ||
21dffb1b MS |
441 | APat(LX lx) { |
442 | super(lx); | |
610db5fe AG |
443 | |
444 | ||
445 | ||
45717f71 | 446 | nPoints = model.points.size(); |
447 | pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym ); | |
448 | pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym ); | |
449 | pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym ); | |
450 | pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup ); | |
451 | pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog ); | |
452 | pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey ); | |
453 | ||
454 | modmin = new PVector(model.xMin, model.yMin, model.zMin); | |
455 | mMax = new PVector(model.xMax, model.yMax, model.zMax); mMax.sub(modmin); | |
456 | mCtr = new PVector(); mCtr.set(mMax); mCtr.mult(.5); | |
457 | mHalf = new PVector(.5,.5,.5); | |
458 | xWaveNz = new float[ceil(mMax.y)+1]; | |
459 | yWaveNz = new float[ceil(mMax.x)+1]; | |
460 | ||
461 | //println (model.xMin + " " + model.yMin + " " + model.zMin); | |
462 | //println (model.xMax + " " + model.yMax + " " + model.zMax); | |
610db5fe AG |
463 | //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}} |
464 | } | |
465 | ||
466 | float spin() { | |
467 | float raw = val(pSpin); | |
468 | if (raw <= 0.45) { | |
469 | return raw + 0.05; | |
470 | } else if (raw >= 0.55) { | |
471 | return raw - 0.05; | |
472 | } | |
473 | return 0.5; | |
474 | } | |
475 | ||
476 | void setAPCOutput(MidiOutput output) { | |
477 | APCOut = output; | |
478 | } | |
479 | ||
480 | void updateLights() { if (APCOut == null) return; | |
45717f71 | 481 | for (int i = 0; i < NumApcRows; ++i) |
482 | for (int j = 0; j < 8; ++j) APCOut.sendNoteOn(j, 53+i, 0); | |
483 | for (int i=0; i<picks .size(); i++) APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3); | |
484 | for (int i=0; i<bools .size(); i++) if (bools.get(i).b) APCOut.sendNoteOn (bools.get(i).col, bools.get(i).row, 1); | |
485 | else APCOut.sendNoteOff (bools.get(i).col, bools.get(i).row, 0); | |
610db5fe AG |
486 | } |
487 | ||
488 | void run(double deltaMs) | |
489 | { | |
490 | if (deltaMs > 100) return; | |
491 | ||
492 | if (this == midiEngine.getFocusedDeck().getActivePattern()) { | |
493 | String Text1="", Text2=""; | |
45717f71 | 494 | for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " "; |
495 | for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " "; | |
610db5fe AG |
496 | uiDebugText.setText(Text1, Text2); |
497 | } | |
498 | ||
45717f71 | 499 | NoiseMove += deltaMs; NoiseMove = NoiseMove % 1e7; |
500 | StartRun (deltaMs); | |
501 | PVector P = new PVector(), tP = new PVector(), pSave = new PVector(); | |
502 | PVector pTrans = new PVector(val(pTransX)*200-100, val(pTransY)*100-50,0); | |
503 | nPoint = 0; | |
504 | ||
505 | if (pJog.b) { | |
506 | float tRamp = (lx.tempo.rampf() % .25); | |
507 | if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2)); | |
508 | LastJog = tRamp; | |
509 | } | |
510 | ||
511 | // precalculate this stuff | |
512 | float wvAmp = val(pWave), sprk = val(pSpark); | |
513 | if (wvAmp > 0) { | |
514 | for (int i=0; i<ceil(mMax.x)+1; i++) | |
515 | yWaveNz[i] = wvAmp * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.); | |
516 | ||
517 | for (int i=0; i<ceil(mMax.y)+1; i++) | |
518 | xWaveNz[i] = wvAmp * (noise(i/(mMax.y*.3)-(1e3+NoiseMove)/1500.) - .5) * (mMax.x/2.); | |
519 | } | |
520 | ||
521 | for (LXPoint p : model.points) { nPoint++; | |
522 | setVec(P,p); | |
523 | P.sub(modmin); | |
524 | P.sub(pTrans); | |
525 | if (sprk > 0) {P.y += sprk*randctr(50); P.x += sprk*randctr(50); P.z += sprk*randctr(50); } | |
526 | if (wvAmp > 0) P.y += interpWv(p.x-modmin.x, yWaveNz); | |
527 | if (wvAmp > 0) P.x += interpWv(p.y-modmin.y, xWaveNz); | |
528 | if (pJog.b) P.add(xyzJog); | |
529 | ||
530 | ||
531 | color cNew, cOld = colors[p.index]; | |
532 | { tP.set(P); cNew = CalcPoint(tP); } | |
533 | if (pXsym.b) { tP.set(mMax.x-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
534 | if (pYsym.b) { tP.set(P.x,mMax.y-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
535 | if (pRsym.b) { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
536 | if (pXdup.b) { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
537 | if (pGrey.b) { cNew = lx.hsb(0, 0, lx.b(cNew)); } | |
538 | colors[p.index] = cNew; | |
539 | } | |
610db5fe AG |
540 | } |
541 | } | |
542 | ||
5bc92bc2 | 543 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
544 | float CH, CW, diag; |
545 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
546 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
45717f71 | 547 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); |
5bc92bc2 AG |
548 | |
549 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
550 | ||
dde75983 MS |
551 | CubeCurl(LX lx){ |
552 | super(lx); | |
5bc92bc2 AG |
553 | addModulator(curl).trigger(); |
554 | addModulator(bg).trigger(); | |
7c7625ec AG |
555 | this.CH = Cube.EDGE_HEIGHT; |
556 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 557 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 558 | |
7c7625ec | 559 | |
b30f14fd | 560 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 561 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
562 | Cube a = model.cubes.get(i); |
563 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
e0cfbe20 | 564 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); |
b30f14fd | 565 | |
45717f71 | 566 | } |
5bc92bc2 AG |
567 | |
568 | } | |
7c7625ec | 569 | //there is definitely a better way of doing this! |
45717f71 | 570 | PVector centerofcube(int i) { |
7c7625ec | 571 | Cube c = model.cubes.get(i); |
df18145f | 572 | PVector cubecenter = new PVector(c.cx, c.cy, c.cz); |
f1370a0b | 573 | |
b30f14fd | 574 | return cubecenter; |
7c7625ec AG |
575 | } |
576 | ||
5bc92bc2 AG |
577 | |
578 | void run(double deltaMs){ | |
45717f71 | 579 | for (int i =0; i < model.cubes.size(); i++) { |
5bc92bc2 AG |
580 | Cube c = model.cubes.get(i); |
581 | float cfloor = c.y; | |
45717f71 | 582 | |
f1370a0b | 583 | // if (i%3 == 0){ |
5bc92bc2 | 584 | |
2bb56822 | 585 | // for (LXPoint p : c.points ){ |
45717f71 | 586 | // // colors[p.index]=color(0,0,0); |
587 | // //float dif = (p.y - c.y); | |
588 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
589 | // } | |
590 | // } | |
5bc92bc2 | 591 | |
f1370a0b | 592 | // else if (i%3 == 1) { |
5bc92bc2 | 593 | |
45717f71 | 594 | // for (LXPoint p: c.points){ |
595 | // colors[p.index]=color(0,0,0); | |
596 | // float dif = (p.y - c.y); | |
597 | // // colors[p.index] = | |
598 | // // color(bg.getValuef(), | |
599 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
600 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
601 | // } | |
602 | // } | |
f1370a0b | 603 | // else if (i%3 == 2){ |
b30f14fd | 604 | // centerlist[i].sub(cubeorigin(i); |
2bb56822 | 605 | for (LXPoint p: c.points) { |
b30f14fd | 606 | PVector pv = new PVector(p.x, p.y, p.z); |
45717f71 | 607 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
608 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); | |
5bc92bc2 AG |
609 | |
610 | ||
b30f14fd | 611 | } |
5bc92bc2 AG |
612 | |
613 | ||
f1370a0b | 614 | //} |
5bc92bc2 AG |
615 | |
616 | } | |
617 | } | |
618 | } | |
45717f71 | 619 | JGraphAdapterDemo graph1; |
620 | ||
621 | ||
622 | // class SpinningCube extends SCPattern{ | |
623 | // LXProjection spin1, spin2, spin3; | |
624 | // SawLFO | |
625 | ||
626 | //} | |
627 | ||
628 | ||
629 | ||
630 | ||
631 | ||
632 | class PixelGraph implements EdgeFactory<dPixel, dVertex> { | |
633 | ||
634 | dPixel p0; dPixel p1; dVertex v0; | |
635 | ||
636 | public dVertex createEdge(dPixel p0, dPixel p1) { | |
637 | ||
638 | return v0; | |
639 | ||
640 | } | |
641 | ||
642 | ||
643 | } | |
644 | ||
645 | class GraphTest extends SCPattern { | |
646 | JGraphAdapterDemo graph1; | |
647 | ||
648 | GraphTest( LX lx) {super(lx); JGraphAdapterDemo graph1 = new JGraphAdapterDemo();} | |
649 | ||
650 | void run(double deltaMs){ | |
651 | } | |
652 | } | |
653 | ||
654 | class SpinningCube extends SCPattern{ | |
655 | ||
656 | LXProjection spin1, spin2, spin3; | |
657 | SawLFO spinx, spiny, spinz; | |
658 | SinLFO spinx1, spiny1, spinz1, cubesize; | |
659 | BasicParameter xoff = new BasicParameter("xoff", 10, 0, 100); | |
660 | BasicParameter toff = new BasicParameter("toff", 10,0,1000); | |
661 | BasicParameter huev = new BasicParameter("hue", 200, 0, 360); | |
662 | BasicParameter density = new BasicParameter("density", 0, 0, 1); | |
663 | BasicParameter Vsize = new BasicParameter("size", model.xMax/3,0, model.xMax); | |
664 | VirtualCube V1, V2, V3; | |
665 | PVector P = new PVector(); | |
666 | float noisetime=0.; | |
667 | class VirtualCube { | |
668 | float x,y,z,d; | |
669 | PVector center; | |
670 | ||
671 | VirtualCube(float x, float y, float z, float d) { | |
672 | this.x=x; | |
673 | this.y= y; | |
674 | this.z=z; | |
675 | this.d=d; | |
676 | this.center=new PVector(x,y,z); | |
677 | } | |
678 | ||
679 | color getcolor(LXVector q) { | |
680 | if ( q.x > this.x + d/2 || q.x < this.x - d/2 || q.y > this.y + d/2 || q.y < this.y - d/2 || q.z > this.z + d/2 || q.z < this.z - d/2 ) | |
681 | {return 0;} | |
682 | else { | |
683 | return lx.hsb(huev.getValuef()*noise(xoff.getValuef()*.001*noisetime ) , constrain(100*noise(xoff.getValuef()*.001*q.x*noisetime), 0, 100), max(100*(noise(xoff.getValuef()*.001*q.x*noisetime)-density.getValuef()), 0) ); | |
684 | } | |
685 | } | |
686 | void setcenter(float x, float y, float z) {this.x=x; this.y = y; this.z=z; } | |
687 | void setsize(float din){ this.d=din ; } | |
688 | ||
689 | } | |
690 | ||
691 | SpinningCube(LX lx) { | |
692 | super(lx); | |
693 | addParameter(xoff); | |
694 | addParameter(toff); | |
695 | addParameter(Vsize); | |
696 | addParameter(huev); | |
697 | addParameter(density); | |
698 | //addModulator() | |
699 | V1 = new VirtualCube(model.cx, model.cy, model.cz, model.xMax/2); | |
700 | spinx= new SawLFO(0, TWO_PI, 8000); | |
701 | spin1 = new LXProjection(model); | |
702 | ||
703 | } | |
704 | ||
705 | ||
706 | void run(double deltaMs) { | |
707 | ||
708 | noisetime+= deltaMs*.0001*toff.getValuef(); | |
709 | ||
710 | spin1.reset() | |
711 | .center() | |
712 | //.scale () | |
713 | .rotate(spinx.getValuef(),0, 1, 0) | |
714 | .translate(model.cx, model.cy, model.cz); | |
715 | ||
716 | for (LXVector p: spin1) { | |
717 | P.set(p.x, p.y, p.z); | |
718 | ||
719 | colors[p.index] = V1.getcolor(p); | |
720 | ||
721 | } | |
722 | ||
723 | V1.setsize(Vsize.getValuef()); | |
724 | ||
725 | ||
726 | }; | |
727 | ||
728 | ||
729 | } | |
730 | ||
731 | ||
732 | ||
733 | ||
734 | ||
5bc92bc2 | 735 | |
a9aad043 AG |
736 | class HueTestHSB extends SCPattern{ |
737 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
738 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
739 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
740 | ||
dde75983 MS |
741 | HueTestHSB(LX lx) { |
742 | super(lx); | |
a9aad043 AG |
743 | addParameter(HueT); |
744 | addParameter(SatT); | |
745 | addParameter(BriT); | |
746 | } | |
747 | void run(double deltaMs){ | |
748 | ||
2bb56822 | 749 | for (LXPoint p : model.points) { |
a9aad043 | 750 | color c = 0; |
a41f334c | 751 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
752 | colors[p.index]= c; |
753 | } | |
754 | int now= millis(); | |
755 | if (now % 1000 <= 20) | |
756 | { | |
45717f71 | 757 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); |
a9aad043 AG |
758 | } |
759 | } | |
0b1785e3 | 760 | |
a41f334c | 761 | } |