-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirHarmonizer.pde
126 lines (103 loc) · 3.09 KB
/
AirHarmonizer.pde
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
import processing.serial.*;
import java.util.Random;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
Serial myPort; // The serial port
int dim = width;
int w_canvas = 1920;
int h_canvas = 1080;
color[] rectCol = new color[5];
void setup() {
// Serial data setup
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
//myPort = new Serial(this, Serial.list()[4], 115200);
myPort = new Serial(this, Serial.list()[4], 9600);
// Setup of OSC messaging
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
//myRemoteLocation = new NetAddress("127.0.0.1",57121);
myRemoteLocation = new NetAddress("127.0.0.1",57120);
// Visualization Setup
//size(1200, 600);
fullScreen();
background(0);
colorMode(RGB);
noStroke();
ellipseMode(RADIUS);
frameRate(125);
rectCol[0] = color(229, 49, 46);
rectCol[1] = color(227, 46, 176);
rectCol[2] = color(163, 46, 227);
rectCol[3] = color(46, 82, 227);
rectCol[4] = color(46, 213, 227);
}
void draw() {
while (myPort.available() > 0) { // questo ciclo dentro draw potrebbe essere un errore, facci caso
String inBuffer = myPort.readString();
inBuffer = inBuffer.substring(2);
String[] parts = inBuffer.split("\t");
//int foo = Integer.parseInt(parts[0]);
int S1, S2, S3, S4, S5;
S1 = Integer.parseInt(parts[1]);
S2 = Integer.parseInt(parts[2]);
S3 = Integer.parseInt(parts[3]);
S4 = Integer.parseInt(parts[4]);
S5 = Integer.parseInt(parts[5]);
//println(S1, S2, S3, S4, S5);
int[] sensor = new int[]{S1, S2, S3, S4, S5};
// define random position generator
//Random rand = new Random();
// Draw something
background(0);
for (int i = 0; i < 5; i++) {
//int x = rand.nextInt(w_canvas - 30) + 30;
//int y = rand.nextInt(h_canvas - 30) + 30;
// drawGradient(x, y, sensor[i]);
if (sensor[i]>0){
drawBar(i,sensor[i]);
}
else{
sensor[i]=0;
}
}
OscMessage myMessage = new OscMessage("/chord");
////myMessage.add(mouseX/(float)width);
////myMessage.add(mouseY/(float)height);
//float MAX = 0;
//int indexMAX = 0;
//for (int i =0; i<5; i++){
// if (sensor[i] > MAX){
// MAX = sensor[i];
// indexMAX = i;
// }
//}
//myMessage.add(indexMAX);
//myMessage.add(MAX);
myMessage.add((float)sensor[0]);
myMessage.add((float)sensor[1]);
myMessage.add((float)sensor[2]);
myMessage.add((float)sensor[3]);
myMessage.add((float)sensor[4]);
oscP5.send(myMessage, myRemoteLocation);
}
}
//void drawGradient(float x, float y, int h) {
// int radius = dim/2;
// for (int r = radius; r > 0; --r) {
// fill(h, 90, 90);
// ellipse(x, y, r, r);
// h = (h + 1) % 360;
// }
//}
void drawBar(int i, int hh){
float x = ((w_canvas-80)/5)*i+80;
float h = h_canvas;
float w = 200;
float y = map(hh,400,40,h_canvas,0);
fill(rectCol[i]);
rect(x,y,w,h);
}