Browse Source

Make headless mode work somewhat.

tags/v2.0.0
Andrew Belt 4 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() {
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;


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

@@ -411,14 +411,17 @@ void Engine::clear() {
std::set<ParamHandle*> 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<Cable*> cables = internal->cables;
for (Cable* cable : cables) {
removeCable(cable);
delete cable;
}
std::vector<Module*> modules = internal->modules;
for (Module* module : modules) {
removeModule(module);
delete module;
}
// Reset engine state
internal->nextModuleId = 0;


+ 6
- 6
src/main.cpp View File

@@ -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");


+ 16
- 8
src/patch.cpp View File

@@ -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



+ 2
- 3
src/settings.cpp View File

@@ -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()));



Loading…
Cancel
Save