2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * Custom UI components using the framework.
14 class UIPatternDeck extends UIWindow {
18 public UIPatternDeck(Engine.Deck deck, String label, float x, float y, float w, float h) {
19 super(label, x, y, w, h);
23 List<ScrollItem> items = new ArrayList<ScrollItem>();
24 for (LXPattern p : deck.getPatterns()) {
25 items.add(new PatternScrollItem(p));
27 final UIScrollList patternList = new UIScrollList(1, yp, w-2, 160).setItems(items);
28 patternList.addToContainer(this);
29 yp += patternList.h + 10;
31 final UIParameterKnob[] parameterKnobs = new UIParameterKnob[12];
32 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
33 parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
34 parameterKnobs[ki].addToContainer(this);
37 Engine.Listener lxListener = new Engine.AbstractListener() {
38 public void patternWillChange(Engine.Deck deck, LXPattern pattern, LXPattern nextPattern) {
41 public void patternDidChange(Engine.Deck deck, LXPattern pattern) {
44 for (LXParameter parameter : pattern.getParameters()) {
45 if (pi >= parameterKnobs.length) {
48 parameterKnobs[pi++].setParameter(parameter);
50 while (pi < parameterKnobs.length) {
51 parameterKnobs[pi++].setParameter(null);
56 deck.addListener(lxListener);
57 lxListener.patternDidChange(deck, deck.getActivePattern());
61 class PatternScrollItem extends AbstractScrollItem {
63 private LXPattern pattern;
66 PatternScrollItem(LXPattern pattern) {
67 this.pattern = pattern;
68 label = className(pattern, "Pattern");
71 public String getLabel() {
75 public boolean isSelected() {
76 return deck.getActivePattern() == pattern;
79 public boolean isPending() {
80 return deck.getNextPattern() == pattern;
83 public void onMousePressed() {
84 deck.goPattern(pattern);
89 class UICrossfader extends UIWindow {
91 private final UIToggleSet displayMode;
93 public UICrossfader(float x, float y, float w, float h) {
94 super("CROSSFADER", x, y, w, h);
96 List<ScrollItem> items = new ArrayList<ScrollItem>();
97 for (LXTransition t : glucose.getTransitions()) {
98 items.add(new TransitionScrollItem(t));
100 final UIScrollList tList;
101 (tList = new UIScrollList(1, titleHeight, w-2, 120)).setItems(items).addToContainer(this);
102 new UIParameterSlider(4, titleHeight + 126, w-10, 24).setParameter(lx.engine.getDeck(1).getCrossfader()).addToContainer(this);
103 (displayMode = new UIToggleSet(4, 182, w-10, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
105 lx.engine.getDeck(1).addListener(new Engine.AbstractListener() {
106 public void blendTransitionDidChange(Engine.Deck deck, LXTransition transition) {
112 public String getDisplayMode() {
113 return displayMode.getValue();
117 class TransitionScrollItem extends AbstractScrollItem {
118 private final LXTransition transition;
119 private String label;
121 TransitionScrollItem(LXTransition transition) {
122 this.transition = transition;
123 label = className(transition, "Transition");
126 public String getLabel() {
130 public boolean isSelected() {
131 return transition == glucose.getSelectedTransition();
134 public boolean isPending() {
138 public void onMousePressed() {
139 glucose.setSelectedTransition(transition);
143 class UIEffects extends UIWindow {
144 UIEffects(float x, float y, float w, float h) {
145 super("FX", x, y, w, h);
147 int yp = titleHeight;
148 List<ScrollItem> items = new ArrayList<ScrollItem>();
149 for (LXEffect fx : glucose.lx.getEffects()) {
150 items.add(new FXScrollItem(fx));
152 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
153 effectsList.addToContainer(this);
154 yp += effectsList.h + 10;
156 final UIParameterKnob[] parameterKnobs = new UIParameterKnob[4];
157 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
158 parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
159 parameterKnobs[ki].addToContainer(this);
162 GLucose.EffectListener fxListener = new GLucose.EffectListener() {
163 public void effectSelected(LXEffect effect) {
165 for (LXParameter p : effect.getParameters()) {
166 if (i >= parameterKnobs.length) {
169 parameterKnobs[i++].setParameter(p);
171 while (i < parameterKnobs.length) {
172 parameterKnobs[i++].setParameter(null);
177 glucose.addEffectListener(fxListener);
178 fxListener.effectSelected(glucose.getSelectedEffect());
182 class FXScrollItem extends AbstractScrollItem {
184 private LXEffect effect;
185 private String label;
187 FXScrollItem(LXEffect effect) {
188 this.effect = effect;
189 label = className(effect, "Effect");
192 public String getLabel() {
196 public boolean isSelected() {
197 return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
200 public boolean isPending() {
201 return effect.isEnabled();
204 public void onMousePressed() {
205 if (glucose.getSelectedEffect() == effect) {
206 if (effect.isMomentary()) {
212 glucose.setSelectedEffect(effect);
216 public void onMouseReleased() {
217 if (effect.isMomentary()) {
226 class UIOutput extends UIWindow {
227 public UIOutput(float x, float y, float w, float h) {
228 super("OUTPUT", x, y, w, h);
229 float yp = titleHeight;
231 final UIScrollList outputs = new UIScrollList(1, titleHeight, w-2, 80);
233 List<ScrollItem> items = new ArrayList<ScrollItem>();
234 for (final PandaDriver panda : pandaBoards) {
235 items.add(new PandaScrollItem(panda));
236 panda.setListener(new PandaDriver.Listener() {
237 public void onToggle(boolean active) {
242 outputs.setItems(items).addToContainer(this);
245 class PandaScrollItem extends AbstractScrollItem {
246 final PandaDriver panda;
247 PandaScrollItem(PandaDriver panda) {
251 public String getLabel() {
255 public boolean isSelected() {
256 return panda.isEnabled();
259 public void onMousePressed() {
265 class UITempo extends UIWindow {
267 private final UIButton tempoButton;
269 UITempo(float x, float y, float w, float h) {
270 super("TEMPO", x, y, w, h);
271 tempoButton = new UIButton(4, titleHeight, w-10, 20) {
272 protected void onToggle(boolean active) {
277 }.setMomentary(true);
278 tempoButton.addToContainer(this);
282 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
285 // Overlay tempo thing with openGL, redraw faster than button UI
286 fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
288 rect(x + 8, y + titleHeight + 5, 12, 12);
292 class UIMapping extends UIWindow {
294 private static final String MAP_MODE_ALL = "ALL";
295 private static final String MAP_MODE_CHANNEL = "CHNL";
296 private static final String MAP_MODE_CUBE = "CUBE";
298 private static final String CUBE_MODE_ALL = "ALL";
299 private static final String CUBE_MODE_STRIP = "SNGL";
300 private static final String CUBE_MODE_PATTERN = "PTRN";
302 private final MappingTool mappingTool;
304 private final UIIntegerBox channelBox;
305 private final UIIntegerBox cubeBox;
306 private final UIIntegerBox stripBox;
308 UIMapping(MappingTool tool, float x, float y, float w, float h) {
309 super("MAPPING", x, y, w, h);
312 int yp = titleHeight;
313 new UIToggleSet(4, yp, w-10, 20) {
314 protected void onToggle(String value) {
315 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
316 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
317 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
319 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
321 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
323 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
324 protected void onValueChange(int value) {
325 mappingTool.setChannel(value-1);
327 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
330 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
332 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
333 protected void onValueChange(int value) {
334 mappingTool.setCube(value-1);
336 }).setRange(1, glucose.model.cubes.size()).addToContainer(this);
339 new UILabel(4, yp+8, w-10, 20).setLabel("COLORS").addToContainer(this);
342 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] {
343 new ColorScrollItem(ColorScrollItem.COLOR_RED),
344 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
345 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
346 })).addToContainer(this);
349 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
352 new UIToggleSet(4, yp, w-10, 20) {
353 protected void onToggle(String value) {
354 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
355 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
356 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
358 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
361 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
364 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
365 protected void onValueChange(int value) {
366 mappingTool.setStrip(value-1);
368 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
372 public void setChannelID(int value) {
373 channelBox.setValue(value);
376 public void setCubeID(int value) {
377 cubeBox.setValue(value);
380 public void setStripID(int value) {
381 stripBox.setValue(value);
384 class ColorScrollItem extends AbstractScrollItem {
386 public static final int COLOR_RED = 1;
387 public static final int COLOR_GREEN = 2;
388 public static final int COLOR_BLUE = 3;
390 private final int colorChannel;
392 ColorScrollItem(int colorChannel) {
393 this.colorChannel = colorChannel;
396 public String getLabel() {
397 switch (colorChannel) {
398 case COLOR_RED: return "Red";
399 case COLOR_GREEN: return "Green";
400 case COLOR_BLUE: return "Blue";
405 public boolean isSelected() {
406 switch (colorChannel) {
407 case COLOR_RED: return mappingTool.channelModeRed;
408 case COLOR_GREEN: return mappingTool.channelModeGreen;
409 case COLOR_BLUE: return mappingTool.channelModeBlue;
414 public void select() {
415 switch (colorChannel) {
416 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
417 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
418 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
424 class UIDebugText extends UIContext {
426 private String line1 = "";
427 private String line2 = "";
429 UIDebugText(float x, float y, float w, float h) {
433 public UIDebugText setText(String line1) {
434 return setText(line1, "");
437 public UIDebugText setText(String line1, String line2) {
438 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
441 setVisible(line1.length() + line2.length() > 0);
447 protected void onDraw(PGraphics pg) {
449 if (line1.length() + line2.length() > 0) {
453 pg.textFont(defaultItemFont);
454 pg.textAlign(LEFT, TOP);
456 pg.text(line1, 4, 4);
457 pg.text(line2, 4, 24);
462 class UISpeed extends UIWindow {
463 UISpeed(float x, float y, float w, float h) {
464 super("SPEED", x, y, w, h);
465 new UIParameterSlider(4, titleHeight, w-10, 20)
466 .setParameter(new BasicParameter("SPEED", 0.5).addListener(new LXParameter.Listener() {
467 public void onParameterChanged(LXParameter parameter) {
468 lx.setSpeed(parameter.getValuef() * 2);
470 })).addToContainer(this);
474 String className(Object p, String suffix) {
475 String s = p.getClass().getName();
477 if ((li = s.lastIndexOf(".")) > 0) {
478 s = s.substring(li + 1);
480 if (s.indexOf("SugarCubes$") == 0) {
481 s = s.substring("SugarCubes$".length());
483 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
484 s = s.substring(0, li);