2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * Custom UI components using the framework.
14 class UICubesLayer extends UICameraComponent {
16 color[] simulationColors = lx.getColors();
17 String displayMode = uiCrossfader.getDisplayMode();
18 if (displayMode == "A") {
19 simulationColors = lx.engine.getDeck(LEFT_DECK).getColors();
20 } else if (displayMode == "B") {
21 simulationColors = lx.engine.getDeck(RIGHT_DECK).getColors();
24 long simulationStart = System.nanoTime();
26 drawSimulation(simulationColors);
28 simulationNanos = System.nanoTime() - simulationStart;
31 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
32 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
33 ((PGraphicsOpenGL)g).endGL();
37 void drawSimulation(color[] simulationColors) {
42 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
47 vertex(TRAILER_WIDTH, 0, 0);
48 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
49 vertex(0, 0, TRAILER_DEPTH);
52 // Draw the logo on the front of platform
57 image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
61 for (Cube c : model.cubes) {
68 for (LXPoint p : model.points) {
69 stroke(simulationColors[p.index]);
70 vertex(p.x, p.y, p.z);
75 void drawCube(Cube c) {
79 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);
82 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
85 rotate(rx / 180. * PI, -1, 0, 0);
86 rotate(ry / 180. * PI, 0, -1, 0);
87 rotate(rz / 180. * PI, 0, 0, -1);
88 for (int i = 0; i < 4; ++i) {
89 float wid = (i % 2 == 0) ? xd : zd;
102 vertex(wid - sw, yd);
103 vertex(wid - sw, yd - sw);
108 translate(wid, 0, 0);
109 rotate(HALF_PI, 0, -1, 0);
115 class UIBlendMode extends UIWindow {
116 public UIBlendMode(float x, float y, float w, float h) {
117 super(lx.ui, "BLEND MODE", x, y, w, h);
118 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
119 for (LXTransition t : transitions) {
120 items.add(new TransitionScrollItem(t));
122 final UIScrollList tList;
123 (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this);
125 lx.engine.getDeck(RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
126 public void faderTransitionDidChange(LXDeck deck, LXTransition transition) {
132 class TransitionScrollItem extends UIScrollList.AbstractItem {
133 private final LXTransition transition;
134 private final String label;
136 TransitionScrollItem(LXTransition transition) {
137 this.transition = transition;
138 this.label = className(transition, "Transition");
141 public String getLabel() {
145 public boolean isSelected() {
146 return this.transition == lx.engine.getDeck(RIGHT_DECK).getFaderTransition();
149 public boolean isPending() {
153 public void onMousePressed() {
154 lx.engine.getDeck(RIGHT_DECK).setFaderTransition(this.transition);
160 class UICrossfader extends UIWindow {
162 private final UIToggleSet displayMode;
164 public UICrossfader(float x, float y, float w, float h) {
165 super(lx.ui, "CROSSFADER", x, y, w, h);
167 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(RIGHT_DECK).getFader()).addToContainer(this);
168 (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
171 public UICrossfader setDisplayMode(String value) {
172 displayMode.setValue(value);
176 public String getDisplayMode() {
177 return displayMode.getValue();
181 class UIEffects extends UIWindow {
182 UIEffects(float x, float y, float w, float h) {
183 super(lx.ui, "FX", x, y, w, h);
185 int yp = UIWindow.TITLE_LABEL_HEIGHT;
186 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
188 for (LXEffect fx : effectsArr) {
189 items.add(new FXScrollItem(fx, i++));
191 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
192 effectsList.addToContainer(this);
193 yp += effectsList.getHeight() + 10;
195 final UIKnob[] parameterKnobs = new UIKnob[4];
196 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
197 parameterKnobs[ki] = new UIKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
198 parameterKnobs[ki].addToContainer(this);
201 LXParameterListener fxListener = new LXParameterListener() {
202 public void onParameterChanged(LXParameter parameter) {
204 for (LXParameter p : getSelectedEffect().getParameters()) {
205 if (i >= parameterKnobs.length) {
208 if (p instanceof BasicParameter) {
209 parameterKnobs[i++].setParameter((BasicParameter) p);
212 while (i < parameterKnobs.length) {
213 parameterKnobs[i++].setParameter(null);
218 selectedEffect.addListener(fxListener);
219 fxListener.onParameterChanged(null);
223 class FXScrollItem extends UIScrollList.AbstractItem {
225 private final LXEffect effect;
226 private final int index;
227 private final String label;
229 FXScrollItem(LXEffect effect, int index) {
230 this.effect = effect;
232 this.label = className(effect, "Effect");
235 public String getLabel() {
239 public boolean isSelected() {
240 return !effect.isEnabled() && (effect == getSelectedEffect());
243 public boolean isPending() {
244 return effect.isEnabled();
247 public void onMousePressed() {
248 if (effect == getSelectedEffect()) {
249 if (effect.isMomentary()) {
255 selectedEffect.setValue(index);
259 public void onMouseReleased() {
260 if (effect.isMomentary()) {
269 class UIOutput extends UIWindow {
270 public UIOutput(GrizzlyOutput[] grizzlies, float x, float y, float w, float h) {
271 super(lx.ui, "OUTPUT", x, y, w, h);
272 float yp = UIWindow.TITLE_LABEL_HEIGHT;
274 final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80);
276 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
277 for (GrizzlyOutput grizzly : grizzlies) {
278 items.add(new GrizzlyScrollItem(grizzly));
279 grizzly.enabled.addListener(new LXParameterListener() {
280 public void onParameterChanged(LXParameter parameter) {
285 outputs.setItems(items).addToContainer(this);
288 class GrizzlyScrollItem extends UIScrollList.AbstractItem {
289 final GrizzlyOutput output;
291 GrizzlyScrollItem(GrizzlyOutput output) {
292 this.output = output;
295 public String getLabel() {
296 return output.ipAddress;
299 public boolean isSelected() {
300 return output.enabled.isOn();
303 public void onMousePressed() {
304 output.enabled.setValue(!isSelected());
309 class UITempo extends UIWindow {
311 private final UIButton tempoButton;
313 UITempo(float x, float y, float w, float h) {
314 super(lx.ui, "TEMPO", x, y, w, h);
315 tempoButton = new UIButton(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20) {
316 protected void onToggle(boolean active) {
321 }.setMomentary(true);
322 tempoButton.addToContainer(this);
323 new UITempoBlipper(8, UIWindow.TITLE_LABEL_HEIGHT + 5, 12, 12).addToContainer(this);
326 class UITempoBlipper extends UIObject {
327 UITempoBlipper(float x, float y, float w, float h) {
331 void onDraw(UI ui, PGraphics pg) {
332 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
334 // Overlay tempo thing with openGL, redraw faster than button UI
335 pg.fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
337 pg.rect(0, 0, width, height);
345 class UIMapping extends UIWindow {
347 private static final String MAP_MODE_ALL = "ALL";
348 private static final String MAP_MODE_CHANNEL = "CHNL";
349 private static final String MAP_MODE_CUBE = "CUBE";
351 private static final String CUBE_MODE_ALL = "ALL";
352 private static final String CUBE_MODE_STRIP = "SNGL";
353 private static final String CUBE_MODE_PATTERN = "PTRN";
355 private final MappingTool mappingTool;
357 private final UIIntegerBox channelBox;
358 private final UIIntegerBox cubeBox;
359 private final UIIntegerBox stripBox;
361 UIMapping(MappingTool tool, float x, float y, float w, float h) {
362 super(lx.ui, "MAPPING", x, y, w, h);
365 int yp = UIWindow.TITLE_LABEL_HEIGHT;
366 new UIToggleSet(4, yp, w-10, 20) {
367 protected void onToggle(String value) {
368 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
369 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
370 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
372 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
374 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
376 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
377 protected void onValueChange(int value) {
378 mappingTool.setChannel(value-1);
380 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
383 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
385 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
386 protected void onValueChange(int value) {
387 mappingTool.setCube(value-1);
389 }).setRange(1, model.cubes.size()).addToContainer(this);
394 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] {
395 new ColorScrollItem(ColorScrollItem.COLOR_RED),
396 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
397 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
398 })).addToContainer(this);
401 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
404 new UIToggleSet(4, yp, w-10, 20) {
405 protected void onToggle(String value) {
406 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
407 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
408 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
410 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
413 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
416 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
417 protected void onValueChange(int value) {
418 mappingTool.setStrip(value-1);
420 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
424 public void setChannelID(int value) {
425 channelBox.setValue(value);
428 public void setCubeID(int value) {
429 cubeBox.setValue(value);
432 public void setStripID(int value) {
433 stripBox.setValue(value);
436 class ColorScrollItem extends UIScrollList.AbstractItem {
438 public static final int COLOR_RED = 1;
439 public static final int COLOR_GREEN = 2;
440 public static final int COLOR_BLUE = 3;
442 private final int colorChannel;
444 ColorScrollItem(int colorChannel) {
445 this.colorChannel = colorChannel;
448 public String getLabel() {
449 switch (colorChannel) {
450 case COLOR_RED: return "Red";
451 case COLOR_GREEN: return "Green";
452 case COLOR_BLUE: return "Blue";
457 public boolean isSelected() {
458 switch (colorChannel) {
459 case COLOR_RED: return mappingTool.channelModeRed;
460 case COLOR_GREEN: return mappingTool.channelModeGreen;
461 case COLOR_BLUE: return mappingTool.channelModeBlue;
466 public void onMousePressed() {
467 switch (colorChannel) {
468 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
469 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
470 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
476 class UIDebugText extends UIContext {
478 private String line1 = "";
479 private String line2 = "";
481 UIDebugText(float x, float y, float w, float h) {
482 super(lx.ui, x, y, w, h);
485 public UIDebugText setText(String line1) {
486 return setText(line1, "");
489 public UIDebugText setText(String line1, String line2) {
490 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
493 setVisible(line1.length() + line2.length() > 0);
499 protected void onDraw(UI ui, PGraphics pg) {
500 super.onDraw(ui, pg);
501 if (line1.length() + line2.length() > 0) {
504 pg.rect(0, 0, width, height);
505 pg.textFont(ui.getItemFont());
507 pg.textAlign(LEFT, TOP);
509 pg.text(line1, 4, 4);
510 pg.text(line2, 4, 24);
515 class UISpeed extends UIWindow {
517 final BasicParameter speed;
519 UISpeed(float x, float y, float w, float h) {
520 super(lx.ui, "SPEED", x, y, w, h);
521 speed = new BasicParameter("SPEED", 0.5);
522 speed.addListener(new LXParameterListener() {
523 public void onParameterChanged(LXParameter parameter) {
524 lx.setSpeed(parameter.getValuef() * 2);
527 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20).setParameter(speed).addToContainer(this);
531 class UIMidi extends UIWindow {
533 private final UIToggleSet deckMode;
534 private final UIButton logMode;
536 UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) {
537 super(lx.ui, "MIDI", x, y, w, h);
539 // Processing compiler doesn't seem to get that list of class objects also conform to interface
540 List<UIScrollList.Item> scrollItems = new ArrayList<UIScrollList.Item>();
541 for (SCMidiInput mc : midiEngine.getControllers()) {
544 final UIScrollList scrollList;
545 (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this);
546 (deckMode = new UIToggleSet(4, 130, 90, 20) {
547 protected void onToggle(String value) {
548 midiEngine.setFocusedDeck(value == "A" ? 0 : 1);
550 }).setOptions(new String[] { "A", "B" }).addToContainer(this);
551 (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this);
553 SCMidiInputListener listener = new SCMidiInputListener() {
554 public void onEnabled(SCMidiInput controller, boolean enabled) {
558 for (SCMidiInput mc : midiEngine.getControllers()) {
559 mc.addListener(listener);
562 midiEngine.addListener(new MidiEngineListener() {
563 public void onFocusedDeck(int deckIndex) {
564 deckMode.setValue(deckIndex == 0 ? "A" : "B");
570 public boolean logMidi() {
571 return logMode.isActive();
574 public LXDeck getFocusedDeck() {
575 return lx.engine.getDeck(deckMode.getValue() == "A" ? LEFT_DECK : RIGHT_DECK);
579 String className(Object p, String suffix) {
580 String s = p.getClass().getName();
582 if ((li = s.lastIndexOf(".")) > 0) {
583 s = s.substring(li + 1);
585 if (s.indexOf("SugarCubes$") == 0) {
586 s = s.substring("SugarCubes$".length());
588 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
589 s = s.substring(0, li);