| 1 | class GenericController { |
| 2 | GenericController(){} |
| 3 | public void RotateKnob(int type, int num, float val){ |
| 4 | LXParameter p = null; |
| 5 | if(type==0) { |
| 6 | p = glucose.patternKnobs.get(num); |
| 7 | if(p!=null) { p.setValue(val); } |
| 8 | } |
| 9 | if(type==1) { |
| 10 | p = glucose.transitionKnobs.get(num); |
| 11 | if(p!=null) { p.setValue(val); } |
| 12 | } |
| 13 | if(type==2) { |
| 14 | p = glucose.effectKnobs.get(num); |
| 15 | if(p!=null) { p.setValue(val); } |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | class MidiController extends GenericController { |
| 21 | MidiController() { |
| 22 | super(); |
| 23 | } |
| 24 | } |
| 25 | //PApplet xparent; // be sure to set |
| 26 | |
| 27 | |
| 28 | |
| 29 | OscP5 listener; |
| 30 | // Setup OSC |
| 31 | //listener = new OscP5(this,7022); |
| 32 | |
| 33 | //boolean[] noteState = new boolean[16]; |
| 34 | // |
| 35 | //void controllerChangeReceived(rwmidi.Controller cc) { |
| 36 | // if (debugMode) { |
| 37 | // println("CC: " + cc.toString()); |
| 38 | // } |
| 39 | // if(cc.getCC()==1){ |
| 40 | // for(int i=0; i<16; i++){ |
| 41 | // if(noteState[i] && i<8) { LXParameter p = glucose.patternKnobs.get(i); p.setValue(cc.getValue()/127.0); } |
| 42 | // else if(noteState[i] && i<12) { LXParameter p = glucose.transitionKnobs.get(i-8); p.setValue(cc.getValue()/127.0); } |
| 43 | // else if(noteState[i] && i<16) { LXParameter p = glucose.effectKnobs.get(i-12); p.setValue(cc.getValue()/127.0); } |
| 44 | // } |
| 45 | // } |
| 46 | //} |
| 47 | // |
| 48 | //void noteOnReceived(Note note) { |
| 49 | // if (debugMode) { |
| 50 | // println("Note On: " + note.toString()); |
| 51 | // } |
| 52 | // int pitch = note.getPitch(); |
| 53 | // if(pitch>=36 && pitch <36+16){ |
| 54 | // noteState[pitch-36]=true; |
| 55 | // } |
| 56 | //} |
| 57 | // |
| 58 | //void noteOffReceived(Note note) { |
| 59 | // if (debugMode) { |
| 60 | // println("Note Off: " + note.toString()); |
| 61 | // } |
| 62 | // int pitch = note.getPitch(); |
| 63 | // if(pitch>=36 && pitch <36+16){ |
| 64 | // noteState[pitch-36]=false; |
| 65 | // } |
| 66 | //} |
| 67 | // |
| 68 | //void oscEvent(OscMessage theOscMessage) { |
| 69 | // println(theOscMessage); |
| 70 | // LXPattern currentPattern = lx.getPattern(); |
| 71 | // if (currentPattern instanceof OSCPattern) { |
| 72 | // ((OSCPattern)currentPattern).oscEvent(theOscMessage); |
| 73 | // } |
| 74 | //} |
| 75 | // |
| 76 | |
| 77 | |
| 78 | class ObjectMuckerEffect extends SCEffect { |
| 79 | ObjectMuckerEffect(GLucose glucose) { |
| 80 | super(glucose); |
| 81 | } |
| 82 | public void doApply(int[] colors){ |
| 83 | /*for(Strip s: model.strips){ |
| 84 | for(int i=0; i<s.points.size(); i++){ |
| 85 | int index = s.points.get(i).index; |
| 86 | color c = colors[index]; |
| 87 | colors[index] = color((i*22.5), saturation(c), brightness(c)); |
| 88 | } |
| 89 | }*/ |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | class BlendFrames extends SCEffect { |
| 94 | int fcount; |
| 95 | int frames[][]; |
| 96 | int maxfbuf; |
| 97 | int blendfactor; |
| 98 | BlendFrames(GLucose glucose) { |
| 99 | super(glucose); |
| 100 | maxfbuf = 30; |
| 101 | blendfactor=30; |
| 102 | fcount=0; |
| 103 | frames = new int[maxfbuf][]; |
| 104 | for(int i=0; i<maxfbuf; i++){ |
| 105 | frames[i] = new int[model.points.size()]; |
| 106 | } |
| 107 | } |
| 108 | public void doApply(int[] colors) { |
| 109 | if(fcount<maxfbuf){ |
| 110 | for(int i=0; i<colors.length; i++){ |
| 111 | frames[(maxfbuf-1)-fcount][i]=colors[i]; |
| 112 | } |
| 113 | fcount++; |
| 114 | return; |
| 115 | } else { |
| 116 | for(int i=maxfbuf-1; i>0; i--){ |
| 117 | frames[i] = frames[i-1]; |
| 118 | } |
| 119 | frames[0] = new int[model.points.size()]; |
| 120 | |
| 121 | for(int i=0; i<colors.length; i++){ |
| 122 | int r,g,b; |
| 123 | r=g=b=0; |
| 124 | for(int j=0; j<blendfactor; j++){ |
| 125 | if(j==0) { frames[0][i] = colors[i]; } |
| 126 | r += ((frames[j][i] >> 16) & 0xFF); |
| 127 | g += ((frames[j][i] >> 8) & 0xFF); |
| 128 | b += ((frames[j][i] >> 0) & 0xFF); |
| 129 | } |
| 130 | r/=blendfactor; |
| 131 | g/=blendfactor; |
| 132 | b/=blendfactor; |
| 133 | colorMode(ARGB); |
| 134 | colors[i] = (0xFF << 24) | (r << 16) | (g << 8) | b; |
| 135 | colorMode(HSB); |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | |
| 143 | import netP5.*; |
| 144 | import oscP5.*; |
| 145 | |
| 146 | |
| 147 | |
| 148 | abstract class OSCPattern extends SCPattern { |
| 149 | public OSCPattern(GLucose glucose){super(glucose);} |
| 150 | public abstract void oscEvent(OscMessage msg); |
| 151 | } |
| 152 | |
| 153 | class Ball { |
| 154 | public int lastSeen; |
| 155 | public float x,y; |
| 156 | public Ball(){ |
| 157 | x=y=lastSeen=0; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | class OSC_Balls extends OSCPattern { |
| 162 | Ball[] balls; |
| 163 | public OSC_Balls(GLucose glucose){ |
| 164 | super(glucose); |
| 165 | balls = new Ball[20]; |
| 166 | for(int i=0; i<balls.length; i++) { balls[i] = new Ball(); } |
| 167 | } |
| 168 | void oscEvent(OscMessage msg){ |
| 169 | String pattern[] = split(msg.addrPattern(), "/"); |
| 170 | int ballnum = int(pattern[3]); |
| 171 | balls[ballnum].lastSeen=millis(); |
| 172 | balls[ballnum].x = msg.get(0).floatValue(); |
| 173 | balls[ballnum].y = msg.get(1).floatValue(); |
| 174 | } |
| 175 | |
| 176 | void run(int deltaMs){ |
| 177 | for(Point p: model.points){ colors[p.index]=0; } |
| 178 | for(int i=1; i<balls.length; i++){ |
| 179 | if(millis() - balls[i].lastSeen < 1000) { |
| 180 | for(Point p: model.points){ |
| 181 | int x = int(balls[i].x * 255.0); |
| 182 | int y = int(balls[i].y * 127.0); |
| 183 | if(p.x < x+4 && p.x > x-4 && p.y < y+4 && p.y > y-4) { colors[p.index] = #FF0000; } |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | import processing.serial.*; |
| 191 | |
| 192 | |
| 193 | /*class ScreenScrape extends SCPattern { |
| 194 | PImage pret; |
| 195 | ScreenShot ss; |
| 196 | public ScreenScrape(GLucose glucose) { |
| 197 | super(glucose); |
| 198 | System.loadLibrary("ScreenShot"); |
| 199 | pret = new PImage(8, 128, ARGB); |
| 200 | ss = new ScreenShot(); |
| 201 | } |
| 202 | void run(int deltaMs){ |
| 203 | int x=(1366/2)+516; |
| 204 | int y=768-516; |
| 205 | int w=8; |
| 206 | int h=128; |
| 207 | pret.pixels = ss.getScreenShotJNI2(x, y, w, h); |
| 208 | //for(int i=0; i<px.length; i++){ pret.pixels[i] = px[i]; } |
| 209 | //println(pret.get(10,10)); |
| 210 | for(Point p: model.points){ |
| 211 | colors[p.index] = pret.get((int(p.x)/8)*8, 128-int(p.y)); |
| 212 | } |
| 213 | } |
| 214 | }*/ |
| 215 | |
| 216 | List<LXParameter> gparams; |
| 217 | |
| 218 | class DualBlender extends SCEffect { |
| 219 | int lastSeen; |
| 220 | BasicParameter p1 = new BasicParameter("p1", 0); |
| 221 | BasicParameter p2 = new BasicParameter("p2", 0); |
| 222 | BasicParameter p3 = new BasicParameter("p3", 0); |
| 223 | BasicParameter p4 = new BasicParameter("p4", 0); |
| 224 | BasicParameter p5 = new BasicParameter("p5", 0); |
| 225 | BasicParameter p6 = new BasicParameter("p6", 0); |
| 226 | BasicParameter p7 = new BasicParameter("p7", 0); |
| 227 | BasicParameter p8 = new BasicParameter("p8", 0); |
| 228 | DualBlender(GLucose glucose){ |
| 229 | super(glucose); |
| 230 | gparams = gplay.getParameters(); |
| 231 | addParameter(p1); |
| 232 | addParameter(p2); |
| 233 | addParameter(p3); |
| 234 | addParameter(p4); |
| 235 | addParameter(p5); |
| 236 | addParameter(p6); |
| 237 | addParameter(p7); |
| 238 | addParameter(p8); |
| 239 | |
| 240 | lastSeen=millis(); |
| 241 | } |
| 242 | |
| 243 | void onParameterChanged(LXParameter p){ |
| 244 | if(p==p1) { gparams.get(0).setValue(p.getValuef()); } |
| 245 | if(p==p2) { gparams.get(1).setValue(p.getValuef()); } |
| 246 | if(p==p3) { gparams.get(2).setValue(p.getValuef()); } |
| 247 | if(p==p4) { gparams.get(3).setValue(p.getValuef()); } |
| 248 | if(p==p5) { gparams.get(4).setValue(p.getValuef()); } |
| 249 | if(p==p6) { gparams.get(5).setValue(p.getValuef()); } |
| 250 | if(p==p7) { gparams.get(6).setValue(p.getValuef()); } |
| 251 | if(p==p8) { gparams.get(7).setValue(p.getValuef()); } |
| 252 | } |
| 253 | |
| 254 | void doApply(int[] colors){ |
| 255 | if (enabled) { |
| 256 | //gplay.onActive(); |
| 257 | gplay.go(millis()-lastSeen); |
| 258 | lastSeen=millis(); |
| 259 | int[] pcolors = gplay.getColors(); |
| 260 | for(int i=0; i<colors.length; i++){ |
| 261 | colors[i]=blendColor(colors[i],pcolors[i], MULTIPLY); |
| 262 | } |
| 263 | } else {}//gplay.onInactive(); } |
| 264 | } |
| 265 | |
| 266 | |
| 267 | } |
| 268 | |