-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathMain.cpp
More file actions
184 lines (153 loc) · 6.74 KB
/
Main.cpp
File metadata and controls
184 lines (153 loc) · 6.74 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
/*==============================================================================
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"
//==============================================================================
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());
}
};
//==============================================================================
START_JUCE_APPLICATION (PluginValidatorApplication)
juce::PropertiesFile& getAppPreferences()
{
auto app = dynamic_cast<PluginValidatorApplication*> (PluginValidatorApplication::getInstance());
return app->getAppPreferences();
}