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[] { 5, 6, 4, 3 }),
114 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
115 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
116 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
117 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
118 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
119 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
120 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
121 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
122 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
123 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
124 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
125 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
126 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
127 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
128 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5, 6, 4, 3 }),
132 "10.200.1.28", new ChannelMapping[] {
133 new ChannelMapping(ChannelMapping.MODE_BASS),
134 new ChannelMapping(ChannelMapping.MODE_FLOOR),
135 new ChannelMapping(ChannelMapping.MODE_SPEAKER, 0),
136 new ChannelMapping(ChannelMapping.MODE_SPEAKER, 1),
142 public final float x, y, z;
143 public final CubeMapping[] cubeMappings;
145 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
149 this.cubeMappings = cubeMappings;
154 public final float dx, dz, ry;
155 public final Cube.Wiring wiring;
157 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
158 this(dx, dz, 0, wiring);
161 CubeMapping(float dx, float dz, float ry) {
162 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
165 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
169 this.wiring = wiring;
174 * Each panda board has an IP address and a fixed number of channels. The channels
175 * each have a fixed number of pixels on them. Whether or not that many physical
176 * pixels are connected to the channel, we still send it that much data.
180 // How many channels are on the panda board
181 public final static int CHANNELS_PER_BOARD = 16;
183 // How many total pixels on the whole board
184 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
187 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
189 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
192 // Ensure our array is the right length and has all valid items in it
193 for (int i = 0; i < channelList.length; ++i) {
194 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
195 if (channelList[i] == null) {
196 channelList[i] = new ChannelMapping();
203 * Each channel on a pandaboard can be mapped in a number of modes. The typial is
204 * to a series of connected cubes, but we also have special mappings for the bass box,
205 * the speaker enclosures, and the DJ booth floor.
207 * This class is just the mapping meta-data. It sanitizes the input to make sure
208 * that the cubes and objects being referenced actually exist in the model.
210 * The logic for how to encode the pixels is contained in the PandaDriver.
212 class ChannelMapping {
214 // How many cubes per channel xc_PB is configured for
215 public final static int CUBES_PER_CHANNEL = 4;
217 // How many total pixels on each channel
218 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
220 public static final int MODE_NULL = 0;
221 public static final int MODE_CUBES = 1;
222 public static final int MODE_BASS = 2;
223 public static final int MODE_SPEAKER = 3;
224 public static final int MODE_FLOOR = 4;
225 public static final int MODE_INVALID = 5;
227 public static final int NO_OBJECT = -1;
230 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
236 ChannelMapping(int mode) {
237 this(mode, new int[]{});
240 ChannelMapping(int mode, int rawObjectIndex) {
241 this(mode, new int[]{ rawObjectIndex });
244 ChannelMapping(int mode, int[] rawObjectIndices) {
245 if (mode < 0 || mode >= MODE_INVALID) {
246 throw new RuntimeException("Invalid channel mapping mode: " + mode);
248 if (mode == MODE_SPEAKER) {
249 if (rawObjectIndices.length != 1) {
250 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
252 int speakerIndex = rawObjectIndices[0];
253 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
254 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
256 } else if ((mode == MODE_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
257 if (rawObjectIndices.length > 0) {
258 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
260 } else if (mode == MODE_CUBES) {
261 for (int rawCubeIndex : rawObjectIndices) {
262 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
263 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
269 for (int i = 0; i < objectIndices.length; ++i) {
270 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;