forked from cjkcjk01/GiantSpaceRobotVisualiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.pde
172 lines (139 loc) · 5.46 KB
/
Config.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// We support two midi controllers, one is traktor itself, it needs to be routed //<>//
// through a virtual midi port. I have used BOME Midi Translator for this
// (its port is called "BMT 1".
// The Traktor Midi output is defined via a tsi file called "Visuliser Controller"
//
// The second is a device that controls the various settings, I am currently using
// a Midi Fighter Twister. Previously I have used a Maschine Jam.
// We only suport Midi CCs.
// there are three JSON config files used
// config.json - This stores the screen setup, midi devices and various other settings
// midiConfigTraktor - Stores the midi commands that are sent by traktor
// midiConfig - Stores the rest of the midi commands that control the visualisers etc.
void loadConfig() {
mainJSON = loadJSONObject("config.json");
loadMidiDevice();
loadMidiChannel();
loadWordPacks();
loadBackgroundPalettes();
}
// ****************************************************************************
// Set up Midi interfaces
// We need a connection from the Maschine Jam and the Traktor controller,
// use the config file to specify the correct names for the machine you are on
// ****************************************************************************
MidiBus[] buses;
//MidiBus busA; //The first MidiBus
//MidiBus busB; //The second MidiBus
void loadMidiDevice() {
// display the available midi devices (uncomment for debugging)
// MidiBus.list();
String deviceName;
// load MIDI device info from config.json
JSONArray d = mainJSON.getJSONArray("MIDIdevice");
if (d.size() == 0) {
println("No Midi device name found in config.json file");
println("Failed to assign any input devices.\nUse in non-Midi mode.");
}
buses = new MidiBus[d.size()];
for (int i=0; i<d.size(); i++) {
JSONObject m = d.getJSONObject(i);
deviceName = m.getString("device");
String[] available_inputs = MidiBus.availableInputs();
for (int j = 0; j < available_inputs.length; j++) {
if (available_inputs[j].indexOf(deviceName) > -1 ) {
buses[i] = new MidiBus(this, deviceName, deviceName, deviceName);
println("Added Midi device - " + buses[i].getBusName());
}
}
}
}
void loadMidiChannel() {
//String midiChannel;
// load MIDI channel info from config.json
JSONArray d = mainJSON.getJSONArray("MIDIchannel");
if (d.size() == 0) {
println("No Midi channel definition found in config.json file");
println("in this case we will assume 11, but that may not be correct for you!");
}
JSONObject m = d.getJSONObject(0);
midiChannel = m.getInt("channel")-1;
}
// *******************************************
// Set up word packs
// *******************************************
void loadWordPacks() {
beatWords = new WordPacks();
JSONArray wordData = mainJSON.getJSONArray("wordpacks");
for (int i = 0; i < wordData.size(); i++) {
JSONObject d2 = wordData.getJSONObject(i);
JSONArray d3 = d2.getJSONArray("words");
// Convert JSON array to String array
String[] s = toStringArray(d3);
// Set up a word pack
beatWords.addWords(s);
}
}
// *******************************************
// Set up backgound palettes
// *******************************************
void loadBackgroundPalettes() {
ArrayList<color[]> palettes = new ArrayList<color[]>();
JSONArray bgData = mainJSON.getJSONArray("palettes");
for (int i = 0; i < bgData.size(); i++) {
JSONObject d2 = bgData.getJSONObject(i);
JSONArray d3 = d2.getJSONArray("colours");
// step through the array, get the hex colour value (in web colour format).
// To use it as a Processing colour we need to convert it to a hex integer
// so we strip of the leading "#" character and add "FF" to the start. The "FF" is the
// alpha value.
color[] palette;
palette = new color[d3.size()];
for (int j = 0; j < d3.size(); j++) {
String s = d3.getString(j);
// strip off the # character
s = s.substring(1, s.length());
// make the colour, we need to prefix it with the alpha value
color c = unhex("FF" + s);
palette[j] = c;
}
palettes.add(palette);
}
// use the list of color palettes to make the background colour handling object
myBgPalette = new BgPalette(palettes);
}
public static String[] toStringArray(JSONArray array) {
String[] arr = new String[array.size()];
for (int i=0; i<arr.length; i++) {
arr[i]=array.getString(i);
}
return arr;
}
void midiConfig() {
midiJSON = loadJSONObject("midiConfig.json");
JSONArray midiControlData = midiJSON.getJSONArray("MIDIControls");
int channel, control, functionKey;
String functionName;
for (int i = 0; i < midiControlData.size(); i++) {
JSONObject d2 = midiControlData.getJSONObject(i);
channel = d2.getInt("channel");
control = d2.getInt("control");
functionName = d2.getString("functionName");
functionKey = (channel * 100) + control;
midiFunctions.put(functionKey, functionName);
}
}
void midiTraktorConfig() {
midiTraktorJSON = loadJSONObject("midiTraktorConfig.json");
JSONArray midiControlData = midiTraktorJSON.getJSONArray("MIDIControls");
int channel, control, functionKey;
String functionName;
for (int i = 0; i < midiControlData.size(); i++) {
JSONObject d2 = midiControlData.getJSONObject(i);
channel = d2.getInt("channel");
control = d2.getInt("control");
functionKey = (channel * 100) + control;
functionName = d2.getString("functionName");
midiFunctions.put(functionKey, functionName);
}
}