-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginEditor.cpp
201 lines (163 loc) · 7.17 KB
/
PluginEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
==============================================================================
This file was auto-generated!
It contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
//==============================================================================
GarageLightsAudioProcessorEditor::GarageLightsAudioProcessorEditor (GarageLightsAudioProcessor& p, AudioProcessorValueTreeState& vts)
: AudioProcessorEditor (&p), processor (p), valueTreeState(vts)
{
setSize(gp.width, gp.height);
addAndMakeVisible(connectUsbButton);
connectUsbButton.setBounds(gp.consoleWidth + gp.padding*3 + gp.connectButtonWidth, gp.consoleY, gp.connectButtonWidth, (gp.consoleHeight+gp.padding)/2);
connectUsbButton.setSize(gp.connectButtonWidth, (gp.consoleHeight - gp.padding) / 2);
connectUsbButton.setLookAndFeel(&myLookAndFeel);
connectUsbButton.setButtonText("Connect USB");
connectUsbButton.addListener(this);
addAndMakeVisible(disconnectButton);
disconnectButton.setBounds(gp.consoleWidth + gp.padding * 3 + gp.connectButtonWidth, gp.consoleY + (gp.consoleHeight + gp.padding) / 2, gp.connectButtonWidth, (gp.consoleHeight + gp.padding) / 2);
disconnectButton.setSize(gp.connectButtonWidth, (gp.consoleHeight - gp.padding) / 2);
disconnectButton.setLookAndFeel(&myLookAndFeel);
disconnectButton.setButtonText("Disconnect");
disconnectButton.addListener(this);
addAndMakeVisible(blackoutButton);
blackoutButton.setBounds(gp.padding, gp.consoleY, gp.connectButtonWidth, gp.consoleHeight);
blackoutButton.setSize(gp.connectButtonWidth, gp.consoleHeight);
blackoutButton.setLookAndFeel(&myLookAndFeel);
blackoutButton.setButtonText("Blackout");
blackoutButton.addListener(this);
//Add page change buttons
addAndMakeVisible(pageLeftButton);
pageLeftButton.setSize(gp.arrowButtonWidth, gp.arrowButtonWidth);
pageLeftButton.setBounds(gp.width * 23 / 60 - gp.arrowButtonWidth/2, gp.channelSelectorY + gp.sliderLabelHeight/2 - gp.arrowButtonWidth/2, gp.arrowButtonWidth, gp.arrowButtonWidth);
pageLeftButton.addListener(this);
addAndMakeVisible(pageRightButton);
pageRightButton.setSize(gp.arrowButtonWidth, gp.arrowButtonWidth);
pageRightButton.setBounds(gp.width * 37 / 60 - gp.arrowButtonWidth / 2, gp.channelSelectorY + gp.sliderLabelHeight / 2 - gp.arrowButtonWidth / 2, gp.arrowButtonWidth, gp.arrowButtonWidth);
pageRightButton.addListener(this);
//Add color buttons
Path square;
square.addRectangle(0, 0, gp.arrowButtonWidth, gp.arrowButtonWidth);
for (int i = 0; i < NUMBER_COLORS; i++) {
colorSelectButtons.add(new ShapeButton("hello", gp.pluginFaceColours[i], gp.pluginFaceColours[i], gp.pluginFaceColours[i]));
addAndMakeVisible(colorSelectButtons[i]);
colorSelectButtons[i]->setShape(square, true, true, true);
colorSelectButtons[i]->addListener(this);
int xValue = gp.width - gp.padding * (NUMBER_COLORS + 1) - gp.arrowButtonWidth * NUMBER_COLORS + gp.arrowButtonWidth * i + gp.padding*i;
int yValue = gp.titleHeight / 2 - gp.arrowButtonWidth / 2;
colorSelectButtons[i]->setBounds(xValue, yValue, gp.arrowButtonWidth, gp.arrowButtonWidth);
}
//Add sliders
for (int slider = 0; slider < 512 ; slider++) {
//Set slider settings.
addChildComponent(dmxLevelSlider[slider]);
dmxLevelSlider[slider].setSliderStyle(Slider::SliderStyle::LinearBarVertical);
dmxLevelSliderAttachment[slider] = new SliderAttachment(valueTreeState, (String)(slider + 1), dmxLevelSlider[slider]);
//Set Slider positions.
int xValue = gp.padding * (slider%16 + 1) + gp.sliderWidth * (slider%16);
int yValue;
if (slider%32 < gp.numSliderColumns) { yValue = gp.sliderRow1Y; }
else { yValue = gp.sliderRow2Y; }
dmxLevelSlider[slider].setBounds(xValue, yValue, gp.sliderWidth, gp.sliderHeight);
}
pageChange(0);
connectAttempt = false;
}
GarageLightsAudioProcessorEditor::~GarageLightsAudioProcessorEditor()
{
}
//==============================================================================
void GarageLightsAudioProcessorEditor::paint (Graphics& g)
{
gp.drawBackground(g, processor.colourId);
gp.drawStaticText(g);
determineConnectionStatus();
gp.drawConsoleText(g, consoleText);
gp.drawChannelLabels(g, processor.channelPage);
}
void GarageLightsAudioProcessorEditor::resized()
{
// This is generally where you'll want to lay out the positions of any
// subcomponents in your editor..
}
void GarageLightsAudioProcessorEditor::buttonClicked(Button* button) {
if (button == &connectUsbButton) {
if (!processor.usbDmxPro->connected) {
processor.usbDmxPro->connect();
connectAttempt = true;
}
}
else if (button == &pageLeftButton) {
pageChange(-1);
}
else if (button == &pageRightButton) {
pageChange(1);
}
else if (button == &blackoutButton) {
if (blackoutButton.getToggleState()) {
blackoutButton.setToggleState(false, juce::NotificationType::dontSendNotification);
processor.blackout = false;
}
else {
blackoutButton.setToggleState(true, juce::NotificationType::dontSendNotification);
processor.blackout = true;
}
}
else if (button == &disconnectButton) {
processor.usbDmxPro->disconnect();
}
for (int i = 0; i < NUMBER_COLORS; i++) {
if (button == colorSelectButtons[i]) {
processor.colourId = i;
}
}
repaint();
}
void GarageLightsAudioProcessorEditor::pageChange(int direction) {
//Turn off visiblility for the current page's sliders.
int startingChannel = (processor.channelPage - 1) * 32 + 1;
for (int slider = startingChannel; slider < startingChannel + 32; slider++) {
dmxLevelSlider[slider - 1].setVisible(false);
}
//Update channel page.
processor.channelPage += direction;
if (processor.channelPage < 1) {
processor.channelPage = 16;
}
if (processor.channelPage > 16) {
processor.channelPage = 1;
}
//Turn on visibility for the new page's sliders.
startingChannel = (processor.channelPage - 1) * 32 + 1;
for (int slider = startingChannel; slider < startingChannel + 32; slider++) {
dmxLevelSlider[slider - 1].setVisible(true);
}
repaint();
}
void GarageLightsAudioProcessorEditor::determineConnectionStatus() {
if (connectAttempt) {
if (processor.usbDmxPro->connected) {
connectUsbButton.setButtonText("Connected");
}
else {
connectUsbButton.setButtonText("Connect USB");
consoleText = "Connection failed.\nMake sure you have an Open DMX compatible device.\nTry disconnecting, then connecting again.";
}
}
connectAttempt = false;
if (processor.usbDmxPro->connected) {
consoleText = processor.usbDmxPro->getConnectionInfoString();
}
else if (processor.usbDmxPro->numDevices == 0) {
consoleText = "No connection.\nCould not find any compatible devices.\nPlease connect a USB Dmx pro compatible device and retry.\nMake sure your FTDI driver is installed.";
}
else if (processor.usbDmxPro->numDevices == 1) {
consoleText = "No connection.\nFound a compatible device!\nClick 'Connect USB' to attempt connection";
}
else {
consoleText = "No connection.\nFound " + (String)processor.usbDmxPro->numDevices + " compatible devices.\nPlease disconnect all devices except the one you wish to use.\nAttempting connection with multiple devices available will connect to a random device.";
}
}