From: Ben Morrow Date: Mon, 3 Mar 2014 06:02:04 +0000 (-0800) Subject: redo with new anti-GLucose X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7d60f6f6ea82fd5c9794524ce11d40e7d6c00bf7;p=SugarCubes.git redo with new anti-GLucose --- 7d60f6f6ea82fd5c9794524ce11d40e7d6c00bf7 diff --cc AlexGreen.pde index 3e164d8,54af5c0..5a35b3e --- a/AlexGreen.pde +++ b/AlexGreen.pde @@@ -1,3 -1,3 +1,4 @@@ ++ class SineSphere extends APat { float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); private BasicParameter yrotspeed = new BasicParameter("yspeed", 3000, 1, 10000); diff --cc Grizzly.pde index 0000000,25d390f..5f46b96 mode 000000,100644..100644 --- a/Grizzly.pde +++ b/Grizzly.pde @@@ -1,0 -1,158 +1,158 @@@ + /** + * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND + * + * //\\ //\\ //\\ //\\ + * ///\\\ ///\\\ ///\\\ ///\\\ + * \\\/// \\\/// \\\/// \\\/// + * \\// \\// \\// \\//H + * + * EXPERTS ONLY!! EXPERTS ONLY!! + * + * If you are an artist, you may ignore this file! It contains + * the code to drive grizzly board outputs. + */ - ++import java.net.*; + GrizzlyOutput[] buildGrizzlies() throws SocketException, UnknownHostException { + return new GrizzlyOutput[] { + new GrizzlyOutput(lx, "192.168.88.100", 6, 5, 6, 7, 7, 8, 1, 2, 4, 3, 11, 10, 9, 9, 12, 13), + new GrizzlyOutput(lx, "192.168.88.101", 25, 23, 24, 43, 45, 44, 1, 1, 1, 1, 1, 41, 42, 21, 20, 22), + new GrizzlyOutput(lx, "192.168.88.104", 26, 28, 27, 19, 18, 17, 1, 1, 18, 19, 15, 16, 14, 29, 30, 31), + new GrizzlyOutput(lx, "192.168.88.105", 1, 1, 1, 39, 38, 40, 34, 35, 33, 32, 37, 37, 1, 1, 1, 1), + }; + } + + /** + * Grizzly Output, sends packets to one grizzly board with a fixed IP and a number + * of channels. + */ + class GrizzlyOutput extends LXDatagramOutput { + + public final String ipAddress; + + private int frameNumber = 0; + + public GrizzlyOutput(LX lx, String ipAddress, int ... cubeIndices) throws UnknownHostException, SocketException { + super(lx); + this.ipAddress = ipAddress; + int channelNum = 0; + for (int rawCubeIndex : cubeIndices) { + if (rawCubeIndex > 0) { + Cube cube = model.getCubeByRawIndex(rawCubeIndex); + addDatagram(new GrizzlyDatagram(this, channelNum, cube).setAddress(ipAddress)); + } + ++channelNum; + } + this.enabled.setValue(false); + } + + protected void beforeSend(int[] colors) { + ++frameNumber; + } + + public int getFrameNumber() { + return this.frameNumber; + } + } + + /** + * Datagram to a Grizzlyboard. A simple fixed OSC packet. + */ + 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 --cc Model.pde index 0000000,3376246..3376246 mode 000000,100644..100644 --- a/Model.pde +++ b/Model.pde diff --cc UIImplementation.pde index 0ea8073,ba0f110..7750ab9 --- a/UIImplementation.pde +++ b/UIImplementation.pde @@@ -10,79 -10,105 +10,103 @@@ * * Custom UI components using the framework. */ - - class UIPatternDeck extends UIWindow { - - LXDeck deck; - - public UIPatternDeck(LXDeck deck, String label, float x, float y, float w, float h) { - super(label, x, y, w, h); - this.deck = deck; - int yp = titleHeight; - - List items = new ArrayList(); - for (LXPattern p : deck.getPatterns()) { - items.add(new PatternScrollItem(p)); - } - final UIScrollList patternList = new UIScrollList(1, yp, w-2, 140).setItems(items); - patternList.addToContainer(this); - yp += patternList.h + 10; - - final UIParameterKnob[] parameterKnobs = new UIParameterKnob[12]; - for (int ki = 0; ki < parameterKnobs.length; ++ki) { - parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48); - parameterKnobs[ki].addToContainer(this); - ++import java.util.Arrays; + class UICubesLayer extends UICameraComponent { + void onDraw(UI ui) { + color[] simulationColors = lx.getColors(); + String displayMode = uiCrossfader.getDisplayMode(); + if (displayMode == "A") { + simulationColors = lx.engine.getDeck(LEFT_DECK).getColors(); + } else if (displayMode == "B") { + simulationColors = lx.engine.getDeck(RIGHT_DECK).getColors(); } + + long simulationStart = System.nanoTime(); + if (simulationOn) { + drawSimulation(simulationColors); + } + simulationNanos = System.nanoTime() - simulationStart; - LXDeck.Listener lxListener = new LXDeck.AbstractListener() { - public void patternWillChange(LXDeck deck, LXPattern pattern, LXPattern nextPattern) { - patternList.redraw(); - } - public void patternDidChange(LXDeck deck, LXPattern pattern) { - patternList.redraw(); - int pi = 0; - for (LXParameter parameter : pattern.getParameters()) { - if (pi >= parameterKnobs.length) { - break; - } - parameterKnobs[pi++].setParameter(parameter); - } - while (pi < parameterKnobs.length) { - parameterKnobs[pi++].setParameter(null); - } - } - }; - - deck.addListener(lxListener); - lxListener.patternDidChange(deck, deck.getActivePattern()); - + camera(); - javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL(); - gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT); - ((PGraphicsOpenGL)g).endGL(); ++ PGraphicsOpenGL gl = (PGraphicsOpenGL) g; + strokeWeight(1); } - class PatternScrollItem extends AbstractScrollItem { - - private LXPattern pattern; - private String label; - - PatternScrollItem(LXPattern pattern) { - this.pattern = pattern; - label = className(pattern, "Pattern"); - } - - public String getLabel() { - return label; - } - - public boolean isSelected() { - return deck.getActivePattern() == pattern; - } + void drawSimulation(color[] simulationColors) { + translate(0, 30, 0); + + noStroke(); + fill(#141414); + drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.); + fill(#070707); + stroke(#222222); + beginShape(); + vertex(0, 0, 0); + vertex(TRAILER_WIDTH, 0, 0); + vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH); + vertex(0, 0, TRAILER_DEPTH); + endShape(); + + // Draw the logo on the front of platform + pushMatrix(); + translate(0, 0, -1); + float s = .07; + scale(s, -s, s); + image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s); + popMatrix(); - public boolean isPending() { - return deck.getNextPattern() == pattern; + noStroke(); + for (Cube c : model.cubes) { + drawCube(c); } - - public void onMousePressed() { - deck.goPattern(pattern); + + noFill(); + strokeWeight(2); + beginShape(POINTS); + for (LXPoint p : model.points) { + stroke(simulationColors[p.index]); + vertex(p.x, p.y, p.z); + } + endShape(); + } + + void drawCube(Cube c) { + float in = .15; + noStroke(); + fill(#393939); + drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in); + } + + void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) { + pushMatrix(); + translate(x, y, z); + rotate(rx / 180. * PI, -1, 0, 0); + rotate(ry / 180. * PI, 0, -1, 0); + rotate(rz / 180. * PI, 0, 0, -1); + for (int i = 0; i < 4; ++i) { + float wid = (i % 2 == 0) ? xd : zd; + + beginShape(); + vertex(0, 0); + vertex(wid, 0); + vertex(wid, yd); + vertex(wid - sw, yd); + vertex(wid - sw, sw); + vertex(0, sw); + endShape(); + beginShape(); + vertex(0, sw); + vertex(0, yd); + vertex(wid - sw, yd); + vertex(wid - sw, yd - sw); + vertex(sw, yd - sw); + vertex(sw, sw); + endShape(); + + translate(wid, 0, 0); + rotate(HALF_PI, 0, -1, 0); } + popMatrix(); } } diff --cc libraries/HeronLX.jar index 0000000,0000000..7c388a7 new file mode 100755 Binary files differ diff --cc libraries/JGraphT.jar index 0000000,0000000..1db92e6 new file mode 100644 Binary files differ diff --cc libraries/ScreenShot.dll index 0000000,0000000..68a6c99 new file mode 100755 Binary files differ diff --cc libraries/ScreenShot.jar index 0000000,0000000..c75b8de new file mode 100755 Binary files differ diff --cc libraries/rwmidi.jar index 0000000,0000000..4788ff6 new file mode 100755 Binary files differ diff --cc libraries/toxiclibscore.jar index 0000000,0000000..18fbbfe new file mode 100755 Binary files differ diff --cc sketch.properties index 0000000,0000000..8630fa2 new file mode 100644 --- /dev/null +++ b/sketch.properties @@@ -1,0 -1,0 +1,2 @@@ ++mode.id=processing.mode.java.JavaMode ++mode=Java