X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=_UIImplementation.pde;h=9fbc8762b958de32e04711c3345dad82a38711fd;hb=344908672b7cfe1efba03f739ef945601dae1b8e;hp=03379ce81d072740ccefc56b05c700f3cd4aa6ae;hpb=1f42cce70281d4d70378a2be362f6cb2c6d5f45f;p=SugarCubes.git diff --git a/_UIImplementation.pde b/_UIImplementation.pde index 03379ce..9fbc876 100644 --- a/_UIImplementation.pde +++ b/_UIImplementation.pde @@ -10,62 +10,31 @@ * * Custom UI components using the framework. */ - -class UIPatternDeck extends UIWindow { - - Engine.Deck deck; - - public UIPatternDeck(Engine.Deck deck, String label, float x, float y, float w, float h) { - super(label, x, y, w, h); - this.deck = deck; - int yp = titleHeight; - - List items = new ArrayList(); - for (LXPattern p : deck.getPatterns()) { - items.add(new PatternScrollItem(p)); - } - final UIScrollList patternList = new UIScrollList(1, yp, w-2, 160).setItems(items); - patternList.addToContainer(this); - yp += patternList.h + 10; - - final UIParameterKnob[] parameterKnobs = new UIParameterKnob[12]; - for (int ki = 0; ki < parameterKnobs.length; ++ki) { - parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48); - parameterKnobs[ki].addToContainer(this); + +class UIBlendMode extends UIWindow { + public UIBlendMode(float x, float y, float w, float h) { + super(lx.ui, "BLEND MODE", x, y, w, h); + List items = new ArrayList(); + for (LXTransition t : glucose.getTransitions()) { + items.add(new TransitionScrollItem(t)); } - - Engine.Listener lxListener = new Engine.Listener() { - public void patternWillChange(Engine.Deck deck, LXPattern pattern, LXPattern nextPattern) { - patternList.redraw(); - } - public void patternDidChange(Engine.Deck deck, LXPattern pattern) { - patternList.redraw(); - int pi = 0; - for (LXParameter parameter : pattern.getParameters()) { - if (pi >= parameterKnobs.length) { - break; - } - parameterKnobs[pi++].setParameter(parameter); - } - while (pi < parameterKnobs.length) { - parameterKnobs[pi++].setParameter(null); - } + final UIScrollList tList; + (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this); + + lx.engine.getDeck(GLucose.RIGHT_DECK).addListener(new LXDeck.AbstractListener() { + public void faderTransitionDidChange(LXDeck deck, LXTransition transition) { + tList.redraw(); } - }; - - deck.addListener(lxListener); - lxListener.patternDidChange(deck, deck.getActivePattern()); - + }); } - - class PatternScrollItem extends AbstractScrollItem { - - private LXPattern pattern; + + class TransitionScrollItem extends UIScrollList.AbstractItem { + private final LXTransition transition; private String label; - PatternScrollItem(LXPattern pattern) { - this.pattern = pattern; - label = className(pattern, "Pattern"); + TransitionScrollItem(LXTransition transition) { + this.transition = transition; + label = className(transition, "Transition"); } public String getLabel() { @@ -73,80 +42,57 @@ class UIPatternDeck extends UIWindow { } public boolean isSelected() { - return deck.getActivePattern() == pattern; + return transition == glucose.getSelectedTransition(); } public boolean isPending() { - return deck.getNextPattern() == pattern; + return false; } - public void select() { - deck.goPattern(pattern); + public void onMousePressed() { + glucose.setSelectedTransition(transition); } } -} -class UICrossfader extends UIWindow { - - public UICrossfader(float x, float y, float w, float h) { - super("CROSSFADER", x, y, w, h); - - List items = new ArrayList(); - for (LXTransition t : transitions) { - items.add(new TransitionScrollItem(t)); - } - new UIScrollList(1, titleHeight, w-2, 120).setItems(items).addToContainer(this); - new UIParameterSlider(4, titleHeight + 126, w-10, 24).setParameter(lx.engine.getDeck(1).getCrossfader()).addToContainer(this); - new UIToggleSet(4, 182, w-10, 20) { - protected void onToggle(String value) { - displayMode = value; - } - }.setOptions(new String[] { "A", "COMP", "B" }).setValue(displayMode = "COMP").addToContainer(this); - } } -class TransitionScrollItem extends AbstractScrollItem { - private final LXTransition transition; - private String label; - - TransitionScrollItem(LXTransition transition) { - this.transition = transition; - label = className(transition, "Transition"); - } +class UICrossfader extends UIWindow { - public String getLabel() { - return label; - } + private final UIToggleSet displayMode; - public boolean isSelected() { - return transition == lx.engine.getDeck(1).getBlendTransition(); + public UICrossfader(float x, float y, float w, float h) { + super(lx.ui, "CROSSFADER", x, y, w, h); + + new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(GLucose.RIGHT_DECK).getFader()).addToContainer(this); + (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this); } - public boolean isPending() { - return false; + public UICrossfader setDisplayMode(String value) { + displayMode.setValue(value); + return this; } - public void select() { - lx.engine.getDeck(1).setBlendTransition(transition); + public String getDisplayMode() { + return displayMode.getValue(); } } class UIEffects extends UIWindow { UIEffects(float x, float y, float w, float h) { - super("FX", x, y, w, h); + super(lx.ui, "FX", x, y, w, h); - int yp = titleHeight; - List items = new ArrayList(); + int yp = UIWindow.TITLE_LABEL_HEIGHT; + List items = new ArrayList(); for (LXEffect fx : glucose.lx.getEffects()) { items.add(new FXScrollItem(fx)); } final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items); effectsList.addToContainer(this); - yp += effectsList.h + 10; + yp += effectsList.getHeight() + 10; - final UIParameterKnob[] parameterKnobs = new UIParameterKnob[4]; + final UIKnob[] parameterKnobs = new UIKnob[4]; for (int ki = 0; ki < parameterKnobs.length; ++ki) { - parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48); + parameterKnobs[ki] = new UIKnob(5 + 34*(ki % 4), yp + (ki/4) * 48); parameterKnobs[ki].addToContainer(this); } @@ -157,7 +103,9 @@ class UIEffects extends UIWindow { if (i >= parameterKnobs.length) { break; } - parameterKnobs[i++].setParameter(p); + if (p instanceof BasicParameter) { + parameterKnobs[i++].setParameter((BasicParameter) p); + } } while (i < parameterKnobs.length) { parameterKnobs[i++].setParameter(null); @@ -170,7 +118,7 @@ class UIEffects extends UIWindow { } - class FXScrollItem extends AbstractScrollItem { + class FXScrollItem extends UIScrollList.AbstractItem { private LXEffect effect; private String label; @@ -192,10 +140,6 @@ class UIEffects extends UIWindow { return effect.isEnabled(); } - public void select() { - glucose.setSelectedEffect(effect); - } - public void onMousePressed() { if (glucose.getSelectedEffect() == effect) { if (effect.isMomentary()) { @@ -203,6 +147,8 @@ class UIEffects extends UIWindow { } else { effect.toggle(); } + } else { + glucose.setSelectedEffect(effect); } } @@ -218,12 +164,12 @@ class UIEffects extends UIWindow { class UIOutput extends UIWindow { public UIOutput(float x, float y, float w, float h) { - super("OUTPUT", x, y, w, h); - float yp = titleHeight; + super(lx.ui, "OUTPUT", x, y, w, h); + float yp = UIWindow.TITLE_LABEL_HEIGHT; - final UIScrollList outputs = new UIScrollList(1, titleHeight, w-2, 80); + final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80); - List items = new ArrayList(); + List items = new ArrayList(); for (final PandaDriver panda : pandaBoards) { items.add(new PandaScrollItem(panda)); panda.setListener(new PandaDriver.Listener() { @@ -235,7 +181,7 @@ class UIOutput extends UIWindow { outputs.setItems(items).addToContainer(this); } - class PandaScrollItem extends AbstractScrollItem { + class PandaScrollItem extends UIScrollList.AbstractItem { final PandaDriver panda; PandaScrollItem(PandaDriver panda) { this.panda = panda; @@ -249,7 +195,7 @@ class UIOutput extends UIWindow { return panda.isEnabled(); } - public void select() { + public void onMousePressed() { panda.toggle(); } } @@ -260,8 +206,8 @@ class UITempo extends UIWindow { private final UIButton tempoButton; UITempo(float x, float y, float w, float h) { - super("TEMPO", x, y, w, h); - tempoButton = new UIButton(4, titleHeight, w-10, 20) { + super(lx.ui, "TEMPO", x, y, w, h); + tempoButton = new UIButton(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20) { protected void onToggle(boolean active) { if (active) { lx.tempo.tap(); @@ -269,17 +215,26 @@ class UITempo extends UIWindow { } }.setMomentary(true); tempoButton.addToContainer(this); + new UITempoBlipper(8, UIWindow.TITLE_LABEL_HEIGHT + 5, 12, 12).addToContainer(this); } - public void draw() { - tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.); - super.draw(); - - // Overlay tempo thing with openGL, redraw faster than button UI - fill(color(0, 0, 24 - 8*lx.tempo.rampf())); - noStroke(); - rect(x + 8, y + titleHeight + 5, 12, 12); + class UITempoBlipper extends UIObject { + UITempoBlipper(float x, float y, float w, float h) { + super(x, y, w, h); + } + + void onDraw(UI ui, PGraphics pg) { + tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.); + + // Overlay tempo thing with openGL, redraw faster than button UI + pg.fill(color(0, 0, 24 - 8*lx.tempo.rampf())); + pg.noStroke(); + pg.rect(0, 0, width, height); + + redraw(); + } } + } class UIMapping extends UIWindow { @@ -299,10 +254,10 @@ class UIMapping extends UIWindow { private final UIIntegerBox stripBox; UIMapping(MappingTool tool, float x, float y, float w, float h) { - super("MAPPING", x, y, w, h); + super(lx.ui, "MAPPING", x, y, w, h); mappingTool = tool; - int yp = titleHeight; + int yp = UIWindow.TITLE_LABEL_HEIGHT; new UIToggleSet(4, yp, w-10, 20) { protected void onToggle(String value) { if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; @@ -329,10 +284,9 @@ class UIMapping extends UIWindow { }).setRange(1, glucose.model.cubes.size()).addToContainer(this); yp += 24; - new UILabel(4, yp+8, w-10, 20).setLabel("COLORS").addToContainer(this); - yp += 24; - - new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] { + yp += 10; + + new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] { new ColorScrollItem(ColorScrollItem.COLOR_RED), new ColorScrollItem(ColorScrollItem.COLOR_GREEN), new ColorScrollItem(ColorScrollItem.COLOR_BLUE), @@ -374,7 +328,7 @@ class UIMapping extends UIWindow { stripBox.setValue(value); } - class ColorScrollItem extends AbstractScrollItem { + class ColorScrollItem extends UIScrollList.AbstractItem { public static final int COLOR_RED = 1; public static final int COLOR_GREEN = 2; @@ -404,7 +358,7 @@ class UIMapping extends UIWindow { return false; } - public void select() { + public void onMousePressed() { switch (colorChannel) { case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break; case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break; @@ -420,7 +374,7 @@ class UIDebugText extends UIContext { private String line2 = ""; UIDebugText(float x, float y, float w, float h) { - super(x, y, w, h); + super(lx.ui, x, y, w, h); } public UIDebugText setText(String line1) { @@ -437,13 +391,14 @@ class UIDebugText extends UIContext { return this; } - protected void onDraw(PGraphics pg) { - super.onDraw(pg); + protected void onDraw(UI ui, PGraphics pg) { + super.onDraw(ui, pg); if (line1.length() + line2.length() > 0) { pg.noStroke(); pg.fill(#444444); - pg.rect(0, 0, w, h); - pg.textFont(defaultItemFont); + pg.rect(0, 0, width, height); + pg.textFont(ui.getItemFont()); + pg.textSize(10); pg.textAlign(LEFT, TOP); pg.fill(#cccccc); pg.text(line1, 4, 4); @@ -452,6 +407,70 @@ class UIDebugText extends UIContext { } } +class UISpeed extends UIWindow { + + final BasicParameter speed; + + UISpeed(float x, float y, float w, float h) { + super(lx.ui, "SPEED", x, y, w, h); + speed = new BasicParameter("SPEED", 0.5); + speed.addListener(new LXParameterListener() { + public void onParameterChanged(LXParameter parameter) { + lx.setSpeed(parameter.getValuef() * 2); + } + }); + new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20).setParameter(speed).addToContainer(this); + } +} + +class UIMidi extends UIWindow { + + private final UIToggleSet deckMode; + private final UIButton logMode; + + UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) { + super(lx.ui, "MIDI", x, y, w, h); + + // Processing compiler doesn't seem to get that list of class objects also conform to interface + List scrollItems = new ArrayList(); + for (SCMidiInput mc : midiEngine.getControllers()) { + scrollItems.add(mc); + } + final UIScrollList scrollList; + (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this); + (deckMode = new UIToggleSet(4, 130, 90, 20) { + protected void onToggle(String value) { + midiEngine.setFocusedDeck(value == "A" ? 0 : 1); + } + }).setOptions(new String[] { "A", "B" }).addToContainer(this); + (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this); + + SCMidiInputListener listener = new SCMidiInputListener() { + public void onEnabled(SCMidiInput controller, boolean enabled) { + scrollList.redraw(); + } + }; + for (SCMidiInput mc : midiEngine.getControllers()) { + mc.addListener(listener); + } + + midiEngine.addListener(new MidiEngineListener() { + public void onFocusedDeck(int deckIndex) { + deckMode.setValue(deckIndex == 0 ? "A" : "B"); + } + }); + + } + + public boolean logMidi() { + return logMode.isActive(); + } + + public LXDeck getFocusedDeck() { + return lx.engine.getDeck(deckMode.getValue() == "A" ? GLucose.LEFT_DECK : GLucose.RIGHT_DECK); + } +} + String className(Object p, String suffix) { String s = p.getClass().getName(); int li;