Commit | Line | Data |
---|---|---|
1ecdb44a MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
186bc4d3 | 11 | * This file implements the mapping functions needed to lay out the physical |
1ecdb44a MS |
12 | * cubes and the output ports on the panda board. It should only be modified |
13 | * when physical changes or tuning is being done to the structure. | |
14 | */ | |
45f43cc2 | 15 | |
f0cc0ba5 MS |
16 | public Model buildModel() { |
17 | ||
f0cc0ba5 MS |
18 | // Shorthand helpers for specifying wiring more quickly |
19 | final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; | |
20 | final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; | |
21 | final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; | |
22 | final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; | |
95c50032 | 23 | |
a3ccf23a | 24 | // Utility value if you need the height of a cube shorthand |
95c50032 | 25 | final float CH = Cube.EDGE_HEIGHT; |
73687629 | 26 | final float CW = Cube.EDGE_WIDTH ; |
7c7625ec AG |
27 | |
28 | ||
ae579223 | 29 | |
a3ccf23a | 30 | // Positions for the bass box |
ae579223 MS |
31 | final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; |
32 | final float BBX = 56; | |
33 | final float BBZ = 2; | |
34 | ||
46fc29d4 MS |
35 | // The model is represented as an array of towers. The cubes in the tower |
36 | // are represenented relatively. Each tower has an x, y, z reference position, | |
37 | // which is typically the base cube's bottom left corner. | |
38 | // | |
39 | // Following that is an array of floats. A 2-d array contains an x-offset | |
f0cc0ba5 MS |
40 | // and a z-offset from the previous reference position. Typically the first cube |
41 | // will just be {0, 0}. Each successive cube uses the position of the previous | |
42 | // cube as its reference. | |
46fc29d4 MS |
43 | // |
44 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
45 | // y-axis. | |
46 | // | |
47 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
e27a8652 | 48 | |
73687629 | 49 | // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. |
50 | // "raw object index" is serialized by running through towermapping and then individual cube mapping below. | |
51 | // We can do better than this. The raw object index should be obvious from the code-- looking through the | |
52 | // rendered simulation and counting through cubes in mapping mode is grossly inefficient. | |
e28f168c | 53 | |
73687629 | 54 | TowerMapping[] towerCubes = new TowerMapping[] {}; |
f0cc0ba5 MS |
55 | |
56 | // Single cubes can be constructed directly here if you need them | |
57 | Cube[] singleCubes = new Cube[] { | |
bf1fe2d4 | 58 | // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker |
f1370a0b | 59 | //new Cube(x, y, z, rx, ry, rz, wiring), |
bf1fe2d4 | 60 | //new Cube(0,0,0,0,225,0, WRR), |
f0cc0ba5 MS |
61 | }; |
62 | ||
63 | // The bass box! | |
73687629 | 64 | // BassBox bassBox = BassBox.unlitBassBox(BBX, 0, BBZ); // frame exists, no lights |
65 | BassBox bassBox = BassBox.noBassBox(); // no bass box at all | |
e89eda9f | 66 | // BassBox bassBox = new BassBox(BBX, 0, BBZ); // bass box with lights |
e28f168c | 67 | |
f0cc0ba5 | 68 | // The speakers! |
3b2e0b4a MS |
69 | List<Speaker> speakers = Arrays.asList(new Speaker[] { |
70 | // Each speaker parameter is x, y, z, rotation, the left speaker comes first | |
73687629 | 71 | // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) |
3b2e0b4a | 72 | }); |
f0cc0ba5 | 73 | |
bf1fe2d4 MS |
74 | |
75 | //////////////////////////////////////////////////////////////////////// | |
76 | // dan's proposed lattice | |
77 | ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>(); | |
3fa45e9e AG |
78 | //if (NumBackTowers != 25) exit(); |
79 | for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower( | |
80 | (i+1)*CW, // x | |
81 | (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
e0cfbe20 | 82 | - ((i % 2 == 0) ? 0 : 11) + 80 , // z |
3fa45e9e | 83 | 225, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) ); // num cubes |
bf1fe2d4 | 84 | |
3fa45e9e AG |
85 | for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower( |
86 | (i+1)*CW, // x | |
87 | (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
e0cfbe20 | 88 | - ((i % 2 == 0) ? 0 : 11) + 80 - pow(CH*CH + CW*CW, .5), // z |
3fa45e9e | 89 | 225, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) ); |
e0cfbe20 AG |
90 | |
91 | // for (int i=0; i<2 ; i++) scubes.add(new StaggeredTower( | |
92 | // (i+1)*CW, // x | |
93 | // 0 , // y | |
94 | // - 0 + 97 - 2*pow(CH*CH + CW*CW, .5), // z | |
95 | // 225, MaxCubeHeight ) ); | |
96 | ||
bf1fe2d4 MS |
97 | ArrayList<Cube> dcubes = new ArrayList<Cube>(); |
98 | // for (int i=1; i<6; i++) { | |
99 | // if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR)); | |
100 | // dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR)); | |
101 | // } | |
102 | ||
a981ea46 | 103 | float current_x_position = 0; |
3fa45e9e AG |
104 | // scubes.add(new StaggeredTower(//tower 1 |
105 | // current_x_position, // x | |
106 | // 15 , // y | |
107 | // 0 , // z | |
108 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
109 | // current_x_position += 25.25; | |
110 | // scubes.add(new StaggeredTower(// tower 2 | |
111 | // current_x_position, // x | |
112 | // 0 , // y | |
113 | // -10.5 , // z | |
114 | // 45, 6, new Cube.Wiring[] { WFR, WFL, WRR, WRR, WFL, WRR}) ); | |
115 | // current_x_position += 25.25; | |
116 | // scubes.add(new StaggeredTower(//tower 3 | |
117 | // current_x_position, // x | |
118 | // 15 , // y | |
119 | // 0, // z | |
120 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WRR, WFL, WRR}) ); | |
121 | // current_x_position += 25.25; | |
122 | // scubes.add(new StaggeredTower(//tower 4 | |
123 | // current_x_position, // x | |
124 | // 0, // y | |
125 | // -10.5 , // z | |
126 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
127 | // current_x_position += 28; | |
128 | // scubes.add(new StaggeredTower(//tower 5 | |
129 | // current_x_position, // x | |
130 | // 15 , // y | |
131 | // -4.5 , // z | |
132 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); | |
133 | // current_x_position += 28; | |
134 | // scubes.add(new StaggeredTower(//tower 6 | |
135 | // current_x_position, // x | |
136 | // 0 , // y | |
137 | // -10.5, // z | |
138 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
139 | // current_x_position += 25.25; | |
140 | // scubes.add(new StaggeredTower(// tower 7 | |
141 | // current_x_position, // x | |
142 | // 15 , // y | |
143 | // 0, // z | |
144 | // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); | |
145 | // current_x_position += 25.25; | |
146 | // scubes.add(new StaggeredTower(//tower 8 | |
147 | // current_x_position, // x | |
148 | // 0 , // y | |
149 | // -10.5 , // z | |
150 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
151 | // current_x_position += 25.25; | |
152 | // scubes.add(new StaggeredTower(//tower 9 | |
153 | // current_x_position, // x | |
154 | // 15 , // y | |
155 | // 0, // z | |
156 | // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
157 | // current_x_position += 25.25; | |
158 | ||
159 | // //TOWERS ON DANCE FLOOR | |
160 | // scubes.add(new StaggeredTower(//tower 10 | |
161 | // 83.75+39+43-124.5, // x | |
162 | // 0, // y | |
163 | // -47.5-43, // z | |
164 | // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); | |
165 | // scubes.add(new StaggeredTower(//tower 11 | |
166 | // 83.75, // x | |
167 | // 0, // y | |
168 | // -47.5, // z | |
169 | // 45, 4, new Cube.Wiring[]{ WFL, WRR, WRR, WFL}) ); | |
170 | // scubes.add(new StaggeredTower(//tower 12 | |
171 | // 83.75+39, // x | |
172 | // 0, // y | |
173 | // -47.5, // z | |
174 | // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); | |
175 | // scubes.add(new StaggeredTower(//tower 13 | |
176 | // 83.75+39+43, // x | |
177 | // 0, // y | |
178 | // -47.5-43, // z | |
179 | // 45, 4, new Cube.Wiring[]{ WFL, WRR, WFL, WRR}) ); | |
d93dc84a | 180 | |
a981ea46 AK |
181 | // scubes.add(new StaggeredTower(// Single cube on top of tower 4 |
182 | // 42, // x | |
183 | // 112 , // y | |
184 | // 72, // z | |
185 | // -10, 1, new Cube.Wiring[]{ WRL}) ); | |
bf1fe2d4 MS |
186 | |
187 | ||
188 | ||
189 | ||
190 | ||
191 | ||
192 | ||
a3ccf23a MS |
193 | ////////////////////////////////////////////////////////////////////// |
194 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
195 | ////////////////////////////////////////////////////////////////////// | |
196 | ||
f0cc0ba5 | 197 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
198 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
199 | ArrayList<Cube> tower; | |
3fa45e9e | 200 | Cube[] cubes = new Cube[200]; |
46fc29d4 | 201 | int cubeIndex = 1; |
f0cc0ba5 MS |
202 | float px, pz, ny; |
203 | for (TowerMapping tm : towerCubes) { | |
204 | px = tm.x; | |
205 | ny = tm.y; | |
206 | pz = tm.z; | |
46fc29d4 | 207 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
208 | for (CubeMapping cm : tm.cubeMappings) { |
209 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
210 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
211 | } |
212 | towerList.add(new Tower(tower)); | |
213 | } | |
73687629 | 214 | |
f1370a0b AG |
215 | |
216 | for (Cube cube : singleCubes) cubes[cubeIndex++] = cube; | |
bf1fe2d4 | 217 | for (Cube cube : dcubes) cubes[cubeIndex++] = cube; |
f1370a0b | 218 | for (StaggeredTower st : scubes) { |
73687629 | 219 | tower = new ArrayList<Cube>(); |
bf1fe2d4 MS |
220 | for (int i=0; i < st.n; i++) { |
221 | Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR; | |
222 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w)); | |
223 | } | |
73687629 | 224 | towerList.add(new Tower(tower)); |
2bb56822 | 225 | } |
e76480d4 | 226 | |
7dceead9 | 227 | return new Model(towerList, cubes, bassBox, speakers); |
186bc4d3 | 228 | } |
e73ef85d | 229 | |
a3ccf23a MS |
230 | /** |
231 | * This function maps the panda boards. We have an array of them, each has | |
232 | * an IP address and a list of channels. | |
233 | */ | |
186bc4d3 | 234 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
235 | final int LEFT_SPEAKER = 0; |
236 | final int RIGHT_SPEAKER = 1; | |
237 | ||
3b2e0b4a | 238 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 239 | return new PandaMapping[] { |
bf1fe2d4 MS |
240 | new PandaMapping( |
241 | "10.200.1.28", new ChannelMapping[] { | |
a981ea46 AK |
242 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18}), |
243 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
244 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3}), | |
245 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6}), | |
246 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9}), | |
247 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12}), | |
248 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15}), | |
249 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
bf1fe2d4 | 250 | }), |
e3da2932 AG |
251 | // new PandaMapping( |
252 | // "10.200.1.29", new ChannelMapping[] { | |
253 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}), | |
254 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
255 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}), | |
256 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}), | |
257 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}), | |
258 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}), | |
259 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}), | |
260 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
261 | // }), | |
262 | // new PandaMapping( | |
263 | // "10.200.1.30", new ChannelMapping[] { | |
264 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J3 * | |
265 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J4 //ORIG * | |
266 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}), // 30 J7 * | |
267 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}), // 30 J8 * | |
268 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}), // 30 J13 (not working) | |
269 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}), // 30 J14 (unplugged) | |
270 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}), // 30 J15 (unplugged) | |
271 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16 | |
272 | // }), | |
273 | // new PandaMapping( | |
274 | // "10.200.1.31", new ChannelMapping[] { | |
275 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}), // J3 | |
276 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
277 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 56}), // 30 J7 | |
278 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 57, 58}), // J8 | |
279 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 59, 60}), // J13 | |
280 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 61, 62}), // 30 J14 | |
281 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 63, 64}), // J15 | |
282 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 | |
283 | // }), | |
284 | // new PandaMapping( | |
285 | // "10.200.1.32", new ChannelMapping[] { | |
286 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J3 | |
287 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
288 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 67, 68}), // 30 J7 | |
289 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 69, 70}), // J8 | |
290 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J13 | |
291 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 | |
292 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J15 | |
293 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 | |
294 | // }), | |
3b2e0b4a | 295 | }; |
45f43cc2 | 296 | } |
e73ef85d | 297 | |
f0cc0ba5 MS |
298 | class TowerMapping { |
299 | public final float x, y, z; | |
300 | public final CubeMapping[] cubeMappings; | |
301 | ||
302 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
303 | this.x = x; | |
304 | this.y = y; | |
305 | this.z = z; | |
306 | this.cubeMappings = cubeMappings; | |
307 | } | |
308 | } | |
309 | ||
310 | class CubeMapping { | |
311 | public final float dx, dz, ry; | |
312 | public final Cube.Wiring wiring; | |
313 | ||
314 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 315 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 316 | } |
f0cc0ba5 MS |
317 | CubeMapping(float dx, float dz, float ry) { |
318 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
319 | } | |
320 | ||
321 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
322 | this.dx = dx; | |
323 | this.dz = dz; | |
324 | this.ry = ry; | |
325 | this.wiring = wiring; | |
326 | } | |
327 | } | |
328 | ||
73687629 | 329 | class StaggeredTower { |
330 | public final float x, y, z, r; | |
331 | public final int n; | |
bf1fe2d4 MS |
332 | public final Cube.Wiring[] wiring; |
333 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); } | |
334 | StaggeredTower(float _x, float _y, float _z, float _r, int _n, Cube.Wiring[] _wiring) { x=_x; y=_y; z=_z; r=_r; n=_n; wiring=_wiring;} | |
73687629 | 335 | } |
336 | ||
a922e963 MS |
337 | /** |
338 | * Each panda board has an IP address and a fixed number of channels. The channels | |
339 | * each have a fixed number of pixels on them. Whether or not that many physical | |
340 | * pixels are connected to the channel, we still send it that much data. | |
341 | */ | |
45f43cc2 MS |
342 | class PandaMapping { |
343 | ||
045b432d | 344 | // How many channels are on the panda board |
e28f168c | 345 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 346 | |
44b8de9c | 347 | // How many total pixels on the whole board |
84086fa3 | 348 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 349 | |
45f43cc2 | 350 | final String ip; |
84086fa3 | 351 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 352 | |
84086fa3 | 353 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 354 | this.ip = ip; |
a922e963 MS |
355 | |
356 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
357 | for (int i = 0; i < channelList.length; ++i) { |
358 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
359 | if (channelList[i] == null) { |
360 | channelList[i] = new ChannelMapping(); | |
361 | } | |
045b432d | 362 | } |
e73ef85d | 363 | } |
1ecdb44a MS |
364 | } |
365 | ||
a922e963 | 366 | /** |
e27a8652 | 367 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
368 | * to a series of connected cubes, but we also have special mappings for the bass box, |
369 | * the speaker enclosures, and the DJ booth floor. | |
370 | * | |
371 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
372 | * that the cubes and objects being referenced actually exist in the model. | |
373 | * | |
374 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
375 | */ | |
84086fa3 MS |
376 | class ChannelMapping { |
377 | ||
378 | // How many cubes per channel xc_PB is configured for | |
379 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 380 | |
84086fa3 MS |
381 | // How many total pixels on each channel |
382 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
383 | ||
384 | public static final int MODE_NULL = 0; | |
385 | public static final int MODE_CUBES = 1; | |
386 | public static final int MODE_BASS = 2; | |
387 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 388 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
389 | public static final int MODE_INVALID = 5; |
390 | ||
391 | public static final int NO_OBJECT = -1; | |
392 | ||
393 | final int mode; | |
394 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
395 | ||
396 | ChannelMapping() { | |
397 | this(MODE_NULL); | |
398 | } | |
399 | ||
400 | ChannelMapping(int mode) { | |
401 | this(mode, new int[]{}); | |
402 | } | |
403 | ||
404 | ChannelMapping(int mode, int rawObjectIndex) { | |
405 | this(mode, new int[]{ rawObjectIndex }); | |
406 | } | |
407 | ||
408 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
409 | if (mode < 0 || mode >= MODE_INVALID) { | |
410 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
411 | } | |
412 | if (mode == MODE_SPEAKER) { | |
413 | if (rawObjectIndices.length != 1) { | |
414 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
415 | } | |
416 | int speakerIndex = rawObjectIndices[0]; | |
417 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 418 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 419 | } |
1d75c8a9 | 420 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 421 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 422 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
423 | } |
424 | } else if (mode == MODE_CUBES) { | |
425 | for (int rawCubeIndex : rawObjectIndices) { | |
426 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
427 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
428 | } | |
429 | } | |
430 | } | |
431 | ||
432 | this.mode = mode; | |
433 | for (int i = 0; i < objectIndices.length; ++i) { | |
434 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
435 | } | |
436 | } | |
2bb56822 | 437 | } |