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.Listener() {
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 select() {
84 deck.goPattern(pattern);
89 class UICrossfader extends UIWindow {
91 public UICrossfader(float x, float y, float w, float h) {
92 super("CROSSFADER", x, y, w, h);
94 List<ScrollItem> items = new ArrayList<ScrollItem>();
95 for (LXTransition t : transitions) {
96 items.add(new TransitionScrollItem(t));
98 new UIScrollList(1, titleHeight, w-2, 120).setItems(items).addToContainer(this);
99 new UIParameterSlider(4, titleHeight + 126, w-10, 24).setParameter(lx.engine.getDeck(1).getCrossfader()).addToContainer(this);
100 new UIToggleSet(4, 182, w-10, 20) {
101 protected void onToggle(String value) {
104 }.setOptions(new String[] { "A", "COMP", "B" }).setValue(displayMode = "COMP").addToContainer(this);
108 class TransitionScrollItem extends AbstractScrollItem {
109 private final LXTransition transition;
110 private String label;
112 TransitionScrollItem(LXTransition transition) {
113 this.transition = transition;
114 label = className(transition, "Transition");
117 public String getLabel() {
121 public boolean isSelected() {
122 return transition == lx.engine.getDeck(1).getBlendTransition();
125 public boolean isPending() {
129 public void select() {
130 lx.engine.getDeck(1).setBlendTransition(transition);
134 class UIEffects extends UIWindow {
135 UIEffects(float x, float y, float w, float h) {
136 super("FX", x, y, w, h);
138 int yp = titleHeight;
139 List<ScrollItem> items = new ArrayList<ScrollItem>();
140 for (LXEffect fx : glucose.lx.getEffects()) {
141 items.add(new FXScrollItem(fx));
143 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
144 effectsList.addToContainer(this);
145 yp += effectsList.h + 10;
147 final UIParameterKnob[] parameterKnobs = new UIParameterKnob[4];
148 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
149 parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
150 parameterKnobs[ki].addToContainer(this);
153 GLucose.EffectListener fxListener = new GLucose.EffectListener() {
154 public void effectSelected(LXEffect effect) {
156 for (LXParameter p : effect.getParameters()) {
157 if (i >= parameterKnobs.length) {
160 parameterKnobs[i++].setParameter(p);
162 while (i < parameterKnobs.length) {
163 parameterKnobs[i++].setParameter(null);
168 glucose.addEffectListener(fxListener);
169 fxListener.effectSelected(glucose.getSelectedEffect());
173 class FXScrollItem extends AbstractScrollItem {
175 private LXEffect effect;
176 private String label;
178 FXScrollItem(LXEffect effect) {
179 this.effect = effect;
180 label = className(effect, "Effect");
183 public String getLabel() {
187 public boolean isSelected() {
188 return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
191 public boolean isPending() {
192 return effect.isEnabled();
195 public void select() {
196 glucose.setSelectedEffect(effect);
199 public void onMousePressed() {
200 if (glucose.getSelectedEffect() == effect) {
201 if (effect.isMomentary()) {
209 public void onMouseReleased() {
210 if (effect.isMomentary()) {
219 class UIOutput extends UIWindow {
220 public UIOutput(float x, float y, float w, float h) {
221 super("OUTPUT", x, y, w, h);
222 float yp = titleHeight;
224 final UIScrollList outputs = new UIScrollList(1, titleHeight, w-2, 80);
226 List<ScrollItem> items = new ArrayList<ScrollItem>();
227 for (final PandaDriver panda : pandaBoards) {
228 items.add(new PandaScrollItem(panda));
229 panda.setListener(new PandaDriver.Listener() {
230 public void onToggle(boolean active) {
235 outputs.setItems(items).addToContainer(this);
238 class PandaScrollItem extends AbstractScrollItem {
239 final PandaDriver panda;
240 PandaScrollItem(PandaDriver panda) {
244 public String getLabel() {
248 public boolean isSelected() {
249 return panda.isEnabled();
252 public void select() {
258 class UITempo extends UIWindow {
260 private final UIButton tempoButton;
262 UITempo(float x, float y, float w, float h) {
263 super("TEMPO", x, y, w, h);
264 tempoButton = new UIButton(4, titleHeight, w-10, 20) {
265 protected void onToggle(boolean active) {
270 }.setMomentary(true);
271 tempoButton.addToContainer(this);
275 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
278 // Overlay tempo thing with openGL, redraw faster than button UI
279 fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
281 rect(x + 8, y + titleHeight + 5, 12, 12);
285 class UIMapping extends UIWindow {
287 private static final String MAP_MODE_ALL = "ALL";
288 private static final String MAP_MODE_CHANNEL = "CHNL";
289 private static final String MAP_MODE_CUBE = "CUBE";
291 private static final String CUBE_MODE_ALL = "ALL";
292 private static final String CUBE_MODE_STRIP = "SNGL";
293 private static final String CUBE_MODE_PATTERN = "PTRN";
295 private final MappingTool mappingTool;
297 private final UIIntegerBox channelBox;
298 private final UIIntegerBox cubeBox;
299 private final UIIntegerBox stripBox;
301 UIMapping(MappingTool tool, float x, float y, float w, float h) {
302 super("MAPPING", x, y, w, h);
305 int yp = titleHeight;
306 new UIToggleSet(4, yp, w-10, 20) {
307 protected void onToggle(String value) {
308 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
309 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
310 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
312 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
314 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
316 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
317 protected void onValueChange(int value) {
318 mappingTool.setChannel(value-1);
320 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
323 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
325 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
326 protected void onValueChange(int value) {
327 mappingTool.setCube(value-1);
329 }).setRange(1, glucose.model.cubes.size()).addToContainer(this);
332 new UILabel(4, yp+8, w-10, 20).setLabel("COLORS").addToContainer(this);
335 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] {
336 new ColorScrollItem(ColorScrollItem.COLOR_RED),
337 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
338 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
339 })).addToContainer(this);
342 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
345 new UIToggleSet(4, yp, w-10, 20) {
346 protected void onToggle(String value) {
347 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
348 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
349 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
351 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
354 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
357 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
358 protected void onValueChange(int value) {
359 mappingTool.setStrip(value-1);
361 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
365 public void setChannelID(int value) {
366 channelBox.setValue(value);
369 public void setCubeID(int value) {
370 cubeBox.setValue(value);
373 public void setStripID(int value) {
374 stripBox.setValue(value);
377 class ColorScrollItem extends AbstractScrollItem {
379 public static final int COLOR_RED = 1;
380 public static final int COLOR_GREEN = 2;
381 public static final int COLOR_BLUE = 3;
383 private final int colorChannel;
385 ColorScrollItem(int colorChannel) {
386 this.colorChannel = colorChannel;
389 public String getLabel() {
390 switch (colorChannel) {
391 case COLOR_RED: return "Red";
392 case COLOR_GREEN: return "Green";
393 case COLOR_BLUE: return "Blue";
398 public boolean isSelected() {
399 switch (colorChannel) {
400 case COLOR_RED: return mappingTool.channelModeRed;
401 case COLOR_GREEN: return mappingTool.channelModeGreen;
402 case COLOR_BLUE: return mappingTool.channelModeBlue;
407 public void select() {
408 switch (colorChannel) {
409 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
410 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
411 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
417 class UIDebugText extends UIContext {
419 private String line1 = "";
420 private String line2 = "";
422 UIDebugText(float x, float y, float w, float h) {
426 public UIDebugText setText(String line1) {
427 return setText(line1, "");
430 public UIDebugText setText(String line1, String line2) {
431 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
434 setVisible(line1.length() + line2.length() > 0);
440 protected void onDraw(PGraphics pg) {
442 if (line1.length() + line2.length() > 0) {
446 pg.textFont(defaultItemFont);
447 pg.textAlign(LEFT, TOP);
449 pg.text(line1, 4, 4);
450 pg.text(line2, 4, 24);
455 String className(Object p, String suffix) {
456 String s = p.getClass().getName();
458 if ((li = s.lastIndexOf(".")) > 0) {
459 s = s.substring(li + 1);
461 if (s.indexOf("SugarCubes$") == 0) {
462 s = s.substring("SugarCubes$".length());
464 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
465 s = s.substring(0, li);