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