finalized mapping
[SugarCubes.git] / _Mappings.pde
1 /**
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
11 * This file implements the mapping functions needed to lay out the physical
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 */
15
16 public Model buildModel() {
17
18
19 // Shorthand helpers for specifying wiring more quickly
20 final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT;
21 final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT;
22 final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT;
23 final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT;
24
25 // Utility value if you need the height of a cube shorthand
26 final float CH = Cube.EDGE_HEIGHT;
27
28 // Positions for the bass box
29 final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH;
30 final float BBX = 56;
31 final float BBZ = 2;
32
33
34 // The model is represented as an array of towers. The cubes in the tower
35 // are represenented relatively. Each tower has an x, y, z reference position,
36 // which is typically the base cube's bottom left corner.
37 //
38 // Following that is an array of floats. A 2-d array contains an x-offset
39 // and a z-offset from the previous reference position. Typically the first cube
40 // will just be {0, 0}. Each successive cube uses the position of the previous
41 // cube as its reference.
42 //
43 // A 3-d array contains an x-offset, a z-offset, and a rotation about the
44 // y-axis.
45 //
46 // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT.
47
48 // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. "raw object index" is serialized by running through towermapping and then individual cube mapping below.
49 // We can do better than this. The raw object index should be obvious from the code-- looking through the rendered simulation and counting through cubes in mapping mode is grossly inefficient.
50 TowerMapping[] towerCubes = new TowerMapping[] {
51
52
53
54 //back left cubes: temp Channel 1
55 new TowerMapping(0, 3*Cube.EDGE_HEIGHT, 72, new CubeMapping[] {
56 new CubeMapping(0, 14, -45 , WRL), // #1
57 new CubeMapping(10, -12, -20, WFL), //#2
58 new CubeMapping(5, 9, 45, WRR), //#3
59
60
61 }),
62 //back left cube tower: Channel 2
63 new TowerMapping(0, Cube.EDGE_HEIGHT, 70, new CubeMapping[] {
64 new CubeMapping(18, -2.5, 45, WRL), //#4
65 new CubeMapping(15, -6, 45, WFR), //#5
66 new CubeMapping(-6 , 7, 5, WRR), //#6
67 new CubeMapping(18, 11, -5, WFL)
68
69 }),
70
71 //second from left back tower: Channel 3
72 new TowerMapping(31, Cube.EDGE_HEIGHT, 73.5, new CubeMapping[] {
73 new CubeMapping( 12.5, 5.5 , 10 , WRR),
74 new CubeMapping( 16.5, 2.5 , 30, WRR),
75 new CubeMapping( 16.5, 3, 10, WRR),
76 new CubeMapping(.5, 4.5, -10 , WFL)
77 } ),
78
79 //center tower, Channel 4
80 new TowerMapping(106, Cube.EDGE_HEIGHT, 84, new CubeMapping[] {
81 new CubeMapping( -3.5, -2, 10, WFL),
82 new CubeMapping( -11, 5, 30, WFR),
83 new CubeMapping( 13.5, 2, 15, WRR),
84 new CubeMapping(20.75, -4, 35 , WRL)
85 } ),
86
87 //second from back right tower, Channel 5
88
89 new TowerMapping(160, Cube.EDGE_HEIGHT, 78, new CubeMapping[] {
90 new CubeMapping( -31.5, -.5 , 5 , WFR),
91 new CubeMapping( 7, -.5, 60, WRL),
92 new CubeMapping( -5.5, -3, 0, WFR),
93 new CubeMapping(22 , 2 , 30 , WRL)
94 }),
95
96
97 //back right cubes: temp Channel 6
98 new TowerMapping(201, Cube.EDGE_HEIGHT, 72, new CubeMapping[] {
99 new CubeMapping(7.5, 6, 25, WRL),
100 new CubeMapping(-4.5, -0.5, 18, WFR),
101 new CubeMapping(8.5, .5, 30, WRL),
102 new CubeMapping(-7, -14, 10, WFR)
103
104 }),
105
106
107
108
109
110 //tower to the right of BASS BOX
111 new TowerMapping (192, Cube.EDGE_HEIGHT, 40, new CubeMapping[] {
112 new CubeMapping(-6, 4, -10, WRL),
113 new CubeMapping(5 ,5 , 5, WFR ),
114 new CubeMapping(-2, .5 , -3, WFL),
115 new CubeMapping(-10, 5.5 , -20, WRR )
116 }),
117
118 //end right tower in middle, right of previous tower
119 //new TowerMapping (214, Cube.EDGE_HEIGHT, 37, new CubeMapping[] {
120 //new CubeMapping(10,0 , 50, WRR),
121 //new CubeMapping(5 ,5 , 65, WFL)
122 //}),
123 // // DJ booth, from back left to back right
124
125 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
126 new CubeMapping(3, 28, 3, WFL),
127 new CubeMapping(-4, -8, 10, WFR),
128 new CubeMapping(-15, 8, 40, WFR)
129
130
131 }),
132
133
134
135 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
136 new CubeMapping(-7.25, 7.5, -25, WFR),
137 new CubeMapping(7.5, -15.75, 12, WRL),
138
139
140 }),
141 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
142 new CubeMapping(19.625, 5.375, -22, WFR),
143 new CubeMapping(8, -14.5, 10, WRR),
144 }),
145 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
146 new CubeMapping(48, 4.75, -35, WRL),
147 new CubeMapping(8, -15, 10, WRR),
148 }),
149 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
150 new CubeMapping(78.75, 3.75, -28, WRR),
151 new CubeMapping(8, -15, 10, WRR),
152 }),
153
154 // next two are right DJ channel
155
156 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
157 new CubeMapping(105, 20.5, 20, WRR),
158 new CubeMapping(6, -6, 30, WFR),
159 }),
160
161 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
162 new CubeMapping(104.75, 0, -27, WRL),
163 new CubeMapping(8, -15, 10, WFL),
164 }),
165
166
167 };
168
169 // Single cubes can be constructed directly here if you need them
170 Cube[] singleCubes = new Cube[] {
171 //back left channel behind speaker
172 new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL),
173
174
175
176 // Top left Channel Above DJ booth
177
178 //new Cube(35, int(5*Cube.EDGE_HEIGHT ), 52, 0, 10, 0, WRR),
179 //new Cube(56, int(5*Cube.EDGE_HEIGHT ), 69, 0, 10, 0, WFL),
180 //new Cube(76, int(5*Cube.EDGE_HEIGHT ), 61, 0, -45, 0, WRL),
181
182 //next channel to the right, same height
183 //new Cube(85, int(5*Cube.EDGE_HEIGHT ), 77, 0, 20, 0, WRL),
184 //new Cube(92, int(6*Cube.EDGE_HEIGHT ), 63, 0,20, 0, WRR),
185 //new Cube(86, int(6*Cube.EDGE_HEIGHT ), 47, 0, -45, 0, WRL),
186 //new Cube(123, int(6*Cube.EDGE_HEIGHT ), 31, 0, 20, 0, WFR),
187
188 // next channel to right, same height
189 //new Cube(111, int(5*Cube.EDGE_HEIGHT ), 79, 0, 30, 0, WRL),
190 //new Cube(125, int(6*Cube.EDGE_HEIGHT ), 76, 0,27, 0, WRL),
191 //new Cube(144, int(5*Cube.EDGE_HEIGHT ), 44, 0, 45, 0, WRR),
192 //new Cube(134, int(5*Cube.EDGE_HEIGHT ), 42, 0, 45, 0, WRL),
193
194 //next channel to right
195 new Cube(185, int(4*Cube.EDGE_HEIGHT ), 73, 0, -45, 0, WRR),
196 //new Cube(170, int(5*Cube.EDGE_HEIGHT ), 58, 0,40, 0, WRL),
197 //new Cube(158, int(6*Cube.EDGE_HEIGHT ), 34, 0, 40, 0, WFR),
198 //new Cube(130, int(6*Cube.EDGE_HEIGHT ), 10, 0, -5, 30, WRL),
199
200 //next channel highest to the right
201 //new Cube(203, int(5*Cube.EDGE_HEIGHT ), 55, 0, 35, 0, WRR),
202 //new Cube(174, int(5*Cube.EDGE_HEIGHT ), 32, 0,35, 0, WFR),
203 //new Cube(178, int(6.5*Cube.EDGE_HEIGHT ), 16, 0, 20 , 30, WRL),
204 //new Cube(212, int(6.5*Cube.EDGE_HEIGHT ), 23, 0, 20 ,30, WRR),
205
206 //last channel
207 //new Cube(204, int(5*Cube.EDGE_HEIGHT ), 28, 0, 25, 0, WFR),
208 ///new Cube(185, int(6*Cube.EDGE_HEIGHT ), 38, 0,40, 0, WRR),
209
210 //new cubes above DJ deck
211
212 new Cube(BBX + 78.5, BBY + 2*Cube.EDGE_HEIGHT, BBZ, 0, 10, 0, WRR),
213 new Cube(BBX + 49.5, BBY + 2*Cube.EDGE_HEIGHT, BBZ - 7, 0, 10, 0, WRR),
214 new Cube(BBX + 13, BBY + 2*Cube.EDGE_HEIGHT, BBZ + 11, 0, -30, 0, WRL),
215 new Cube(BBX - 15, BBY + 2*Cube.EDGE_HEIGHT, BBZ + 30, 0, -35, 0, WRR),
216
217 // new cubes above DJ deck at crazy angles
218 new Cube(BBX - 5, BBY + 3*Cube.EDGE_HEIGHT, BBZ + 15.5, 0, -15, 0, WRL),
219 new Cube(BBX + 27, BBY + 3*Cube.EDGE_HEIGHT, BBZ + 12.5, 0, -18, -15, WRR),
220 new Cube(BBX + 59, BBY + 3*Cube.EDGE_HEIGHT + 4, BBZ + 12.5, -12, 10, -10, WRL),
221 new Cube(BBX + 93, BBY + 3*Cube.EDGE_HEIGHT + 7, BBZ + 20.5, -15, 20, -35, WRR),
222
223 //new cubes on right side of DJ deck
224 new Cube(161, BBY + 2*Cube.EDGE_HEIGHT, 15, 0, -40, 0, WFR),
225 new Cube(161, BBY + 3*Cube.EDGE_HEIGHT, 24, 0, -30, 0, WFL),
226 new Cube(165, BBY + 4*Cube.EDGE_HEIGHT, 41, 0, 5, 0, WFR),
227
228 //new cubes top back left
229 new Cube(BBX + 32, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 7, 0, -25, 0, WFR),
230 new Cube(BBX + 5.5, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH +7, 0, -25, 0, WFL),
231 new Cube(BBX - 23, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 11, 0, -25, 0, WFL),
232 new Cube(BBX - 33, 5*Cube.EDGE_HEIGHT + 8, BBZ +BassBox.EDGE_DEPTH- 29, 0, 10, 0, WFL),
233
234 //on top of previous channel
235 new Cube(BBX + 22, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH , 0, 5, 0, WRL),
236 new Cube(BBX + 27, 6*Cube.EDGE_HEIGHT - 13, BBZ + BassBox.EDGE_DEPTH- 25, 0, 3, -20, WRR),
237 new Cube(BBX +5, 6*Cube.EDGE_HEIGHT - 13, BBZ + BassBox.EDGE_DEPTH -27, 0, 5, -15, WRL),
238 new Cube(BBX - 11, 6*Cube.EDGE_HEIGHT -1.5, BBZ +BassBox.EDGE_DEPTH - 11, 0, 30, 0, WRR),
239
240 //top center
241 new Cube(BBX +37, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH +13 , 0, 15, 0, WRR),
242 new Cube(BBX + 64, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 25, 0, 15, 0, WFR),
243 new Cube(BBX + 64, 6*Cube.EDGE_HEIGHT - 3, BBZ + BassBox.EDGE_DEPTH -4 , 0, 0, -30, WRL),
244 new Cube(BBX + 87.5, 6*Cube.EDGE_HEIGHT + 13, BBZ +BassBox.EDGE_DEPTH - 10, 0, 0, 0, WRL),
245
246 //top right
247 new Cube(BBX + 76, 107.5, BBZ + BassBox.EDGE_DEPTH + 23, 0, -40, 0, WRR),
248 new Cube(BBX + 98, 129, BBZ + BassBox.EDGE_DEPTH - 5, 0, 10, 0, WRR),
249 new Cube(BBX + 104, 107.5, BBZ + BassBox.EDGE_DEPTH + 17, 0, -35, 0, WRR),
250 new Cube(BBX + 129, 107.5, BBZ +BassBox.EDGE_DEPTH +10, 0, -35, 0, WFL),
251
252 new Cube(179, 4*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 14,0, -20, 0 , WFR),
253
254 //lonely cube at top left, one cube channel
255
256 new Cube(BBX - 36, 4*Cube.EDGE_HEIGHT + 8, BBZ +BassBox.EDGE_DEPTH- 38, 0, 10, 0, WFL)
257
258 // new Cube(x, y, z, rx, ry, rz, wiring),
259 };
260
261 // The bass box!
262 //BassBox bassBox = new BassBox(BBX, 0, BBZ);
263 //test for Alex, should be commented out
264
265 // The speakers!
266 //List<Speaker> speakers = Arrays.asList(new Speaker[] {
267 // each speaker parameter is x, y, z, rotation, the left speaker comes first
268 // new Speaker(-12, 6, 0, 15),
269 // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
270 // });
271
272 //////////////////////////////////////////////////////////////////////
273 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
274 //////////////////////////////////////////////////////////////////////
275
276 // These guts just convert the shorthand mappings into usable objects
277 ArrayList<Tower> towerList = new ArrayList<Tower>();
278 ArrayList<Cube> tower;
279 Cube[] cubes = new Cube[80];
280 int cubeIndex = 1;
281 float px, pz, ny;
282 for (TowerMapping tm : towerCubes) {
283 px = tm.x;
284 ny = tm.y;
285 pz = tm.z;
286 tower = new ArrayList<Cube>();
287 for (CubeMapping cm : tm.cubeMappings) {
288 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
289 ny += Cube.EDGE_HEIGHT;
290 }
291 towerList.add(new Tower(tower));
292 }
293 for (Cube cube : singleCubes) {
294 cubes[cubeIndex++] = cube;
295 }
296
297 return new Model(towerList, cubes, null, null);
298 }
299
300 /**
301 * This function maps the panda boards. We have an array of them, each has
302 * an IP address and a list of channels.
303 */
304 public PandaMapping[] buildPandaList() {
305 final int LEFT_SPEAKER = 0;
306 final int RIGHT_SPEAKER = 1;
307
308 return new PandaMapping[] {
309 new PandaMapping(
310 // 8 maps to: 3, 4, 7, 8, 13, 14, 15, 16. So if it's J4,
311 "10.200.1.30", new ChannelMapping[] {
312 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39,40,41,42 }), //30 J3 *
313 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 36, 35}), //30 J4 //ORIG *
314 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20,21,22,23}), //30 J7 *
315 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18, 19}), //30 J8 *
316 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1}), //30 J13 (not working)
317 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {1,1,1,1}), //30 J14 (unplugged)
318 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1 }), // 30 J15 (unplugged)
319 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 53, 54, 55, 72}), // 30 J16
320 }),
321 new PandaMapping(
322 "10.200.1.29", new ChannelMapping[] {
323 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1}), //29 J3 (not connected)
324 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 1, 1, 1}), //29 J4 (not connected)
325 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30, 2}), // 29 J7
326 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33,34,32,31}), //29 J8 //XXX
327 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 1, 1, 1 }), //29 J13 //XX //bassbox (not working)
328 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1}), //29 J14 (not working)
329 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {12, 13, 14, 15 }), //29 J15
330 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {8,9,10,11 } ), //29 J16
331 }),
332 new PandaMapping(
333 "10.200.1.28", new ChannelMapping[] {
334 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 60, 61, 62, 63 }), //28 J3
335 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 56, 57, 58, 59}), //28 J4
336 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45,46,47,48 }), //28 J7
337 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {1,1,1,1}), //28 J8
338 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4,5,6,7}), //28 J13
339 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 64, 65, 66, 67 }), //28 J14
340 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 68, 69, 70, 71 }), //28 J15
341 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49,50,51,52}), //28 J16
342 }),
343 new PandaMapping(
344 "10.200.1.31", new ChannelMapping[] {
345 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[]{1,1,1,1}), //placeholders
346 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[]{1,1,1,1}),
347 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {1,1,1,1 }),
348 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] {24,25,26,27}), //28 J8
349 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1}),
350 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1 }),
351 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 73 }),
352 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1,1}), //31 J16
353
354
355 }
356
357
358
359
360 )
361 };
362
363 }
364
365
366
367 class TowerMapping {
368 public final float x, y, z;
369 public final CubeMapping[] cubeMappings;
370
371 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
372 this.x = x;
373 this.y = y;
374 this.z = z;
375 this.cubeMappings = cubeMappings;
376 }
377 }
378
379 class CubeMapping {
380 public final float dx, dz, ry;
381 public final Cube.Wiring wiring;
382
383 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
384 this(dx, dz, 0, wiring);
385 }
386
387 CubeMapping(float dx, float dz, float ry) {
388 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
389 }
390
391 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
392 this.dx = dx;
393 this.dz = dz;
394 this.ry = ry;
395 this.wiring = wiring;
396 }
397 }
398
399 /**
400 * Each panda board has an IP address and a fixed number of channels. The channels
401 * each have a fixed number of pixels on them. Whether or not that many physical
402 * pixels are connected to the channel, we still send it that much data.
403 */
404 class PandaMapping {
405
406 // How many channels are on the panda board
407 public final static int CHANNELS_PER_BOARD = 8;
408
409 // How many total pixels on the whole board
410 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
411
412 final String ip;
413 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
414
415 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
416 this.ip = ip;
417
418 // Ensure our array is the right length and has all valid items in it
419 for (int i = 0; i < channelList.length; ++i) {
420 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
421 if (channelList[i] == null) {
422 channelList[i] = new ChannelMapping();
423 }
424 }
425 }
426 }
427
428 /**
429 * Each channel on a pandaboard can be mapped in a number of modes. The typical is
430 * to a series of connected cubes, but we also have special mappings for the bass box,
431 * the speaker enclosures, and the DJ booth floor.
432 *
433 * This class is just the mapping meta-data. It sanitizes the input to make sure
434 * that the cubes and objects being referenced actually exist in the model.
435 *
436 * The logic for how to encode the pixels is contained in the PandaDriver.
437 */
438 class ChannelMapping {
439
440 // How many cubes per channel xc_PB is configured for
441 public final static int CUBES_PER_CHANNEL = 4;
442
443 // How many total pixels on each channel
444 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
445
446 public static final int MODE_NULL = 0;
447 public static final int MODE_CUBES = 1;
448 public static final int MODE_BASS = 2;
449 public static final int MODE_SPEAKER = 3;
450 public static final int MODE_STRUTS_AND_FLOOR = 4;
451 public static final int MODE_INVALID = 5;
452
453 public static final int NO_OBJECT = -1;
454
455 final int mode;
456 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
457
458 ChannelMapping() {
459 this(MODE_NULL);
460 }
461
462 ChannelMapping(int mode) {
463 this(mode, new int[]{});
464 }
465
466 ChannelMapping(int mode, int rawObjectIndex) {
467 this(mode, new int[]{ rawObjectIndex });
468 }
469
470 ChannelMapping(int mode, int[] rawObjectIndices) {
471 if (mode < 0 || mode >= MODE_INVALID) {
472 throw new RuntimeException("Invalid channel mapping mode: " + mode);
473 }
474 if (mode == MODE_SPEAKER) {
475 if (rawObjectIndices.length != 1) {
476 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
477 }
478 int speakerIndex = rawObjectIndices[0];
479 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
480 //throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
481 }
482 } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
483 if (rawObjectIndices.length > 0) {
484 //throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
485 }
486 } else if (mode == MODE_CUBES) {
487 for (int rawCubeIndex : rawObjectIndices) {
488 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
489 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
490 }
491 }
492 }
493
494 this.mode = mode;
495 for (int i = 0; i < objectIndices.length; ++i) {
496 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;
497 }
498 }
499 }