+ // How many total pixels on each channel
+ public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
+
+ public static final int MODE_NULL = 0;
+ public static final int MODE_CUBES = 1;
+ public static final int MODE_BASS = 2;
+ public static final int MODE_SPEAKER = 3;
+ public static final int MODE_FLOOR = 4;
+ public static final int MODE_INVALID = 5;
+
+ public static final int NO_OBJECT = -1;
+
+ final int mode;
+ final int[] objectIndices = new int[CUBES_PER_CHANNEL];
+
+ ChannelMapping() {
+ this(MODE_NULL);
+ }
+
+ ChannelMapping(int mode) {
+ this(mode, new int[]{});
+ }
+
+ ChannelMapping(int mode, int rawObjectIndex) {
+ this(mode, new int[]{ rawObjectIndex });
+ }
+
+ ChannelMapping(int mode, int[] rawObjectIndices) {
+ if (mode < 0 || mode >= MODE_INVALID) {
+ throw new RuntimeException("Invalid channel mapping mode: " + mode);
+ }
+ if (mode == MODE_SPEAKER) {
+ if (rawObjectIndices.length != 1) {
+ throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
+ }
+ int speakerIndex = rawObjectIndices[0];
+ if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
+ throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
+ }
+ } else if ((mode == MODE_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
+ if (rawObjectIndices.length > 0) {
+ throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
+ }
+ } else if (mode == MODE_CUBES) {
+ for (int rawCubeIndex : rawObjectIndices) {
+ if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
+ throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
+ }
+ }
+ }
+
+ this.mode = mode;
+ for (int i = 0; i < objectIndices.length; ++i) {
+ objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;
+ }
+ }
+}