2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * Custom UI components using the framework.
14 class UIBlendMode extends UIWindow {
15 public UIBlendMode(float x, float y, float w, float h) {
16 super(lx.ui, "BLEND MODE", x, y, w, h);
17 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
18 for (LXTransition t : glucose.getTransitions()) {
19 items.add(new TransitionScrollItem(t));
21 final UIScrollList tList;
22 (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this);
24 lx.engine.getDeck(GLucose.RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
25 public void faderTransitionDidChange(LXDeck deck, LXTransition transition) {
31 class TransitionScrollItem extends UIScrollList.AbstractItem {
32 private final LXTransition transition;
35 TransitionScrollItem(LXTransition transition) {
36 this.transition = transition;
37 label = className(transition, "Transition");
40 public String getLabel() {
44 public boolean isSelected() {
45 return transition == glucose.getSelectedTransition();
48 public boolean isPending() {
52 public void onMousePressed() {
53 glucose.setSelectedTransition(transition);
59 class UICrossfader extends UIWindow {
61 private final UIToggleSet displayMode;
63 public UICrossfader(float x, float y, float w, float h) {
64 super(lx.ui, "CROSSFADER", x, y, w, h);
66 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(GLucose.RIGHT_DECK).getFader()).addToContainer(this);
67 (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
70 public UICrossfader setDisplayMode(String value) {
71 displayMode.setValue(value);
75 public String getDisplayMode() {
76 return displayMode.getValue();
80 class UIEffects extends UIWindow {
81 UIEffects(float x, float y, float w, float h) {
82 super(lx.ui, "FX", x, y, w, h);
84 int yp = UIWindow.TITLE_LABEL_HEIGHT;
85 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
86 for (LXEffect fx : glucose.lx.getEffects()) {
87 items.add(new FXScrollItem(fx));
89 final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
90 effectsList.addToContainer(this);
91 yp += effectsList.getHeight() + 10;
93 final UIKnob[] parameterKnobs = new UIKnob[4];
94 for (int ki = 0; ki < parameterKnobs.length; ++ki) {
95 parameterKnobs[ki] = new UIKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
96 parameterKnobs[ki].addToContainer(this);
99 GLucose.EffectListener fxListener = new GLucose.EffectListener() {
100 public void effectSelected(LXEffect effect) {
102 for (LXParameter p : effect.getParameters()) {
103 if (i >= parameterKnobs.length) {
106 if (p instanceof BasicParameter) {
107 parameterKnobs[i++].setParameter((BasicParameter) p);
110 while (i < parameterKnobs.length) {
111 parameterKnobs[i++].setParameter(null);
116 glucose.addEffectListener(fxListener);
117 fxListener.effectSelected(glucose.getSelectedEffect());
121 class FXScrollItem extends UIScrollList.AbstractItem {
123 private LXEffect effect;
124 private String label;
126 FXScrollItem(LXEffect effect) {
127 this.effect = effect;
128 label = className(effect, "Effect");
131 public String getLabel() {
135 public boolean isSelected() {
136 return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
139 public boolean isPending() {
140 return effect.isEnabled();
143 public void onMousePressed() {
144 if (glucose.getSelectedEffect() == effect) {
145 if (effect.isMomentary()) {
151 glucose.setSelectedEffect(effect);
155 public void onMouseReleased() {
156 if (effect.isMomentary()) {
165 class UIOutput extends UIWindow {
166 public UIOutput(GrizzlyOutput[] grizzlies, float x, float y, float w, float h) {
167 super(lx.ui, "OUTPUT", x, y, w, h);
168 float yp = UIWindow.TITLE_LABEL_HEIGHT;
170 final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80);
172 List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
173 for (GrizzlyOutput grizzly : grizzlies) {
174 items.add(new GrizzlyScrollItem(grizzly));
175 grizzly.enabled.addListener(new LXParameterListener() {
176 public void onParameterChanged(LXParameter parameter) {
181 outputs.setItems(items).addToContainer(this);
184 class GrizzlyScrollItem extends UIScrollList.AbstractItem {
185 final GrizzlyOutput output;
187 GrizzlyScrollItem(GrizzlyOutput output) {
188 this.output = output;
191 public String getLabel() {
192 return output.ipAddress;
195 public boolean isSelected() {
196 return output.enabled.isOn();
199 public void onMousePressed() {
200 output.enabled.setValue(!isSelected());
205 class UITempo extends UIWindow {
207 private final UIButton tempoButton;
209 UITempo(float x, float y, float w, float h) {
210 super(lx.ui, "TEMPO", x, y, w, h);
211 tempoButton = new UIButton(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20) {
212 protected void onToggle(boolean active) {
217 }.setMomentary(true);
218 tempoButton.addToContainer(this);
219 new UITempoBlipper(8, UIWindow.TITLE_LABEL_HEIGHT + 5, 12, 12).addToContainer(this);
222 class UITempoBlipper extends UIObject {
223 UITempoBlipper(float x, float y, float w, float h) {
227 void onDraw(UI ui, PGraphics pg) {
228 tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
230 // Overlay tempo thing with openGL, redraw faster than button UI
231 pg.fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
233 pg.rect(0, 0, width, height);
241 class UIMapping extends UIWindow {
243 private static final String MAP_MODE_ALL = "ALL";
244 private static final String MAP_MODE_CHANNEL = "CHNL";
245 private static final String MAP_MODE_CUBE = "CUBE";
247 private static final String CUBE_MODE_ALL = "ALL";
248 private static final String CUBE_MODE_STRIP = "SNGL";
249 private static final String CUBE_MODE_PATTERN = "PTRN";
251 private final MappingTool mappingTool;
253 private final UIIntegerBox channelBox;
254 private final UIIntegerBox cubeBox;
255 private final UIIntegerBox stripBox;
257 UIMapping(MappingTool tool, float x, float y, float w, float h) {
258 super(lx.ui, "MAPPING", x, y, w, h);
261 int yp = UIWindow.TITLE_LABEL_HEIGHT;
262 new UIToggleSet(4, yp, w-10, 20) {
263 protected void onToggle(String value) {
264 if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
265 else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
266 else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
268 }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
270 new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
272 (channelBox = new UIIntegerBox(4, yp, w-10, 20) {
273 protected void onValueChange(int value) {
274 mappingTool.setChannel(value-1);
276 }).setRange(1, mappingTool.numChannels()).addToContainer(this);
279 new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
281 (cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
282 protected void onValueChange(int value) {
283 mappingTool.setCube(value-1);
285 }).setRange(1, model.cubes.size()).addToContainer(this);
290 new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] {
291 new ColorScrollItem(ColorScrollItem.COLOR_RED),
292 new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
293 new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
294 })).addToContainer(this);
297 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
300 new UIToggleSet(4, yp, w-10, 20) {
301 protected void onToggle(String value) {
302 if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
303 else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
304 else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
306 }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
309 new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
312 (stripBox = new UIIntegerBox(4, yp, w-10, 20) {
313 protected void onValueChange(int value) {
314 mappingTool.setStrip(value-1);
316 }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
320 public void setChannelID(int value) {
321 channelBox.setValue(value);
324 public void setCubeID(int value) {
325 cubeBox.setValue(value);
328 public void setStripID(int value) {
329 stripBox.setValue(value);
332 class ColorScrollItem extends UIScrollList.AbstractItem {
334 public static final int COLOR_RED = 1;
335 public static final int COLOR_GREEN = 2;
336 public static final int COLOR_BLUE = 3;
338 private final int colorChannel;
340 ColorScrollItem(int colorChannel) {
341 this.colorChannel = colorChannel;
344 public String getLabel() {
345 switch (colorChannel) {
346 case COLOR_RED: return "Red";
347 case COLOR_GREEN: return "Green";
348 case COLOR_BLUE: return "Blue";
353 public boolean isSelected() {
354 switch (colorChannel) {
355 case COLOR_RED: return mappingTool.channelModeRed;
356 case COLOR_GREEN: return mappingTool.channelModeGreen;
357 case COLOR_BLUE: return mappingTool.channelModeBlue;
362 public void onMousePressed() {
363 switch (colorChannel) {
364 case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
365 case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
366 case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
372 class UIDebugText extends UIContext {
374 private String line1 = "";
375 private String line2 = "";
377 UIDebugText(float x, float y, float w, float h) {
378 super(lx.ui, x, y, w, h);
381 public UIDebugText setText(String line1) {
382 return setText(line1, "");
385 public UIDebugText setText(String line1, String line2) {
386 if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
389 setVisible(line1.length() + line2.length() > 0);
395 protected void onDraw(UI ui, PGraphics pg) {
396 super.onDraw(ui, pg);
397 if (line1.length() + line2.length() > 0) {
400 pg.rect(0, 0, width, height);
401 pg.textFont(ui.getItemFont());
403 pg.textAlign(LEFT, TOP);
405 pg.text(line1, 4, 4);
406 pg.text(line2, 4, 24);
411 class UISpeed extends UIWindow {
413 final BasicParameter speed;
415 UISpeed(float x, float y, float w, float h) {
416 super(lx.ui, "SPEED", x, y, w, h);
417 speed = new BasicParameter("SPEED", 0.5);
418 speed.addListener(new LXParameterListener() {
419 public void onParameterChanged(LXParameter parameter) {
420 lx.setSpeed(parameter.getValuef() * 2);
423 new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20).setParameter(speed).addToContainer(this);
427 class UIMidi extends UIWindow {
429 private final UIToggleSet deckMode;
430 private final UIButton logMode;
432 UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) {
433 super(lx.ui, "MIDI", x, y, w, h);
435 // Processing compiler doesn't seem to get that list of class objects also conform to interface
436 List<UIScrollList.Item> scrollItems = new ArrayList<UIScrollList.Item>();
437 for (SCMidiInput mc : midiEngine.getControllers()) {
440 final UIScrollList scrollList;
441 (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this);
442 (deckMode = new UIToggleSet(4, 130, 90, 20) {
443 protected void onToggle(String value) {
444 midiEngine.setFocusedDeck(value == "A" ? 0 : 1);
446 }).setOptions(new String[] { "A", "B" }).addToContainer(this);
447 (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this);
449 SCMidiInputListener listener = new SCMidiInputListener() {
450 public void onEnabled(SCMidiInput controller, boolean enabled) {
454 for (SCMidiInput mc : midiEngine.getControllers()) {
455 mc.addListener(listener);
458 midiEngine.addListener(new MidiEngineListener() {
459 public void onFocusedDeck(int deckIndex) {
460 deckMode.setValue(deckIndex == 0 ? "A" : "B");
466 public boolean logMidi() {
467 return logMode.isActive();
470 public LXDeck getFocusedDeck() {
471 return lx.engine.getDeck(deckMode.getValue() == "A" ? GLucose.LEFT_DECK : GLucose.RIGHT_DECK);
475 String className(Object p, String suffix) {
476 String s = p.getClass().getName();
478 if ((li = s.lastIndexOf(".")) > 0) {
479 s = s.substring(li + 1);
481 if (s.indexOf("SugarCubes$") == 0) {
482 s = s.substring("SugarCubes$".length());
484 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
485 s = s.substring(0, li);