-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnobMatrix.java
More file actions
executable file
·81 lines (65 loc) · 1.83 KB
/
Copy pathKnobMatrix.java
File metadata and controls
executable file
·81 lines (65 loc) · 1.83 KB
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
import processing.core.PVector;
import controlP5.*;
import java.util.List;
import java.lang.Integer;
import java.lang.Math;
class KnobMatrix{
ControlP5 cp5;
//int[][] controlID;
//ensuring uniqueness of ID is responsibilty of this class
String[][] names;
int n;
float k;
public KnobMatrix(ControlP5 cp5,
String uniqueID,
int n, float size, PVector offset){
this.cp5 = cp5;
names = new String[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
/*
String name = uniqueID
+ "Knob"
+ Integer.toString(i)
+ Integer.toString(j);
*/
String si = Integer.toString(i);
String sj = Integer.toString(j);
String name = uniqueID + ":x" + si + "*y" + sj;
float range = (float)Math.exp(-1.1*Math.pow((i+j), 2));
//set initial values so that x' = x, y' = y
float initialValue;
boolean isX = (uniqueID == "x" && (i == 1 && j == 0));
boolean isY = (uniqueID == "y" && (i == 0 && j == 1));
if (isX ^ isY) initialValue = 1.0f;
else initialValue = 0.0f;
this.cp5.addKnob(name)
//TEMP SCALE DOWN - COULD LEAD TO INFINITIES
.setRange(-range, range)
.setValue(initialValue)
.setPosition(offset.x + i*size, offset.y + j*size)
.setRadius(size/3.0f);
names[i][j] = name;
}
}
}
public float getValue(int i, int j){
try{
return this.cp5.getController(names[i][j]).getValue();
}
catch(NullPointerException e){
System.out.println("ID not found.");
return 0.0f;
}
}
public float[][] getValueArray(){
float[][] values = new float[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
values[i][j] = this.getValue(i, j);
System.out.printf(this.getValue(i, j) + ", ");
}
}
return values;
}
}