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[] { |
6702151a MS |
127 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), |
128 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
129 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
130 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
131 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
132 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
133 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
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), | |
6702151a MS |
138 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), |
139 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
140 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
141 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
142 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
186bc4d3 | 143 | }), |
45f43cc2 | 144 | |
186bc4d3 | 145 | new PandaMapping( |
29674806 | 146 | "10.200.1.28", new ChannelMapping[] { |
1d75c8a9 MS |
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 }), | |
158 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
159 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
160 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
161 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
162 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }), | |
186bc4d3 | 163 | }), |
186bc4d3 | 164 | }; |
45f43cc2 | 165 | } |
e73ef85d | 166 | |
f0cc0ba5 MS |
167 | class TowerMapping { |
168 | public final float x, y, z; | |
169 | public final CubeMapping[] cubeMappings; | |
170 | ||
171 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
172 | this.x = x; | |
173 | this.y = y; | |
174 | this.z = z; | |
175 | this.cubeMappings = cubeMappings; | |
176 | } | |
177 | } | |
178 | ||
179 | class CubeMapping { | |
180 | public final float dx, dz, ry; | |
181 | public final Cube.Wiring wiring; | |
182 | ||
183 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
184 | this(dx, dz, 0, wiring); | |
185 | } | |
186 | ||
187 | CubeMapping(float dx, float dz, float ry) { | |
188 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
189 | } | |
190 | ||
191 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
192 | this.dx = dx; | |
193 | this.dz = dz; | |
194 | this.ry = ry; | |
195 | this.wiring = wiring; | |
196 | } | |
197 | } | |
198 | ||
a922e963 MS |
199 | /** |
200 | * Each panda board has an IP address and a fixed number of channels. The channels | |
201 | * each have a fixed number of pixels on them. Whether or not that many physical | |
202 | * pixels are connected to the channel, we still send it that much data. | |
203 | */ | |
45f43cc2 MS |
204 | class PandaMapping { |
205 | ||
045b432d | 206 | // How many channels are on the panda board |
1627a617 | 207 | public final static int CHANNELS_PER_BOARD = 16; |
045b432d | 208 | |
44b8de9c | 209 | // How many total pixels on the whole board |
84086fa3 | 210 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 211 | |
45f43cc2 | 212 | final String ip; |
84086fa3 | 213 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 214 | |
84086fa3 | 215 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 216 | this.ip = ip; |
a922e963 MS |
217 | |
218 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
219 | for (int i = 0; i < channelList.length; ++i) { |
220 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
221 | if (channelList[i] == null) { |
222 | channelList[i] = new ChannelMapping(); | |
223 | } | |
045b432d | 224 | } |
e73ef85d | 225 | } |
1ecdb44a MS |
226 | } |
227 | ||
a922e963 MS |
228 | /** |
229 | * Each channel on a pandaboard can be mapped in a number of modes. The typial is | |
230 | * to a series of connected cubes, but we also have special mappings for the bass box, | |
231 | * the speaker enclosures, and the DJ booth floor. | |
232 | * | |
233 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
234 | * that the cubes and objects being referenced actually exist in the model. | |
235 | * | |
236 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
237 | */ | |
84086fa3 MS |
238 | class ChannelMapping { |
239 | ||
240 | // How many cubes per channel xc_PB is configured for | |
241 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 242 | |
84086fa3 MS |
243 | // How many total pixels on each channel |
244 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
245 | ||
246 | public static final int MODE_NULL = 0; | |
247 | public static final int MODE_CUBES = 1; | |
248 | public static final int MODE_BASS = 2; | |
249 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 250 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
251 | public static final int MODE_INVALID = 5; |
252 | ||
253 | public static final int NO_OBJECT = -1; | |
254 | ||
255 | final int mode; | |
256 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
257 | ||
258 | ChannelMapping() { | |
259 | this(MODE_NULL); | |
260 | } | |
261 | ||
262 | ChannelMapping(int mode) { | |
263 | this(mode, new int[]{}); | |
264 | } | |
265 | ||
266 | ChannelMapping(int mode, int rawObjectIndex) { | |
267 | this(mode, new int[]{ rawObjectIndex }); | |
268 | } | |
269 | ||
270 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
271 | if (mode < 0 || mode >= MODE_INVALID) { | |
272 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
273 | } | |
274 | if (mode == MODE_SPEAKER) { | |
275 | if (rawObjectIndices.length != 1) { | |
276 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
277 | } | |
278 | int speakerIndex = rawObjectIndices[0]; | |
279 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
280 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); | |
281 | } | |
1d75c8a9 | 282 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 MS |
283 | if (rawObjectIndices.length > 0) { |
284 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); | |
285 | } | |
286 | } else if (mode == MODE_CUBES) { | |
287 | for (int rawCubeIndex : rawObjectIndices) { | |
288 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
289 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
290 | } | |
291 | } | |
292 | } | |
293 | ||
294 | this.mode = mode; | |
295 | for (int i = 0; i < objectIndices.length; ++i) { | |
296 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
297 | } | |
298 | } | |
299 | } | |
a922e963 | 300 |