From 538f5589c249b92dfdba7330fd7f257b1f09de54 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Dec 2019 08:02:30 -0500 Subject: [PATCH] Make headless mode work somewhat. --- src/app.cpp | 8 ++++---- src/engine/Engine.cpp | 3 +++ src/main.cpp | 12 ++++++------ src/patch.cpp | 24 ++++++++++++++++-------- src/settings.cpp | 5 ++--- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 52a6e912..1e8a622a 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -12,11 +12,11 @@ namespace rack { void App::init() { engine = new engine::Engine; + patch = new PatchManager; if (!settings::headless) { event = new event::State; history = new history::State; window = new Window; - patch = new PatchManager; scene = new app::Scene; event->rootWidget = scene; } @@ -27,9 +27,6 @@ App::~App() { if (scene) delete scene; scene = NULL; - if (patch) - delete patch; - patch = NULL; if (event) delete event; event = NULL; @@ -39,6 +36,9 @@ App::~App() { if (window) delete window; window = NULL; + if (patch) + delete patch; + patch = NULL; if (engine) delete engine; engine = NULL; diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 0f6f2529..fb6d0d1c 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -411,14 +411,17 @@ void Engine::clear() { std::set paramHandles = internal->paramHandles; for (ParamHandle* paramHandle : paramHandles) { removeParamHandle(paramHandle); + // Don't delete paramHandle because they're owned by other things (e.g. Modules) } std::vector cables = internal->cables; for (Cable* cable : cables) { removeCable(cable); + delete cable; } std::vector modules = internal->modules; for (Module* module : modules) { removeModule(module); + delete module; } // Reset engine state internal->nextModuleId = 0; diff --git a/src/main.cpp b/src/main.cpp index d5ab0c81..c31b6349 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -185,13 +185,11 @@ int main(int argc, char* argv[]) { } #endif - if (!settings::headless) { - APP->patch->init(patchPath); - } + APP->patch->init(patchPath); 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) { INFO("Taking screenshots of all modules at %gx zoom", screenshotZoom); @@ -209,7 +207,9 @@ int main(int argc, char* argv[]) { } INFO("Destroying app"); appDestroy(); - settings::save(asset::settingsPath); + if (!settings::headless) { + settings::save(asset::settingsPath); + } // Destroy environment INFO("Destroying environment"); diff --git a/src/patch.cpp b/src/patch.cpp index 84a00bcf..eb8be637 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -55,9 +55,11 @@ void PatchManager::init(std::string path) { } 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(); path = ""; @@ -183,9 +185,11 @@ bool PatchManager::load(std::string path) { 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(); fromJson(rootJ); return true; @@ -255,7 +259,9 @@ json_t* PatchManager::toJson() { json_object_set_new(rootJ, "version", versionJ); json_t* engineJ = APP->engine->toJson(); - APP->scene->rack->mergeJson(engineJ); + if (!settings::headless) { + APP->scene->rack->mergeJson(engineJ); + } // Merge with rootJ json_object_update(rootJ, engineJ); @@ -289,7 +295,9 @@ void PatchManager::fromJson(json_t* 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. // TODO Assert this diff --git a/src/settings.cpp b/src/settings.cpp index 0fad8abe..b46d4977 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -81,9 +81,8 @@ json_t* toJson() { 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()));