Commit | Line | Data |
---|---|---|
d626bc9b MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
11 | * Custom UI components using the framework. | |
12 | */ | |
13 | ||
14 | class UIPatternDeck extends UIWindow { | |
15 | ||
16 | Engine.Deck deck; | |
17 | ||
18 | public UIPatternDeck(Engine.Deck deck, String label, float x, float y, float w, float h) { | |
19 | super(label, x, y, w, h); | |
20 | this.deck = deck; | |
21 | int yp = titleHeight; | |
22 | ||
23 | List<ScrollItem> items = new ArrayList<ScrollItem>(); | |
24 | for (LXPattern p : deck.getPatterns()) { | |
25 | items.add(new PatternScrollItem(p)); | |
26 | } | |
27 | final UIScrollList patternList = new UIScrollList(1, yp, w-2, 160).setItems(items); | |
28 | patternList.addToContainer(this); | |
29 | yp += patternList.h + 10; | |
30 | ||
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); | |
35 | } | |
36 | ||
37 | Engine.Listener lxListener = new Engine.Listener() { | |
38 | public void patternWillChange(Engine.Deck deck, LXPattern pattern, LXPattern nextPattern) { | |
39 | patternList.redraw(); | |
40 | } | |
41 | public void patternDidChange(Engine.Deck deck, LXPattern pattern) { | |
42 | patternList.redraw(); | |
43 | int pi = 0; | |
44 | for (LXParameter parameter : pattern.getParameters()) { | |
45 | if (pi >= parameterKnobs.length) { | |
46 | break; | |
47 | } | |
48 | parameterKnobs[pi++].setParameter(parameter); | |
49 | } | |
50 | while (pi < parameterKnobs.length) { | |
51 | parameterKnobs[pi++].setParameter(null); | |
52 | } | |
53 | } | |
54 | }; | |
55 | ||
56 | deck.addListener(lxListener); | |
57 | lxListener.patternDidChange(deck, deck.getActivePattern()); | |
58 | ||
59 | } | |
60 | ||
61 | class PatternScrollItem extends AbstractScrollItem { | |
62 | ||
63 | private LXPattern pattern; | |
64 | private String label; | |
65 | ||
66 | PatternScrollItem(LXPattern pattern) { | |
67 | this.pattern = pattern; | |
68 | label = className(pattern, "Pattern"); | |
69 | } | |
70 | ||
71 | public String getLabel() { | |
72 | return label; | |
73 | } | |
74 | ||
75 | public boolean isSelected() { | |
76 | return deck.getActivePattern() == pattern; | |
77 | } | |
78 | ||
79 | public boolean isPending() { | |
80 | return deck.getNextPattern() == pattern; | |
81 | } | |
82 | ||
83 | public void select() { | |
84 | deck.goPattern(pattern); | |
85 | } | |
86 | } | |
87 | } | |
88 | ||
89 | class UICrossfader extends UIWindow { | |
90 | ||
91 | public UICrossfader(float x, float y, float w, float h) { | |
92 | super("CROSSFADER", x, y, w, h); | |
93 | ||
94 | List<ScrollItem> items = new ArrayList<ScrollItem>(); | |
95 | for (LXTransition t : transitions) { | |
96 | items.add(new TransitionScrollItem(t)); | |
97 | } | |
fe30b226 MS |
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) { | |
d626bc9b MS |
101 | protected void onToggle(String value) { |
102 | displayMode = value; | |
103 | } | |
104 | }.setOptions(new String[] { "A", "COMP", "B" }).setValue(displayMode = "COMP").addToContainer(this); | |
105 | } | |
106 | } | |
107 | ||
108 | class TransitionScrollItem extends AbstractScrollItem { | |
109 | private final LXTransition transition; | |
110 | private String label; | |
111 | ||
112 | TransitionScrollItem(LXTransition transition) { | |
113 | this.transition = transition; | |
114 | label = className(transition, "Transition"); | |
115 | } | |
116 | ||
117 | public String getLabel() { | |
118 | return label; | |
119 | } | |
120 | ||
121 | public boolean isSelected() { | |
122 | return transition == lx.engine.getDeck(1).getBlendTransition(); | |
123 | } | |
124 | ||
125 | public boolean isPending() { | |
126 | return false; | |
127 | } | |
128 | ||
129 | public void select() { | |
130 | lx.engine.getDeck(1).setBlendTransition(transition); | |
131 | } | |
132 | } | |
133 | ||
134 | class UIEffects extends UIWindow { | |
135 | UIEffects(float x, float y, float w, float h) { | |
136 | super("FX", x, y, w, h); | |
137 | ||
138 | int yp = titleHeight; | |
139 | List<ScrollItem> items = new ArrayList<ScrollItem>(); | |
140 | for (LXEffect fx : glucose.lx.getEffects()) { | |
141 | items.add(new FXScrollItem(fx)); | |
142 | } | |
143 | final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items); | |
144 | effectsList.addToContainer(this); | |
145 | yp += effectsList.h + 10; | |
146 | ||
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); | |
151 | } | |
152 | ||
153 | GLucose.EffectListener fxListener = new GLucose.EffectListener() { | |
154 | public void effectSelected(LXEffect effect) { | |
155 | int i = 0; | |
156 | for (LXParameter p : effect.getParameters()) { | |
157 | if (i >= parameterKnobs.length) { | |
158 | break; | |
159 | } | |
160 | parameterKnobs[i++].setParameter(p); | |
161 | } | |
162 | while (i < parameterKnobs.length) { | |
163 | parameterKnobs[i++].setParameter(null); | |
164 | } | |
165 | } | |
166 | }; | |
167 | ||
168 | glucose.addEffectListener(fxListener); | |
169 | fxListener.effectSelected(glucose.getSelectedEffect()); | |
170 | ||
171 | } | |
172 | ||
173 | class FXScrollItem extends AbstractScrollItem { | |
174 | ||
175 | private LXEffect effect; | |
176 | private String label; | |
177 | ||
178 | FXScrollItem(LXEffect effect) { | |
179 | this.effect = effect; | |
180 | label = className(effect, "Effect"); | |
181 | } | |
182 | ||
183 | public String getLabel() { | |
184 | return label; | |
185 | } | |
186 | ||
187 | public boolean isSelected() { | |
188 | return !effect.isEnabled() && (glucose.getSelectedEffect() == effect); | |
189 | } | |
190 | ||
191 | public boolean isPending() { | |
192 | return effect.isEnabled(); | |
193 | } | |
194 | ||
195 | public void select() { | |
196 | glucose.setSelectedEffect(effect); | |
197 | } | |
198 | ||
199 | public void onMousePressed() { | |
200 | if (glucose.getSelectedEffect() == effect) { | |
201 | if (effect.isMomentary()) { | |
202 | effect.enable(); | |
203 | } else { | |
204 | effect.toggle(); | |
205 | } | |
206 | } | |
207 | } | |
208 | ||
209 | public void onMouseReleased() { | |
210 | if (effect.isMomentary()) { | |
211 | effect.disable(); | |
212 | } | |
213 | } | |
214 | ||
215 | } | |
216 | ||
217 | } | |
218 | ||
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; | |
223 | for (final PandaDriver panda : pandaBoards) { | |
78a44a1b | 224 | final UIButton button = new UIButton(4, yp, w-10, 20) { |
d626bc9b MS |
225 | protected void onToggle(boolean active) { |
226 | panda.setEnabled(active); | |
227 | } | |
228 | }.setLabel(panda.ip); | |
229 | button.addToContainer(this); | |
230 | panda.setListener(new PandaDriver.Listener() { | |
231 | public void onToggle(boolean active) { | |
232 | button.setActive(active); | |
233 | } | |
234 | }); | |
235 | yp += 24; | |
236 | } | |
237 | } | |
238 | } | |
239 | ||
240 | class UITempo extends UIWindow { | |
241 | ||
242 | private final UIButton tempoButton; | |
243 | ||
244 | UITempo(float x, float y, float w, float h) { | |
245 | super("TEMPO", x, y, w, h); | |
78a44a1b | 246 | tempoButton = new UIButton(4, titleHeight, w-10, 20) { |
d626bc9b MS |
247 | protected void onToggle(boolean active) { |
248 | if (active) { | |
249 | lx.tempo.tap(); | |
250 | } | |
251 | } | |
252 | }.setMomentary(true); | |
253 | tempoButton.addToContainer(this); | |
254 | } | |
255 | ||
256 | public void draw() { | |
257 | tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.); | |
258 | super.draw(); | |
259 | ||
260 | // Overlay tempo thing with openGL, redraw faster than button UI | |
261 | fill(color(0, 0, 24 - 8*lx.tempo.rampf())); | |
262 | noStroke(); | |
263 | rect(x + 8, y + titleHeight + 5, 12, 12); | |
264 | } | |
265 | } | |
266 | ||
267 | class UIMapping extends UIWindow { | |
268 | ||
269 | private static final String MAP_MODE_ALL = "ALL"; | |
270 | private static final String MAP_MODE_CHANNEL = "CHNL"; | |
271 | private static final String MAP_MODE_CUBE = "CUBE"; | |
272 | ||
273 | private static final String CUBE_MODE_ALL = "ALL"; | |
274 | private static final String CUBE_MODE_STRIP = "SNGL"; | |
275 | private static final String CUBE_MODE_PATTERN = "PTRN"; | |
276 | ||
277 | private final MappingTool mappingTool; | |
278 | ||
279 | private final UIIntegerBox channelBox; | |
280 | private final UIIntegerBox cubeBox; | |
281 | private final UIIntegerBox stripBox; | |
282 | ||
283 | UIMapping(MappingTool tool, float x, float y, float w, float h) { | |
284 | super("MAPPING", x, y, w, h); | |
285 | mappingTool = tool; | |
286 | ||
287 | int yp = titleHeight; | |
78a44a1b | 288 | new UIToggleSet(4, yp, w-10, 20) { |
d626bc9b MS |
289 | protected void onToggle(String value) { |
290 | if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; | |
291 | else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; | |
292 | else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; | |
293 | } | |
294 | }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this); | |
295 | yp += 24; | |
78a44a1b | 296 | new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this); |
d626bc9b | 297 | yp += 24; |
78a44a1b | 298 | (channelBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
299 | protected void onValueChange(int value) { |
300 | mappingTool.setChannel(value-1); | |
301 | } | |
302 | }).setRange(1, mappingTool.numChannels()).addToContainer(this); | |
303 | yp += 24; | |
304 | ||
78a44a1b | 305 | new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this); |
d626bc9b | 306 | yp += 24; |
78a44a1b | 307 | (cubeBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
308 | protected void onValueChange(int value) { |
309 | mappingTool.setCube(value-1); | |
310 | } | |
311 | }).setRange(1, glucose.model.cubes.size()).addToContainer(this); | |
312 | yp += 24; | |
313 | ||
78a44a1b | 314 | new UILabel(4, yp+8, w-10, 20).setLabel("COLORS").addToContainer(this); |
d626bc9b MS |
315 | yp += 24; |
316 | ||
317 | new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] { | |
318 | new ColorScrollItem(ColorScrollItem.COLOR_RED), | |
319 | new ColorScrollItem(ColorScrollItem.COLOR_GREEN), | |
320 | new ColorScrollItem(ColorScrollItem.COLOR_BLUE), | |
321 | })).addToContainer(this); | |
322 | yp += 64; | |
323 | ||
78a44a1b | 324 | new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this); |
d626bc9b MS |
325 | yp += 24; |
326 | ||
78a44a1b | 327 | new UIToggleSet(4, yp, w-10, 20) { |
d626bc9b MS |
328 | protected void onToggle(String value) { |
329 | if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL; | |
330 | else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP; | |
331 | else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN; | |
332 | } | |
333 | }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this); | |
334 | ||
335 | yp += 24; | |
78a44a1b | 336 | new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this); |
d626bc9b MS |
337 | |
338 | yp += 24; | |
78a44a1b | 339 | (stripBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
340 | protected void onValueChange(int value) { |
341 | mappingTool.setStrip(value-1); | |
342 | } | |
343 | }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this); | |
344 | ||
345 | } | |
346 | ||
347 | public void setChannelID(int value) { | |
348 | channelBox.setValue(value); | |
349 | } | |
350 | ||
351 | public void setCubeID(int value) { | |
352 | cubeBox.setValue(value); | |
353 | } | |
354 | ||
355 | public void setStripID(int value) { | |
356 | stripBox.setValue(value); | |
357 | } | |
358 | ||
359 | class ColorScrollItem extends AbstractScrollItem { | |
360 | ||
361 | public static final int COLOR_RED = 1; | |
362 | public static final int COLOR_GREEN = 2; | |
363 | public static final int COLOR_BLUE = 3; | |
364 | ||
365 | private final int colorChannel; | |
366 | ||
367 | ColorScrollItem(int colorChannel) { | |
368 | this.colorChannel = colorChannel; | |
369 | } | |
370 | ||
371 | public String getLabel() { | |
372 | switch (colorChannel) { | |
373 | case COLOR_RED: return "Red"; | |
374 | case COLOR_GREEN: return "Green"; | |
375 | case COLOR_BLUE: return "Blue"; | |
376 | } | |
377 | return ""; | |
378 | } | |
379 | ||
380 | public boolean isSelected() { | |
381 | switch (colorChannel) { | |
382 | case COLOR_RED: return mappingTool.channelModeRed; | |
383 | case COLOR_GREEN: return mappingTool.channelModeGreen; | |
384 | case COLOR_BLUE: return mappingTool.channelModeBlue; | |
385 | } | |
386 | return false; | |
387 | } | |
388 | ||
389 | public void select() { | |
390 | switch (colorChannel) { | |
391 | case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break; | |
392 | case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break; | |
393 | case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break; | |
394 | } | |
395 | } | |
396 | } | |
397 | } | |
398 | ||
399 | class UIDebugText extends UIContext { | |
400 | ||
401 | private String line1 = ""; | |
402 | private String line2 = ""; | |
403 | ||
404 | UIDebugText(float x, float y, float w, float h) { | |
405 | super(x, y, w, h); | |
406 | } | |
407 | ||
408 | public UIDebugText setText(String line1) { | |
409 | return setText(line1, ""); | |
410 | } | |
411 | ||
412 | public UIDebugText setText(String line1, String line2) { | |
413 | if (!line1.equals(this.line1) || !line2.equals(this.line2)) { | |
414 | this.line1 = line1; | |
415 | this.line2 = line2; | |
416 | setVisible(line1.length() + line2.length() > 0); | |
417 | redraw(); | |
418 | } | |
419 | return this; | |
420 | } | |
421 | ||
422 | protected void onDraw(PGraphics pg) { | |
423 | super.onDraw(pg); | |
424 | if (line1.length() + line2.length() > 0) { | |
425 | pg.noStroke(); | |
426 | pg.fill(#444444); | |
427 | pg.rect(0, 0, w, h); | |
428 | pg.textFont(defaultItemFont); | |
429 | pg.textAlign(LEFT, TOP); | |
430 | pg.fill(#cccccc); | |
431 | pg.text(line1, 4, 4); | |
432 | pg.text(line2, 4, 24); | |
433 | } | |
434 | } | |
435 | } | |
436 | ||
437 | String className(Object p, String suffix) { | |
438 | String s = p.getClass().getName(); | |
439 | int li; | |
440 | if ((li = s.lastIndexOf(".")) > 0) { | |
441 | s = s.substring(li + 1); | |
442 | } | |
443 | if (s.indexOf("SugarCubes$") == 0) { | |
444 | s = s.substring("SugarCubes$".length()); | |
445 | } | |
446 | if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) { | |
447 | s = s.substring(0, li); | |
448 | } | |
449 | return s; | |
450 | } |