forked from markqvist/MidiKatapult
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmidikatapult.pde
More file actions
143 lines (129 loc) · 3.83 KB
/
midikatapult.pde
File metadata and controls
143 lines (129 loc) · 3.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
License license = new License();
boolean lpdetect = false;
boolean allgood = false;
int delay;
void settings() {
size(WINDOWSIZE, WINDOWSIZE);
}
void setup(){
loadConfig();
setupDemos();
f10 = loadFont("10.vlw");
f11 = loadFont("11.vlw");
f14 = loadFont("14.vlw");
f18 = loadFont("18.vlw");
f20 = loadFont("20.vlw");
f40 = loadFont("40.vlw");
background(0);
frameRate(FRAMERATE);
launchpad = new MIDI("Launchpad");
if (launchpad.initialised) launchpad.sendCtl(0, 0, 0);
sleep(500);
if (launchpad.initialised) launchpad.sendCtl(0, 0, 0);
if (launchpad.initialised) {
//console("Launchpad detected, huzzah!");
launchpad.reset();
splash(true);
} else {
//console("Oh sorrow... No Launchpad was detected...");
splash(false);
}
}
void splash(boolean success) {
if (SILENTMODE) {
if (!SOFTWARE.equals("") && !SOFTWAREIN.equals("")) {
fill(#FFFFFF);
textFont(f10, 10);
textAlign(LEFT);
smooth();
text("Out: "+SOFTWARE+"\nIn: "+SOFTWAREIN, 2, 12);
initMidiSystem();
} else {
SILENTMODE = false;
}
}
if (!SILENTMODE) {
if (success) { launchpad.reset(); DEMO = true; displaystate = true; }
lpdetect = success;
delay = 15;
state = "splash";
menustate = "midiout";
katapult = new MText("Katapult", 0, WINDOWSIZE/2);
mline = new MLine(WINDOWSIZE, WINDOWSIZE/2+3);
katapult.setDestination(WINDOWSIZE/2, WINDOWSIZE/2);
katapult.setDuration(16);
mline.setDestination(0, WINDOWSIZE/2+3);
mline.setDuration(20);
mline.animate();
katapult.animate();
}
}
void initMidiSystem() {
//console("Initiaing MIDI system...");
//console("SOFTWARE: " + SOFTWARE);
//console("SOFTWAREIN: " + SOFTWAREIN);
receiverA = new MIDIListener("Launchpad");
receiverB = new MIDIListener("Software");
software = new MIDI(SOFTWARE);
softwareIn = new MIDIinput(SOFTWAREIN, receiverB);
launchpadIn = new MIDIinput("Launchpad", receiverA);
software.reset();
softwareIn.reset();
launchpadIn.reset();
displaystate = true;
clearDisplay();
displaystate = false;
loadLayouts();
for (int i = 0; i < numberOfPages; i++) {
loadLayout(pageNumbers[i]);
loadLayout(PAGESELECTOR);
}
displaystate = true;
loadLayout(1);
demo = sdemo;
allgood = true;
}
void draw() {
if (online) readServer();
if (DEMO) demos();
menus();
}
void cleanup() {
clearDisplay();
if (launchpad != null) launchpad.close();
if (software != null) software.close();
if (launchpadIn != null) launchpadIn.close();
if (softwareIn != null) softwareIn.close();
}
public void stop() {
cleanup();
clearDisplay();
super.stop();
}
void mousePressed() {
if (mousestate.equals("quit")) {
displaystate = false;
clearDisplay();
exit();
}
}
void keyPressed() {
if ((int)keyCode == 40 && mselection < mselmax - 1) mselection = (mselection + 1)%mselmax;
if ((int)keyCode == 38 && mselection > 0) mselection = (mselection - 1)%mselmax;
if ((int)keyCode == 10) { mselout = mselection; mselection = MFINAL; }
if ((int)keyCode == 37 && (HEADLESS == true || NETWORK == true) && currentPage > 1) { selectedPage = pageNumbers[indexForKey(pageNumbers, selectedPage)-1]; loadLayout(selectedPage); }
if ((int)keyCode == 39 && (HEADLESS == true || NETWORK == true) && currentPage < pageNumbers[numberOfPages-1]) { selectedPage = pageNumbers[indexForKey(pageNumbers, selectedPage)+1]; loadLayout(selectedPage); }
if ((int)keyCode == 80 && (HEADLESS == true || NETWORK == true || LIVEENABLED == true)) { reloadLayouts(); }
//if ((int)keyCode == 80 && (HEADLESS == true || NETWORK == true)) { DEMO = !(DEMO); }
// if ((int)keyCode == 27) cleanup();
}
// Testing functions
void console(String msg) {
if (DEBUG) println(msg);
}
int indexForKey(int[] a, int target) {
for (int i = 0; i < a.length; i++) {
if (a[i] == target) return i;
}
return 0;
}