Browse Source

Make headless mode work somewhat.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
538f5589c2
5 changed files with 31 additions and 21 deletions
  1. +4
    -4
      src/app.cpp
  2. +3
    -0
      src/engine/Engine.cpp
  3. +6
    -6
      src/main.cpp
  4. +16
    -8
      src/patch.cpp
  5. +2
    -3
      src/settings.cpp

+ 4
- 4
src/app.cpp View File

@@ -12,11 +12,11 @@ namespace rack {


void App::init() { void App::init() {
engine = new engine::Engine; engine = new engine::Engine;
patch = new PatchManager;
if (!settings::headless) { if (!settings::headless) {
event = new event::State; event = new event::State;
history = new history::State; history = new history::State;
window = new Window; window = new Window;
patch = new PatchManager;
scene = new app::Scene; scene = new app::Scene;
event->rootWidget = scene; event->rootWidget = scene;
} }
@@ -27,9 +27,6 @@ App::~App() {
if (scene) if (scene)
delete scene; delete scene;
scene = NULL; scene = NULL;
if (patch)
delete patch;
patch = NULL;
if (event) if (event)
delete event; delete event;
event = NULL; event = NULL;
@@ -39,6 +36,9 @@ App::~App() {
if (window) if (window)
delete window; delete window;
window = NULL; window = NULL;
if (patch)
delete patch;
patch = NULL;
if (engine) if (engine)
delete engine; delete engine;
engine = NULL; engine = NULL;


+ 3
- 0
src/engine/Engine.cpp View File

@@ -411,14 +411,17 @@ void Engine::clear() {
std::set<ParamHandle*> paramHandles = internal->paramHandles; std::set<ParamHandle*> paramHandles = internal->paramHandles;
for (ParamHandle* paramHandle : paramHandles) { for (ParamHandle* paramHandle : paramHandles) {
removeParamHandle(paramHandle); removeParamHandle(paramHandle);
// Don't delete paramHandle because they're owned by other things (e.g. Modules)
} }
std::vector<Cable*> cables = internal->cables; std::vector<Cable*> cables = internal->cables;
for (Cable* cable : cables) { for (Cable* cable : cables) {
removeCable(cable); removeCable(cable);
delete cable;
} }
std::vector<Module*> modules = internal->modules; std::vector<Module*> modules = internal->modules;
for (Module* module : modules) { for (Module* module : modules) {
removeModule(module); removeModule(module);
delete module;
} }
// Reset engine state // Reset engine state
internal->nextModuleId = 0; internal->nextModuleId = 0;


+ 6
- 6
src/main.cpp View File

@@ -185,13 +185,11 @@ int main(int argc, char* argv[]) {
} }
#endif #endif


if (!settings::headless) {
APP->patch->init(patchPath);
}
APP->patch->init(patchPath);


if (settings::headless) { if (settings::headless) {
// TEMP Prove that the app doesn't crash
std::this_thread::sleep_for(std::chrono::seconds(2));
printf("Press enter to exit.\n");
getchar();
} }
else if (screenshot) { else if (screenshot) {
INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom); INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom);
@@ -209,7 +207,9 @@ int main(int argc, char* argv[]) {
} }
INFO("Destroying app"); INFO("Destroying app");
appDestroy(); appDestroy();
settings::save(asset::settingsPath);
if (!settings::headless) {
settings::save(asset::settingsPath);
}


// Destroy environment // Destroy environment
INFO("Destroying environment"); INFO("Destroying environment");


+ 16
- 8
src/patch.cpp View File

@@ -55,9 +55,11 @@ void PatchManager::init(std::string path) {
} }


void PatchManager::reset() { void PatchManager::reset() {
APP->history->clear();
APP->scene->rack->clear();
APP->scene->rackScroll->reset();
if (!settings::headless) {
APP->history->clear();
APP->scene->rack->clear();
APP->scene->rackScroll->reset();
}
APP->engine->clear(); APP->engine->clear();


path = ""; path = "";
@@ -183,9 +185,11 @@ bool PatchManager::load(std::string path) {
json_decref(rootJ); json_decref(rootJ);
}); });


APP->history->clear();
APP->scene->rack->clear();
APP->scene->rackScroll->reset();
if (!settings::headless) {
APP->history->clear();
APP->scene->rack->clear();
APP->scene->rackScroll->reset();
}
APP->engine->clear(); APP->engine->clear();
fromJson(rootJ); fromJson(rootJ);
return true; return true;
@@ -255,7 +259,9 @@ json_t* PatchManager::toJson() {
json_object_set_new(rootJ, "version", versionJ); json_object_set_new(rootJ, "version", versionJ);


json_t* engineJ = APP->engine->toJson(); json_t* engineJ = APP->engine->toJson();
APP->scene->rack->mergeJson(engineJ);
if (!settings::headless) {
APP->scene->rack->mergeJson(engineJ);
}


// Merge with rootJ // Merge with rootJ
json_object_update(rootJ, engineJ); json_object_update(rootJ, engineJ);
@@ -289,7 +295,9 @@ void PatchManager::fromJson(json_t* rootJ) {
} }


APP->engine->fromJson(rootJ); APP->engine->fromJson(rootJ);
APP->scene->rack->fromJson(rootJ);
if (!settings::headless) {
APP->scene->rack->fromJson(rootJ);
}
// At this point, ModuleWidgets and CableWidgets should own all Modules and Cables. // At this point, ModuleWidgets and CableWidgets should own all Modules and Cables.
// TODO Assert this // TODO Assert this




+ 2
- 3
src/settings.cpp View File

@@ -81,9 +81,8 @@ json_t* toJson() {


json_object_set_new(rootJ, "autosavePeriod", json_real(autosavePeriod)); json_object_set_new(rootJ, "autosavePeriod", json_real(autosavePeriod));


if (skipLoadOnLaunch) {
json_object_set_new(rootJ, "skipLoadOnLaunch", json_true());
}
if (skipLoadOnLaunch)
json_object_set_new(rootJ, "skipLoadOnLaunch", json_boolean(true));


json_object_set_new(rootJ, "patchPath", json_string(patchPath.c_str())); json_object_set_new(rootJ, "patchPath", json_string(patchPath.c_str()));




Loading…
Cancel
Save