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>(); | |
78 | if (NumBackTowers != 11) exit(); | |
79 | // for (int i=0; i<NumBackTowers; i++) scubes.add(new StaggeredTower( | |
80 | // (i+1)*CW, // x | |
81 | // (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
82 | // - ((i % 2 == 0) ? 0 : 11) + 97 , // z | |
83 | // 225, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) ); // num cubes | |
84 | ||
85 | ArrayList<Cube> dcubes = new ArrayList<Cube>(); | |
86 | // for (int i=1; i<6; i++) { | |
87 | // if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR)); | |
88 | // dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR)); | |
89 | // } | |
90 | ||
a981ea46 | 91 | float current_x_position = 0; |
bf1fe2d4 | 92 | scubes.add(new StaggeredTower(//tower 1 |
a981ea46 | 93 | current_x_position, // x |
d93dc84a | 94 | 15 , // y |
bf1fe2d4 | 95 | 0 , // z |
a981ea46 AK |
96 | 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); |
97 | current_x_position += 25.25; | |
bf1fe2d4 | 98 | scubes.add(new StaggeredTower(// tower 2 |
a981ea46 | 99 | current_x_position, // x |
bf1fe2d4 | 100 | 0 , // y |
a981ea46 AK |
101 | -10.5 , // z |
102 | 45, 6, new Cube.Wiring[] { WFR, WFL, WRR, WRR, WFL, WRR}) ); | |
103 | current_x_position += 25.25; | |
bf1fe2d4 | 104 | scubes.add(new StaggeredTower(//tower 3 |
a981ea46 | 105 | current_x_position, // x |
d93dc84a | 106 | 15 , // y |
a981ea46 AK |
107 | 0, // z |
108 | 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WRR, WFL, WRR}) ); | |
109 | current_x_position += 25.25; | |
bf1fe2d4 | 110 | scubes.add(new StaggeredTower(//tower 4 |
a981ea46 AK |
111 | current_x_position, // x |
112 | 0, // y | |
113 | -10.5 , // z | |
114 | 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
d93dc84a | 115 | current_x_position += 28; |
bf1fe2d4 | 116 | scubes.add(new StaggeredTower(//tower 5 |
a981ea46 | 117 | current_x_position, // x |
d93dc84a AK |
118 | 15 , // y |
119 | -4.5 , // z | |
a981ea46 | 120 | 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); |
d93dc84a | 121 | current_x_position += 28; |
bf1fe2d4 | 122 | scubes.add(new StaggeredTower(//tower 6 |
a981ea46 AK |
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 += 25.25; | |
bf1fe2d4 | 128 | scubes.add(new StaggeredTower(// tower 7 |
a981ea46 | 129 | current_x_position, // x |
d93dc84a | 130 | 15 , // y |
a981ea46 AK |
131 | 0, // z |
132 | 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) ); | |
133 | current_x_position += 25.25; | |
bf1fe2d4 | 134 | scubes.add(new StaggeredTower(//tower 8 |
a981ea46 AK |
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; | |
bf1fe2d4 | 140 | scubes.add(new StaggeredTower(//tower 9 |
a981ea46 | 141 | current_x_position, // x |
d93dc84a | 142 | 15 , // y |
a981ea46 AK |
143 | 0, // z |
144 | 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) ); | |
145 | current_x_position += 25.25; | |
146 | ||
d93dc84a AK |
147 | //TOWERS ON DANCE FLOOR |
148 | scubes.add(new StaggeredTower(//tower 10 | |
149 | 83.75+39+43-124.5, // x | |
150 | 0, // y | |
151 | -47.5-43, // z | |
7911e643 | 152 | 0, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); |
a981ea46 | 153 | scubes.add(new StaggeredTower(//tower 11 |
d93dc84a AK |
154 | 83.75, // x |
155 | 0, // y | |
156 | -47.5, // z | |
7911e643 | 157 | 0, 4, new Cube.Wiring[]{ WFL, WRR, WRR, WFL}) ); |
a981ea46 | 158 | scubes.add(new StaggeredTower(//tower 12 |
d93dc84a AK |
159 | 83.75+39, // x |
160 | 0, // y | |
161 | -47.5, // z | |
7911e643 | 162 | 0, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) ); |
a981ea46 | 163 | scubes.add(new StaggeredTower(//tower 13 |
d93dc84a AK |
164 | 83.75+39+43, // x |
165 | 0, // y | |
166 | -47.5-43, // z | |
7911e643 | 167 | 0, 4, new Cube.Wiring[]{ WFL, WRR, WFL, WRR}) ); |
d93dc84a | 168 | |
a981ea46 AK |
169 | // scubes.add(new StaggeredTower(// Single cube on top of tower 4 |
170 | // 42, // x | |
171 | // 112 , // y | |
172 | // 72, // z | |
173 | // -10, 1, new Cube.Wiring[]{ WRL}) ); | |
bf1fe2d4 MS |
174 | |
175 | ||
176 | ||
177 | ||
178 | ||
179 | ||
180 | ||
a3ccf23a MS |
181 | ////////////////////////////////////////////////////////////////////// |
182 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
183 | ////////////////////////////////////////////////////////////////////// | |
184 | ||
f0cc0ba5 | 185 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
186 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
187 | ArrayList<Cube> tower; | |
7e3329d2 | 188 | Cube[] cubes = new Cube[100]; |
46fc29d4 | 189 | int cubeIndex = 1; |
f0cc0ba5 MS |
190 | float px, pz, ny; |
191 | for (TowerMapping tm : towerCubes) { | |
192 | px = tm.x; | |
193 | ny = tm.y; | |
194 | pz = tm.z; | |
46fc29d4 | 195 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
196 | for (CubeMapping cm : tm.cubeMappings) { |
197 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
198 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
199 | } |
200 | towerList.add(new Tower(tower)); | |
201 | } | |
73687629 | 202 | |
f1370a0b AG |
203 | |
204 | for (Cube cube : singleCubes) cubes[cubeIndex++] = cube; | |
bf1fe2d4 | 205 | for (Cube cube : dcubes) cubes[cubeIndex++] = cube; |
f1370a0b | 206 | for (StaggeredTower st : scubes) { |
73687629 | 207 | tower = new ArrayList<Cube>(); |
bf1fe2d4 MS |
208 | for (int i=0; i < st.n; i++) { |
209 | Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR; | |
210 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w)); | |
211 | } | |
73687629 | 212 | towerList.add(new Tower(tower)); |
f0cc0ba5 | 213 | } |
e76480d4 | 214 | |
7dceead9 | 215 | return new Model(towerList, cubes, bassBox, speakers); |
186bc4d3 | 216 | } |
e73ef85d | 217 | |
a3ccf23a MS |
218 | /** |
219 | * This function maps the panda boards. We have an array of them, each has | |
220 | * an IP address and a list of channels. | |
221 | */ | |
186bc4d3 | 222 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
223 | final int LEFT_SPEAKER = 0; |
224 | final int RIGHT_SPEAKER = 1; | |
225 | ||
3b2e0b4a | 226 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 227 | return new PandaMapping[] { |
bf1fe2d4 MS |
228 | new PandaMapping( |
229 | "10.200.1.28", new ChannelMapping[] { | |
a981ea46 AK |
230 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18}), |
231 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
232 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3}), | |
233 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6}), | |
234 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9}), | |
235 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12}), | |
236 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15}), | |
237 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
bf1fe2d4 MS |
238 | }), |
239 | new PandaMapping( | |
240 | "10.200.1.29", new ChannelMapping[] { | |
a981ea46 AK |
241 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}), |
242 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
243 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}), | |
244 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}), | |
245 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}), | |
246 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}), | |
247 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}), | |
248 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
bf1fe2d4 | 249 | }), |
7c7625ec | 250 | new PandaMapping( |
41c436e4 | 251 | "10.200.1.30", new ChannelMapping[] { |
a981ea46 | 252 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J3 * |
bf1fe2d4 | 253 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J4 //ORIG * |
a981ea46 AK |
254 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}), // 30 J7 * |
255 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}), // 30 J8 * | |
256 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}), // 30 J13 (not working) | |
257 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}), // 30 J14 (unplugged) | |
258 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}), // 30 J15 (unplugged) | |
259 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16 | |
73687629 | 260 | }), |
a981ea46 AK |
261 | new PandaMapping( |
262 | "10.200.1.31", new ChannelMapping[] { | |
11c6a1c8 | 263 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}), // J3 |
a981ea46 AK |
264 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 |
265 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 56}), // 30 J7 | |
d93dc84a | 266 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 57, 58}), // J8 |
a981ea46 AK |
267 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 59, 60}), // J13 |
268 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 61, 62}), // 30 J14 | |
d93dc84a | 269 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 63, 64}), // J15 |
11c6a1c8 | 270 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 |
d93dc84a AK |
271 | }), |
272 | new PandaMapping( | |
273 | "10.200.1.32", new ChannelMapping[] { | |
274 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J3 | |
275 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
276 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 67, 68}), // 30 J7 | |
277 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 69, 70}), // J8 | |
278 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J13 | |
279 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 | |
a981ea46 AK |
280 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J15 |
281 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 | |
282 | }), | |
3b2e0b4a | 283 | }; |
45f43cc2 | 284 | } |
e73ef85d | 285 | |
f0cc0ba5 MS |
286 | class TowerMapping { |
287 | public final float x, y, z; | |
288 | public final CubeMapping[] cubeMappings; | |
289 | ||
290 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
291 | this.x = x; | |
292 | this.y = y; | |
293 | this.z = z; | |
294 | this.cubeMappings = cubeMappings; | |
295 | } | |
296 | } | |
297 | ||
298 | class CubeMapping { | |
299 | public final float dx, dz, ry; | |
300 | public final Cube.Wiring wiring; | |
301 | ||
302 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 303 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 304 | } |
f0cc0ba5 MS |
305 | CubeMapping(float dx, float dz, float ry) { |
306 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
307 | } | |
308 | ||
309 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
310 | this.dx = dx; | |
311 | this.dz = dz; | |
312 | this.ry = ry; | |
313 | this.wiring = wiring; | |
314 | } | |
315 | } | |
316 | ||
73687629 | 317 | class StaggeredTower { |
318 | public final float x, y, z, r; | |
319 | public final int n; | |
bf1fe2d4 MS |
320 | public final Cube.Wiring[] wiring; |
321 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); } | |
322 | 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 | 323 | } |
324 | ||
a922e963 MS |
325 | /** |
326 | * Each panda board has an IP address and a fixed number of channels. The channels | |
327 | * each have a fixed number of pixels on them. Whether or not that many physical | |
328 | * pixels are connected to the channel, we still send it that much data. | |
329 | */ | |
45f43cc2 MS |
330 | class PandaMapping { |
331 | ||
045b432d | 332 | // How many channels are on the panda board |
e28f168c | 333 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 334 | |
44b8de9c | 335 | // How many total pixels on the whole board |
84086fa3 | 336 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 337 | |
45f43cc2 | 338 | final String ip; |
84086fa3 | 339 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 340 | |
84086fa3 | 341 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 342 | this.ip = ip; |
a922e963 MS |
343 | |
344 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
345 | for (int i = 0; i < channelList.length; ++i) { |
346 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
347 | if (channelList[i] == null) { |
348 | channelList[i] = new ChannelMapping(); | |
349 | } | |
045b432d | 350 | } |
e73ef85d | 351 | } |
1ecdb44a MS |
352 | } |
353 | ||
a922e963 | 354 | /** |
e27a8652 | 355 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
356 | * to a series of connected cubes, but we also have special mappings for the bass box, |
357 | * the speaker enclosures, and the DJ booth floor. | |
358 | * | |
359 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
360 | * that the cubes and objects being referenced actually exist in the model. | |
361 | * | |
362 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
363 | */ | |
84086fa3 MS |
364 | class ChannelMapping { |
365 | ||
366 | // How many cubes per channel xc_PB is configured for | |
367 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 368 | |
84086fa3 MS |
369 | // How many total pixels on each channel |
370 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
371 | ||
372 | public static final int MODE_NULL = 0; | |
373 | public static final int MODE_CUBES = 1; | |
374 | public static final int MODE_BASS = 2; | |
375 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 376 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
377 | public static final int MODE_INVALID = 5; |
378 | ||
379 | public static final int NO_OBJECT = -1; | |
380 | ||
381 | final int mode; | |
382 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
383 | ||
384 | ChannelMapping() { | |
385 | this(MODE_NULL); | |
386 | } | |
387 | ||
388 | ChannelMapping(int mode) { | |
389 | this(mode, new int[]{}); | |
390 | } | |
391 | ||
392 | ChannelMapping(int mode, int rawObjectIndex) { | |
393 | this(mode, new int[]{ rawObjectIndex }); | |
394 | } | |
395 | ||
396 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
397 | if (mode < 0 || mode >= MODE_INVALID) { | |
398 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
399 | } | |
400 | if (mode == MODE_SPEAKER) { | |
401 | if (rawObjectIndices.length != 1) { | |
402 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
403 | } | |
404 | int speakerIndex = rawObjectIndices[0]; | |
405 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 406 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 407 | } |
1d75c8a9 | 408 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 409 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 410 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
411 | } |
412 | } else if (mode == MODE_CUBES) { | |
413 | for (int rawCubeIndex : rawObjectIndices) { | |
414 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
415 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
416 | } | |
417 | } | |
418 | } | |
419 | ||
420 | this.mode = mode; | |
421 | for (int i = 0; i < objectIndices.length; ++i) { | |
422 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
423 | } | |
424 | } | |
a981ea46 | 425 | } |