-
Notifications
You must be signed in to change notification settings - Fork 3
/
LaunchControlDemo.pde
95 lines (77 loc) · 2.13 KB
/
LaunchControlDemo.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
// Example of the library pLaunchControl. This sketch is a good way to test
// the library and see the dynamics of using the controller and its effect on the screen.
// It illustrates that when the sketch starts, it is not possible to read the actual position of
// knob - values are updated as soon as you move the knob.
import pLaunchControl.*;
LaunchControl controller;
void setup() {
size(1000, 500);
try {
controller = new LaunchControl(this, true);
// If you have renamed your Launch Control in the system
// preferences, use this version of the constructor:
// controller = new LaunchControl(this, true, "THE NAME YOU GAVE TO THE CONTROLLER");
}
catch(Exception e) {
println("Unfortunately we could not detect that Launch Control is connected to this computer :(");
println(e);
noLoop();
}
textAlign(CENTER);
}
void draw() {
background(0);
translate(20, 20);
stroke(255);
strokeWeight(3);
float s = width/16;
translate(s/2, s);
if (controller !=null) {
drawKnobs(s);
drawPads(s);
}
}
/**
* Draws the knobs of the controller as simple arcs.
*/
void drawKnobs(float s) {
//drawing positions
float start = HALF_PI * 1.3;
float end = TWO_PI + HALF_PI * .7;
pushMatrix();
for (int i = 0; i < 16; i++) {
//draw knob background, simple arc
fill(255);
arc(2*s*(i%8), 0, s, s, start, end);
//draw knob position
fill(80);
Knob knob = controller.getKnob(i);
float normal = knob.valueNormal();
float realValue = knob.value();
arc(2*s*(i%8), 0, s, s, start, start + normal*(end-start));
fill(255);
text(round(realValue), 2*s*(i%8), s );
if (i == 7)
translate(0, height * .3);
}
popMatrix();
}
/**
* Draws the pads of the controller as simple arcs.
*/
void drawPads(float s) {
translate(0, height * .6);
rectMode(CENTER);
for (int i = 0; i < 8; i++) {
//draw pad background, simple arc
fill(255);
rect(2*s*i, 0, s, s);
//draw pad state position
fill(80);
boolean padState = controller.getPad(i).value();
if (padState)
rect(2*s*i, 0, s, s);
fill(255);
text(round(i), 2*s*(i%8), s );
}
}