2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * This file implements the mapping functions needed to lay out the physical
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.
16 public Model buildModel() {
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;
25 final float CH = Cube.EDGE_HEIGHT;
27 final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH;
32 // The model is represented as an array of towers. The cubes in the tower
33 // are represenented relatively. Each tower has an x, y, z reference position,
34 // which is typically the base cube's bottom left corner.
36 // Following that is an array of floats. A 2-d array contains an x-offset
37 // and a z-offset from the previous reference position. Typically the first cube
38 // will just be {0, 0}. Each successive cube uses the position of the previous
39 // cube as its reference.
41 // A 3-d array contains an x-offset, a z-offset, and a rotation about the
44 // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT.
45 TowerMapping[] towerCubes = new TowerMapping[] {
47 // DJ booth, from left to right
48 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
49 new CubeMapping(-7.25, 7.5, -25, WFR),
50 new CubeMapping(7.5, -15.75, 12, WRL),
52 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
53 new CubeMapping(19.625, 5.375, -22, WFR),
54 new CubeMapping(8, -14.5, 10, WRR),
56 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
57 new CubeMapping(48, 4.75, -35, WRL),
58 new CubeMapping(8, -15, 10, WRR),
60 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
61 new CubeMapping(78.75, 3.75, -28, WRR),
62 new CubeMapping(8, -15, 10, WRR),
64 new TowerMapping(BBX, BBY, BBZ, new CubeMapping[] {
65 new CubeMapping(104.75, 0, -27, WRL),
66 new CubeMapping(8, -15, 10, WFL),
71 // Single cubes can be constructed directly here if you need them
72 Cube[] singleCubes = new Cube[] {
73 // new Cube(x, y, z, rx, ry, rz, wiring),
77 BassBox bassBox = new BassBox(BBX, 0, BBZ);
80 List<Speaker> speakers = Arrays.asList(new Speaker[] {
81 new Speaker(-12, 6, 0, 15),
82 new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
85 // These guts just convert the shorthand mappings into usable objects
86 ArrayList<Tower> towerList = new ArrayList<Tower>();
87 ArrayList<Cube> tower;
88 Cube[] cubes = new Cube[80];
91 for (TowerMapping tm : towerCubes) {
95 tower = new ArrayList<Cube>();
96 for (CubeMapping cm : tm.cubeMappings) {
97 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
98 ny += Cube.EDGE_HEIGHT;
100 towerList.add(new Tower(tower));
102 for (Cube cube : singleCubes) {
103 cubes[cubeIndex++] = cube;
106 return new Model(towerList, cubes, bassBox, speakers);
109 public PandaMapping[] buildPandaList() {
110 return new PandaMapping[] {
112 "10.200.1.29", new ChannelMapping[] {
113 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3, 4 }),
114 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 7, 8 }),
115 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 9, 10 }),
116 new ChannelMapping(ChannelMapping.MODE_BASS),
117 new ChannelMapping(ChannelMapping.MODE_FLOOR),
118 new ChannelMapping(ChannelMapping.MODE_SPEAKER, 0),
119 new ChannelMapping(ChannelMapping.MODE_SPEAKER, 1),
120 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
121 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
122 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
123 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
124 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
125 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
129 "10.200.1.28", new ChannelMapping[] {
130 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
131 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
132 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
133 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
134 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
135 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
136 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
137 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
138 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
139 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
140 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
141 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
142 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
148 public final float x, y, z;
149 public final CubeMapping[] cubeMappings;
151 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
155 this.cubeMappings = cubeMappings;
160 public final float dx, dz, ry;
161 public final Cube.Wiring wiring;
163 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
164 this(dx, dz, 0, wiring);
167 CubeMapping(float dx, float dz, float ry) {
168 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
171 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
175 this.wiring = wiring;
180 * Each panda board has an IP address and a fixed number of channels. The channels
181 * each have a fixed number of pixels on them. Whether or not that many physical
182 * pixels are connected to the channel, we still send it that much data.
186 // How many channels are on the panda board
187 public final static int CHANNELS_PER_BOARD = 13;
189 // How many total pixels on the whole board
190 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
193 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
195 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
198 // Ensure our array is the right length and has all valid items in it
199 for (int i = 0; i < channelList.length; ++i) {
200 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
201 if (channelList[i] == null) {
202 channelList[i] = new ChannelMapping();
209 * Each channel on a pandaboard can be mapped in a number of modes. The typial is
210 * to a series of connected cubes, but we also have special mappings for the bass box,
211 * the speaker enclosures, and the DJ booth floor.
213 * This class is just the mapping meta-data. It sanitizes the input to make sure
214 * that the cubes and objects being referenced actually exist in the model.
216 * The logic for how to encode the pixels is contained in the PandaDriver.
218 class ChannelMapping {
220 // How many cubes per channel xc_PB is configured for
221 public final static int CUBES_PER_CHANNEL = 4;
223 // How many total pixels on each channel
224 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
226 public static final int MODE_NULL = 0;
227 public static final int MODE_CUBES = 1;
228 public static final int MODE_BASS = 2;
229 public static final int MODE_SPEAKER = 3;
230 public static final int MODE_FLOOR = 4;
231 public static final int MODE_INVALID = 5;
233 public static final int NO_OBJECT = -1;
236 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
242 ChannelMapping(int mode) {
243 this(mode, new int[]{});
246 ChannelMapping(int mode, int rawObjectIndex) {
247 this(mode, new int[]{ rawObjectIndex });
250 ChannelMapping(int mode, int[] rawObjectIndices) {
251 if (mode < 0 || mode >= MODE_INVALID) {
252 throw new RuntimeException("Invalid channel mapping mode: " + mode);
254 if (mode == MODE_SPEAKER) {
255 if (rawObjectIndices.length != 1) {
256 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
258 int speakerIndex = rawObjectIndices[0];
259 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
260 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
262 } else if ((mode == MODE_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
263 if (rawObjectIndices.length > 0) {
264 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
266 } else if (mode == MODE_CUBES) {
267 for (int rawCubeIndex : rawObjectIndices) {
268 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
269 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
275 for (int i = 0; i < objectIndices.length; ++i) {
276 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;