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, 140).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 UIBlendMode extends UIWindow {
90 public UIBlendMode(float x, float y, float w, float h) {
91 super("BLEND MODE", x, y, w, h);
92 List<ScrollItem> items = new ArrayList<ScrollItem>();
93 for (LXTransition t : glucose.getTransitions()) {
94 items.add(new TransitionScrollItem(t));
96 final UIScrollList tList;
97 (tList = new UIScrollList(1, titleHeight, w-2, 60)).setItems(items).addToContainer(this);
99 lx.engine.getDeck(1).addListener(new Engine.AbstractListener() {
100 public void blendTransitionDidChange(Engine.Deck deck, LXTransition transition) {
106 class TransitionScrollItem extends AbstractScrollItem {
107 private final LXTransition transition;
108 private String label;
110 TransitionScrollItem(LXTransition transition) {
111 this.transition = transition;
112 label = className(transition, "Transition");
115 public String getLabel() {
119 public boolean isSelected() {
120 return transition == glucose.getSelectedTransition();
123 public boolean isPending() {
127 public void onMousePressed() {
128 glucose.setSelectedTransition(transition);
134 class UICrossfader extends UIWindow {
136 private final UIToggleSet displayMode;
138 public UICrossfader(float x, float y, float w, float h) {
139 super("CROSSFADER", x, y, w, h);
141 new UIParameterSlider(4, titleHeight, w-9, 32).setParameter(lx.engine.getDeck(1).getCrossfader()).addToContainer(this);
142 (displayMode = new UIToggleSet(4, titleHeight + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
145 public String getDisplayMode() {
146 return displayMode.getValue();
150 class UIEffects extends UIWindow {
151 UIEffects(float x, float y, float w, float h) {
152 super("FX", x, y, w, h);
154 int yp = titleHeight;
155 List<ScrollItem> items = new ArrayList<ScrollItem>();
156 for (LXEffect fx : glucose.lx.getEffects()) {
157 items.add(new FXScrollItem(fx));
159 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
160 effectsList.addToContainer(this);
161 yp += effectsList.h + 10;
163 final UIParameterKnob[] parameterKnobs = new UIParameterKnob[4];
164 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
165 parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
166 parameterKnobs[ki].addToContainer(this);
169 GLucose.EffectListener fxListener = new GLucose.EffectListener() {
170 public void effectSelected(LXEffect effect) {
172 for (LXParameter p : effect.getParameters()) {
173 if (i >= parameterKnobs.length) {
176 parameterKnobs[i++].setParameter(p);
178 while (i < parameterKnobs.length) {
179 parameterKnobs[i++].setParameter(null);
184 glucose.addEffectListener(fxListener);
185 fxListener.effectSelected(glucose.getSelectedEffect());
189 class FXScrollItem extends AbstractScrollItem {
191 private LXEffect effect;
192 private String label;
194 FXScrollItem(LXEffect effect) {
195 this.effect = effect;
196 label = className(effect, "Effect");
199 public String getLabel() {
203 public boolean isSelected() {
204 return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
207 public boolean isPending() {
208 return effect.isEnabled();
211 public void onMousePressed() {
212 if (glucose.getSelectedEffect() == effect) {
213 if (effect.isMomentary()) {
219 glucose.setSelectedEffect(effect);
223 public void onMouseReleased() {
224 if (effect.isMomentary()) {
233 class UIOutput extends UIWindow {
234 public UIOutput(float x, float y, float w, float h) {
235 super("OUTPUT", x, y, w, h);
236 float yp = titleHeight;
238 final UIScrollList outputs = new UIScrollList(1, titleHeight, w-2, 80);
240 List<ScrollItem> items = new ArrayList<ScrollItem>();
241 for (final PandaDriver panda : pandaBoards) {
242 items.add(new PandaScrollItem(panda));
243 panda.setListener(new PandaDriver.Listener() {
244 public void onToggle(boolean active) {
249 outputs.setItems(items).addToContainer(this);
252 class PandaScrollItem extends AbstractScrollItem {
253 final PandaDriver panda;
254 PandaScrollItem(PandaDriver panda) {
258 public String getLabel() {
262 public boolean isSelected() {
263 return panda.isEnabled();
266 public void onMousePressed() {
272 class UITempo extends UIWindow {
274 private final UIButton tempoButton;
276 UITempo(float x, float y, float w, float h) {
277 super("TEMPO", x, y, w, h);
278 tempoButton = new UIButton(4, titleHeight, w-10, 20) {
279 protected void onToggle(boolean active) {
284 }.setMomentary(true);
285 tempoButton.addToContainer(this);
289 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
292 // Overlay tempo thing with openGL, redraw faster than button UI
293 fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
295 rect(x + 8, y + titleHeight + 5, 12, 12);
299 class UIMapping extends UIWindow {
301 private static final String MAP_MODE_ALL = "ALL";
302 private static final String MAP_MODE_CHANNEL = "CHNL";
303 private static final String MAP_MODE_CUBE = "CUBE";
305 private static final String CUBE_MODE_ALL = "ALL";
306 private static final String CUBE_MODE_STRIP = "SNGL";
307 private static final String CUBE_MODE_PATTERN = "PTRN";
309 private final MappingTool mappingTool;
311 private final UIIntegerBox channelBox;
312 private final UIIntegerBox cubeBox;
313 private final UIIntegerBox stripBox;
315 UIMapping(MappingTool tool, float x, float y, float w, float h) {
316 super("MAPPING", x, y, w, h);
319 int yp = titleHeight;
320 new UIToggleSet(4, yp, w-10, 20) {
321 protected void onToggle(String value) {
322 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
323 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
324 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
326 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
328 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
330 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
331 protected void onValueChange(int value) {
332 mappingTool.setChannel(value-1);
334 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
337 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
339 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
340 protected void onValueChange(int value) {
341 mappingTool.setCube(value-1);
343 }).setRange(1, glucose.model.cubes.size()).addToContainer(this);
348 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] {
349 new ColorScrollItem(ColorScrollItem.COLOR_RED),
350 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
351 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
352 })).addToContainer(this);
355 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
358 new UIToggleSet(4, yp, w-10, 20) {
359 protected void onToggle(String value) {
360 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
361 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
362 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
364 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
367 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
370 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
371 protected void onValueChange(int value) {
372 mappingTool.setStrip(value-1);
374 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
378 public void setChannelID(int value) {
379 channelBox.setValue(value);
382 public void setCubeID(int value) {
383 cubeBox.setValue(value);
386 public void setStripID(int value) {
387 stripBox.setValue(value);
390 class ColorScrollItem extends AbstractScrollItem {
392 public static final int COLOR_RED = 1;
393 public static final int COLOR_GREEN = 2;
394 public static final int COLOR_BLUE = 3;
396 private final int colorChannel;
398 ColorScrollItem(int colorChannel) {
399 this.colorChannel = colorChannel;
402 public String getLabel() {
403 switch (colorChannel) {
404 case COLOR_RED: return "Red";
405 case COLOR_GREEN: return "Green";
406 case COLOR_BLUE: return "Blue";
411 public boolean isSelected() {
412 switch (colorChannel) {
413 case COLOR_RED: return mappingTool.channelModeRed;
414 case COLOR_GREEN: return mappingTool.channelModeGreen;
415 case COLOR_BLUE: return mappingTool.channelModeBlue;
420 public void onMousePressed() {
421 switch (colorChannel) {
422 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
423 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
424 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
430 class UIDebugText extends UIContext {
432 private String line1 = "";
433 private String line2 = "";
435 UIDebugText(float x, float y, float w, float h) {
439 public UIDebugText setText(String line1) {
440 return setText(line1, "");
443 public UIDebugText setText(String line1, String line2) {
444 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
447 setVisible(line1.length() + line2.length() > 0);
453 protected void onDraw(PGraphics pg) {
455 if (line1.length() + line2.length() > 0) {
459 pg.textFont(defaultItemFont);
461 pg.textAlign(LEFT, TOP);
463 pg.text(line1, 4, 4);
464 pg.text(line2, 4, 24);
469 class UISpeed extends UIWindow {
470 UISpeed(float x, float y, float w, float h) {
471 super("SPEED", x, y, w, h);
472 new UIParameterSlider(4, titleHeight, w-10, 20)
473 .setParameter(new BasicParameter("SPEED", 0.5).addListener(new LXParameter.Listener() {
474 public void onParameterChanged(LXParameter parameter) {
475 lx.setSpeed(parameter.getValuef() * 2);
477 })).addToContainer(this);
481 class UIMidi extends UIWindow {
483 private final UIToggleSet deckMode;
484 private final UIButton logMode;
486 UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) {
487 super("MIDI", x, y, w, h);
489 // Processing compiler doesn't seem to get that list of class objects also conform to interface
490 List<ScrollItem> scrollItems = new ArrayList<ScrollItem>();
491 for (SCMidiInput mc : midiEngine.getControllers()) {
494 final UIScrollList scrollList;
495 (scrollList = new UIScrollList(1, titleHeight, w-2, 100)).setItems(scrollItems).addToContainer(this);
496 (deckMode = new UIToggleSet(4, 130, 90, 20) {
497 protected void onToggle(String value) {
498 midiEngine.setFocusedDeck(value == "A" ? 0 : 1);
500 }).setOptions(new String[] { "A", "B" }).addToContainer(this);
501 (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this);
503 SCMidiInputListener listener = new SCMidiInputListener() {
504 public void onEnabled(SCMidiInput controller, boolean enabled) {
508 for (SCMidiInput mc : midiEngine.getControllers()) {
509 mc.addListener(listener);
512 midiEngine.addListener(new MidiEngineListener() {
513 public void onFocusedDeck(int deckIndex) {
514 deckMode.setValue(deckIndex == 0 ? "A" : "B");
520 public boolean logMidi() {
521 return logMode.isActive();
524 public Engine.Deck getFocusedDeck() {
525 return lx.engine.getDeck(deckMode.getValue() == "A" ? 0 : 1);
529 String className(Object p, String suffix) {
530 String s = p.getClass().getName();
532 if ((li = s.lastIndexOf(".")) > 0) {
533 s = s.substring(li + 1);
535 if (s.indexOf("SugarCubes$") == 0) {
536 s = s.substring("SugarCubes$".length());
538 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
539 s = s.substring(0, li);