forked from VCVRack/Rack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
106 lines (92 loc) · 2.46 KB
/
main.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
#include "util/common.hpp"
#include "engine.hpp"
#include "window.hpp"
#include "app.hpp"
#include "plugin.hpp"
#include "settings.hpp"
#include "asset.hpp"
#include "bridge.hpp"
#include "midi.hpp"
#include "rtmidi.hpp"
#include "keyboard.hpp"
#include "gamepad.hpp"
#include "util/color.hpp"
#include "osdialog.h"
#include <unistd.h>
#include "r4xh4x.hpp"
using namespace rack;
int main(int argc, char* argv[]) {
bool devMode = false;
std::string patchFile;
// Parse command line arguments
int c;
opterr = 0;
while ((c = getopt(argc, argv, "d")) != -1) {
switch (c) {
case 'd': {
devMode = true;
} break;
default: break;
}
}
if (optind < argc) {
patchFile = argv[optind];
}
// Initialize environment
randomInit();
assetInit(devMode);
loggerInit(devMode);
// Log environment
info("%s %s", gApplicationName.c_str(), gApplicationVersion.c_str());
if (devMode)
info("Development mode");
info("Global directory: %s", assetGlobal("").c_str());
info("Local directory: %s", assetLocal("").c_str());
// Initialize app
pluginInit(devMode);
engineInit();
rtmidiInit();
bridgeInit();
keyboardInit();
gamepadInit();
windowInit();
appInit(devMode);
settingsLoad(assetLocal("settings.json"));
R4xH4x r4xh4x;
r4xh4x.settingsLoad("r4xh4x.json");
if (patchFile.empty()) {
// To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded.
bool oldSkipAutosaveOnLaunch = gSkipAutosaveOnLaunch;
gSkipAutosaveOnLaunch = true;
settingsSave(assetLocal("settings.json"));
gSkipAutosaveOnLaunch = false;
if (oldSkipAutosaveOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Clear your patch and start over?")) {
gRackWidget->lastPath = "";
}
else {
// Load autosave
std::string oldLastPath = gRackWidget->lastPath;
gRackWidget->load(assetLocal("autosave.vcv"));
gRackWidget->lastPath = oldLastPath;
}
}
else {
// Load patch
gRackWidget->load(patchFile);
}
engineStart();
windowRun();
engineStop();
// Destroy namespaces
gRackWidget->save(assetLocal("autosave.vcv"));
settingsSave(assetLocal("settings.json"));
r4xh4x.settingsSave("r4xh4x.json");
appDestroy();
windowDestroy();
bridgeDestroy();
engineDestroy();
midiDestroy();
pluginDestroy();
loggerDestroy();
return 0;
}