-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathMain.cpp
More file actions
239 lines (201 loc) · 8.6 KB
/
Main.cpp
File metadata and controls
239 lines (201 loc) · 8.6 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
/*==============================================================================
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.
==============================================================================*/
#include <juce_gui_basics/juce_gui_basics.h>
#include "MainComponent.h"
#include "Validator.h"
#include "CommandLine.h"
#include "PluginvalLookAndFeel.h"
#if PLUGINVAL_VST3_VALIDATOR
#include "vst3validator/VST3ValidatorRunner.h"
#include <cstring>
#include <iostream>
#endif
//==============================================================================
class PluginValidatorApplication : public juce::JUCEApplication,
private juce::AsyncUpdater
{
public:
//==============================================================================
PluginValidatorApplication() = default;
juce::PropertiesFile& getAppPreferences()
{
jassert (propertiesFile); // Calling this from the child process?
return *propertiesFile;
}
//==============================================================================
const juce::String getApplicationName() override { return "pluginval"; }
const juce::String getApplicationVersion() override { return VERSION; }
bool moreThanOneInstanceAllowed() override { return true; }
//==============================================================================
void initialise (const juce::String& commandLine) override
{
if (shouldPerformCommandLine (commandLine))
{
triggerAsyncUpdate();
return;
}
#if JUCE_DEBUG
juce::UnitTestRunner testRunner;
testRunner.runTestsInCategory ("pluginval");
#endif
juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
validator = std::make_unique<Validator>();
propertiesFile.reset (getPropertiesFile());
mainWindow = std::make_unique<MainWindow> (*validator, getApplicationName() + " v" + getApplicationVersion());
}
void shutdown() override
{
mainWindow.reset();
validator.reset();
juce::LookAndFeel::setDefaultLookAndFeel (nullptr);
juce::Logger::setCurrentLogger (nullptr);
}
//==============================================================================
void systemRequestedQuit() override
{
// This is called when the app is being asked to quit: you can ignore this
// request and let the app carry on running, or call quit() to allow the app to close.
quit();
}
void anotherInstanceStarted (const juce::String&) override
{
// When another instance of the app is launched while this one is running,
// this method is invoked, and the commandLine parameter tells you what
// the other instance's command-line arguments were.
}
//==============================================================================
/*
This class implements the desktop window that contains an instance of
our MainComponent class.
*/
class MainWindow : public juce::DocumentWindow
{
public:
MainWindow (Validator& v, juce::String name)
: DocumentWindow (name,
juce::Desktop::getInstance().getDefaultLookAndFeel()
.findColour (ResizableWindow::backgroundColourId),
DocumentWindow::allButtons)
{
setUsingNativeTitleBar (true);
setContentOwned (new MainComponent (v), true);
setResizable (true, false);
centreWithSize (getWidth(), getHeight());
setVisible (true);
}
void closeButtonPressed() override
{
// This is called when the user tries to close this window. Here, we'll just
// ask the app to quit when this happens, but you can change this to do
// whatever you need.
juce::JUCEApplication::getInstance()->systemRequestedQuit();
}
/* Note: Be careful if you override any DocumentWindow methods - the base
class uses a lot of them, so by overriding you might break its functionality.
It's best to do all your work in your content component instead, but if
you really have to override any DocumentWindow methods, make sure your
subclass also calls the superclass's method.
*/
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
PluginvalLookAndFeel lookAndFeel;
std::unique_ptr<Validator> validator;
std::unique_ptr<juce::PropertiesFile> propertiesFile;
std::unique_ptr<MainWindow> mainWindow;
std::unique_ptr<juce::FileLogger> fileLogger;
std::unique_ptr<CommandLineValidator> commandLineValidator;
static juce::PropertiesFile::Options getPropertiesFileOptions()
{
juce::PropertiesFile::Options opts;
opts.millisecondsBeforeSaving = 2000;
opts.storageFormat = juce::PropertiesFile::storeAsXML;
opts.applicationName = juce::String ("pluginval");
opts.filenameSuffix = ".xml";
opts.folderName = opts.applicationName;
opts.osxLibrarySubFolder = "Application Support";
// Move old settings if possible
if (! opts.getDefaultFile().exists())
{
const auto newFile = opts.getDefaultFile();
auto oldOpts = opts;
oldOpts.applicationName = oldOpts.folderName = "PluginValidator";
const auto oldFile = oldOpts.getDefaultFile();
if (oldFile.existsAsFile())
{
oldFile.getParentDirectory().copyDirectoryTo (newFile.getParentDirectory());
newFile.getParentDirectory().getChildFile (oldFile.getFileName()).moveFileTo (newFile);
oldFile.getParentDirectory().deleteRecursively();
}
}
return opts;
}
static juce::PropertiesFile* getPropertiesFile()
{
auto opts = getPropertiesFileOptions();
return new juce::PropertiesFile (opts.getDefaultFile(), opts);
}
void handleAsyncUpdate() override
{
commandLineValidator = std::make_unique<CommandLineValidator>();
performCommandLine (*commandLineValidator, juce::JUCEApplication::getCommandLineParameters());
}
};
//==============================================================================
#if PLUGINVAL_VST3_VALIDATOR
// Custom main() to intercept --vst3-validator-mode before JUCE starts.
// This avoids the "Periodic events are already being generated" crash on macOS
// that occurs when JUCE's event loop conflicts with the validator subprocess.
int main (int argc, char* argv[])
{
// Check for --vst3-validator-mode before starting JUCE
for (int i = 1; i < argc; ++i)
{
if (std::strcmp (argv[i], "--vst3-validator-mode") == 0)
{
// Parse arguments for validator mode
vst3validator::Options opts;
// The plugin path should be the next argument
if (i + 1 < argc && argv[i + 1][0] != '-')
opts.pluginPath = argv[i + 1];
// Check for optional flags
for (int j = 1; j < argc; ++j)
{
if (std::strcmp (argv[j], "-e") == 0)
opts.extendedMode = true;
else if (std::strcmp (argv[j], "-v") == 0)
opts.verbose = true;
}
if (opts.pluginPath.empty())
{
std::cerr << "Error: No plugin path specified for --vst3-validator-mode\n";
return 1;
}
// Run the validator directly without JUCE
auto result = vst3validator::runValidator (opts);
std::cout << result.output;
return result.exitCode;
}
}
// Normal JUCE application startup
return juce::JUCEApplicationBase::main (argc, const_cast<const char**> (argv));
}
// Provide the JUCE application class
juce::JUCEApplicationBase* juce_CreateApplication() { return new PluginValidatorApplication(); }
#else
// Standard JUCE application macro when VST3 validator is disabled
START_JUCE_APPLICATION (PluginValidatorApplication)
#endif
juce::PropertiesFile& getAppPreferences()
{
auto app = dynamic_cast<PluginValidatorApplication*> (PluginValidatorApplication::getInstance());
return app->getAppPreferences();
}