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 | ||
18 | final float BASS_FLOOR = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; | |
46fc29d4 | 19 | |
f0cc0ba5 MS |
20 | // Shorthand helpers for specifying wiring more quickly |
21 | final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; | |
22 | final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; | |
23 | final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; | |
24 | final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; | |
95c50032 MS |
25 | |
26 | final float CH = Cube.EDGE_HEIGHT; | |
46fc29d4 | 27 | |
46fc29d4 MS |
28 | // The model is represented as an array of towers. The cubes in the tower |
29 | // are represenented relatively. Each tower has an x, y, z reference position, | |
30 | // which is typically the base cube's bottom left corner. | |
31 | // | |
32 | // Following that is an array of floats. A 2-d array contains an x-offset | |
f0cc0ba5 MS |
33 | // and a z-offset from the previous reference position. Typically the first cube |
34 | // will just be {0, 0}. Each successive cube uses the position of the previous | |
35 | // cube as its reference. | |
46fc29d4 MS |
36 | // |
37 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
38 | // y-axis. | |
39 | // | |
40 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
f0cc0ba5 | 41 | TowerMapping[] towerCubes = new TowerMapping[] { |
46fc29d4 | 42 | |
f0cc0ba5 MS |
43 | new TowerMapping(50, 0, 80, new CubeMapping[] { |
44 | new CubeMapping(0, 0, WFL), | |
46fc29d4 MS |
45 | }), |
46 | ||
47 | }; | |
f0cc0ba5 MS |
48 | |
49 | // Single cubes can be constructed directly here if you need them | |
50 | Cube[] singleCubes = new Cube[] { | |
51 | // new Cube(x, y, z, rx, ry, rz, wiring), | |
52 | }; | |
53 | ||
54 | // The bass box! | |
55 | BassBox bassBox = new BassBox(56, 0, 2); | |
51d0d59a | 56 | |
f0cc0ba5 MS |
57 | // The speakers! |
58 | List<Speaker> speakers = Arrays.asList(new Speaker[] { | |
59 | new Speaker(-12, 6, 0, 15), | |
60 | new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH, 6, 6, -15) | |
61 | }); | |
62 | ||
63 | // These guts just convert the shorthand mappings into usable objects | |
46fc29d4 MS |
64 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
65 | ArrayList<Cube> tower; | |
f0cc0ba5 | 66 | Cube[] cubes = new Cube[80]; |
46fc29d4 | 67 | int cubeIndex = 1; |
f0cc0ba5 MS |
68 | float px, pz, ny; |
69 | for (TowerMapping tm : towerCubes) { | |
70 | px = tm.x; | |
71 | ny = tm.y; | |
72 | pz = tm.z; | |
46fc29d4 | 73 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
74 | for (CubeMapping cm : tm.cubeMappings) { |
75 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
76 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
77 | } |
78 | towerList.add(new Tower(tower)); | |
79 | } | |
f0cc0ba5 MS |
80 | for (Cube cube : singleCubes) { |
81 | cubes[cubeIndex++] = cube; | |
82 | } | |
e76480d4 MS |
83 | |
84 | return new Model(towerList, cubes, bassBox, speakers); | |
186bc4d3 | 85 | } |
e73ef85d | 86 | |
186bc4d3 MS |
87 | public PandaMapping[] buildPandaList() { |
88 | return new PandaMapping[] { | |
89 | new PandaMapping( | |
84086fa3 MS |
90 | "10.200.1.28", new ChannelMapping[] { |
91 | new ChannelMapping(ChannelMapping.MODE_BASS), | |
92 | new ChannelMapping(ChannelMapping.MODE_FLOOR), | |
93 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, 0), | |
94 | new ChannelMapping(ChannelMapping.MODE_SPEAKER, 1), | |
f0cc0ba5 MS |
95 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1 }), |
96 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
97 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
98 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
99 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
100 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
101 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
102 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
103 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
186bc4d3 | 104 | }), |
45f43cc2 | 105 | |
186bc4d3 | 106 | new PandaMapping( |
84086fa3 | 107 | "10.200.1.29", new ChannelMapping[] { |
f0cc0ba5 MS |
108 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), |
109 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
110 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
111 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
112 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
113 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
114 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
115 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
116 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
117 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
118 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
119 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
120 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), | |
186bc4d3 | 121 | }), |
186bc4d3 | 122 | }; |
45f43cc2 | 123 | } |
e73ef85d | 124 | |
f0cc0ba5 MS |
125 | class TowerMapping { |
126 | public final float x, y, z; | |
127 | public final CubeMapping[] cubeMappings; | |
128 | ||
129 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
130 | this.x = x; | |
131 | this.y = y; | |
132 | this.z = z; | |
133 | this.cubeMappings = cubeMappings; | |
134 | } | |
135 | } | |
136 | ||
137 | class CubeMapping { | |
138 | public final float dx, dz, ry; | |
139 | public final Cube.Wiring wiring; | |
140 | ||
141 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
142 | this(dx, dz, 0, wiring); | |
143 | } | |
144 | ||
145 | CubeMapping(float dx, float dz, float ry) { | |
146 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
147 | } | |
148 | ||
149 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
150 | this.dx = dx; | |
151 | this.dz = dz; | |
152 | this.ry = ry; | |
153 | this.wiring = wiring; | |
154 | } | |
155 | } | |
156 | ||
a922e963 MS |
157 | /** |
158 | * Each panda board has an IP address and a fixed number of channels. The channels | |
159 | * each have a fixed number of pixels on them. Whether or not that many physical | |
160 | * pixels are connected to the channel, we still send it that much data. | |
161 | */ | |
45f43cc2 MS |
162 | class PandaMapping { |
163 | ||
045b432d | 164 | // How many channels are on the panda board |
f0cc0ba5 | 165 | public final static int CHANNELS_PER_BOARD = 13; |
045b432d | 166 | |
44b8de9c | 167 | // How many total pixels on the whole board |
84086fa3 | 168 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 169 | |
45f43cc2 | 170 | final String ip; |
84086fa3 | 171 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 172 | |
84086fa3 | 173 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 174 | this.ip = ip; |
a922e963 MS |
175 | |
176 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
177 | for (int i = 0; i < channelList.length; ++i) { |
178 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
179 | if (channelList[i] == null) { |
180 | channelList[i] = new ChannelMapping(); | |
181 | } | |
045b432d | 182 | } |
e73ef85d | 183 | } |
1ecdb44a MS |
184 | } |
185 | ||
a922e963 MS |
186 | /** |
187 | * Each channel on a pandaboard can be mapped in a number of modes. The typial is | |
188 | * to a series of connected cubes, but we also have special mappings for the bass box, | |
189 | * the speaker enclosures, and the DJ booth floor. | |
190 | * | |
191 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
192 | * that the cubes and objects being referenced actually exist in the model. | |
193 | * | |
194 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
195 | */ | |
84086fa3 MS |
196 | class ChannelMapping { |
197 | ||
198 | // How many cubes per channel xc_PB is configured for | |
199 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 200 | |
84086fa3 MS |
201 | // How many total pixels on each channel |
202 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
203 | ||
204 | public static final int MODE_NULL = 0; | |
205 | public static final int MODE_CUBES = 1; | |
206 | public static final int MODE_BASS = 2; | |
207 | public static final int MODE_SPEAKER = 3; | |
208 | public static final int MODE_FLOOR = 4; | |
209 | public static final int MODE_INVALID = 5; | |
210 | ||
211 | public static final int NO_OBJECT = -1; | |
212 | ||
213 | final int mode; | |
214 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
215 | ||
216 | ChannelMapping() { | |
217 | this(MODE_NULL); | |
218 | } | |
219 | ||
220 | ChannelMapping(int mode) { | |
221 | this(mode, new int[]{}); | |
222 | } | |
223 | ||
224 | ChannelMapping(int mode, int rawObjectIndex) { | |
225 | this(mode, new int[]{ rawObjectIndex }); | |
226 | } | |
227 | ||
228 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
229 | if (mode < 0 || mode >= MODE_INVALID) { | |
230 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
231 | } | |
232 | if (mode == MODE_SPEAKER) { | |
233 | if (rawObjectIndices.length != 1) { | |
234 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
235 | } | |
236 | int speakerIndex = rawObjectIndices[0]; | |
237 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
238 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); | |
239 | } | |
240 | } else if ((mode == MODE_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { | |
241 | if (rawObjectIndices.length > 0) { | |
242 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); | |
243 | } | |
244 | } else if (mode == MODE_CUBES) { | |
245 | for (int rawCubeIndex : rawObjectIndices) { | |
246 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
247 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
248 | } | |
249 | } | |
250 | } | |
251 | ||
252 | this.mode = mode; | |
253 | for (int i = 0; i < objectIndices.length; ++i) { | |
254 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
255 | } | |
256 | } | |
257 | } | |
a922e963 | 258 |