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 | 216 | |
cd1c3313 MS |
217 | for (Cube cube : singleCubes) { |
218 | cubes[cubeIndex++] = cube; | |
219 | } | |
220 | for (Cube cube : dcubes) { | |
221 | cubes[cubeIndex++] = cube; | |
222 | } | |
270a8b44 | 223 | for (StaggeredTower st : scubes) { |
73687629 | 224 | tower = new ArrayList<Cube>(); |
bf1fe2d4 MS |
225 | for (int i=0; i < st.n; i++) { |
226 | Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR; | |
227 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w)); | |
228 | } | |
73687629 | 229 | towerList.add(new Tower(tower)); |
2bb56822 | 230 | } |
e76480d4 | 231 | |
7dceead9 | 232 | return new Model(towerList, cubes, bassBox, speakers); |
186bc4d3 | 233 | } |
e73ef85d | 234 | |
a3ccf23a MS |
235 | /** |
236 | * This function maps the panda boards. We have an array of them, each has | |
237 | * an IP address and a list of channels. | |
238 | */ | |
186bc4d3 | 239 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
240 | final int LEFT_SPEAKER = 0; |
241 | final int RIGHT_SPEAKER = 1; | |
242 | ||
3b2e0b4a | 243 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 244 | return new PandaMapping[] { |
bf1fe2d4 MS |
245 | new PandaMapping( |
246 | "10.200.1.28", new ChannelMapping[] { | |
270a8b44 MS |
247 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39 }), |
248 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
249 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45 }), | |
250 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48 }), | |
251 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new front thing | |
252 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new back thing | |
253 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15 }), // new back thing | |
bf1fe2d4 | 254 | }), |
df18145f AG |
255 | new PandaMapping( |
256 | "10.200.1.29", new ChannelMapping[] { | |
270a8b44 MS |
257 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21 }), |
258 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
259 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3 }), | |
260 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6 }), | |
261 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9 }), | |
cd1c3313 | 262 | |
270a8b44 MS |
263 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12 }), |
264 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18 }), | |
265 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}), | |
266 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
267 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}), | |
268 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}), | |
269 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}), | |
270 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}), | |
271 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}), | |
272 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
df18145f AG |
273 | }), |
274 | new PandaMapping( | |
275 | "10.200.1.30", new ChannelMapping[] { | |
270a8b44 MS |
276 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42 }), |
277 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
278 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24 }), | |
279 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27 }), | |
280 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30 }), | |
281 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33 }), | |
282 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36 }), | |
283 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J3 * | |
284 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J4 //ORIG * | |
285 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}), // 30 J7 * | |
286 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}), // 30 J8 * | |
287 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}), // 30 J13 (not working) | |
288 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}), // 30 J14 (unplugged) | |
289 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}), // 30 J15 (unplugged) | |
290 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16 | |
df18145f | 291 | }), |
270a8b44 MS |
292 | // new PandaMapping( |
293 | // "10.200.1.31", new ChannelMapping[] { | |
294 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}), // J3 | |
295 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J4 | |
296 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 56}), // 30 J7 | |
297 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 57, 58}), // J8 | |
298 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 59, 60}), // J13 | |
299 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 61, 62}), // 30 J14 | |
300 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 63, 64}), // J15 | |
301 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J16 | |
302 | // }), | |
303 | ||
1a92d73a AG |
304 | // new PandaMapping( |
305 | // "10.200.1.32", new ChannelMapping[] { | |
306 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J3 | |
307 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
308 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 67, 68}), // 30 J7 | |
309 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 69, 70}), // J8 | |
310 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J13 | |
311 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 | |
312 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J15 | |
313 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16 | |
314 | // }), | |
3b2e0b4a | 315 | }; |
45f43cc2 | 316 | } |
e73ef85d | 317 | |
f0cc0ba5 MS |
318 | class TowerMapping { |
319 | public final float x, y, z; | |
320 | public final CubeMapping[] cubeMappings; | |
321 | ||
322 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
323 | this.x = x; | |
324 | this.y = y; | |
325 | this.z = z; | |
326 | this.cubeMappings = cubeMappings; | |
327 | } | |
328 | } | |
329 | ||
330 | class CubeMapping { | |
331 | public final float dx, dz, ry; | |
332 | public final Cube.Wiring wiring; | |
333 | ||
334 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 335 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 336 | } |
f0cc0ba5 MS |
337 | CubeMapping(float dx, float dz, float ry) { |
338 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
339 | } | |
340 | ||
341 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
342 | this.dx = dx; | |
343 | this.dz = dz; | |
344 | this.ry = ry; | |
345 | this.wiring = wiring; | |
346 | } | |
347 | } | |
348 | ||
73687629 | 349 | class StaggeredTower { |
350 | public final float x, y, z, r; | |
351 | public final int n; | |
bf1fe2d4 MS |
352 | public final Cube.Wiring[] wiring; |
353 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); } | |
354 | 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 | 355 | } |
356 | ||
a922e963 MS |
357 | /** |
358 | * Each panda board has an IP address and a fixed number of channels. The channels | |
359 | * each have a fixed number of pixels on them. Whether or not that many physical | |
360 | * pixels are connected to the channel, we still send it that much data. | |
361 | */ | |
45f43cc2 MS |
362 | class PandaMapping { |
363 | ||
045b432d | 364 | // How many channels are on the panda board |
e28f168c | 365 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 366 | |
44b8de9c | 367 | // How many total pixels on the whole board |
84086fa3 | 368 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 369 | |
45f43cc2 | 370 | final String ip; |
84086fa3 | 371 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 372 | |
84086fa3 | 373 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 374 | this.ip = ip; |
a922e963 MS |
375 | |
376 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
377 | for (int i = 0; i < channelList.length; ++i) { |
378 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
379 | if (channelList[i] == null) { |
380 | channelList[i] = new ChannelMapping(); | |
381 | } | |
045b432d | 382 | } |
e73ef85d | 383 | } |
1ecdb44a MS |
384 | } |
385 | ||
a922e963 | 386 | /** |
e27a8652 | 387 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
388 | * to a series of connected cubes, but we also have special mappings for the bass box, |
389 | * the speaker enclosures, and the DJ booth floor. | |
390 | * | |
391 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
392 | * that the cubes and objects being referenced actually exist in the model. | |
393 | * | |
394 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
395 | */ | |
84086fa3 MS |
396 | class ChannelMapping { |
397 | ||
398 | // How many cubes per channel xc_PB is configured for | |
399 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 400 | |
84086fa3 MS |
401 | // How many total pixels on each channel |
402 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
403 | ||
404 | public static final int MODE_NULL = 0; | |
405 | public static final int MODE_CUBES = 1; | |
406 | public static final int MODE_BASS = 2; | |
407 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 408 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
409 | public static final int MODE_INVALID = 5; |
410 | ||
411 | public static final int NO_OBJECT = -1; | |
412 | ||
413 | final int mode; | |
414 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
415 | ||
416 | ChannelMapping() { | |
417 | this(MODE_NULL); | |
418 | } | |
419 | ||
420 | ChannelMapping(int mode) { | |
421 | this(mode, new int[]{}); | |
422 | } | |
423 | ||
424 | ChannelMapping(int mode, int rawObjectIndex) { | |
425 | this(mode, new int[]{ rawObjectIndex }); | |
426 | } | |
427 | ||
428 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
429 | if (mode < 0 || mode >= MODE_INVALID) { | |
430 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
431 | } | |
432 | if (mode == MODE_SPEAKER) { | |
433 | if (rawObjectIndices.length != 1) { | |
434 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
435 | } | |
436 | int speakerIndex = rawObjectIndices[0]; | |
437 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 438 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 439 | } |
1d75c8a9 | 440 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 441 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 442 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
443 | } |
444 | } else if (mode == MODE_CUBES) { | |
445 | for (int rawCubeIndex : rawObjectIndices) { | |
446 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
447 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
448 | } | |
449 | } | |
450 | } | |
451 | ||
452 | this.mode = mode; | |
453 | for (int i = 0; i < objectIndices.length; ++i) { | |
454 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
455 | } | |
456 | } | |
2bb56822 | 457 | } |