From 344908672b7cfe1efba03f739ef945601dae1b8e Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Mon, 24 Feb 2014 21:15:16 -0800 Subject: [PATCH] New Grizzly code using LXOutput framework --- _Grizzly.pde | 146 +++++++++++++++++++++++++++++++++++++++++++++++ _Internals.pde | 12 +++- code/HeronLX.jar | Bin 131584 -> 131634 bytes 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 _Grizzly.pde diff --git a/_Grizzly.pde b/_Grizzly.pde new file mode 100644 index 0000000..cc7dec8 --- /dev/null +++ b/_Grizzly.pde @@ -0,0 +1,146 @@ +/** + * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND + * + * //\\ //\\ //\\ //\\ + * ///\\\ ///\\\ ///\\\ ///\\\ + * \\\/// \\\/// \\\/// \\\/// + * \\// \\// \\// \\//H + * + * EXPERTS ONLY!! EXPERTS ONLY!! + * + * If you are an artist, you may ignore this file! It just sets + * up the framework to run the patterns. Should not need modification + * for general animation work. + */ + +GrizzlyOutput[] buildGrizzlies() throws SocketException, UnknownHostException { + return new GrizzlyOutput[] { + new GrizzlyOutput(lx, "192.168.88.100", 1, 2, 3, 4, 5, 6, 7, 8), + new GrizzlyOutput(lx, "192.168.88.101", 9, 10, 11, 12, 13, 14, 15, 16), + }; +} + +class GrizzlyOutput extends LXDatagramOutput { + + private int frameNumber = 0; + + GrizzlyOutput(LX lx, String ipAddress, int ... cubeIndices) throws UnknownHostException, SocketException { + super(lx); + int channelNum = 1; + for (int rawCubeIndex : cubeIndices) { + if (rawCubeIndex > 0) { + Cube cube = model.getCubeByRawIndex(rawCubeIndex); + addDatagram(new GrizzlyDatagram(this, channelNum, cube).setAddress(ipAddress)); + } + ++channelNum; + } + } + + protected void beforeSend(int[] colors) { + ++frameNumber; + } + + public int getFrameNumber() { + return this.frameNumber; + } +} + +static class GrizzlyDatagram extends LXDatagram { + + private static byte[] oscString(String s) { + int len = s.length(); + int padding = (4 - ((len + 1) % 4)) % 4; + byte[] bytes = new byte[len + 1 + padding]; + System.arraycopy(s.getBytes(), 0, bytes, 0, len); + for (int i = len; i < bytes.length; ++i) { + bytes[i] = 0; + } + return bytes; + } + + private static int oscIntCopy(int i, byte[] buffer, int pos) { + buffer[pos] = (byte) ((i >> 24) & 0xff); + buffer[pos + 1] = (byte) ((i >> 16) & 0xff); + buffer[pos + 2] = (byte) ((i >> 8) & 0xff); + buffer[pos + 3] = (byte) (i & 0xff); + return 4; + } + + private final static int[] STRIP_ORDERING = new int[] { 9, 8, 11, 5, 4, 7, 6, 10, 14, 2, 1, 0, 3, 13, 12, 15 }; + + private static int[] cubePointIndices(Cube cube) { + int[] pointIndices = new int[Cube.POINTS_PER_CUBE - 2]; + int pi = 0; + for (int stripIndex : STRIP_ORDERING) { + Strip strip = cube.strips.get(stripIndex); + int stripLen = ((stripIndex == 9) || (stripIndex == 15)) ? 15 : 16; + for (int i = stripLen-1; i >= 0; --i) { + pointIndices[pi++] = strip.points.get(i).index; + } + } + return pointIndices; + } + + private final static byte[] OSC_ADDRESS = oscString("/shady/pointbuffer"); + private final static byte[] OSC_TYPETAG = oscString(",iiiiibi"); + + private final static int HEADER_LENGTH = OSC_ADDRESS.length + OSC_TYPETAG.length + 24; + private final static int FOOTER_LENGTH = 4; + + private final static int OSC_PORT = 779; + + private GrizzlyOutput output; + + private int[] pointIndices; + + private final int frameNumberPos; + + private final int dataPos; + + public GrizzlyDatagram(GrizzlyOutput output, int channelNum, Cube cube) { + this(output, channelNum, cubePointIndices(cube)); + } + + public GrizzlyDatagram(GrizzlyOutput output, int channelNum, int[] pointIndices) { + super(HEADER_LENGTH + 4*pointIndices.length + FOOTER_LENGTH); + setPort(OSC_PORT); + + this.output = output; + this.pointIndices = pointIndices; + int dataLength = 4*pointIndices.length; + + int pos = 0; + + // OSC address + System.arraycopy(OSC_ADDRESS, 0, this.buffer, pos, OSC_ADDRESS.length); + pos += OSC_ADDRESS.length; + + // OSC typetag + System.arraycopy(OSC_TYPETAG, 0, this.buffer, pos, OSC_TYPETAG.length); + pos += OSC_TYPETAG.length; + this.frameNumberPos = pos; + pos += oscIntCopy(0, this.buffer, pos); // placeholder for frame number + pos += oscIntCopy(0xDEADBEEF, this.buffer, pos); + pos += oscIntCopy(channelNum, this.buffer, pos); + pos += oscIntCopy(0xFEEDBEEF, this.buffer, pos); + pos += oscIntCopy(dataLength, this.buffer, pos); + pos += oscIntCopy(dataLength, this.buffer, pos); + this.dataPos = pos; + + // end header + oscIntCopy(0xBEFFFFEB, this.buffer, this.buffer.length - 4); + } + + void onSend(int[] colors) { + oscIntCopy(this.output.getFrameNumber(), this.buffer, frameNumberPos); + int dataIndex = this.dataPos; + for (int index : this.pointIndices) { + color c = (index >= 0) ? colors[index] : 0; + this.buffer[dataIndex] = (byte) 0; // unused, alpha + this.buffer[dataIndex + 1] = (byte) ((c >> 16) & 0xff); // r + this.buffer[dataIndex + 2] = (byte) ((c >> 8) & 0xff); // g + this.buffer[dataIndex + 3] = (byte) (c & 0xff); // b + dataIndex += 4; + } + } +} diff --git a/_Internals.pde b/_Internals.pde index 326f6e3..0100c05 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -45,6 +45,7 @@ int startMillis, lastMillis; // Core engine variables GLucose glucose; LX lx; +Model model; LXPattern[] patterns; Effects effects; MappingTool mappingTool; @@ -128,7 +129,7 @@ void setup() { logTime("Created viewport"); // Create the GLucose engine to run the cubes - glucose = new GLucose(this, buildModel()); + glucose = new GLucose(this, model = buildModel()); lx = glucose.lx; lx.enableKeyboardTempo(); logTime("Built GLucose engine"); @@ -152,6 +153,15 @@ void setup() { logTime("Setup MIDI devices"); // Build output driver + try { + GrizzlyOutput[] grizzlies = buildGrizzlies(); + for (LXOutput output : grizzlies) { + lx.addOutput(output); + } + } catch (Exception x) { + x.printStackTrace(); + } + PandaMapping[] pandaMappings = buildPandaList(); pandaBoards = new PandaDriver[pandaMappings.length]; int pbi = 0; diff --git a/code/HeronLX.jar b/code/HeronLX.jar index 277c57180fce262898d0f8b5e3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