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 | ||
46fc29d4 | 18 | |
f0cc0ba5 MS |
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; | |
95c50032 | 24 | |
a3ccf23a | 25 | // Utility value if you need the height of a cube shorthand |
95c50032 | 26 | final float CH = Cube.EDGE_HEIGHT; |
ae579223 | 27 | |
a3ccf23a | 28 | // Positions for the bass box |
ae579223 MS |
29 | final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; |
30 | final float BBX = 56; | |
31 | final float BBZ = 2; | |
32 | ||
46fc29d4 | 33 | |
46fc29d4 MS |
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 | |
f0cc0ba5 MS |
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. | |
46fc29d4 MS |
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. | |
f0cc0ba5 | 47 | TowerMapping[] towerCubes = new TowerMapping[] { |
46fc29d4 | 48 | |
ae579223 MS |
49 | // DJ booth, from left to right |
50 | new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] { | |
51 | new CubeMapping(-7.25, 7.5, -25, WFR), | |
52 | new CubeMapping(7.5, -15.75, 12, WRL), | |
53 | }), | |
54 | new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] { | |
55 | new CubeMapping(19.625, 5.375, -22, WFR), | |
56 | new CubeMapping(8, -14.5, 10, WRR), | |
57 | }), | |
58 | new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] { | |
59 | new CubeMapping(48, 4.75, -35, WRL), | |
60 | new CubeMapping(8, -15, 10, WRR), | |
61 | }), | |
62 | new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] { | |
63 | new CubeMapping(78.75, 3.75, -28, WRR), | |
64 | new CubeMapping(8, -15, 10, WRR), | |
46fc29d4 | 65 | }), |
ae579223 MS |
66 | new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] { |
67 | new CubeMapping(104.75, 0, -27, WRL), | |
68 | new CubeMapping(8, -15, 10, WFL), | |
69 | }), | |
46fc29d4 MS |
70 | |
71 | }; | |
f0cc0ba5 MS |
72 | |
73 | // Single cubes can be constructed directly here if you need them | |
74 | Cube[] singleCubes = new Cube[] { | |
75 | // new Cube(x, y, z, rx, ry, rz, wiring), | |
76 | }; | |
77 | ||
78 | // The bass box! | |
ae579223 | 79 | BassBox bassBox = new BassBox(BBX, 0, BBZ); |
51d0d59a | 80 | |
f0cc0ba5 MS |
81 | // The speakers! |
82 | List<Speaker> speakers = Arrays.asList(new Speaker[] { | |
a3ccf23a | 83 | // each speaker parameter is x, y, z, rotation, the left speaker comes first |
f0cc0ba5 | 84 | new Speaker(-12, 6, 0, 15), |
ae579223 | 85 | new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) |
f0cc0ba5 MS |
86 | }); |
87 | ||
a3ccf23a MS |
88 | ////////////////////////////////////////////////////////////////////// |
89 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
90 | ////////////////////////////////////////////////////////////////////// | |
91 | ||
f0cc0ba5 | 92 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
93 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
94 | ArrayList<Cube> tower; | |
f0cc0ba5 | 95 | Cube[] cubes = new Cube[80]; |
46fc29d4 | 96 | int cubeIndex = 1; |
f0cc0ba5 MS |
97 | float px, pz, ny; |
98 | for (TowerMapping tm : towerCubes) { | |
99 | px = tm.x; | |
100 | ny = tm.y; | |
101 | pz = tm.z; | |
46fc29d4 | 102 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
103 | for (CubeMapping cm : tm.cubeMappings) { |
104 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
105 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
106 | } |
107 | towerList.add(new Tower(tower)); | |
108 | } | |
f0cc0ba5 MS |
109 | for (Cube cube : singleCubes) { |
110 | cubes[cubeIndex++] = cube; | |
111 | } | |
e76480d4 MS |
112 | |
113 | return new Model(towerList, cubes, bassBox, speakers); | |
186bc4d3 | 114 | } |
e73ef85d | 115 | |
a3ccf23a MS |
116 | /** |
117 | * This function maps the panda boards. We have an array of them, each has | |
118 | * an IP address and a list of channels. | |
119 | */ | |
186bc4d3 | 120 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
121 | final int LEFT_SPEAKER = 0; |
122 | final int RIGHT_SPEAKER = 1; | |
123 | ||
186bc4d3 MS |
124 | return new PandaMapping[] { |
125 | new PandaMapping( | |
29674806 | 126 | "10.200.1.29", new ChannelMapping[] { |
1d75c8a9 MS |
127 | new ChannelMapping(), |
128 | new ChannelMapping(), | |
129 | new ChannelMapping(), | |
130 | new ChannelMapping(), | |
131 | new ChannelMapping(), | |
132 | new ChannelMapping(), | |
a3ccf23a | 133 | new ChannelMapping(), |
1d75c8a9 MS |
134 | new ChannelMapping(ChannelMapping.MODE_BASS), |
135 | new ChannelMapping(ChannelMapping.MODE_STRUTS_AND_FLOOR), | |
136 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, LEFT_SPEAKER), | |
137 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, RIGHT_SPEAKER), | |
186bc4d3 | 138 | }), |
45f43cc2 | 139 | |
186bc4d3 | 140 | new PandaMapping( |
29674806 | 141 | "10.200.1.28", new ChannelMapping[] { |
1d75c8a9 MS |
142 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), |
143 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
144 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
145 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
146 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
147 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
148 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
149 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
150 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
151 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
152 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
153 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
154 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
155 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
156 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
157 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
186bc4d3 | 158 | }), |
186bc4d3 | 159 | }; |
45f43cc2 | 160 | } |
e73ef85d | 161 | |
f0cc0ba5 MS |
162 | class TowerMapping { |
163 | public final float x, y, z; | |
164 | public final CubeMapping[] cubeMappings; | |
165 | ||
166 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
167 | this.x = x; | |
168 | this.y = y; | |
169 | this.z = z; | |
170 | this.cubeMappings = cubeMappings; | |
171 | } | |
172 | } | |
173 | ||
174 | class CubeMapping { | |
175 | public final float dx, dz, ry; | |
176 | public final Cube.Wiring wiring; | |
177 | ||
178 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
179 | this(dx, dz, 0, wiring); | |
180 | } | |
181 | ||
182 | CubeMapping(float dx, float dz, float ry) { | |
183 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
184 | } | |
185 | ||
186 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
187 | this.dx = dx; | |
188 | this.dz = dz; | |
189 | this.ry = ry; | |
190 | this.wiring = wiring; | |
191 | } | |
192 | } | |
193 | ||
a922e963 MS |
194 | /** |
195 | * Each panda board has an IP address and a fixed number of channels. The channels | |
196 | * each have a fixed number of pixels on them. Whether or not that many physical | |
197 | * pixels are connected to the channel, we still send it that much data. | |
198 | */ | |
45f43cc2 MS |
199 | class PandaMapping { |
200 | ||
045b432d | 201 | // How many channels are on the panda board |
1627a617 | 202 | public final static int CHANNELS_PER_BOARD = 16; |
045b432d | 203 | |
44b8de9c | 204 | // How many total pixels on the whole board |
84086fa3 | 205 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 206 | |
45f43cc2 | 207 | final String ip; |
84086fa3 | 208 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 209 | |
84086fa3 | 210 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 211 | this.ip = ip; |
a922e963 MS |
212 | |
213 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
214 | for (int i = 0; i < channelList.length; ++i) { |
215 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
216 | if (channelList[i] == null) { |
217 | channelList[i] = new ChannelMapping(); | |
218 | } | |
045b432d | 219 | } |
e73ef85d | 220 | } |
1ecdb44a MS |
221 | } |
222 | ||
a922e963 MS |
223 | /** |
224 | * Each channel on a pandaboard can be mapped in a number of modes. The typial is | |
225 | * to a series of connected cubes, but we also have special mappings for the bass box, | |
226 | * the speaker enclosures, and the DJ booth floor. | |
227 | * | |
228 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
229 | * that the cubes and objects being referenced actually exist in the model. | |
230 | * | |
231 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
232 | */ | |
84086fa3 MS |
233 | class ChannelMapping { |
234 | ||
235 | // How many cubes per channel xc_PB is configured for | |
236 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 237 | |
84086fa3 MS |
238 | // How many total pixels on each channel |
239 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
240 | ||
241 | public static final int MODE_NULL = 0; | |
242 | public static final int MODE_CUBES = 1; | |
243 | public static final int MODE_BASS = 2; | |
244 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 245 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
246 | public static final int MODE_INVALID = 5; |
247 | ||
248 | public static final int NO_OBJECT = -1; | |
249 | ||
250 | final int mode; | |
251 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
252 | ||
253 | ChannelMapping() { | |
254 | this(MODE_NULL); | |
255 | } | |
256 | ||
257 | ChannelMapping(int mode) { | |
258 | this(mode, new int[]{}); | |
259 | } | |
260 | ||
261 | ChannelMapping(int mode, int rawObjectIndex) { | |
262 | this(mode, new int[]{ rawObjectIndex }); | |
263 | } | |
264 | ||
265 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
266 | if (mode < 0 || mode >= MODE_INVALID) { | |
267 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
268 | } | |
269 | if (mode == MODE_SPEAKER) { | |
270 | if (rawObjectIndices.length != 1) { | |
271 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
272 | } | |
273 | int speakerIndex = rawObjectIndices[0]; | |
274 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
275 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); | |
276 | } | |
1d75c8a9 | 277 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 MS |
278 | if (rawObjectIndices.length > 0) { |
279 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); | |
280 | } | |
281 | } else if (mode == MODE_CUBES) { | |
282 | for (int rawCubeIndex : rawObjectIndices) { | |
283 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
284 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
285 | } | |
286 | } | |
287 | } | |
288 | ||
289 | this.mode = mode; | |
290 | for (int i = 0; i < objectIndices.length; ++i) { | |
291 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
292 | } | |
293 | } | |
294 | } | |
a922e963 | 295 |