forked from Tracktion/pluginval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainComponent.h
More file actions
255 lines (206 loc) · 7.2 KB
/
MainComponent.h
File metadata and controls
255 lines (206 loc) · 7.2 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 "juce_gui_extra/juce_gui_extra.h"
#include "Validator.h"
#include "CrashHandler.h"
juce::PropertiesFile& getAppPreferences();
//==============================================================================
struct ConnectionState : public juce::Component,
private juce::ChangeListener,
private Validator::Listener
{
ConnectionState (Validator& v)
: validator (v)
{
validator.addListener (this);
validator.addChangeListener (this);
}
~ConnectionState() override
{
validator.removeListener (this);
validator.removeChangeListener (this);
}
void paint (juce::Graphics& g) override
{
auto r = getLocalBounds().toFloat();
g.setColour ([this] {
switch (state)
{
case State::disconnected: return juce::Colours::darkred;
case State::validating: return juce::Colours::orange;
case State::connected:
case State::complete: return juce::Colours::lightgreen;
}
return juce::Colours::darkred;
}());
g.fillEllipse (r);
g.setColour (juce::Colours::darkgrey);
g.drawEllipse (r.reduced (1.0f), 2.0f);
}
private:
enum class State
{
disconnected,
connected,
validating,
complete
};
Validator& validator;
std::atomic<State> state { State::disconnected };
void setState (State newStatus)
{
state = newStatus;
juce::MessageManager::callAsync ([sp = SafePointer<Component> (this)] () mutable { if (sp != nullptr) sp->repaint(); });
}
void changeListenerCallback (juce::ChangeBroadcaster*) override
{
setState (validator.isConnected() ? State::connected : State::disconnected);
}
void validationStarted (const juce::String&) override
{
setState (State::validating);
}
void logMessage (const juce::String&) override
{
}
void itemComplete (const juce::String&, uint32_t) override
{
}
void allItemsComplete() override
{
setState (State::complete);
}
};
//==============================================================================
struct ConsoleComponent : public juce::Component,
private juce::ChangeListener,
private juce::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);
}
juce::String getLog() const
{
return codeDocument.getAllContent();
}
void clearLog()
{
codeDocument.replaceAllContent (juce::String());
}
void resized() override
{
auto r = getLocalBounds();
editor.setBounds (r);
}
private:
Validator& validator;
juce::CodeDocument codeDocument;
juce::CodeEditorComponent editor { codeDocument, nullptr };
juce::String currentID;
juce::CriticalSection logMessagesLock;
juce::StringArray pendingLogMessages;
void handleAsyncUpdate() override
{
juce::StringArray logMessages;
{
const juce::ScopedLock sl (logMessagesLock);
pendingLogMessages.swapWith (logMessages);
}
for (auto&& m : logMessages)
{
codeDocument.insertText (editor.getCaretPos(), m);
editor.scrollToKeepCaretOnScreen();
}
}
void changeListenerCallback (juce::ChangeBroadcaster*) override
{
if (! validator.isConnected() && currentID.isNotEmpty())
{
logMessage ("\n*** FAILED: VALIDATION CRASHED\n");
logMessage (getCrashLog());
currentID = juce::String();
}
}
void validationStarted (const juce::String& id) override
{
currentID = id;
logMessage ("Started validating: " + id + "\n");
}
void logMessage (const juce::String& m) override
{
{
const juce::ScopedLock sl (logMessagesLock);
pendingLogMessages.add (m);
triggerAsyncUpdate();
}
std::cout << m;
}
void itemComplete (const juce::String& id, uint32_t exitCode) override
{
logMessage ("\nFinished validating: " + id + "\n");
if (exitCode == 0)
logMessage ("ALL TESTS PASSED\n");
else
logMessage ("*** FAILED WITH EXIT CODE: " + juce::String (exitCode) + "\n");
currentID = juce::String();
}
void allItemsComplete() override
{
logMessage ("\nFinished batch validation\n");
}
};
//==============================================================================
/*
This component lives inside our window, and this is where you should put all
your controls and content.
*/
class MainComponent : public juce::Component,
private juce::ChangeListener
{
public:
//==============================================================================
MainComponent (Validator&);
~MainComponent() override;
//==============================================================================
void paint (juce::Graphics&) override;
void resized() override;
private:
//==============================================================================
Validator& validator;
juce::AudioPluginFormatManager formatManager;
juce::KnownPluginList knownPluginList;
juce::TabbedComponent tabbedComponent { juce::TabbedButtonBar::TabsAtTop };
juce::PluginListComponent pluginListComponent { formatManager, knownPluginList,
getAppPreferences().getFile().getSiblingFile ("PluginsListDeadMansPedal"),
&getAppPreferences() };
ConsoleComponent console { validator };
juce::TextButton testSelectedButton { "Test Selected" }, testAllButton { "Test All" }, testFileButton { "Test File" },
clearButton { "Clear Log" }, saveButton { "Save Log" }, optionsButton { "Options" };
juce::Slider strictnessSlider;
juce::Label strictnessLabel { {}, "Strictness Level" };
ConnectionState connectionStatus { validator };
void savePluginList();
void changeListenerCallback (juce::ChangeBroadcaster*) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};