From: Mark Slee Date: Sun, 11 Aug 2013 01:55:57 +0000 (-0700) Subject: Change mapping and debug tools to be generic, panda mappings totally generic X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=commitdiff_plain;h=45f43cc2debb7f90b01e7a5c7d355218ab9cdeed Change mapping and debug tools to be generic, panda mappings totally generic --- diff --git a/TestPatterns.pde b/TestPatterns.pde index acc50c7..52e8ea4 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -178,30 +178,37 @@ class MappingTool extends SCPattern { public boolean channelModeGreen = false; public boolean channelModeBlue = false; - private final static int NUM_CHANNELS = 16; + private final int numChannels; - private final int[][] frontChannels; - private final int[][] rearChannels; - private int[] activeChannels; + private final PandaMapping[] pandaMappings; + private PandaMapping activeMapping; + private int mappingChannelIndex; - MappingTool(GLucose glucose, int[][]frontChannels, int[][]rearChannels) { + MappingTool(GLucose glucose, PandaMapping[] pandaMappings) { super(glucose); - this.frontChannels = frontChannels; - this.rearChannels = rearChannels; + this.pandaMappings = pandaMappings; + int totalChannels = 0; + for (PandaMapping pm : pandaMappings) { + totalChannels += pm.channelList.length; + } + numChannels = totalChannels; setChannel(); } private void setChannel() { - if (channelIndex < frontChannels.length) { - activeChannels = frontChannels[channelIndex]; - } else { - activeChannels = rearChannels[channelIndex - frontChannels.length]; + mappingChannelIndex = channelIndex; + for (PandaMapping pm : pandaMappings) { + if (mappingChannelIndex < pm.channelList.length) { + activeMapping = pm; + break; + } + mappingChannelIndex -= pm.channelList.length; } } private int cubeInChannel(Cube c) { int i = 1; - for (int index : activeChannels) { + for (int index : activeMapping.channelList[mappingChannelIndex]) { if (c == model.getCubeByRawIndex(index)) { return i; } @@ -221,7 +228,7 @@ class MappingTool extends SCPattern { } public void strip(int delta) { - int len = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE; + int len = Cube.STRIPS_PER_CUBE; stripIndex = (len + stripIndex + delta) % len; printInfo(); } @@ -299,14 +306,14 @@ class MappingTool extends SCPattern { } public void incChannel() { - channelIndex = (channelIndex + 1) % NUM_CHANNELS; + channelIndex = (channelIndex + 1) % numChannels; setChannel(); } public void decChannel() { --channelIndex; if (channelIndex < 0) { - channelIndex += NUM_CHANNELS; + channelIndex += numChannels; } setChannel(); } diff --git a/_Internals.pde b/_Internals.pde index e2c343a..82feb2d 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -47,6 +47,7 @@ final float BASS_Z = (TRAILER_DEPTH - BASS_DEPTH) / 2.; int targetFramerate = 60; int startMillis, lastMillis; +SCMapping mapping; GLucose glucose; HeronLX lx; MappingTool mappingTool; @@ -75,7 +76,8 @@ void setup() { logTime("Created viewport"); // Create the GLucose engine to run the cubes - glucose = new GLucose(this, new SCMapping()); + mapping = new SCMapping(); + glucose = new GLucose(this, mapping); lx = glucose.lx; lx.enableKeyboardTempo(); logTime("Built GLucose engine"); @@ -89,19 +91,19 @@ void setup() { logTime("Built transitions"); // Build output driver - int[][] frontChannels = glucose.mapping.buildFrontChannelList(); - int[][] rearChannels = glucose.mapping.buildRearChannelList(); - mappingTool = new MappingTool(glucose, frontChannels, rearChannels); - pandaBoards = new PandaDriver[] { - new PandaDriver("10.200.1.28", glucose.model, frontChannels), - new PandaDriver("10.200.1.29", glucose.model, rearChannels), - }; - logTime("Build PandaDriver"); + PandaMapping[] pandaMappings = mapping.buildPandaList(); + pandaBoards = new PandaDriver[pandaMappings.length]; + int pbi = 0; + for (PandaMapping pm : pandaMappings) { + pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm.channelList); + } + mappingTool = new MappingTool(glucose, pandaMappings); + logTime("Built PandaDriver"); // Build overlay UI ui = controlUI = new ControlUI(); mappingUI = new MappingUI(mappingTool); - debugUI = new DebugUI(frontChannels, rearChannels); + debugUI = new DebugUI(pandaMappings); logTime("Built overlay UI"); // MIDI devices diff --git a/_Mappings.pde b/_Mappings.pde index 47e4d2e..3959846 100644 --- a/_Mappings.pde +++ b/_Mappings.pde @@ -13,6 +13,7 @@ * when physical changes or tuning is being done to the structure. */ class SCMapping implements GLucose.Mapping { + public Cube[] buildCubeArray() { // TODO(mcslee): find a cleaner way of representing this data, probably // serialized in some more neutral form. also figure out what's going on @@ -129,30 +130,45 @@ class SCMapping implements GLucose.Mapping { return cubes; } - public int[][] buildFrontChannelList() { - return new int[][] { - { 1, 2, 3, 4 }, // ch1 - { 5, 6, 7, 8 }, // ch2 - { 9, 10, 11, 12 }, // ch3 - { 13, 14, 15, 16 }, // ch4 - { 17, 18, 19, 20 }, // ch5 - { 21, 22, 23, 24 }, // ch6 - { 25, 26, 27, 28 }, // ch7 - { 29, 30, 31, 32 }, // ch8 + public PandaMapping[] buildPandaList() { + return new PandaMapping[] { + new PandaMapping( + "10.200.1.28", new int[][] { + { 1, 2, 3, 4 }, // ch1 + { 5, 6, 7, 8 }, // ch2 + { 9, 10, 11, 12 }, // ch3 + { 13, 14, 15, 16 }, // ch4 + { 17, 18, 19, 20 }, // ch5 + { 21, 22, 23, 24 }, // ch6 + { 25, 26, 27, 28 }, // ch7 + { 29, 30, 31, 32 }, // ch8 + }), + + new PandaMapping( + "10.200.1.29", new int[][] { + { 33, 34, 35, 36 }, // ch9 + { 37, 38, 39, 40 }, // ch10 + { 41, 42, 43, 44 }, // ch11 + { 45, 46, 47, 48 }, // ch12 + { 49, 50, 51, 52 }, // ch13 + { 53, 54, 55, 56 }, // ch14 + { 57, 58, 59, 60 }, // ch15 + { 61, 62, 63, 64 }, // ch16 + }), + }; } +} - public int[][] buildRearChannelList() { - return new int[][] { - { 33, 34, 35, 36 }, // ch9 - { 37, 38, 39, 40 }, // ch10 - { 41, 42, 43, 44 }, // ch11 - { 45, 46, 47, 48 }, // ch12 - { 49, 50, 51, 52 }, // ch13 - { 53, 54, 55, 56 }, // ch14 - { 57, 58, 59, 60 }, // ch15 - { 61, 62, 63, 64 }, // ch16 - }; +class PandaMapping { + + final String ip; + final int[][] channelList; + + PandaMapping(String ip, int[][] channelList) { + this.ip = ip; + this.channelList = channelList; } } + diff --git a/_Overlay.pde b/_Overlay.pde index 971ffde..a07db2c 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -712,14 +712,17 @@ class DebugUI { final int DEBUG_STATE_WHITE = 1; final int DEBUG_STATE_OFF = 2; - DebugUI(int[][] frontChannels, int[][] rearChannels) { - channelList = new int[frontChannels.length + rearChannels.length][]; - int channelIndex = 0; - for (int[] channel : frontChannels) { - channelList[channelIndex++] = channel; + DebugUI(PandaMapping[] pandaMappings) { + int totalChannels = 0; + for (PandaMapping pm : pandaMappings) { + totalChannels += pm.channelList.length; } - for (int[] channel : rearChannels) { - channelList[channelIndex++] = channel; + channelList = new int[totalChannels][]; + int channelIndex = 0; + for (PandaMapping pm : pandaMappings) { + for (int[] channel : pm.channelList) { + channelList[channelIndex++] = channel; + } } for (int i = 0; i < debugState.length; ++i) { for (int j = 0; j < debugState[i].length; ++j) { diff --git a/_PandaDriver.pde b/_PandaDriver.pde index 5e47764..d90613e 100644 --- a/_PandaDriver.pde +++ b/_PandaDriver.pde @@ -54,7 +54,7 @@ public class PandaDriver { public void toggle() { enabled = !enabled; - println("PandaBoard/" + ip + " Output: " + (enabled ? "ON" : "OFF")); + println("PandaBoard Output/" + ip + ": " + (enabled ? "ON" : "OFF")); } private ArrayList buildMappedList(Model model, int[][] channelList) { diff --git a/code/GLucose.jar b/code/GLucose.jar index 346b56f..c8f7976 100644 Binary files a/code/GLucose.jar and b/code/GLucose.jar differ