New Heron and GLucose jars, bring bass box back
[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 BassBox bassBox = new BassBox(BBX, 0, BBZ);
259
260 // The speakers!
261 List<Speaker> speakers = Arrays.asList(new Speaker[] {
262 // Each speaker parameter is x, y, z, rotation, the left speaker comes first
263 // new Speaker(-12, 6, 0, 15),
264 // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
265 });
266
267 //////////////////////////////////////////////////////////////////////
268 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
269 //////////////////////////////////////////////////////////////////////
270
271 // These guts just convert the shorthand mappings into usable objects
272 ArrayList<Tower> towerList = new ArrayList<Tower>();
273 ArrayList<Cube> tower;
274 Cube[] cubes = new Cube[80];
275 int cubeIndex = 1;
276 float px, pz, ny;
277 for (TowerMapping tm : towerCubes) {
278 px = tm.x;
279 ny = tm.y;
280 pz = tm.z;
281 tower = new ArrayList<Cube>();
282 for (CubeMapping cm : tm.cubeMappings) {
283 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
284 ny += Cube.EDGE_HEIGHT;
285 }
286 towerList.add(new Tower(tower));
287 }
288 for (Cube cube : singleCubes) {
289 cubes[cubeIndex++] = cube;
290 }
291
292 return new Model(towerList, cubes, bassBox, speakers);
293 }
294
295 /**
296 * This function maps the panda boards. We have an array of them, each has
297 * an IP address and a list of channels.
298 */
299 public PandaMapping[] buildPandaList() {
300 final int LEFT_SPEAKER = 0;
301 final int RIGHT_SPEAKER = 1;
302
303 // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16.
304 return new PandaMapping[] {
305 new PandaMapping(
306 "10.200.1.30", new ChannelMapping[] {
307 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39, 40, 41, 42 }), // 30 J3 *
308 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 36, 35}), // 30 J4 //ORIG *
309 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20, 21, 22, 23}), // 30 J7 *
310 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18, 19}), // 30 J8 *
311 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J13 (not working)
312 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 (unplugged)
313 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J15 (unplugged)
314 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 53, 54, 55, 72 }), // 30 J16
315 }),
316 new PandaMapping(
317 "10.200.1.29", new ChannelMapping[] {
318 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J3 (not connected)
319 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J4 (not connected)
320 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30, 2}), // 29 J7
321 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 32, 31}), // 29 J8 //XXX
322 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J13 //XX //bassbox (not working)
323 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 29 J14 (not working)
324 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 12, 13, 14, 15 }), // 29 J15
325 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8, 9, 10, 11 }), // 29 J16
326 }),
327 new PandaMapping(
328 "10.200.1.28", new ChannelMapping[] {
329 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 60, 61, 62, 63 }), // 28 J3
330 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 56, 57, 58, 59}), // 28 J4
331 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45, 46, 47, 48 }), // 28 J7
332 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 28 J8
333 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6, 7}), // 28 J13
334 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 64, 65, 66, 67 }), // 28 J14
335 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 68, 69, 70, 71 }), // 28 J15
336 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51, 52}), // 28 J16
337 }),
338 new PandaMapping(
339 "10.200.1.31", new ChannelMapping[] {
340 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
341 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
342 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
343 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24, 25, 26, 27}), // 31 J8
344 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
345 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
346 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 73 }),
347 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 31 J16
348 }),
349 };
350 }
351
352 class TowerMapping {
353 public final float x, y, z;
354 public final CubeMapping[] cubeMappings;
355
356 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
357 this.x = x;
358 this.y = y;
359 this.z = z;
360 this.cubeMappings = cubeMappings;
361 }
362 }
363
364 class CubeMapping {
365 public final float dx, dz, ry;
366 public final Cube.Wiring wiring;
367
368 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
369 this(dx, dz, 0, wiring);
370 }
371
372 CubeMapping(float dx, float dz, float ry) {
373 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
374 }
375
376 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
377 this.dx = dx;
378 this.dz = dz;
379 this.ry = ry;
380 this.wiring = wiring;
381 }
382 }
383
384 /**
385 * Each panda board has an IP address and a fixed number of channels. The channels
386 * each have a fixed number of pixels on them. Whether or not that many physical
387 * pixels are connected to the channel, we still send it that much data.
388 */
389 class PandaMapping {
390
391 // How many channels are on the panda board
392 public final static int CHANNELS_PER_BOARD = 8;
393
394 // How many total pixels on the whole board
395 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
396
397 final String ip;
398 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
399
400 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
401 this.ip = ip;
402
403 // Ensure our array is the right length and has all valid items in it
404 for (int i = 0; i < channelList.length; ++i) {
405 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
406 if (channelList[i] == null) {
407 channelList[i] = new ChannelMapping();
408 }
409 }
410 }
411 }
412
413 /**
414 * Each channel on a pandaboard can be mapped in a number of modes. The typical is
415 * to a series of connected cubes, but we also have special mappings for the bass box,
416 * the speaker enclosures, and the DJ booth floor.
417 *
418 * This class is just the mapping meta-data. It sanitizes the input to make sure
419 * that the cubes and objects being referenced actually exist in the model.
420 *
421 * The logic for how to encode the pixels is contained in the PandaDriver.
422 */
423 class ChannelMapping {
424
425 // How many cubes per channel xc_PB is configured for
426 public final static int CUBES_PER_CHANNEL = 4;
427
428 // How many total pixels on each channel
429 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
430
431 public static final int MODE_NULL = 0;
432 public static final int MODE_CUBES = 1;
433 public static final int MODE_BASS = 2;
434 public static final int MODE_SPEAKER = 3;
435 public static final int MODE_STRUTS_AND_FLOOR = 4;
436 public static final int MODE_INVALID = 5;
437
438 public static final int NO_OBJECT = -1;
439
440 final int mode;
441 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
442
443 ChannelMapping() {
444 this(MODE_NULL);
445 }
446
447 ChannelMapping(int mode) {
448 this(mode, new int[]{});
449 }
450
451 ChannelMapping(int mode, int rawObjectIndex) {
452 this(mode, new int[]{ rawObjectIndex });
453 }
454
455 ChannelMapping(int mode, int[] rawObjectIndices) {
456 if (mode < 0 || mode >= MODE_INVALID) {
457 throw new RuntimeException("Invalid channel mapping mode: " + mode);
458 }
459 if (mode == MODE_SPEAKER) {
460 if (rawObjectIndices.length != 1) {
461 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
462 }
463 int speakerIndex = rawObjectIndices[0];
464 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
465 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
466 }
467 } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
468 if (rawObjectIndices.length > 0) {
469 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
470 }
471 } else if (mode == MODE_CUBES) {
472 for (int rawCubeIndex : rawObjectIndices) {
473 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
474 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
475 }
476 }
477 }
478
479 this.mode = mode;
480 for (int i = 0; i < objectIndices.length; ++i) {
481 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;
482 }
483 }
484 }