diff --git a/include/util/common.hpp b/include/util/common.hpp index 4f392459..2856abdc 100644 --- a/include/util/common.hpp +++ b/include/util/common.hpp @@ -150,7 +150,8 @@ void openBrowser(std::string url); // logger.cpp //////////////////// -extern FILE *gLogFile; +void loggerInit(); +void loggerDestroy(); void debug(const char *format, ...); void info(const char *format, ...); void warn(const char *format, ...); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index fdacb6c4..4fd88670 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -114,6 +114,7 @@ void ModuleWidget::fromJson(json_t *rootJ) { json_t *paramJ; json_array_foreach(paramsJ, i, paramJ) { if (legacy && legacy <= 1) { + // Legacy 1 mode // The index in the array we're iterating is the index of the ParamWidget in the params vector. if (i < params.size()) { // Create upgraded version of param JSON object diff --git a/src/app/RackScene.cpp b/src/app/RackScene.cpp index 906f7bb9..01bbf71c 100644 --- a/src/app/RackScene.cpp +++ b/src/app/RackScene.cpp @@ -9,27 +9,6 @@ namespace rack { -static std::string newVersion = ""; - - -#if defined(RELEASE) -static void checkVersion() { - json_t *resJ = requestJson(METHOD_GET, gApiHost + "/version", NULL); - - if (resJ) { - json_t *versionJ = json_object_get(resJ, "version"); - if (versionJ) { - const char *version = json_string_value(versionJ); - if (version && strlen(version) > 0 && version != gApplicationVersion) { - newVersion = version; - } - } - json_decref(resJ); - } -} -#endif - - RackScene::RackScene() { scrollWidget = new RackScrollWidget(); { @@ -46,12 +25,6 @@ RackScene::RackScene() { gToolbar = new Toolbar(); addChild(gToolbar); scrollWidget->box.pos.y = gToolbar->box.size.y; - - // Check for new version -#if defined(RELEASE) - std::thread versionThread(checkVersion); - versionThread.detach(); -#endif } void RackScene::step() { @@ -68,17 +41,6 @@ void RackScene::step() { Scene::step(); zoomWidget->box.size = gRackWidget->box.size.mult(zoomWidget->zoom); - - // Version popup message - if (!newVersion.empty()) { - std::string versionMessage = stringf("Rack %s is available.\n\nYou have Rack %s.\n\nWould you like to download the new version on the website?", newVersion.c_str(), gApplicationVersion.c_str()); - if (osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, versionMessage.c_str())) { - std::thread t(openBrowser, "https://vcvrack.com/"); - t.detach(); - windowClose(); - } - newVersion = ""; - } } void RackScene::draw(NVGcontext *vg) { diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index f9e3917d..e410fb9d 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -225,8 +225,6 @@ void RackWidget::fromJson(json_t *rootJ) { json_t *versionJ = json_object_get(rootJ, "version"); if (versionJ) { version = json_string_value(versionJ); - if (!version.empty() && gApplicationVersion != version) - message += stringf("This patch was created with Rack %s. Saving it will convert it to a Rack %s patch.\n\n", version.c_str(), gApplicationVersion.c_str()); } // Detect old patches with ModuleWidget::params/inputs/outputs indices. @@ -234,6 +232,7 @@ void RackWidget::fromJson(json_t *rootJ) { int legacy = 0; if (startsWith(version, "0.3.") || startsWith(version, "0.4.") || startsWith(version, "0.5.") || version == "" || version == "dev") { legacy = 1; + message += "This patch was created with Rack 0.5 or earlier. Saving it will convert it to a Rack 0.6+ patch.\n\n"; } if (legacy) { info("Loading patch using legacy mode %d", legacy); @@ -246,9 +245,10 @@ void RackWidget::fromJson(json_t *rootJ) { size_t moduleId; json_t *moduleJ; json_array_foreach(modulesJ, moduleId, moduleJ) { - // Set legacy property - if (legacy) - json_object_set_new(moduleJ, "legacy", json_integer(legacy)); + // Add "legacy" property if in legacy mode + if (legacy) { + json_object_set(moduleJ, "legacy", json_integer(legacy)); + } json_t *pluginSlugJ = json_object_get(moduleJ, "plugin"); if (!pluginSlugJ) continue; @@ -259,7 +259,7 @@ void RackWidget::fromJson(json_t *rootJ) { Model *model = pluginGetModel(pluginSlug, modelSlug); if (!model) { - message += stringf("Could not find module \"%s\" in plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); + message += stringf("Could not find module \"%s\" of plugin \"%s\"\n", modelSlug.c_str(), pluginSlug.c_str()); continue; } @@ -292,6 +292,8 @@ void RackWidget::fromJson(json_t *rootJ) { Port *outputPort = NULL; Port *inputPort = NULL; if (legacy && legacy <= 1) { + // Legacy 1 mode + // The index of the "ports" array is the index of the Port in the `outputs` and `inputs` vector. outputPort = outputModuleWidget->outputs[outputId]; inputPort = inputModuleWidget->inputs[inputId]; } diff --git a/src/main.cpp b/src/main.cpp index 9443ebeb..bc17ecb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,11 +14,7 @@ using namespace rack; int main(int argc, char* argv[]) { randomInit(); - -#ifdef RELEASE - std::string logFilename = assetLocal("log.txt"); - gLogFile = fopen(logFilename.c_str(), "w"); -#endif + loggerInit(); info("Rack %s", gApplicationVersion.c_str()); @@ -64,10 +60,7 @@ int main(int argc, char* argv[]) { bridgeDestroy(); engineDestroy(); pluginDestroy(); - -#ifdef RELEASE - fclose(gLogFile); -#endif + loggerDestroy(); return 0; } diff --git a/src/util/logger.cpp b/src/util/logger.cpp index 1c6d8963..5d833ea4 100644 --- a/src/util/logger.cpp +++ b/src/util/logger.cpp @@ -1,49 +1,66 @@ #include "util/common.hpp" +#include "asset.hpp" #include namespace rack { -FILE *gLogFile = stderr; +static FILE *logFile = stderr; +static auto startTime = std::chrono::high_resolution_clock::now(); + + +void loggerInit() { + #ifdef RELEASE + std::string logFilename = assetLocal("log.txt"); + gLogFile = fopen(logFilename.c_str(), "w"); + #endif +} + +void loggerDestroy() { + #ifdef RELEASE + fclose(gLogFile); + #endif +} + +static void printTimestamp() { +} + +static void printLog(const char *type, const char *format, va_list args) { + auto nowTime = std::chrono::high_resolution_clock::now(); + int duration = std::chrono::duration_cast(nowTime - startTime).count(); + printTimestamp(); + fprintf(logFile, "[%s %.03f] ", duration / 1000.0, type); + vfprintf(logFile, format, args); + fprintf(logFile, "\n"); + fflush(logFile); +} void debug(const char *format, ...) { va_list args; va_start(args, format); - fprintf(gLogFile, "[debug] "); - vfprintf(gLogFile, format, args); - fprintf(gLogFile, "\n"); - fflush(gLogFile); + printLog("debug", format, args); va_end(args); } void info(const char *format, ...) { va_list args; va_start(args, format); - fprintf(gLogFile, "[info] "); - vfprintf(gLogFile, format, args); - fprintf(gLogFile, "\n"); - fflush(gLogFile); + printLog("info", format, args); va_end(args); } void warn(const char *format, ...) { va_list args; va_start(args, format); - fprintf(gLogFile, "[warning] "); - vfprintf(gLogFile, format, args); - fprintf(gLogFile, "\n"); - fflush(gLogFile); + printLog("warn", format, args); va_end(args); } void fatal(const char *format, ...) { va_list args; va_start(args, format); - fprintf(gLogFile, "[fatal] "); - vfprintf(gLogFile, format, args); - fprintf(gLogFile, "\n"); - fflush(gLogFile); + printLog("fatal", format, args); va_end(args); }