2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * Custom UI components using the framework.
15 import java.util.Arrays;
16 class UICubesLayer extends UICameraComponent {
19 int SIZEOF_INT = Integer.SIZE / 8;
20 int SIZEOF_FLOAT = Float.SIZE / 8;
31 boolean initted = false;
33 int numPoints = 10000;
37 nvert = model.points.size();
38 sh = loadShader("frag.glsl", "vert.glsl");
39 /*color[] simulationColors = lx.getColors();
41 sha1.beginShape(POINTS);
42 for (LXPoint p : model.points) {
43 stroke(simulationColors[p.index]);
44 //pointColor(simulationColors[p.index]);
46 sha1.vertex(p.x, p.y, p.z);
49 float[] temp = new float[nvert * 7];
50 for (LXPoint p : model.points) {
52 temp[p.index * 7 + 0] = p.x;
53 temp[p.index * 7 + 1] = p.y;
54 temp[p.index * 7 + 2] = p.z;
57 temp[p.index * 7 + 3] = 0.0;
58 temp[p.index * 7 + 4] = 0.0;
59 temp[p.index * 7 + 5] = 0.0;
60 temp[p.index * 7 + 6] = 1.0;
63 vertData = allocateDirectFloatBuffer(nvert * 7);
67 vboName = allocateDirectIntBuffer(1);
76 color[] simulationColors = lx.getColors();
77 String displayMode = uiCrossfader.getDisplayMode();
78 if (displayMode == "A") {
79 simulationColors = lx.engine.getDeck(LEFT_DECK).getColors();
80 } else if (displayMode == "B") {
81 simulationColors = lx.engine.getDeck(RIGHT_DECK).getColors();
84 long simulationStart = System.nanoTime();
86 hint(DISABLE_DEPTH_TEST);
87 drawSimulation(simulationColors);
88 hint(ENABLE_DEPTH_TEST);
90 simulationNanos = System.nanoTime() - simulationStart;
95 void drawSimulation(color[] simulationColors) {
99 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
104 vertex(TRAILER_WIDTH, 0, 0);
105 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
106 vertex(0, 0, TRAILER_DEPTH);
109 // Draw the logo on the front of platform
114 image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
118 for (Cube c : model.cubes) {
133 vertLoc = pgl.getAttribLocation(sh.glProgram, "vertex");
134 colorLoc = pgl.getAttribLocation(sh.glProgram, "color");
136 pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
137 pgl.enableVertexAttribArray(vertLoc);
138 pgl.enableVertexAttribArray(colorLoc);
140 pgl.vertexAttribPointer(vertLoc, 3, PGL.FLOAT, false, 7 * SIZEOF_FLOAT, 0);
141 pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT);
143 pgl.drawArrays(PGL.POINTS, 0, nvert);
145 pgl.disableVertexAttribArray(vertLoc);
146 pgl.disableVertexAttribArray(colorLoc);
147 pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
151 createGeometry(simulationColors);
152 pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
153 pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW);
156 void createGeometry(color[] simulationColors) {
157 for (LXPoint p : model.points) {
158 vertData.put(p.index * 7 + 3, ((simulationColors[p.index] >> 16) & 0xFF)/255.0);
159 vertData.put(p.index * 7 + 4, ((simulationColors[p.index] >> 8) & 0xFF)/255.0);
160 vertData.put(p.index * 7 + 5, (simulationColors[p.index]& 0xFF)/255.0);
166 pgl.genBuffers(1, vboName);
167 pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
168 pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.DYNAMIC_DRAW);
169 pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
173 IntBuffer allocateDirectIntBuffer(int n) {
174 return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer();
177 FloatBuffer allocateDirectFloatBuffer(int n) {
178 return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
181 void drawCube(Cube c) {
185 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);
188 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
191 rotate(rx / 180. * PI, -1, 0, 0);
192 rotate(ry / 180. * PI, 0, -1, 0);
193 rotate(rz / 180. * PI, 0, 0, -1);
194 for (int i = 0; i < 4; ++i) {
195 float wid = (i % 2 == 0) ? xd : zd;
201 vertex(wid - sw, yd);
202 vertex(wid - sw, sw);
208 vertex(wid - sw, yd);
209 vertex(wid - sw, yd - sw);
214 translate(wid, 0, 0);
215 rotate(HALF_PI, 0, -1, 0);
221 class UIBlendMode extends UIWindow {
222 public UIBlendMode(float x, float y, float w, float h) {
223 super(lx.ui, "BLEND MODE", x, y, w, h);
224 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
225 for (LXTransition t : transitions) {
226 items.add(new TransitionScrollItem(t));
228 final UIScrollList tList;
229 (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this);
231 lx.engine.getDeck(RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
232 public void faderTransitionDidChange(LXDeck deck, LXTransition transition) {
238 class TransitionScrollItem extends UIScrollList.AbstractItem {
239 private final LXTransition transition;
240 private final String label;
242 TransitionScrollItem(LXTransition transition) {
243 this.transition = transition;
244 this.label = className(transition, "Transition");
247 public String getLabel() {
251 public boolean isSelected() {
252 return this.transition == lx.engine.getDeck(RIGHT_DECK).getFaderTransition();
255 public boolean isPending() {
259 public void onMousePressed() {
260 lx.engine.getDeck(RIGHT_DECK).setFaderTransition(this.transition);
266 class UICrossfader extends UIWindow {
268 private final UIToggleSet displayMode;
270 public UICrossfader(float x, float y, float w, float h) {
271 super(lx.ui, "CROSSFADER", x, y, w, h);
273 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(RIGHT_DECK).getFader()).addToContainer(this);
274 (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
277 public UICrossfader setDisplayMode(String value) {
278 displayMode.setValue(value);
282 public String getDisplayMode() {
283 return displayMode.getValue();
287 class UIEffects extends UIWindow {
288 UIEffects(float x, float y, float w, float h) {
289 super(lx.ui, "FX", x, y, w, h);
291 int yp = UIWindow.TITLE_LABEL_HEIGHT;
292 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
294 for (LXEffect fx : effectsArr) {
295 items.add(new FXScrollItem(fx, i++));
297 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
298 effectsList.addToContainer(this);
299 yp += effectsList.getHeight() + 10;
301 final UIKnob[] parameterKnobs = new UIKnob[4];
302 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
303 parameterKnobs[ki] = new UIKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
304 parameterKnobs[ki].addToContainer(this);
307 LXParameterListener fxListener = new LXParameterListener() {
308 public void onParameterChanged(LXParameter parameter) {
310 for (LXParameter p : getSelectedEffect().getParameters()) {
311 if (i >= parameterKnobs.length) {
314 if (p instanceof BasicParameter) {
315 parameterKnobs[i++].setParameter((BasicParameter) p);
318 while (i < parameterKnobs.length) {
319 parameterKnobs[i++].setParameter(null);
324 selectedEffect.addListener(fxListener);
325 fxListener.onParameterChanged(null);
329 class FXScrollItem extends UIScrollList.AbstractItem {
331 private final LXEffect effect;
332 private final int index;
333 private final String label;
335 FXScrollItem(LXEffect effect, int index) {
336 this.effect = effect;
338 this.label = className(effect, "Effect");
341 public String getLabel() {
345 public boolean isSelected() {
346 return !effect.isEnabled() && (effect == getSelectedEffect());
349 public boolean isPending() {
350 return effect.isEnabled();
353 public void onMousePressed() {
354 if (effect == getSelectedEffect()) {
355 if (effect.isMomentary()) {
361 selectedEffect.setValue(index);
365 public void onMouseReleased() {
366 if (effect.isMomentary()) {
375 class UIOutput extends UIWindow {
376 public UIOutput(GrizzlyOutput[] grizzlies, float x, float y, float w, float h) {
377 super(lx.ui, "OUTPUT", x, y, w, h);
378 float yp = UIWindow.TITLE_LABEL_HEIGHT;
380 final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80);
382 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
383 for (GrizzlyOutput grizzly : grizzlies) {
384 items.add(new GrizzlyScrollItem(grizzly));
385 grizzly.enabled.addListener(new LXParameterListener() {
386 public void onParameterChanged(LXParameter parameter) {
391 outputs.setItems(items).addToContainer(this);
394 class GrizzlyScrollItem extends UIScrollList.AbstractItem {
395 final GrizzlyOutput output;
397 GrizzlyScrollItem(GrizzlyOutput output) {
398 this.output = output;
401 public String getLabel() {
402 return output.ipAddress;
405 public boolean isSelected() {
406 return output.enabled.isOn();
409 public void onMousePressed() {
410 output.enabled.setValue(!isSelected());
415 class UITempo extends UIWindow {
417 private final UIButton tempoButton;
419 UITempo(float x, float y, float w, float h) {
420 super(lx.ui, "TEMPO", x, y, w, h);
421 tempoButton = new UIButton(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20) {
422 protected void onToggle(boolean active) {
427 }.setMomentary(true);
428 tempoButton.addToContainer(this);
429 new UITempoBlipper(8, UIWindow.TITLE_LABEL_HEIGHT + 5, 12, 12).addToContainer(this);
432 class UITempoBlipper extends UIObject {
433 UITempoBlipper(float x, float y, float w, float h) {
437 void onDraw(UI ui, PGraphics pg) {
438 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
440 // Overlay tempo thing with openGL, redraw faster than button UI
441 pg.fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
443 pg.rect(0, 0, width, height);
451 class UIMapping extends UIWindow {
453 private static final String MAP_MODE_ALL = "ALL";
454 private static final String MAP_MODE_CHANNEL = "CHNL";
455 private static final String MAP_MODE_CUBE = "CUBE";
457 private static final String CUBE_MODE_ALL = "ALL";
458 private static final String CUBE_MODE_STRIP = "SNGL";
459 private static final String CUBE_MODE_PATTERN = "PTRN";
461 private final MappingTool mappingTool;
463 private final UIIntegerBox channelBox;
464 private final UIIntegerBox cubeBox;
465 private final UIIntegerBox stripBox;
467 UIMapping(MappingTool tool, float x, float y, float w, float h) {
468 super(lx.ui, "MAPPING", x, y, w, h);
471 int yp = UIWindow.TITLE_LABEL_HEIGHT;
472 new UIToggleSet(4, yp, w-10, 20) {
473 protected void onToggle(String value) {
474 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
475 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
476 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
478 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
480 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
482 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
483 protected void onValueChange(int value) {
484 mappingTool.setChannel(value-1);
486 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
489 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
491 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
492 protected void onValueChange(int value) {
493 mappingTool.setCube(value-1);
495 }).setRange(1, model.cubes.size()).addToContainer(this);
500 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] {
501 new ColorScrollItem(ColorScrollItem.COLOR_RED),
502 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
503 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
504 })).addToContainer(this);
507 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
510 new UIToggleSet(4, yp, w-10, 20) {
511 protected void onToggle(String value) {
512 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
513 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
514 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
516 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
519 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
522 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
523 protected void onValueChange(int value) {
524 mappingTool.setStrip(value-1);
526 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
530 public void setChannelID(int value) {
531 channelBox.setValue(value);
534 public void setCubeID(int value) {
535 cubeBox.setValue(value);
538 public void setStripID(int value) {
539 stripBox.setValue(value);
542 class ColorScrollItem extends UIScrollList.AbstractItem {
544 public static final int COLOR_RED = 1;
545 public static final int COLOR_GREEN = 2;
546 public static final int COLOR_BLUE = 3;
548 private final int colorChannel;
550 ColorScrollItem(int colorChannel) {
551 this.colorChannel = colorChannel;
554 public String getLabel() {
555 switch (colorChannel) {
556 case COLOR_RED: return "Red";
557 case COLOR_GREEN: return "Green";
558 case COLOR_BLUE: return "Blue";
563 public boolean isSelected() {
564 switch (colorChannel) {
565 case COLOR_RED: return mappingTool.channelModeRed;
566 case COLOR_GREEN: return mappingTool.channelModeGreen;
567 case COLOR_BLUE: return mappingTool.channelModeBlue;
572 public void onMousePressed() {
573 switch (colorChannel) {
574 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
575 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
576 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
582 class UIDebugText extends UIContext {
584 private String line1 = "";
585 private String line2 = "";
587 UIDebugText(float x, float y, float w, float h) {
588 super(lx.ui, x, y, w, h);
591 public UIDebugText setText(String line1) {
592 return setText(line1, "");
595 public UIDebugText setText(String line1, String line2) {
596 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
599 setVisible(line1.length() + line2.length() > 0);
605 protected void onDraw(UI ui, PGraphics pg) {
606 super.onDraw(ui, pg);
607 if (line1.length() + line2.length() > 0) {
610 pg.rect(0, 0, width, height);
611 pg.textFont(ui.getItemFont());
613 pg.textAlign(LEFT, TOP);
615 pg.text(line1, 4, 4);
616 pg.text(line2, 4, 24);
621 class UISpeed extends UIWindow {
623 final BasicParameter speed;
625 UISpeed(float x, float y, float w, float h) {
626 super(lx.ui, "SPEED", x, y, w, h);
627 speed = new BasicParameter("SPEED", 0.5);
628 speed.addListener(new LXParameterListener() {
629 public void onParameterChanged(LXParameter parameter) {
630 lx.setSpeed(parameter.getValuef() * 2);
633 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20).setParameter(speed).addToContainer(this);
637 class UIMidi extends UIWindow {
639 private final UIToggleSet deckMode;
640 private final UIButton logMode;
642 UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) {
643 super(lx.ui, "MIDI", x, y, w, h);
645 // Processing compiler doesn't seem to get that list of class objects also conform to interface
646 List<UIScrollList.Item> scrollItems = new ArrayList<UIScrollList.Item>();
647 for (SCMidiInput mc : midiEngine.getControllers()) {
650 final UIScrollList scrollList;
651 (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this);
652 (deckMode = new UIToggleSet(4, 130, 90, 20) {
653 protected void onToggle(String value) {
654 midiEngine.setFocusedDeck(value == "A" ? 0 : 1);
656 }).setOptions(new String[] { "A", "B" }).addToContainer(this);
657 (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this);
659 SCMidiInputListener listener = new SCMidiInputListener() {
660 public void onEnabled(SCMidiInput controller, boolean enabled) {
664 for (SCMidiInput mc : midiEngine.getControllers()) {
665 mc.addListener(listener);
668 midiEngine.addListener(new MidiEngineListener() {
669 public void onFocusedDeck(int deckIndex) {
670 deckMode.setValue(deckIndex == 0 ? "A" : "B");
676 public boolean logMidi() {
677 return logMode.isActive();
680 public LXDeck getFocusedDeck() {
681 return lx.engine.getDeck(deckMode.getValue() == "A" ? LEFT_DECK : RIGHT_DECK);
685 String className(Object p, String suffix) {
686 String s = p.getClass().getName();
688 if ((li = s.lastIndexOf(".")) > 0) {
689 s = s.substring(li + 1);
691 if (s.indexOf("SugarCubes$") == 0) {
692 s = s.substring("SugarCubes$".length());
694 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
695 s = s.substring(0, li);