This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchpad.ck
113 lines (98 loc) · 1.92 KB
/
launchpad.ck
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
public class Launchpad
{
// launchpad -> chuck
MidiIn lp_in;
MidiMsg msg_lp_in;
// chuck -> launchpad
MidiOut lp_out;
MidiMsg msg_lp_out;
//keys state
int key_state[9][9];
//leds state
int led_state[9][9];
fun void connect(int lp_id)
{
// open the midi ports
if (!lp_out.open(lp_id)) {
<<< "can't open midi out" >>>;
me.exit();
}
if (!lp_in.open(lp_id)) {
<<< "can't open midi in" >>>;
me.exit();
}
<<< "[launchpad] connected" >>>;
<<< "[launchpad] reset" >>>;
send3(176,0,0);
}
fun void listen()
{
int row; // row
int col; // col
int press; // press
while (true)
{
lp_in => now;
while (lp_in.recv(msg_lp_in))
{
if (msg_lp_in.data1 == 176)
{
msg_lp_in.data2 - 104 => col;
msg_lp_in.data3 != 0 => press;
press => key_state[8][col];
keyEvent(-1,col,press);
} else {
msg_lp_in.data2 / 16 $ int => row;
msg_lp_in.data2 % 16 $ int => col;
msg_lp_in.data3 != 0 => press;
press => key_state[row][col];
keyEvent(row,col,press);
}
}
}
}
fun void keyEvent(int row, int col, int press)
{
<<< "key event", row, col, press >>>;
}
fun void send3(int data1, int data2, int data3)
{
data1 => msg_lp_out.data1;
data2 => msg_lp_out.data2;
data3 => msg_lp_out.data3;
lp_out.send(msg_lp_out);
}
fun void setColor(int row, int col, int color)
{
if (row == -1) {
8 => row;
}
if (led_state[row][col] != color) {
color => led_state[row][col];
if (row == 8) {
send3(176, 104+col, color);
} else {
send3(144, row*16 + col, color);
}
}
}
fun void setColor(int row, int col, int red, int green)
{
red + (green * 16) + 12 => int color;
setColor(row, col, color);
}
fun int getColor(int row, int col)
{
if (row == -1) {
8 => row;
}
return led_state[row][col];
}
fun int isPressed(int row, int col)
{
if (row == -1) {
8 => row;
}
return key_state[row][col];
}
}