From 34af736ee5a2c89a757fffb5700452b1291cb36d Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 3 Aug 2018 06:09:52 -0400 Subject: [PATCH] Add rack0.hpp backward compatibility header for ease of migration --- include/common.hpp | 5 +-- include/logger.hpp | 9 +--- include/math.hpp | 34 -------------- include/rack0.hpp | 75 +++++++++++++++++++++++++++++++ include/random.hpp | 9 ---- src/Core/AudioInterface.cpp | 6 +-- src/Core/MIDIToCVInterface.cpp | 2 +- src/app/ModuleWidget.cpp | 14 +++--- src/app/RackWidget.cpp | 10 ++--- src/audio.cpp | 24 +++++----- src/bridge.cpp | 46 +++++++++---------- src/main.cpp | 8 ++-- src/network.cpp | 2 +- src/plugin.cpp | 56 +++++++++++------------ src/settings.cpp | 6 +-- src/system.cpp | 4 +- src/widgets/FramebufferWidget.cpp | 2 +- src/window.cpp | 16 +++---- 18 files changed, 175 insertions(+), 153 deletions(-) create mode 100644 include/rack0.hpp diff --git a/include/common.hpp b/include/common.hpp index 95e72ec1..558da865 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -84,7 +84,7 @@ to get its size in bytes. /** C#-style property constructor Example: - Foo *foo = construct(&Foo::greeting, "Hello world"); + Foo *foo = construct(&Foo::greeting, "Hello world", &Foo::legs, 2); */ template T *construct() { @@ -120,6 +120,3 @@ DeferWrapper deferWrapper(F f) { } #define DEFER(code) auto CONCAT(_defer_, __COUNTER__) = deferWrapper([&]() code) - -/** Deprecated lowercase macro */ -#define defer(...) DEFER(__VA_ARGS__) diff --git a/include/logger.hpp b/include/logger.hpp index 75ce1c2b..0fe4b6a1 100644 --- a/include/logger.hpp +++ b/include/logger.hpp @@ -3,7 +3,7 @@ /** Example usage: - debug("error: %d", errno); + DEBUG("error: %d", errno); will print something like [0.123 debug myfile.cpp:45] error: 67 */ @@ -13,13 +13,6 @@ will print something like #define FATAL(format, ...) rack::logger::log(rack::logger::FATAL_LEVEL, __FILE__, __LINE__, format, ##__VA_ARGS__) -/** Deprecated lowercase log functions */ -#define debug(...) DEBUG(__VA_ARGS__) -#define info(...) INFO(__VA_ARGS__) -#define warn(...) WARN(__VA_ARGS__) -#define fatal(...) FATAL(__VA_ARGS__) - - namespace rack { namespace logger { diff --git a/include/math.hpp b/include/math.hpp index dfe93c05..987a13b6 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -305,39 +305,5 @@ inline Vec Vec::clampBetween(Rect bound) { inline Vec Vec::clamp2(Rect bound) {return clampBetween(bound);} -//////////////////// -// Deprecated functions -//////////////////// - -DEPRECATED inline int min(int a, int b) {return std::min(a, b);} -DEPRECATED inline int max(int a, int b) {return std::max(a, b);} -DEPRECATED inline int eucmod(int a, int base) {return eucMod(a, base);} -DEPRECATED inline bool ispow2(int n) {return isPow2(n);} -DEPRECATED inline int clamp2(int x, int a, int b) {return clampBetween(x, a, b);} -DEPRECATED inline float min(float a, float b) {return std::min(a, b);} -DEPRECATED inline float max(float a, float b) {return std::max(a, b);} -DEPRECATED inline float eucmod(float a, float base) {return eucMod(a, base);} -DEPRECATED inline float clamp2(float x, float a, float b) {return clampBetween(x, a, b);} - -DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} -DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} -DEPRECATED inline int clampi(int x, int min, int max) {return clamp(x, min, max);} -DEPRECATED inline int absi(int a) {return std::abs(a);} -DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);} -DEPRECATED inline int log2i(int n) {return log2(n);} -DEPRECATED inline bool ispow2i(int n) {return isPow2(n);} -DEPRECATED inline float absf(float x) {return std::abs(x);} -DEPRECATED inline float sgnf(float x) {return sgn(x);} -DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} -DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return isNear(a, b, epsilon);} -DEPRECATED inline float clampf(float x, float min, float max) {return clamp(x, min, max);} -DEPRECATED inline float clamp2f(float x, float min, float max) {return clampBetween(x, min, max);} -DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);} -DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return rescale(x, a, b, yMin, yMax);} -DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);} -DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);} -DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return cmult(cr, ci, ar, ai, br, bi);} - - } // namespace math } // namespace rack diff --git a/include/rack0.hpp b/include/rack0.hpp new file mode 100644 index 00000000..19e04015 --- /dev/null +++ b/include/rack0.hpp @@ -0,0 +1,75 @@ +#pragma once + +#include "rack.hpp" + + +namespace rack { + +//////////////////// +// common +//////////////////// + +/** Deprecated lowercase macro */ +#define defer(...) DEFER(__VA_ARGS__) + +//////////////////// +// math +//////////////////// + +DEPRECATED inline int min(int a, int b) {return std::min(a, b);} +DEPRECATED inline int max(int a, int b) {return std::max(a, b);} +DEPRECATED inline int eucmod(int a, int base) {return eucMod(a, base);} +DEPRECATED inline bool ispow2(int n) {return isPow2(n);} +DEPRECATED inline int clamp2(int x, int a, int b) {return clampBetween(x, a, b);} +DEPRECATED inline float min(float a, float b) {return std::min(a, b);} +DEPRECATED inline float max(float a, float b) {return std::max(a, b);} +DEPRECATED inline float eucmod(float a, float base) {return eucMod(a, base);} +DEPRECATED inline float clamp2(float x, float a, float b) {return clampBetween(x, a, b);} + +DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} +DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} +DEPRECATED inline int clampi(int x, int min, int max) {return clamp(x, min, max);} +DEPRECATED inline int absi(int a) {return std::abs(a);} +DEPRECATED inline int eucmodi(int a, int base) {return eucMod(a, base);} +DEPRECATED inline int log2i(int n) {return log2(n);} +DEPRECATED inline bool ispow2i(int n) {return isPow2(n);} +DEPRECATED inline float absf(float x) {return std::abs(x);} +DEPRECATED inline float sgnf(float x) {return sgn(x);} +DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} +DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return isNear(a, b, epsilon);} +DEPRECATED inline float clampf(float x, float min, float max) {return clamp(x, min, max);} +DEPRECATED inline float clamp2f(float x, float min, float max) {return clampBetween(x, min, max);} +DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);} +DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return rescale(x, a, b, yMin, yMax);} +DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);} +DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);} +DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return cmult(cr, ci, ar, ai, br, bi);} + +//////////////////// +// random +//////////////////// + +DEPRECATED inline float randomu32() {return random::u32();} +DEPRECATED inline float randomu64() {return random::u64();} +DEPRECATED inline float randomUniform() {return random::uniform();} +DEPRECATED inline float randomNormal() {return random::normal();} +DEPRECATED inline float randomf() {return random::uniform();} + +//////////////////// +// string +//////////////////// + +using string::stringf; + +//////////////////// +// logger +//////////////////// + +/** Deprecated lowercase log functions */ +#define debug(...) DEBUG(__VA_ARGS__) +#define info(...) INFO(__VA_ARGS__) +#define warn(...) WARN(__VA_ARGS__) +#define fatal(...) FATAL(__VA_ARGS__) + + +} // namespace rack diff --git a/include/random.hpp b/include/random.hpp index 5993259a..55c08e57 100644 --- a/include/random.hpp +++ b/include/random.hpp @@ -19,13 +19,4 @@ float normal(); } // namespace random - - -DEPRECATED inline float randomu32() {return random::u32();} -DEPRECATED inline float randomu64() {return random::u64();} -DEPRECATED inline float randomUniform() {return random::uniform();} -DEPRECATED inline float randomNormal() {return random::normal();} -DEPRECATED inline float randomf() {return random::uniform();} - - } // namespace rack diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index ff94125e..66df0ec1 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -71,7 +71,7 @@ struct AudioInterfaceIO : AudioIO { else { // Timed out, fill output with zeros memset(output, 0, frames * numOutputs * sizeof(float)); - debug("Audio Interface IO underflow"); + DEBUG("Audio Interface IO underflow"); } } @@ -171,7 +171,7 @@ void AudioInterface::step() { else { // Give up on pulling input audioIO.active = false; - debug("Audio Interface underflow"); + DEBUG("Audio Interface underflow"); } } @@ -221,7 +221,7 @@ void AudioInterface::step() { // Give up on pushing output audioIO.active = false; outputBuffer.clear(); - debug("Audio Interface underflow"); + DEBUG("Audio Interface underflow"); } } diff --git a/src/Core/MIDIToCVInterface.cpp b/src/Core/MIDIToCVInterface.cpp index d40e803d..09874087 100644 --- a/src/Core/MIDIToCVInterface.cpp +++ b/src/Core/MIDIToCVInterface.cpp @@ -166,7 +166,7 @@ struct MIDIToCVInterface : Module { } void processMessage(MidiMessage msg) { - // debug("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.note(), msg.value()); + // DEBUG("MIDI: %01x %01x %02x %02x", msg.status(), msg.channel(), msg.note(), msg.value()); switch (msg.status()) { // note off diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index b95a8508..fbbd0143 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -91,7 +91,7 @@ void ModuleWidget::fromJson(json_t *rootJ) { if (pluginJ) { pluginSlug = json_string_value(pluginJ); if (pluginSlug != model->plugin->slug) { - warn("Plugin %s does not match ModuleWidget's plugin %s.", pluginSlug.c_str(), model->plugin->slug.c_str()); + WARN("Plugin %s does not match ModuleWidget's plugin %s.", pluginSlug.c_str(), model->plugin->slug.c_str()); return; } } @@ -101,7 +101,7 @@ void ModuleWidget::fromJson(json_t *rootJ) { if (modelJ) { modelSlug = json_string_value(modelJ); if (modelSlug != model->slug) { - warn("Model %s does not match ModuleWidget's model %s.", modelSlug.c_str(), model->slug.c_str()); + WARN("Model %s does not match ModuleWidget's model %s.", modelSlug.c_str(), model->slug.c_str()); return; } } @@ -111,7 +111,7 @@ void ModuleWidget::fromJson(json_t *rootJ) { if (versionJ) { std::string version = json_string_value(versionJ); if (version != model->plugin->version) { - info("Patch created with %s version %s, using version %s.", pluginSlug.c_str(), version.c_str(), model->plugin->version.c_str()); + INFO("Patch created with %s version %s, using version %s.", pluginSlug.c_str(), version.c_str(), model->plugin->version.c_str()); } } @@ -169,7 +169,7 @@ void ModuleWidget::copyClipboard() { void ModuleWidget::pasteClipboard() { const char *moduleJson = glfwGetClipboardString(gWindow); if (!moduleJson) { - warn("Could not get text from clipboard."); + WARN("Could not get text from clipboard."); return; } @@ -180,12 +180,12 @@ void ModuleWidget::pasteClipboard() { json_decref(moduleJ); } else { - warn("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); + WARN("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); } } void ModuleWidget::load(std::string filename) { - info("Loading preset %s", filename.c_str()); + INFO("Loading preset %s", filename.c_str()); FILE *file = fopen(filename.c_str(), "r"); if (!file) { // Exit silently @@ -207,7 +207,7 @@ void ModuleWidget::load(std::string filename) { } void ModuleWidget::save(std::string filename) { - info("Saving preset %s", filename.c_str()); + INFO("Saving preset %s", filename.c_str()); json_t *moduleJ = toJson(); if (!moduleJ) return; diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 4ea61823..2f202e05 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -121,7 +121,7 @@ void RackWidget::saveAsDialog() { } void RackWidget::save(std::string filename) { - info("Saving patch %s", filename.c_str()); + INFO("Saving patch %s", filename.c_str()); json_t *rootJ = toJson(); if (!rootJ) return; @@ -136,7 +136,7 @@ void RackWidget::save(std::string filename) { } void RackWidget::load(std::string filename) { - info("Loading patch %s", filename.c_str()); + INFO("Loading patch %s", filename.c_str()); FILE *file = fopen(filename.c_str(), "r"); if (!file) { // Exit silently @@ -259,7 +259,7 @@ void RackWidget::fromJson(json_t *rootJ) { legacy = 1; } if (legacy) { - info("Loading patch using legacy mode %d", legacy); + INFO("Loading patch using legacy mode %d", legacy); } // modules @@ -386,7 +386,7 @@ ModuleWidget *RackWidget::moduleFromJson(json_t *moduleJ) { void RackWidget::pastePresetClipboard() { const char *moduleJson = glfwGetClipboardString(gWindow); if (!moduleJson) { - warn("Could not get text from clipboard."); + WARN("Could not get text from clipboard."); return; } @@ -402,7 +402,7 @@ void RackWidget::pastePresetClipboard() { json_decref(moduleJ); } else { - warn("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); + WARN("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); } } diff --git a/src/audio.cpp b/src/audio.cpp index 15efc558..176b1cb8 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -89,7 +89,7 @@ bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { return true; } catch (RtAudioError &e) { - warn("Failed to query RtAudio device: %s", e.what()); + WARN("Failed to query RtAudio device: %s", e.what()); } } } @@ -166,7 +166,7 @@ std::vector AudioIO::getSampleRates() { return sampleRates; } catch (RtAudioError &e) { - warn("Failed to query RtAudio device: %s", e.what()); + WARN("Failed to query RtAudio device: %s", e.what()); } } return {}; @@ -219,7 +219,7 @@ void AudioIO::openStream() { deviceInfo = rtAudio->getDeviceInfo(device); } catch (RtAudioError &e) { - warn("Failed to query RtAudio device: %s", e.what()); + WARN("Failed to query RtAudio device: %s", e.what()); return; } @@ -229,7 +229,7 @@ void AudioIO::openStream() { setChannels(math::clamp((int) deviceInfo.outputChannels - offset, 0, maxChannels), math::clamp((int) deviceInfo.inputChannels - offset, 0, maxChannels)); if (numOutputs == 0 && numInputs == 0) { - warn("RtAudio device %d has 0 inputs and 0 outputs", device); + WARN("RtAudio device %d has 0 inputs and 0 outputs", device); return; } @@ -255,7 +255,7 @@ void AudioIO::openStream() { } try { - info("Opening audio RtAudio device %d with %d in %d out", device, numInputs, numOutputs); + INFO("Opening audio RtAudio device %d with %d in %d out", device, numInputs, numOutputs); rtAudio->openStream( numOutputs == 0 ? NULL : &outParameters, numInputs == 0 ? NULL : &inParameters, @@ -263,16 +263,16 @@ void AudioIO::openStream() { &rtCallback, this, &options, NULL); } catch (RtAudioError &e) { - warn("Failed to open RtAudio stream: %s", e.what()); + WARN("Failed to open RtAudio stream: %s", e.what()); return; } try { - info("Starting RtAudio stream %d", device); + INFO("Starting RtAudio stream %d", device); rtAudio->startStream(); } catch (RtAudioError &e) { - warn("Failed to start RtAudio stream: %s", e.what()); + WARN("Failed to start RtAudio stream: %s", e.what()); return; } @@ -291,21 +291,21 @@ void AudioIO::closeStream() { if (rtAudio) { if (rtAudio->isStreamRunning()) { - info("Stopping RtAudio stream %d", device); + INFO("Stopping RtAudio stream %d", device); try { rtAudio->stopStream(); } catch (RtAudioError &e) { - warn("Failed to stop RtAudio stream %s", e.what()); + WARN("Failed to stop RtAudio stream %s", e.what()); } } if (rtAudio->isStreamOpen()) { - info("Closing RtAudio stream %d", device); + INFO("Closing RtAudio stream %d", device); try { rtAudio->closeStream(); } catch (RtAudioError &e) { - warn("Failed to close RtAudio stream %s", e.what()); + WARN("Failed to close RtAudio stream %s", e.what()); } } deviceInfo = RtAudio::DeviceInfo(); diff --git a/src/bridge.cpp b/src/bridge.cpp index 72328c68..828b0def 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -102,13 +102,13 @@ struct BridgeClientConnection { } void run() { - info("Bridge client connected"); + INFO("Bridge client connected"); // Check hello key uint32_t hello = -1; recv(&hello); if (hello != BRIDGE_HELLO) { - info("Bridge client protocol mismatch %x %x", hello, BRIDGE_HELLO); + INFO("Bridge client protocol mismatch %x %x", hello, BRIDGE_HELLO); return; } @@ -118,7 +118,7 @@ struct BridgeClientConnection { step(); } - info("Bridge client closed"); + INFO("Bridge client closed"); } /** Accepts a command from the client */ @@ -131,7 +131,7 @@ struct BridgeClientConnection { switch (command) { default: case NO_COMMAND: { - warn("Bridge client: bad command %d detected, closing", command); + WARN("Bridge client: bad command %d detected, closing", command); ready = false; } break; @@ -169,7 +169,7 @@ struct BridgeClientConnection { float input[BRIDGE_INPUTS * frames]; if (!recv(&input, BRIDGE_INPUTS * frames * sizeof(float))) { - debug("Failed to receive"); + DEBUG("Failed to receive"); return; } @@ -177,7 +177,7 @@ struct BridgeClientConnection { memset(&output, 0, sizeof(output)); processStream(input, output, frames); if (!send(&output, BRIDGE_OUTPUTS * frames * sizeof(float))) { - debug("Failed to send"); + DEBUG("Failed to send"); return; } // flush(); @@ -237,17 +237,17 @@ struct BridgeClientConnection { static void clientRun(int client) { - defer({ + DEFER({ #if ARCH_WIN if (shutdown(client, SD_SEND)) { - warn("Bridge client shutdown() failed"); + WARN("Bridge client shutdown() failed"); } if (closesocket(client)) { - warn("Bridge client closesocket() failed"); + WARN("Bridge client closesocket() failed"); } #else if (close(client)) { - warn("Bridge client close() failed"); + WARN("Bridge client close() failed"); } #endif }); @@ -256,7 +256,7 @@ static void clientRun(int client) { // Avoid SIGPIPE int flag = 1; if (setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &flag, sizeof(int))) { - warn("Bridge client setsockopt() failed"); + WARN("Bridge client setsockopt() failed"); return; } #endif @@ -265,12 +265,12 @@ static void clientRun(int client) { #if ARCH_WIN unsigned long blockingMode = 0; if (ioctlsocket(client, FIONBIO, &blockingMode)) { - warn("Bridge client ioctlsocket() failed"); + WARN("Bridge client ioctlsocket() failed"); return; } #else if (fcntl(client, F_SETFL, fcntl(client, F_GETFL, 0) & ~O_NONBLOCK)) { - warn("Bridge client fcntl() failed"); + WARN("Bridge client fcntl() failed"); return; } #endif @@ -286,10 +286,10 @@ static void serverConnect() { #if ARCH_WIN WSADATA wsaData; if (WSAStartup(MAKEWORD(2, 2), &wsaData)) { - warn("Bridge server WSAStartup() failed"); + WARN("Bridge server WSAStartup() failed"); return; } - defer({ + DEFER({ WSACleanup(); }); #endif @@ -308,15 +308,15 @@ static void serverConnect() { // Open socket int server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (server < 0) { - warn("Bridge server socket() failed"); + WARN("Bridge server socket() failed"); return; } - defer({ + DEFER({ if (close(server)) { - warn("Bridge server close() failed"); + WARN("Bridge server close() failed"); return; } - info("Bridge server closed"); + INFO("Bridge server closed"); }); #if ARCH_MAC || ARCH_LIN @@ -326,22 +326,22 @@ static void serverConnect() { // Bind socket to address if (bind(server, (struct sockaddr*) &addr, sizeof(addr))) { - warn("Bridge server bind() failed"); + WARN("Bridge server bind() failed"); return; } // Listen for clients if (listen(server, 20)) { - warn("Bridge server listen() failed"); + WARN("Bridge server listen() failed"); return; } - info("Bridge server started"); + INFO("Bridge server started"); // Enable non-blocking #if ARCH_WIN unsigned long blockingMode = 1; if (ioctlsocket(server, FIONBIO, &blockingMode)) { - warn("Bridge server ioctlsocket() failed"); + WARN("Bridge server ioctlsocket() failed"); return; } #else diff --git a/src/main.cpp b/src/main.cpp index 26b32363..7a32c172 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,11 +56,11 @@ int main(int argc, char* argv[]) { logger::init(devMode); // Log environment - info("%s %s", gApplicationName.c_str(), gApplicationVersion.c_str()); + INFO("%s %s", gApplicationName.c_str(), gApplicationVersion.c_str()); if (devMode) - info("Development mode"); - info("Global directory: %s", asset::global("").c_str()); - info("Local directory: %s", asset::local("").c_str()); + INFO("Development mode"); + INFO("Global directory: %s", asset::global("").c_str()); + INFO("Local directory: %s", asset::local("").c_str()); // Initialize app pluginInit(devMode); diff --git a/src/network.cpp b/src/network.cpp index 326fce9c..1a888f88 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -85,7 +85,7 @@ json_t *requestJson(Method method, std::string url, json_t *dataJ) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resText); // Perform request - // info("Requesting %s", url.c_str()); + // INFO("Requesting %s", url.c_str()); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); CURLcode res = curl_easy_perform(curl); diff --git a/src/plugin.cpp b/src/plugin.cpp index 46485846..b1643af4 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -64,7 +64,7 @@ static bool loadPlugin(std::string path) { // Check file existence if (!system::isFile(libraryFilename)) { - warn("Plugin file %s does not exist", libraryFilename.c_str()); + WARN("Plugin file %s does not exist", libraryFilename.c_str()); return false; } @@ -75,13 +75,13 @@ static bool loadPlugin(std::string path) { SetErrorMode(0); if (!handle) { int error = GetLastError(); - warn("Failed to load library %s: code %d", libraryFilename.c_str(), error); + WARN("Failed to load library %s: code %d", libraryFilename.c_str(), error); return false; } #else void *handle = dlopen(libraryFilename.c_str(), RTLD_NOW); if (!handle) { - warn("Failed to load library %s: %s", libraryFilename.c_str(), dlerror()); + WARN("Failed to load library %s: %s", libraryFilename.c_str(), dlerror()); return false; } #endif @@ -95,7 +95,7 @@ static bool loadPlugin(std::string path) { initCallback = (InitCallback) dlsym(handle, "init"); #endif if (!initCallback) { - warn("Failed to read init() symbol in %s", libraryFilename.c_str()); + WARN("Failed to read init() symbol in %s", libraryFilename.c_str()); return false; } @@ -108,7 +108,7 @@ static bool loadPlugin(std::string path) { // Reject plugin if slug already exists Plugin *oldPlugin = pluginGetPlugin(plugin->slug); if (oldPlugin) { - warn("Plugin \"%s\" is already loaded, not attempting to load it again", plugin->slug.c_str()); + WARN("Plugin \"%s\" is already loaded, not attempting to load it again", plugin->slug.c_str()); // TODO // Fix memory leak with `plugin` here return false; @@ -116,7 +116,7 @@ static bool loadPlugin(std::string path) { // Add plugin to list gPlugins.push_back(plugin); - info("Loaded plugin %s %s from %s", plugin->slug.c_str(), plugin->version.c_str(), libraryFilename.c_str()); + INFO("Loaded plugin %s %s from %s", plugin->slug.c_str(), plugin->version.c_str(), libraryFilename.c_str()); return true; } @@ -135,7 +135,7 @@ static bool syncPlugin(std::string slug, json_t *manifestJ, bool dryRun) { // Get latest version json_t *latestVersionJ = json_object_get(manifestJ, "latestVersion"); if (!latestVersionJ) { - warn("Could not get latest version of plugin %s", slug.c_str()); + WARN("Could not get latest version of plugin %s", slug.c_str()); return false; } std::string latestVersion = json_string_value(latestVersionJ); @@ -178,10 +178,10 @@ static bool syncPlugin(std::string slug, json_t *manifestJ, bool dryRun) { // Check if available json_t *availableResJ = network::requestJson(network::METHOD_GET, downloadUrl, NULL); if (!availableResJ) { - warn("Could not check whether download is available"); + WARN("Could not check whether download is available"); return false; } - defer({ + DEFER({ json_decref(availableResJ); }); json_t *successJ = json_object_get(availableResJ, "success"); @@ -190,12 +190,12 @@ static bool syncPlugin(std::string slug, json_t *manifestJ, bool dryRun) { else { downloadName = name; downloadProgress = 0.0; - info("Downloading plugin %s %s %s", slug.c_str(), latestVersion.c_str(), arch.c_str()); + INFO("Downloading plugin %s %s %s", slug.c_str(), latestVersion.c_str(), arch.c_str()); // Download zip std::string pluginDest = asset::local("plugins/" + slug + ".zip"); if (!network::requestDownload(downloadUrl, pluginDest, &downloadProgress)) { - warn("Plugin %s download was unsuccessful", slug.c_str()); + WARN("Plugin %s download was unsuccessful", slug.c_str()); return false; } @@ -226,7 +226,7 @@ static int extractZipHandle(zip_t *za, const char *dir) { zip_stat_t zs; err = zip_stat_index(za, i, 0, &zs); if (err) { - warn("zip_stat_index() failed: error %d", err); + WARN("zip_stat_index() failed: error %d", err); return err; } int nameLen = strlen(zs.name); @@ -237,7 +237,7 @@ static int extractZipHandle(zip_t *za, const char *dir) { if (zs.name[nameLen - 1] == '/') { if (mkdir(path, 0755)) { if (errno != EEXIST) { - warn("mkdir(%s) failed: error %d", path, errno); + WARN("mkdir(%s) failed: error %d", path, errno); return errno; } } @@ -245,7 +245,7 @@ static int extractZipHandle(zip_t *za, const char *dir) { else { zip_file_t *zf = zip_fopen_index(za, i, 0); if (!zf) { - warn("zip_fopen_index() failed"); + WARN("zip_fopen_index() failed"); return -1; } @@ -263,7 +263,7 @@ static int extractZipHandle(zip_t *za, const char *dir) { err = zip_fclose(zf); if (err) { - warn("zip_fclose() failed: error %d", err); + WARN("zip_fclose() failed: error %d", err); return err; } fclose(outFile); @@ -277,10 +277,10 @@ static int extractZip(const char *filename, const char *path) { int err; zip_t *za = zip_open(filename, 0, &err); if (!za) { - warn("Could not open zip %s: error %d", filename, err); + WARN("Could not open zip %s: error %d", filename, err); return err; } - defer({ + DEFER({ zip_close(za); }); @@ -294,16 +294,16 @@ static void extractPackages(std::string path) { for (std::string packagePath : system::listEntries(path)) { if (string::extension(packagePath) != "zip") continue; - info("Extracting package %s", packagePath.c_str()); + INFO("Extracting package %s", packagePath.c_str()); // Extract package if (extractZip(packagePath.c_str(), path.c_str())) { - warn("Package %s failed to extract", packagePath.c_str()); + WARN("Package %s failed to extract", packagePath.c_str()); message += string::stringf("Could not extract package %s\n", packagePath.c_str()); continue; } // Remove package if (remove(packagePath.c_str())) { - warn("Could not delete file %s: error %d", packagePath.c_str(), errno); + WARN("Could not delete file %s: error %d", packagePath.c_str(), errno); } } if (!message.empty()) { @@ -372,7 +372,7 @@ bool pluginSync(bool dryRun) { downloadProgress = 0.0; downloadName = "Updating plugins..."; } - defer({ + DEFER({ isDownloading = false; }); @@ -382,38 +382,38 @@ bool pluginSync(bool dryRun) { json_t *pluginsResJ = network::requestJson(network::METHOD_GET, gApiHost + "/plugins", pluginsReqJ); json_decref(pluginsReqJ); if (!pluginsResJ) { - warn("Request for user's plugins failed"); + WARN("Request for user's plugins failed"); return false; } - defer({ + DEFER({ json_decref(pluginsResJ); }); json_t *errorJ = json_object_get(pluginsResJ, "error"); if (errorJ) { - warn("Request for user's plugins returned an error: %s", json_string_value(errorJ)); + WARN("Request for user's plugins returned an error: %s", json_string_value(errorJ)); return false; } // Get community manifests json_t *manifestsResJ = network::requestJson(network::METHOD_GET, gApiHost + "/community/manifests", NULL); if (!manifestsResJ) { - warn("Request for community manifests failed"); + WARN("Request for community manifests failed"); return false; } - defer({ + DEFER({ json_decref(manifestsResJ); }); // Check each plugin in list of plugin slugs json_t *pluginsJ = json_object_get(pluginsResJ, "plugins"); if (!pluginsJ) { - warn("No plugins array"); + WARN("No plugins array"); return false; } json_t *manifestsJ = json_object_get(manifestsResJ, "manifests"); if (!manifestsJ) { - warn("No manifests object"); + WARN("No manifests object"); return false; } diff --git a/src/settings.cpp b/src/settings.cpp index 5e4b239b..2cc8e413 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -152,7 +152,7 @@ static void settingsFromJson(json_t *rootJ) { void settingsSave(std::string filename) { - info("Saving settings %s", filename.c_str()); + INFO("Saving settings %s", filename.c_str()); json_t *rootJ = settingsToJson(); if (rootJ) { FILE *file = fopen(filename.c_str(), "w"); @@ -166,7 +166,7 @@ void settingsSave(std::string filename) { } void settingsLoad(std::string filename) { - info("Loading settings %s", filename.c_str()); + INFO("Loading settings %s", filename.c_str()); FILE *file = fopen(filename.c_str(), "r"); if (!file) return; @@ -178,7 +178,7 @@ void settingsLoad(std::string filename) { json_decref(rootJ); } else { - warn("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); + WARN("JSON parsing error at %s %d:%d %s", error.source, error.line, error.column, error.text); } fclose(file); diff --git a/src/system.cpp b/src/system.cpp index f2e01d63..a4c013fa 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -48,13 +48,13 @@ void copyFile(std::string srcPath, std::string destPath) { FILE *source = fopen(srcPath.c_str(), "rb"); if (!source) return; - defer({ + DEFER({ fclose(source); }); FILE *dest = fopen(destPath.c_str(), "wb"); if (!dest) return; - defer({ + DEFER({ fclose(dest); }); // Copy buffer diff --git a/src/widgets/FramebufferWidget.cpp b/src/widgets/FramebufferWidget.cpp index ec5a3d00..d3e0614a 100644 --- a/src/widgets/FramebufferWidget.cpp +++ b/src/widgets/FramebufferWidget.cpp @@ -62,7 +62,7 @@ void FramebufferWidget::draw(NVGcontext *vg) { if (fbSize.isZero()) return; - // info("rendering framebuffer %f %f", fbSize.x, fbSize.y); + // INFO("rendering framebuffer %f %f", fbSize.x, fbSize.y); // Delete old one first to free up GPU memory internal->setFramebuffer(NULL); // Create a framebuffer from the main nanovg context. We will draw to this in the secondary nanovg context. diff --git a/src/window.cpp b/src/window.cpp index 76cfcfbc..08054a4c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -300,7 +300,7 @@ void dropCallback(GLFWwindow *window, int count, const char **paths) { } void errorCallback(int error, const char *description) { - warn("GLFW error %d: %s", error, description); + WARN("GLFW error %d: %s", error, description); } void renderGui() { @@ -496,7 +496,7 @@ void windowRun() { std::this_thread::sleep_for(std::chrono::duration(minTime - frameTime)); } endTime = glfwGetTime(); - // info("%lf fps", 1.0 / (endTime - startTime)); + // INFO("%lf fps", 1.0 / (endTime - startTime)); } } @@ -637,10 +637,10 @@ bool windowGetFullScreen() { Font::Font(const std::string &filename) { handle = nvgCreateFont(gVg, filename.c_str(), filename.c_str()); if (handle >= 0) { - info("Loaded font %s", filename.c_str()); + INFO("Loaded font %s", filename.c_str()); } else { - warn("Failed to load font %s", filename.c_str()); + WARN("Failed to load font %s", filename.c_str()); } } @@ -663,10 +663,10 @@ std::shared_ptr Font::load(const std::string &filename) { Image::Image(const std::string &filename) { handle = nvgCreateImage(gVg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (handle > 0) { - info("Loaded image %s", filename.c_str()); + INFO("Loaded image %s", filename.c_str()); } else { - warn("Failed to load image %s", filename.c_str()); + WARN("Failed to load image %s", filename.c_str()); } } @@ -690,10 +690,10 @@ std::shared_ptr Image::load(const std::string &filename) { SVG::SVG(const std::string &filename) { handle = nsvgParseFromFile(filename.c_str(), "px", SVG_DPI); if (handle) { - info("Loaded SVG %s", filename.c_str()); + INFO("Loaded SVG %s", filename.c_str()); } else { - warn("Failed to load SVG %s", filename.c_str()); + WARN("Failed to load SVG %s", filename.c_str()); } }