| @@ -84,7 +84,7 @@ to get its size in bytes. | |||
| /** C#-style property constructor | |||
| Example: | |||
| Foo *foo = construct<Foo>(&Foo::greeting, "Hello world"); | |||
| Foo *foo = construct<Foo>(&Foo::greeting, "Hello world", &Foo::legs, 2); | |||
| */ | |||
| template<typename T> | |||
| T *construct() { | |||
| @@ -120,6 +120,3 @@ DeferWrapper<F> deferWrapper(F f) { | |||
| } | |||
| #define DEFER(code) auto CONCAT(_defer_, __COUNTER__) = deferWrapper([&]() code) | |||
| /** Deprecated lowercase macro */ | |||
| #define defer(...) DEFER(__VA_ARGS__) | |||
| @@ -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 { | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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"); | |||
| } | |||
| } | |||
| @@ -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 | |||
| @@ -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; | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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<int> 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(); | |||
| @@ -102,13 +102,13 @@ struct BridgeClientConnection { | |||
| } | |||
| void run() { | |||
| info("Bridge client connected"); | |||
| INFO("Bridge client connected"); | |||
| // Check hello key | |||
| uint32_t hello = -1; | |||
| recv<uint32_t>(&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 | |||
| @@ -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); | |||
| @@ -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); | |||
| @@ -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; | |||
| } | |||
| @@ -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); | |||
| @@ -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 | |||
| @@ -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. | |||
| @@ -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<double>(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> 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> 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()); | |||
| } | |||
| } | |||