-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathMainComponent.h
More file actions
255 lines (206 loc) · 6.95 KB
/
MainComponent.h
File metadata and controls
255 lines (206 loc) · 6.95 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*==============================================================================
Copyright 2018 by Tracktion Corporation.
For more information visit www.tracktion.com
You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================*/
#pragma once
#include <JuceHeader.h>
#include "PluginTestResult.h"
#include "Validator.h"
#include "CrashHandler.h"
PropertiesFile& getAppPreferences();
//==============================================================================
struct ConnectionStatus : public Component,
private ChangeListener,
private Validator::Listener
{
ConnectionStatus (Validator& v)
: validator (v)
{
validator.addListener (this);
validator.addChangeListener (this);
}
~ConnectionStatus() override
{
validator.removeListener (this);
validator.removeChangeListener (this);
}
void paint (Graphics& g) override
{
auto r = getLocalBounds().toFloat();
g.setColour ([this] {
switch (status)
{
case Status::disconnected: return Colours::darkred;
case Status::validating: return Colours::orange;
case Status::connected:
case Status::complete: return Colours::lightgreen;
}
return Colours::darkred;
}());
g.fillEllipse (r);
g.setColour (Colours::darkgrey);
g.drawEllipse (r.reduced (1.0f), 2.0f);
}
private:
enum class Status
{
disconnected,
connected,
validating,
complete
};
Validator& validator;
std::atomic<Status> status { Status::disconnected };
void setStatus (Status newStatus)
{
status = newStatus;
MessageManager::callAsync ([sp = SafePointer<Component> (this)] () mutable { if (sp != nullptr) sp->repaint(); });
}
void changeListenerCallback (ChangeBroadcaster*) override
{
setStatus (validator.isConnected() ? Status::connected : Status::disconnected);
}
void validationStarted (const String&) override
{
setStatus (Status::validating);
}
void logMessage (const String&) override
{
}
void itemComplete (const String&, int, const PluginTestResultArray&) override
{
}
void allItemsComplete() override
{
setStatus (Status::complete);
}
};
//==============================================================================
struct ConsoleComponent : public Component,
private ChangeListener,
private AsyncUpdater,
private Validator::Listener
{
ConsoleComponent (Validator& v)
: validator (v)
{
validator.addChangeListener (this);
validator.addListener (this);
addAndMakeVisible (editor);
editor.setReadOnly (true);
editor.setLineNumbersShown (false);
editor.setScrollbarThickness (8);
}
~ConsoleComponent() override
{
validator.removeChangeListener (this);
validator.removeListener (this);
}
String getLog() const
{
return codeDocument.getAllContent();
}
void clearLog()
{
codeDocument.replaceAllContent (String());
}
void resized() override
{
auto r = getLocalBounds();
editor.setBounds (r);
}
private:
Validator& validator;
CodeDocument codeDocument;
CodeEditorComponent editor { codeDocument, nullptr };
String currentID;
CriticalSection logMessagesLock;
StringArray pendingLogMessages;
void handleAsyncUpdate() override
{
StringArray logMessages;
{
const ScopedLock sl (logMessagesLock);
pendingLogMessages.swapWith (logMessages);
}
for (auto&& m : logMessages)
{
codeDocument.insertText (editor.getCaretPos(), m + "\n");
editor.scrollToKeepCaretOnScreen();
}
}
void changeListenerCallback (ChangeBroadcaster*) override
{
if (! validator.isConnected() && currentID.isNotEmpty())
{
logMessage ("\n*** FAILED: VALIDATION CRASHED");
logMessage (getCrashLog());
currentID = String();
}
}
void validationStarted (const String& id) override
{
currentID = id;
logMessage ("Started validating: " + id);
}
void logMessage (const String& m) override
{
{
const ScopedLock sl (logMessagesLock);
pendingLogMessages.add (m);
triggerAsyncUpdate();
}
std::cout << m << "\n";
}
void itemComplete (const String& id, int numFailures, const PluginTestResultArray&) override
{
logMessage ("\nFinished validating: " + id);
if (numFailures == 0)
logMessage ("ALL TESTS PASSED");
else
logMessage ("*** FAILED: " + String (numFailures) + " TESTS");
currentID = String();
}
void allItemsComplete() override
{
}
};
//==============================================================================
/*
This component lives inside our window, and this is where you should put all
your controls and content.
*/
class MainComponent : public Component,
private ChangeListener
{
public:
//==============================================================================
MainComponent (Validator&);
~MainComponent() override;
//==============================================================================
void paint (Graphics&) override;
void resized() override;
private:
//==============================================================================
Validator& validator;
AudioPluginFormatManager formatManager;
KnownPluginList knownPluginList;
TabbedComponent tabbedComponent { TabbedButtonBar::TabsAtTop };
PluginListComponent pluginListComponent { formatManager, knownPluginList,
getAppPreferences().getFile().getSiblingFile ("PluginsListDeadMansPedal"),
&getAppPreferences() };
ConsoleComponent console { validator };
TextButton testSelectedButton { "Test Selected" }, testAllButton { "Test All" }, testFileButton { "Test File" },
clearButton { "Clear Log" }, saveButton { "Save Log" }, optionsButton { "Options" };
Slider strictnessSlider;
Label strictnessLabel { {}, "Strictness Level" };
ConnectionStatus connectionStatus { validator };
void savePluginList();
void changeListenerCallback (ChangeBroadcaster*) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};