| @@ -20,7 +20,7 @@ | |||
| #include <cstdint> | |||
| #include "carla_includes.h" | |||
| #include "carla_defines.h" | |||
| #define CARLA_BACKEND_START_NAMESPACE namespace CarlaBackend { | |||
| #define CARLA_BACKEND_END_NAMESPACE } | |||
| @@ -726,8 +726,8 @@ void CarlaEngine::idlePluginGuis() | |||
| void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], uint32_t frames) | |||
| { | |||
| // initialize outputs (zero) | |||
| zeroF(outBuf[0], frames); | |||
| zeroF(outBuf[1], frames); | |||
| carla_zeroF(outBuf[0], frames); | |||
| carla_zeroF(outBuf[1], frames); | |||
| memset(rackControlEventsOut, 0, sizeof(CarlaEngineControlEvent)*MAX_ENGINE_CONTROL_EVENTS); | |||
| memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS); | |||
| @@ -748,8 +748,8 @@ void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], uint32_t frames | |||
| memcpy(rackMidiEventsIn, rackMidiEventsOut, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS); | |||
| // initialize outputs (zero) | |||
| zeroF(outBuf[0], frames); | |||
| zeroF(outBuf[1], frames); | |||
| carla_zeroF(outBuf[0], frames); | |||
| carla_zeroF(outBuf[1], frames); | |||
| memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS); | |||
| } | |||
| @@ -566,10 +566,10 @@ private: | |||
| static void processPluginNOT(CarlaPlugin* const p, const uint32_t nframes) | |||
| { | |||
| for (uint32_t i=0; i < p->aIn.count; i++) | |||
| zeroF(p->aIn.ports[i]->getJackAudioBuffer(nframes), nframes); | |||
| carla_zeroF(p->aIn.ports[i]->getJackAudioBuffer(nframes), nframes); | |||
| for (uint32_t i=0; i < p->aOut.count; i++) | |||
| zeroF(p->aOut.ports[i]->getJackAudioBuffer(nframes), nframes); | |||
| carla_zeroF(p->aOut.ports[i]->getJackAudioBuffer(nframes), nframes); | |||
| } | |||
| static void latencyPlugin(CarlaPlugin* const p, jack_latency_callback_mode_t mode) | |||
| @@ -1364,7 +1364,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -19,7 +19,7 @@ | |||
| #define CARLA_OSC_H | |||
| #include "carla_backend.h" | |||
| #include "carla_osc_includes.h" | |||
| #include "carla_osc_utils.h" | |||
| #define CARLA_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin | |||
| #define CARLA_OSC_HANDLE_ARGS2 CARLA_OSC_HANDLE_ARGS1, const int argc, const lo_arg* const* const argv, const char* const types | |||
| @@ -22,7 +22,7 @@ | |||
| #include "carla_midi.h" | |||
| #include "carla_shared.h" | |||
| #include "carla_lib_includes.h" | |||
| #include "carla_lib_utils.h" | |||
| #ifdef BUILD_BRIDGE | |||
| # include "carla_bridge_osc.h" | |||
| @@ -34,19 +34,19 @@ | |||
| // ------------------------------------------------- | |||
| inline | |||
| float d_absf(float value) | |||
| float d_absf(const float& value) | |||
| { | |||
| return (value < 0.0f) ? -value : value; | |||
| } | |||
| inline | |||
| float d_minf(float x, float y) | |||
| float d_minf(const float& x, const float& y) | |||
| { | |||
| return (x < y ? x : y); | |||
| } | |||
| inline | |||
| float d_maxf(float x, float y) | |||
| float d_maxf(const float& x, const float& y) | |||
| { | |||
| return (x > y ? x : y); | |||
| } | |||
| @@ -1382,7 +1382,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -1198,7 +1198,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -1058,7 +1058,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -662,7 +662,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -2714,7 +2714,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -49,10 +49,11 @@ HEADERS = \ | |||
| ../plugins/carla_native.h \ | |||
| ../plugins/carla_nativemm.h \ | |||
| ../../carla-jackbridge/carla_jackbridge.h \ | |||
| ../../carla-includes/carla_includes.h \ | |||
| ../../carla-includes/carla_lib_includes.h \ | |||
| ../../carla-includes/carla_osc_includes.h \ | |||
| ../../carla-includes/carla_defines.h \ | |||
| ../../carla-includes/carla_midi.h \ | |||
| ../../carla-includes/carla_utils.h \ | |||
| ../../carla-includes/carla_lib_utils.h \ | |||
| ../../carla-includes/carla_osc_utils.h \ | |||
| ../../carla-includes/carla_ladspa.h \ | |||
| ../../carla-includes/carla_dssi.h \ | |||
| ../../carla-includes/carla_lv2.h \ | |||
| @@ -1263,7 +1263,7 @@ public: | |||
| else | |||
| { | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| #if ! VST_FORCE_DEPRECATED | |||
| isProcessing = true; | |||
| @@ -1369,7 +1369,7 @@ public: | |||
| { | |||
| // disable any output sound if not active | |||
| for (i=0; i < aOut.count; i++) | |||
| zeroF(outBuffer[i], frames); | |||
| carla_zeroF(outBuffer[i], frames); | |||
| aOutsPeak[0] = 0.0; | |||
| aOutsPeak[1] = 0.0; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Carla common includes | |||
| * Carla common defines | |||
| * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or modify | |||
| @@ -15,8 +15,8 @@ | |||
| * For a full copy of the GNU General Public License see the COPYING file | |||
| */ | |||
| #ifndef CARLA_INCLUDES_H | |||
| #define CARLA_INCLUDES_H | |||
| #ifndef CARLA_DEFINES_H | |||
| #define CARLA_DEFINES_H | |||
| #ifdef __WINE__ | |||
| # define Q_CORE_EXPORT | |||
| @@ -38,26 +38,16 @@ | |||
| // Common includes and macros | |||
| #ifdef Q_OS_WIN | |||
| # include <winsock2.h> | |||
| # include <windows.h> | |||
| //# define uintptr_t size_t // FIXME | |||
| # define carla_sleep(t) Sleep(t * 1000) | |||
| # define carla_msleep(t) Sleep(t) | |||
| # define carla_usleep(t) Sleep(t / 1000) | |||
| # define carla_setenv(key, value) SetEnvironmentVariableA(key, value) | |||
| #else | |||
| # include <dlfcn.h> | |||
| # include <unistd.h> | |||
| # define carla_sleep(t) sleep(t) | |||
| # define carla_msleep(t) usleep(t * 1000) | |||
| # define carla_usleep(t) usleep(t) | |||
| # define carla_setenv(key, value) setenv(key, value, 1) | |||
| # ifndef __cdecl | |||
| # define __cdecl | |||
| # endif | |||
| #endif | |||
| // ..., needed for qDebug/Warning/Critical sections | |||
| // Define various string format types, needed for qDebug/Warning/Critical sections | |||
| #if defined(Q_OS_WIN64) && ! defined(__WINE__) | |||
| # define P_INT64 "%I64i" | |||
| # define P_INTPTR "%I64i" | |||
| @@ -95,14 +85,14 @@ | |||
| // Define CARLA_ASSERT* | |||
| #ifdef NDEBUG | |||
| # define CARLA_ASSERT(cond) ((!(cond)) ? carla_assert(#cond, __FILE__, __LINE__) : pass()) | |||
| # define CARLA_ASSERT_INT(cond, value) ((!(cond)) ? carla_assert_int(#cond, __FILE__, __LINE__, value) : pass()) | |||
| # define CARLA_ASSERT(cond) ((!(cond)) ? carla_assert(#cond, __FILE__, __LINE__) : qt_noop()) | |||
| # define CARLA_ASSERT_INT(cond, value) ((!(cond)) ? carla_assert_int(#cond, __FILE__, __LINE__, value) : qt_noop()) | |||
| #else | |||
| # define CARLA_ASSERT Q_ASSERT | |||
| # define CARLA_ASSERT_INT(cond, value) Q_ASSERT(cond) | |||
| #endif | |||
| // Export symbols if needed | |||
| // Define CARLA_EXPORT | |||
| #ifdef BUILD_BRIDGE | |||
| # define CARLA_EXPORT extern "C" | |||
| #else | |||
| @@ -113,48 +103,4 @@ | |||
| # endif | |||
| #endif | |||
| // Inline functions | |||
| #ifdef Q_OS_LINUX | |||
| # include <sys/prctl.h> | |||
| # include <linux/prctl.h> | |||
| static inline | |||
| void carla_setprocname(const char* const name) | |||
| { | |||
| prctl(PR_SET_NAME, name); | |||
| } | |||
| #else | |||
| static inline | |||
| void carla_setprocname(const char* const) | |||
| { | |||
| } | |||
| #endif | |||
| static inline | |||
| void carla_assert(const char* const assertion, const char* const file, const int line) | |||
| { | |||
| qCritical("Carla assertion failure: \"%s\" in file %s, line %i", assertion, file, line); | |||
| } | |||
| static inline | |||
| void carla_assert_int(const char* const assertion, const char* const file, const int line, const int value) | |||
| { | |||
| qCritical("Carla assertion failure: \"%s\" in file %s, line %i, value %i", assertion, file, line, value); | |||
| } | |||
| static inline | |||
| const char* bool2str(const bool yesNo) | |||
| { | |||
| return yesNo ? "true" : "false"; | |||
| } | |||
| static inline | |||
| void pass() {} | |||
| static inline | |||
| void zeroF(float* data, const unsigned int size) | |||
| { | |||
| for (unsigned int i=0; i < size; i++) | |||
| *data++ = 0.0f; | |||
| } | |||
| #endif // CARLA_INCLUDES_H | |||
| #endif // CARLA_DEFINES_H | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Carla common library code | |||
| * Carla library utils | |||
| * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or modify | |||
| @@ -15,19 +15,22 @@ | |||
| * For a full copy of the GNU General Public License see the COPYING file | |||
| */ | |||
| #ifndef CARLA_LIB_INCLUDES_H | |||
| #define CARLA_LIB_INCLUDES_H | |||
| #ifndef CARLA_LIBRARY_UTILS_H | |||
| #define CARLA_LIBRARY_UTILS_H | |||
| #include "carla_includes.h" | |||
| #include "carla_defines.h" | |||
| #ifdef Q_OS_WIN | |||
| # include <cstdio> | |||
| # include <cstdio> | |||
| #else | |||
| # include <dlfcn.h> | |||
| #endif | |||
| static inline | |||
| void* lib_open(const char* const filename) | |||
| { | |||
| CARLA_ASSERT(filename); | |||
| #ifdef Q_OS_WIN | |||
| return LoadLibraryA(filename); | |||
| #else | |||
| @@ -39,6 +42,10 @@ static inline | |||
| bool lib_close(void* const lib) | |||
| { | |||
| CARLA_ASSERT(lib); | |||
| if (! lib) | |||
| return false; | |||
| #ifdef Q_OS_WIN | |||
| return FreeLibrary((HMODULE)lib); | |||
| #else | |||
| @@ -51,6 +58,10 @@ void* lib_symbol(void* const lib, const char* const symbol) | |||
| { | |||
| CARLA_ASSERT(lib); | |||
| CARLA_ASSERT(symbol); | |||
| if (! lib) | |||
| return nullptr; | |||
| #ifdef Q_OS_WIN | |||
| return (void*)GetProcAddress((HMODULE)lib, symbol); | |||
| #else | |||
| @@ -62,13 +73,14 @@ static inline | |||
| const char* lib_error(const char* const filename) | |||
| { | |||
| CARLA_ASSERT(filename); | |||
| #ifdef Q_OS_WIN | |||
| static char libError[2048]; | |||
| memset(libError, 0, sizeof(char)*2048); | |||
| LPVOID winErrorString; | |||
| DWORD winErrorCode = GetLastError(); | |||
| FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, winErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&winErrorString, 0, nullptr); | |||
| FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, winErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&winErrorString, 0, nullptr); | |||
| snprintf(libError, 2048, "%s: error code %i: %s", filename, winErrorCode, (const char*)winErrorString); | |||
| LocalFree(winErrorString); | |||
| @@ -80,4 +92,4 @@ const char* lib_error(const char* const filename) | |||
| #endif | |||
| } | |||
| #endif // CARLA_LIB_INCLUDES_H | |||
| #endif // CARLA_LIBRARY_UTILS_H | |||
| @@ -58,7 +58,7 @@ | |||
| #include "lilv/lilvmm.hpp" | |||
| #include "sratom/sratom.h" | |||
| #include "carla_includes.h" | |||
| #include "carla_defines.h" | |||
| #include <QtCore/QMap> | |||
| #include <QtCore/QStringList> | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Carla common OSC code | |||
| * Carla OSC utils | |||
| * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or modify | |||
| @@ -15,14 +15,12 @@ | |||
| * For a full copy of the GNU General Public License see the COPYING file | |||
| */ | |||
| #ifndef CARLA_OSC_INCLUDES_H | |||
| #define CARLA_OSC_INCLUDES_H | |||
| #ifndef CARLA_OSC_UTILS_H | |||
| #define CARLA_OSC_UTILS_H | |||
| #include "carla_includes.h" | |||
| #include "carla_utils.h" | |||
| #include <cstdint> | |||
| #include <cstdlib> | |||
| #include <cstring> | |||
| #include <lo/lo.h> | |||
| @@ -42,10 +40,10 @@ struct CarlaOscData { | |||
| ::free((void*)path); | |||
| if (source) | |||
| lo_address_free(source); | |||
| ::lo_address_free(source); | |||
| if (target) | |||
| lo_address_free(target); | |||
| ::lo_address_free(target); | |||
| path = nullptr; | |||
| source = nullptr; | |||
| @@ -61,7 +59,7 @@ void osc_send_configure(const CarlaOscData* const oscData, const char* const key | |||
| CARLA_ASSERT(value); | |||
| qDebug("osc_send_configure(path:\"%s\", \"%s\", \"%s\")", oscData->path, key, value); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && key && value) | |||
| { | |||
| char targetPath[strlen(oscData->path)+11]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -74,10 +72,10 @@ static inline | |||
| void osc_send_control(const CarlaOscData* const oscData, const int32_t index, const float value) | |||
| { | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| CARLA_ASSERT(index != -1); | |||
| CARLA_ASSERT(index != -1); // -1 == PARAMETER_NULL | |||
| qDebug("osc_send_control(path:\"%s\", %i, %f)", oscData->path, index, value); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && index != -1) | |||
| { | |||
| char targetPath[strlen(oscData->path)+9]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -93,7 +91,7 @@ void osc_send_program(const CarlaOscData* const oscData, const int32_t index) | |||
| CARLA_ASSERT(index >= 0); | |||
| qDebug("osc_send_program(path:\"%s\", %i)", oscData->path, index); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && index >= 0) | |||
| { | |||
| char targetPath[strlen(oscData->path)+9]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -106,11 +104,11 @@ static inline | |||
| void osc_send_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program) | |||
| { | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| CARLA_ASSERT(program >= 0 && program < 128); | |||
| CARLA_ASSERT(program >= 0); | |||
| CARLA_ASSERT(bank >= 0); | |||
| qDebug("osc_send_program(path:\"%s\", %i, %i)", oscData->path, bank, program); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && bank >= 0 && program >= 0) | |||
| { | |||
| char targetPath[strlen(oscData->path)+9]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -126,7 +124,7 @@ void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t inde | |||
| CARLA_ASSERT(index >= 0); | |||
| qDebug("osc_send_midi_program(path:\"%s\", %i)", oscData->path, index); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && index >= 0) | |||
| { | |||
| char targetPath[strlen(oscData->path)+14]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -139,11 +137,11 @@ static inline | |||
| void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program) | |||
| { | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| CARLA_ASSERT(program >= 0 && program < 128); | |||
| CARLA_ASSERT(program >= 0); | |||
| CARLA_ASSERT(bank >= 0); | |||
| qDebug("osc_send_midi_program(path:\"%s\", %i, %i)", oscData->path, bank, program); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && bank >= 0 && program >= 0) | |||
| { | |||
| char targetPath[strlen(oscData->path)+14]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -160,7 +158,7 @@ void osc_send_midi(const CarlaOscData* const oscData, const uint8_t buf[4]) | |||
| CARLA_ASSERT(buf[1] != 0); | |||
| qDebug("osc_send_midi(path:\"%s\", 0x%X, %03u, %03u)", oscData->path, buf[1], buf[2], buf[3]); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && buf[0] == 0 && buf[1] != 0) | |||
| { | |||
| char targetPath[strlen(oscData->path)+6]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -176,9 +174,9 @@ void osc_send_sample_rate(const CarlaOscData* const oscData, const float sampleR | |||
| CARLA_ASSERT(sampleRate > 0.0f); | |||
| qDebug("osc_send_sample_rate(path:\"%s\", %f)", oscData->path, sampleRate); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && sampleRate > 0.0f) | |||
| { | |||
| char targetPath[strlen(oscData->path)+12]; | |||
| char targetPath[strlen(oscData->path)+13]; | |||
| strcpy(targetPath, oscData->path); | |||
| strcat(targetPath, "/sample-rate"); | |||
| lo_send(oscData->target, targetPath, "f", sampleRate); | |||
| @@ -193,7 +191,7 @@ void osc_send_update(const CarlaOscData* const oscData, const char* const url) | |||
| CARLA_ASSERT(url); | |||
| qDebug("osc_send_update(path:\"%s\", \"%s\")", oscData->path, url); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && url) | |||
| { | |||
| char targetPath[strlen(oscData->path)+8]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -208,7 +206,7 @@ void osc_send_exiting(const CarlaOscData* const oscData) | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| qDebug("osc_send_exiting(path:\"%s\")", oscData->path); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target) | |||
| { | |||
| char targetPath[strlen(oscData->path)+9]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -216,7 +214,6 @@ void osc_send_exiting(const CarlaOscData* const oscData) | |||
| lo_send(oscData->target, targetPath, ""); | |||
| } | |||
| } | |||
| #else | |||
| static inline | |||
| void osc_send_show(const CarlaOscData* const oscData) | |||
| @@ -224,7 +221,7 @@ void osc_send_show(const CarlaOscData* const oscData) | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| qDebug("osc_send_show(path:\"%s\")", oscData->path); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target) | |||
| { | |||
| char targetPath[strlen(oscData->path)+6]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -239,7 +236,7 @@ void osc_send_hide(const CarlaOscData* const oscData) | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| qDebug("osc_send_hide(path:\"%s\")", oscData->path); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target) | |||
| { | |||
| char targetPath[strlen(oscData->path)+6]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -254,7 +251,7 @@ void osc_send_quit(const CarlaOscData* const oscData) | |||
| CARLA_ASSERT(oscData && oscData->path); | |||
| qDebug("osc_send_quit(path:\"%s\")", oscData->path); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target) | |||
| { | |||
| char targetPath[strlen(oscData->path)+6]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -272,7 +269,7 @@ void osc_send_bridge_update(const CarlaOscData* const oscData, const char* const | |||
| CARLA_ASSERT(url); | |||
| qDebug("osc_send_bridge_update(path:\"%s\", \"%s\")", oscData->path, url); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && url) | |||
| { | |||
| char targetPath[strlen(oscData->path)+15]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -288,7 +285,7 @@ void osc_send_bridge_error(const CarlaOscData* const oscData, const char* const | |||
| CARLA_ASSERT(error); | |||
| qDebug("osc_send_bridge_error(path:\"%s\", \"%s\")", oscData->path, error); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && error) | |||
| { | |||
| char targetPath[strlen(oscData->path)+14]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -305,9 +302,9 @@ void osc_send_lv2_transfer_atom(const CarlaOscData* const oscData, const int32_t | |||
| CARLA_ASSERT(portIndex >= 0); | |||
| CARLA_ASSERT(typeStr); | |||
| CARLA_ASSERT(atomBuf); | |||
| qDebug("osc_send_lv2_transfer_atom(path:\"%s\", %i, \"%s\", \"%s\")", oscData->path, portIndex, typeStr, atomBuf); | |||
| qDebug("osc_send_lv2_transfer_atom(path:\"%s\", %i, \"%s\", <atomBuf:%p>)", oscData->path, portIndex, typeStr, atomBuf); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && portIndex >= 0 && typeStr && atomBuf) | |||
| { | |||
| char targetPath[strlen(oscData->path)+19]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -323,9 +320,9 @@ void osc_send_lv2_transfer_event(const CarlaOscData* const oscData, const int32_ | |||
| CARLA_ASSERT(portIndex >= 0); | |||
| CARLA_ASSERT(typeStr); | |||
| CARLA_ASSERT(atomBuf); | |||
| qDebug("osc_send_lv2_transfer_event(path:\"%s\", %i, \"%s\", \"%s\")", oscData->path, portIndex, typeStr, atomBuf); | |||
| qDebug("osc_send_lv2_transfer_event(path:\"%s\", %i, \"%s\", <atomBuf:%p>)", oscData->path, portIndex, typeStr, atomBuf); | |||
| if (oscData->target) | |||
| if (oscData && oscData->path && oscData->target && portIndex >= 0 && typeStr && atomBuf) | |||
| { | |||
| char targetPath[strlen(oscData->path)+20]; | |||
| strcpy(targetPath, oscData->path); | |||
| @@ -334,4 +331,4 @@ void osc_send_lv2_transfer_event(const CarlaOscData* const oscData, const int32_ | |||
| } | |||
| } | |||
| #endif // CARLA_OSC_INCLUDES_H | |||
| #endif // CARLA_OSC_UTILS_H | |||
| @@ -0,0 +1,315 @@ | |||
| /* | |||
| * Carla common utils | |||
| * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com> | |||
| * | |||
| * This program is free software; you can redistribute it and/or modify | |||
| * it under the terms of the GNU General Public License as published by | |||
| * the Free Software Foundation; either version 2 of the License, or | |||
| * any later version. | |||
| * | |||
| * This program is distributed in the hope that it will be useful, | |||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| * GNU General Public License for more details. | |||
| * | |||
| * For a full copy of the GNU General Public License see the COPYING file | |||
| */ | |||
| #ifndef CARLA_UTILS_H | |||
| #define CARLA_UTILS_H | |||
| #include "carla_defines.h" | |||
| #include <cstdio> | |||
| #include <cstdlib> | |||
| #include <cstring> | |||
| #if defined(Q_OS_HAIKU) | |||
| # include <kernel/OS.h> | |||
| #elif defined(Q_OS_LINUX) | |||
| # include <sys/prctl.h> | |||
| # include <linux/prctl.h> | |||
| #endif | |||
| // carla_*sleep | |||
| #ifdef Q_OS_WIN | |||
| # define carla_sleep(t) Sleep(t * 1000) | |||
| # define carla_msleep(t) Sleep(t) | |||
| # define carla_usleep(t) Sleep(t / 1000) | |||
| #else | |||
| # define carla_sleep(t) sleep(t) | |||
| # define carla_msleep(t) usleep(t * 1000) | |||
| # define carla_usleep(t) usleep(t) | |||
| #endif | |||
| // carla_setenv | |||
| #ifdef Q_OS_WIN | |||
| # define carla_setenv(key, value) SetEnvironmentVariableA(key, value) | |||
| #else | |||
| # define carla_setenv(key, value) setenv(key, value, 1) | |||
| #endif | |||
| // carla_assert* | |||
| static inline | |||
| void carla_assert(const char* const assertion, const char* const file, const int line) | |||
| { | |||
| qCritical("Carla assertion failure: \"%s\" in file %s, line %i", assertion, file, line); | |||
| } | |||
| static inline | |||
| void carla_assert_int(const char* const assertion, const char* const file, const int line, const int value) | |||
| { | |||
| qCritical("Carla assertion failure: \"%s\" in file %s, line %i, value %i", assertion, file, line, value); | |||
| } | |||
| // carla_setprocname (not available on all platforms) | |||
| static inline | |||
| void carla_setprocname(const char* const name) | |||
| { | |||
| CARLA_ASSERT(name); | |||
| #if defined(Q_OS_HAIKU) | |||
| if ((thread_id this_thread = find_thread(nullptr)) != B_NAME_NOT_FOUND) | |||
| rename_thread(this_thread, name); | |||
| #elif defined(Q_OS_LINUX) | |||
| prctl(PR_SET_NAME, name); | |||
| #else | |||
| qWarning("carla_setprocname(\"%s\") - unsupported on this platform"); | |||
| #endif | |||
| } | |||
| // math functions | |||
| inline | |||
| float carla_absF(const float& value) | |||
| { | |||
| return (value < 0.0f) ? -value : value; | |||
| } | |||
| inline | |||
| float carla_minF(const float& x, const float& y) | |||
| { | |||
| return (x < y ? x : y); | |||
| } | |||
| inline | |||
| float carla_maxF(const float& x, const float& y) | |||
| { | |||
| return (x > y ? x : y); | |||
| } | |||
| static inline | |||
| void carla_zeroF(float* data, const unsigned int size) | |||
| { | |||
| for (unsigned int i=0; i < size; i++) | |||
| *data++ = 0.0f; | |||
| } | |||
| // other misc functions | |||
| static inline | |||
| const char* bool2str(const bool yesNo) | |||
| { | |||
| return yesNo ? "true" : "false"; | |||
| } | |||
| static inline | |||
| void pass() {} | |||
| // carla_string class | |||
| class carla_string | |||
| { | |||
| public: | |||
| // --------------------------------------------- | |||
| // constructors (no explicit conversions allowed) | |||
| explicit carla_string() | |||
| { | |||
| buffer = ::strdup(""); | |||
| } | |||
| explicit carla_string(char* const strBuf) | |||
| { | |||
| buffer = ::strdup(strBuf ? strBuf : ""); | |||
| } | |||
| carla_string(const char* const strBuf) | |||
| { | |||
| buffer = ::strdup(strBuf ? strBuf : ""); | |||
| } | |||
| explicit carla_string(const carla_string& str) | |||
| { | |||
| buffer = ::strdup(str.buffer); | |||
| } | |||
| explicit carla_string(const int value) | |||
| { | |||
| const size_t strBufSize = ::abs(value/10) + 3; | |||
| char strBuf[strBufSize]; | |||
| ::snprintf(strBuf, strBufSize, "%d", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| explicit carla_string(const unsigned int value, const bool hexadecimal = false) | |||
| { | |||
| const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); | |||
| char strBuf[strBufSize]; | |||
| ::snprintf(strBuf, strBufSize, hexadecimal ? "%u" : "0x%x", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| explicit carla_string(const long int value) | |||
| { | |||
| const size_t strBufSize = ::labs(value/10) + 3; | |||
| char strBuf[strBufSize]; | |||
| ::snprintf(strBuf, strBufSize, "%ld", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| explicit carla_string(const unsigned long int value, const bool hexadecimal = false) | |||
| { | |||
| const size_t strBufSize = value/10 + 2 + (hexadecimal ? 2 : 0); | |||
| char strBuf[strBufSize]; | |||
| ::snprintf(strBuf, strBufSize, hexadecimal ? "%lu" : "0x%lx", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| explicit carla_string(const float value) | |||
| { | |||
| char strBuf[0xff]; | |||
| ::snprintf(strBuf, 0xff, "%f", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| explicit carla_string(const double value) | |||
| { | |||
| char strBuf[0xff]; | |||
| ::snprintf(strBuf, 0xff, "%g", value); | |||
| buffer = ::strdup(strBuf); | |||
| } | |||
| // --------------------------------------------- | |||
| // deconstructor | |||
| ~carla_string() | |||
| { | |||
| ::free(buffer); | |||
| } | |||
| // --------------------------------------------- | |||
| // public methods | |||
| size_t length() const | |||
| { | |||
| return ::strlen(buffer); | |||
| } | |||
| bool isEmpty() const | |||
| { | |||
| return (*buffer == 0); | |||
| } | |||
| // --------------------------------------------- | |||
| // public operators | |||
| operator const char*() const | |||
| { | |||
| return buffer; | |||
| } | |||
| bool operator==(const char* const strBuf) const | |||
| { | |||
| return (strBuf && ::strcmp(buffer, strBuf) == 0); | |||
| } | |||
| bool operator==(const carla_string& str) const | |||
| { | |||
| return operator==(str.buffer); | |||
| } | |||
| bool operator!=(const char* const strBuf) const | |||
| { | |||
| return !operator==(strBuf); | |||
| } | |||
| bool operator!=(const carla_string& str) const | |||
| { | |||
| return !operator==(str.buffer); | |||
| } | |||
| carla_string& operator=(const char* const strBuf) | |||
| { | |||
| ::free(buffer); | |||
| buffer = ::strdup(strBuf ? strBuf : ""); | |||
| return *this; | |||
| } | |||
| carla_string& operator=(const carla_string& str) | |||
| { | |||
| return operator=(str.buffer); | |||
| } | |||
| carla_string& operator+=(const char* const strBuf) | |||
| { | |||
| const size_t newBufSize = ::strlen(buffer) + (strBuf ? ::strlen(strBuf) : 0) + 1; | |||
| char newBuf[newBufSize]; | |||
| ::strcpy(newBuf, buffer); | |||
| ::strcat(newBuf, strBuf); | |||
| ::free(buffer); | |||
| buffer = ::strdup(newBuf); | |||
| return *this; | |||
| } | |||
| carla_string& operator+=(const carla_string& str) | |||
| { | |||
| return operator+=(str.buffer); | |||
| } | |||
| carla_string operator+(const char* const strBuf) | |||
| { | |||
| const size_t newBufSize = ::strlen(buffer) + (strBuf ? ::strlen(strBuf) : 0) + 1; | |||
| char newBuf[newBufSize]; | |||
| ::strcpy(newBuf, buffer); | |||
| ::strcat(newBuf, strBuf); | |||
| return carla_string(newBuf); | |||
| } | |||
| carla_string operator+(const carla_string& str) | |||
| { | |||
| return operator+(str.buffer); | |||
| } | |||
| // --------------------------------------------- | |||
| private: | |||
| char* buffer; | |||
| }; | |||
| static inline | |||
| carla_string operator+(const char* const strBufBefore, const carla_string& strAfter) | |||
| { | |||
| const char* const strBufAfter = (const char*)strAfter; | |||
| const size_t newBufSize = (strBufBefore ? ::strlen(strBufBefore) : 0) + ::strlen(strBufAfter) + 1; | |||
| char newBuf[newBufSize]; | |||
| ::strcpy(newBuf, strBufBefore); | |||
| ::strcat(newBuf, strBufAfter); | |||
| return carla_string(newBuf); | |||
| } | |||
| // ------------------------------------------------- | |||
| #endif // CARLA_UTILS_H | |||
| @@ -18,7 +18,7 @@ | |||
| #ifndef CARLA_JACKBRIDGE_H | |||
| #define CARLA_JACKBRIDGE_H | |||
| #include "carla_includes.h" | |||
| #include "carla_defines.h" | |||
| #include <jack/jack.h> | |||
| #include <jack/midiport.h> | |||