Clean up mappings changes
[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 // Top left Channel Above DJ booth
175
176 //new Cube(35, int(5*Cube.EDGE_HEIGHT ), 52, 0, 10, 0, WRR),
177 //new Cube(56, int(5*Cube.EDGE_HEIGHT ), 69, 0, 10, 0, WFL),
178 //new Cube(76, int(5*Cube.EDGE_HEIGHT ), 61, 0, -45, 0, WRL),
179
180 // Next channel to the right, same height
181 //new Cube(85, int(5*Cube.EDGE_HEIGHT ), 77, 0, 20, 0, WRL),
182 //new Cube(92, int(6*Cube.EDGE_HEIGHT ), 63, 0,20, 0, WRR),
183 //new Cube(86, int(6*Cube.EDGE_HEIGHT ), 47, 0, -45, 0, WRL),
184 //new Cube(123, int(6*Cube.EDGE_HEIGHT ), 31, 0, 20, 0, WFR),
185
186 // Next channel to right, same height
187 //new Cube(111, int(5*Cube.EDGE_HEIGHT ), 79, 0, 30, 0, WRL),
188 //new Cube(125, int(6*Cube.EDGE_HEIGHT ), 76, 0,27, 0, WRL),
189 //new Cube(144, int(5*Cube.EDGE_HEIGHT ), 44, 0, 45, 0, WRR),
190 //new Cube(134, int(5*Cube.EDGE_HEIGHT ), 42, 0, 45, 0, WRL),
191
192 // Next channel to right
193 new Cube(185, int(4*Cube.EDGE_HEIGHT ), 73, 0, -45, 0, WRR),
194 //new Cube(170, int(5*Cube.EDGE_HEIGHT ), 58, 0,40, 0, WRL),
195 //new Cube(158, int(6*Cube.EDGE_HEIGHT ), 34, 0, 40, 0, WFR),
196 //new Cube(130, int(6*Cube.EDGE_HEIGHT ), 10, 0, -5, 30, WRL),
197
198 // Next channel highest to the right
199 //new Cube(203, int(5*Cube.EDGE_HEIGHT ), 55, 0, 35, 0, WRR),
200 //new Cube(174, int(5*Cube.EDGE_HEIGHT ), 32, 0,35, 0, WFR),
201 //new Cube(178, int(6.5*Cube.EDGE_HEIGHT ), 16, 0, 20 , 30, WRL),
202 //new Cube(212, int(6.5*Cube.EDGE_HEIGHT ), 23, 0, 20 ,30, WRR),
203
204 // Last channel
205 //new Cube(204, int(5*Cube.EDGE_HEIGHT ), 28, 0, 25, 0, WFR),
206 //new Cube(185, int(6*Cube.EDGE_HEIGHT ), 38, 0,40, 0, WRR),
207
208 // New cubes above DJ deck
209 new Cube(BBX + 78.5, BBY + 2*Cube.EDGE_HEIGHT, BBZ, 0, 10, 0, WRR),
210 new Cube(BBX + 49.5, BBY + 2*Cube.EDGE_HEIGHT, BBZ - 7, 0, 10, 0, WRR),
211 new Cube(BBX + 13, BBY + 2*Cube.EDGE_HEIGHT, BBZ + 11, 0, -30, 0, WRL),
212 new Cube(BBX - 15, BBY + 2*Cube.EDGE_HEIGHT, BBZ + 30, 0, -35, 0, WRR),
213
214 // New cubes above DJ deck at crazy angles
215 new Cube(BBX - 5, BBY + 3*Cube.EDGE_HEIGHT, BBZ + 15.5, 0, -15, 0, WRL),
216 new Cube(BBX + 27, BBY + 3*Cube.EDGE_HEIGHT, BBZ + 12.5, 0, -18, -15, WRR),
217 new Cube(BBX + 59, BBY + 3*Cube.EDGE_HEIGHT + 4, BBZ + 12.5, -12, 10, -10, WRL),
218 new Cube(BBX + 93, BBY + 3*Cube.EDGE_HEIGHT + 7, BBZ + 20.5, -15, 20, -35, WRR),
219
220 // New cubes on right side of DJ deck
221 new Cube(161, BBY + 2*Cube.EDGE_HEIGHT, 15, 0, -40, 0, WFR),
222 new Cube(161, BBY + 3*Cube.EDGE_HEIGHT, 24, 0, -30, 0, WFL),
223 new Cube(165, BBY + 4*Cube.EDGE_HEIGHT, 41, 0, 5, 0, WFR),
224
225 // New cubes top back left
226 new Cube(BBX + 32, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 7, 0, -25, 0, WFR),
227 new Cube(BBX + 5.5, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH +7, 0, -25, 0, WFL),
228 new Cube(BBX - 23, 5*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 11, 0, -25, 0, WFL),
229 new Cube(BBX - 33, 5*Cube.EDGE_HEIGHT + 8, BBZ +BassBox.EDGE_DEPTH- 29, 0, 10, 0, WFL),
230
231 // On top of previous channel
232 new Cube(BBX + 22, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH , 0, 5, 0, WRL),
233 new Cube(BBX + 27, 6*Cube.EDGE_HEIGHT - 13, BBZ + BassBox.EDGE_DEPTH- 25, 0, 3, -20, WRR),
234 new Cube(BBX +5, 6*Cube.EDGE_HEIGHT - 13, BBZ + BassBox.EDGE_DEPTH -27, 0, 5, -15, WRL),
235 new Cube(BBX - 11, 6*Cube.EDGE_HEIGHT -1.5, BBZ +BassBox.EDGE_DEPTH - 11, 0, 30, 0, WRR),
236
237 // Top center
238 new Cube(BBX +37, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH +13 , 0, 15, 0, WRR),
239 new Cube(BBX + 64, 6*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 25, 0, 15, 0, WFR),
240 new Cube(BBX + 64, 6*Cube.EDGE_HEIGHT - 3, BBZ + BassBox.EDGE_DEPTH -4 , 0, 0, -30, WRL),
241 new Cube(BBX + 87.5, 6*Cube.EDGE_HEIGHT + 13, BBZ +BassBox.EDGE_DEPTH - 10, 0, 0, 0, WRL),
242
243 // Top right
244 new Cube(BBX + 76, 107.5, BBZ + BassBox.EDGE_DEPTH + 23, 0, -40, 0, WRR),
245 new Cube(BBX + 98, 129, BBZ + BassBox.EDGE_DEPTH - 5, 0, 10, 0, WRR),
246 new Cube(BBX + 104, 107.5, BBZ + BassBox.EDGE_DEPTH + 17, 0, -35, 0, WRR),
247 new Cube(BBX + 129, 107.5, BBZ +BassBox.EDGE_DEPTH +10, 0, -35, 0, WFL),
248
249 new Cube(179, 4*Cube.EDGE_HEIGHT, BBZ + BassBox.EDGE_DEPTH + 14,0, -20, 0 , WFR),
250
251 // Lonely cube at top left, one cube channel
252 new Cube(BBX - 36, 4*Cube.EDGE_HEIGHT + 8, BBZ +BassBox.EDGE_DEPTH- 38, 0, 10, 0, WFL)
253
254 // new Cube(x, y, z, rx, ry, rz, wiring),
255 };
256
257 // The bass box!
258 /*
259 BassBox bassBox = new BassBox(BBX, 0, BBZ);
260
261 // The speakers!
262 List<Speaker> speakers = Arrays.asList(new Speaker[] {
263 // Each speaker parameter is x, y, z, rotation, the left speaker comes first
264 new Speaker(-12, 6, 0, 15),
265 new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
266 });
267 */
268
269 //////////////////////////////////////////////////////////////////////
270 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
271 //////////////////////////////////////////////////////////////////////
272
273 // These guts just convert the shorthand mappings into usable objects
274 ArrayList<Tower> towerList = new ArrayList<Tower>();
275 ArrayList<Cube> tower;
276 Cube[] cubes = new Cube[80];
277 int cubeIndex = 1;
278 float px, pz, ny;
279 for (TowerMapping tm : towerCubes) {
280 px = tm.x;
281 ny = tm.y;
282 pz = tm.z;
283 tower = new ArrayList<Cube>();
284 for (CubeMapping cm : tm.cubeMappings) {
285 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
286 ny += Cube.EDGE_HEIGHT;
287 }
288 towerList.add(new Tower(tower));
289 }
290 for (Cube cube : singleCubes) {
291 cubes[cubeIndex++] = cube;
292 }
293
294 return new Model(towerList, cubes, null, null);
295 }
296
297 /**
298 * This function maps the panda boards. We have an array of them, each has
299 * an IP address and a list of channels.
300 */
301 public PandaMapping[] buildPandaList() {
302 final int LEFT_SPEAKER = 0;
303 final int RIGHT_SPEAKER = 1;
304
305 // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16.
306 return new PandaMapping[] {
307 new PandaMapping(
308 "10.200.1.30", new ChannelMapping[] {
309 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39, 40, 41, 42 }), // 30 J3 *
310 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 36, 35}), // 30 J4 //ORIG *
311 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20, 21, 22, 23}), // 30 J7 *
312 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18, 19}), // 30 J8 *
313 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J13 (not working)
314 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 (unplugged)
315 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J15 (unplugged)
316 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 53, 54, 55, 72 }), // 30 J16
317 }),
318 new PandaMapping(
319 "10.200.1.29", new ChannelMapping[] {
320 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J3 (not connected)
321 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J4 (not connected)
322 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30, 2}), // 29 J7
323 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 32, 31}), // 29 J8 //XXX
324 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J13 //XX //bassbox (not working)
325 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J14 (not working)
326 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 12, 13, 14, 15 }), // 29 J15
327 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8, 9, 10, 11 }), // 29 J16
328 }),
329 new PandaMapping(
330 "10.200.1.28", new ChannelMapping[] {
331 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 60, 61, 62, 63 }), // 28 J3
332 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 56, 57, 58, 59}), // 28 J4
333 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45, 46, 47, 48 }), // 28 J7
334 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 28 J8
335 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6, 7}), // 28 J13
336 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 64, 65, 66, 67 }), // 28 J14
337 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 68, 69, 70, 71 }), // 28 J15
338 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51, 52}), // 28 J16
339 }),
340 new PandaMapping(
341 "10.200.1.31", new ChannelMapping[] {
342 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), //placeholders
343 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
344 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
345 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24,25,26,27}), //28 J8
346 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
347 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
348 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 73 }),
349 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), //31 J16
350 }),
351 };
352 }
353
354 class TowerMapping {
355 public final float x, y, z;
356 public final CubeMapping[] cubeMappings;
357
358 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
359 this.x = x;
360 this.y = y;
361 this.z = z;
362 this.cubeMappings = cubeMappings;
363 }
364 }
365
366 class CubeMapping {
367 public final float dx, dz, ry;
368 public final Cube.Wiring wiring;
369
370 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
371 this(dx, dz, 0, wiring);
372 }
373
374 CubeMapping(float dx, float dz, float ry) {
375 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
376 }
377
378 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
379 this.dx = dx;
380 this.dz = dz;
381 this.ry = ry;
382 this.wiring = wiring;
383 }
384 }
385
386 /**
387 * Each panda board has an IP address and a fixed number of channels. The channels
388 * each have a fixed number of pixels on them. Whether or not that many physical
389 * pixels are connected to the channel, we still send it that much data.
390 */
391 class PandaMapping {
392
393 // How many channels are on the panda board
394 public final static int CHANNELS_PER_BOARD = 8;
395
396 // How many total pixels on the whole board
397 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
398
399 final String ip;
400 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
401
402 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
403 this.ip = ip;
404
405 // Ensure our array is the right length and has all valid items in it
406 for (int i = 0; i < channelList.length; ++i) {
407 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
408 if (channelList[i] == null) {
409 channelList[i] = new ChannelMapping();
410 }
411 }
412 }
413 }
414
415 /**
416 * Each channel on a pandaboard can be mapped in a number of modes. The typical is
417 * to a series of connected cubes, but we also have special mappings for the bass box,
418 * the speaker enclosures, and the DJ booth floor.
419 *
420 * This class is just the mapping meta-data. It sanitizes the input to make sure
421 * that the cubes and objects being referenced actually exist in the model.
422 *
423 * The logic for how to encode the pixels is contained in the PandaDriver.
424 */
425 class ChannelMapping {
426
427 // How many cubes per channel xc_PB is configured for
428 public final static int CUBES_PER_CHANNEL = 4;
429
430 // How many total pixels on each channel
431 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
432
433 public static final int MODE_NULL = 0;
434 public static final int MODE_CUBES = 1;
435 public static final int MODE_BASS = 2;
436 public static final int MODE_SPEAKER = 3;
437 public static final int MODE_STRUTS_AND_FLOOR = 4;
438 public static final int MODE_INVALID = 5;
439
440 public static final int NO_OBJECT = -1;
441
442 final int mode;
443 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
444
445 ChannelMapping() {
446 this(MODE_NULL);
447 }
448
449 ChannelMapping(int mode) {
450 this(mode, new int[]{});
451 }
452
453 ChannelMapping(int mode, int rawObjectIndex) {
454 this(mode, new int[]{ rawObjectIndex });
455 }
456
457 ChannelMapping(int mode, int[] rawObjectIndices) {
458 if (mode < 0 || mode >= MODE_INVALID) {
459 throw new RuntimeException("Invalid channel mapping mode: " + mode);
460 }
461 if (mode == MODE_SPEAKER) {
462 if (rawObjectIndices.length != 1) {
463 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
464 }
465 int speakerIndex = rawObjectIndices[0];
466 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
467 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
468 }
469 } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
470 if (rawObjectIndices.length > 0) {
471 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
472 }
473 } else if (mode == MODE_CUBES) {
474 for (int rawCubeIndex : rawObjectIndices) {
475 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
476 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
477 }
478 }
479 }
480
481 this.mode = mode;
482 for (int i = 0; i < objectIndices.length; ++i) {
483 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;
484 }
485 }
486 }