Merge branch 'master' of https://github.com/sugarcubes/SugarCubes
[SugarCubes.git] / DanKaminsky.pde
CommitLineData
e28f168c
AG
1class 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
20class MidiController extends GenericController {
21 MidiController() {
22 super();
23 }
24}
25//PApplet xparent; // be sure to set
26
27
28
29OscP5 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
78class 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];
a41f334c 87 colors[index] = lx.hsb((i*22.5), saturation(c), brightness(c));
e28f168c
AG
88 }
89 }*/
90 }
91}
92
93class 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
143import netP5.*;
144import oscP5.*;
145
146
147
148abstract class OSCPattern extends SCPattern {
149 public OSCPattern(GLucose glucose){super(glucose);}
150 public abstract void oscEvent(OscMessage msg);
151}
152
153class Ball {
154 public int lastSeen;
155 public float x,y;
156 public Ball(){
157 x=y=lastSeen=0;
158 }
159}
160
161class 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
34327c96 176 void run(double deltaMs){
e28f168c
AG
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
190import 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 }
34327c96 202 void run(double deltaMs){
e28f168c
AG
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