Browse Source

More cleanup

tags/1.9.4
falkTX 12 years ago
parent
commit
5f39a77ac4
23 changed files with 470 additions and 498 deletions
  1. +5
    -5
      source/backend/CarlaEngine.hpp
  2. +159
    -171
      source/backend/engine/CarlaEngine.cpp
  3. +13
    -13
      source/backend/engine/CarlaEngineInternal.hpp
  4. +1
    -1
      source/backend/plugin/CarlaPluginThread.cpp
  5. +8
    -7
      source/backend/plugin/CarlaPluginThread.hpp
  6. +4
    -4
      source/libs/rtmempool/list.h
  7. +50
    -14
      source/tests/ANSI.cpp
  8. +2
    -2
      source/tests/Makefile
  9. +28
    -29
      source/utils/CarlaBackendUtils.hpp
  10. +3
    -5
      source/utils/CarlaBridgeUtils.hpp
  11. +4
    -6
      source/utils/CarlaLadspaUtils.hpp
  12. +1
    -3
      source/utils/CarlaLibUtils.hpp
  13. +1
    -1
      source/utils/CarlaLogThread.hpp
  14. +2
    -2
      source/utils/CarlaLv2Utils.hpp
  15. +9
    -37
      source/utils/CarlaMutex.hpp
  16. +127
    -129
      source/utils/CarlaOscUtils.hpp
  17. +2
    -2
      source/utils/CarlaRingBuffer.hpp
  18. +1
    -1
      source/utils/CarlaShmUtils.hpp
  19. +1
    -1
      source/utils/CarlaStateUtils.hpp
  20. +6
    -4
      source/utils/CarlaString.hpp
  21. +31
    -49
      source/utils/CarlaUtils.hpp
  22. +2
    -0
      source/utils/Lv2AtomQueue.hpp
  23. +10
    -12
      source/utils/RtList.hpp

+ 5
- 5
source/backend/CarlaEngine.hpp View File

@@ -234,9 +234,9 @@ struct EngineOptions {
unsigned int oscUiTimeout;

bool jackAutoConnect;
bool jackTimeMaster;

#ifdef WANT_RTAUDIO
unsigned int rtaudioNumberPeriods;
unsigned int rtaudioBufferSize;
unsigned int rtaudioSampleRate;
CarlaString rtaudioDevice;
@@ -285,9 +285,9 @@ struct EngineOptions {
maxParameters(MAX_DEFAULT_PARAMETERS),
oscUiTimeout(4000),
jackAutoConnect(false),
jackTimeMaster(false),
# ifdef WANT_RTAUDIO
rtaudioBufferSize(1024),
rtaudioNumberPeriods(0),
rtaudioBufferSize(512),
rtaudioSampleRate(44100),
# endif
resourceDir() {}
@@ -1134,11 +1134,11 @@ protected:
void offlineModeChanged(const bool isOffline);

/*!
* Run any RT pending events.\n
* Run any pending RT events.\n
* Must always be called at the end of audio processing.
* \note RT call
*/
void runRtPendingEvents();
void runPendingRtEvents();

/*!
* Set a plugin (stereo) peak values.


+ 159
- 171
source/backend/engine/CarlaEngine.cpp
File diff suppressed because it is too large
View File


+ 13
- 13
source/backend/engine/CarlaEngineInternal.hpp View File

@@ -222,10 +222,10 @@ struct CarlaEngineProtectedData {
#ifndef BUILD_BRIDGE
static void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
{
CARLA_ASSERT(id == engine->kData->curPluginCount);
CARLA_ASSERT(id == engine->pData->curPluginCount);

if (id == engine->kData->curPluginCount)
engine->kData->plugins[id].plugin = plugin;
if (id == engine->pData->curPluginCount)
engine->pData->plugins[id].plugin = plugin;
}
#endif

@@ -316,36 +316,36 @@ struct CarlaEngineProtectedData {
{
public:
ScopedPluginAction(CarlaEngineProtectedData* const data, const EnginePostAction action, const unsigned int pluginId, const unsigned int value, const bool lockWait)
: kData(data)
: fData(data)
{
kData->nextAction.mutex.lock();
fData->nextAction.mutex.lock();

CARLA_ASSERT(kData->nextAction.opcode == kEnginePostActionNull);
CARLA_ASSERT(fData->nextAction.opcode == kEnginePostActionNull);

kData->nextAction.opcode = action;
kData->nextAction.pluginId = pluginId;
kData->nextAction.value = value;
fData->nextAction.opcode = action;
fData->nextAction.pluginId = pluginId;
fData->nextAction.value = value;

if (lockWait)
{
// block wait for unlock on proccessing side
carla_stdout("ScopedPluginAction(%i) - blocking START", pluginId);
kData->nextAction.mutex.lock();
fData->nextAction.mutex.lock();
carla_stdout("ScopedPluginAction(%i) - blocking DONE", pluginId);
}
else
{
kData->doNextPluginAction(false);
fData->doNextPluginAction(false);
}
}

~ScopedPluginAction()
{
kData->nextAction.mutex.unlock();
fData->nextAction.mutex.unlock();
}

private:
CarlaEngineProtectedData* const kData;
CarlaEngineProtectedData* const fData;
};
};



+ 1
- 1
source/backend/plugin/CarlaPluginThread.cpp View File

@@ -64,7 +64,7 @@ CarlaPluginThread::~CarlaPluginThread()
}
}

void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode)
void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode) noexcept
{
fMode = mode;
}


+ 8
- 7
source/backend/plugin/CarlaPluginThread.hpp View File

@@ -12,11 +12,11 @@
* 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 GPL.txt file
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef __CARLA_PLUGIN_THREAD_HPP__
#define __CARLA_PLUGIN_THREAD_HPP__
#ifndef CARLA_PLUGIN_THREAD_HPP_INCLUDED
#define CARLA_PLUGIN_THREAD_HPP_INCLUDED

#include "CarlaBackend.hpp"
#include "CarlaString.hpp"
@@ -41,15 +41,15 @@ public:
CarlaPluginThread(CarlaEngine* const engine, CarlaPlugin* const plugin, const Mode mode = PLUGIN_THREAD_NULL);
~CarlaPluginThread();

void setMode(const CarlaPluginThread::Mode mode);
void setMode(const CarlaPluginThread::Mode mode) noexcept;
void setOscData(const char* const binary, const char* const label, const char* const extra1="", const char* const extra2="");

protected:
void run();

private:
CarlaEngine* const kEngine;
CarlaPlugin* const kPlugin;
CarlaEngine* const fEngine;
CarlaPlugin* const fPlugin;

Mode fMode;
CarlaString fBinary;
@@ -58,9 +58,10 @@ private:
CarlaString fExtra2;
QProcess* fProcess;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginThread)
};

CARLA_BACKEND_END_NAMESPACE

#endif // __CARLA_PLUGIN_THREAD_HPP__
#endif // CARLA_PLUGIN_THREAD_HPP_INCLUDED

+ 4
- 4
source/libs/rtmempool/list.h View File

@@ -21,8 +21,8 @@
*
*****************************************************************************/

#ifndef __LINUX_LIST_H__
#define __LINUX_LIST_H__
#ifndef LINUX_LIST_H_INCLUDED
#define LINUX_LIST_H_INCLUDED

/* This file is from Linux Kernel (include/linux/list.h)
* and modified by removing hardware prefetching of list items
@@ -300,7 +300,7 @@ static inline void list_splice_tail_init(struct list_head *list, struct list_hea
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#if defined(__GNUC__) && ! defined(QTCREATOR_TEST)
#if defined(__GNUC__) && ! (defined(BUILD_ANSI_TEST) || defined(QTCREATOR_TEST))
# define list_entry(ptr, type, member) \
container_of(ptr, type, member)
#else
@@ -452,4 +452,4 @@ static inline void list_splice_tail_init(struct list_head *list, struct list_hea
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))

#endif // __LINUX_LIST_H__
#endif // LINUX_LIST_H_INCLUDED

+ 50
- 14
source/tests/ANSI.cpp View File

@@ -53,31 +53,33 @@
// Carla Standalone API
#include "CarlaStandalone.hpp"

// // Carla Plugin Thread
// #include "CarlaPluginThread.hpp"
//
// #include "CarlaBackendUtils.hpp"
// #include "CarlaOscUtils.hpp"
// #include "CarlaMutex.hpp"
// #include "RtList.hpp"
//
// // Carla Plugin
// Carla Plugin Thread
#include "CarlaPluginThread.hpp"

// Carla Backend utils
#include "CarlaBackendUtils.hpp"

// Carla OSC utils
#include "CarlaOscUtils.hpp"

// Carla Mutex
#include "CarlaMutex.hpp"

// RT List
#include "RtList.hpp"

// Carla Plugin
// #include "CarlaPluginInternal.hpp"

//#include "standalone/CarlaStandalone.cpp"

// #include "CarlaMutex.hpp"

// #include "CarlaBackendUtils.hpp"
// #include "CarlaBridgeUtils.hpp"
// #include "CarlaLadspaUtils.hpp"
// #include "CarlaLibUtils.hpp"
// #include "CarlaLv2Utils.hpp"
// #include "CarlaOscUtils.hpp"
// #include "CarlaShmUtils.hpp"
// #include "CarlaStateUtils.hpp"
// #include "CarlaVstUtils.hpp"
// #include "RtList.hpp"

int safe_assert_return_test(bool test)
{
@@ -434,5 +436,39 @@ int main()
c = new PluginDescriptorClassTest(&a);
}

// Carla Backend utils
{
class TestClass { public: int i; char pad[50]; };

TestClass a, b, c;
uintptr_t ad = CarlaBackend::getAddressFromPointer(&a);
uintptr_t bd = CarlaBackend::getAddressFromPointer(&b);
uintptr_t cd = CarlaBackend::getAddressFromPointer(&c);
assert(bd > ad);
assert(cd > bd);

TestClass* ap = CarlaBackend::getPointerFromAddress<TestClass>(ad);
TestClass* bp = CarlaBackend::getPointerFromAddress<TestClass>(bd);
TestClass* cp = CarlaBackend::getPointerFromAddress<TestClass>(cd);
assert(ap == &a);
assert(bp == &b);
assert(cp == &c);

ap->i = 4;
bp->i = 5;
cp->i = 6;
assert(a.i == 4);
assert(b.i == 5);
assert(c.i == 6);
}

// Carla Mutex
{
CarlaMutex m;
m.tryLock();
m.unlock();
const CarlaMutex::ScopedLocker sl(m);
}

return 0;
}

+ 2
- 2
source/tests/Makefile View File

@@ -8,11 +8,11 @@ include ../Makefile.mk

# --------------------------------------------------------------

BUILD_CXX_FLAGS += -I../backend -I../includes -I../libs -I../theme -I../utils
BUILD_CXX_FLAGS += -I../backend -I../backend/plugin -I../includes -I../libs -I../theme -I../utils
BUILD_CXX_FLAGS += -DWANT_NATIVE -DWANT_LADSPA -DWANT_DSSI -DWANT_LV2 -DWANT_VST -DWANT_FLUIDSYNTH -DWANT_LINUXSAMPLER
BUILD_CXX_FLAGS += -DWANT_RTAUDIO -DWANT_OPENGL -DWANT_AUDIOFILE -DWANT_MIDIFILE -DWANT_ZYNADDSUBFX -DWANT_ZYNADDSUBFX_UI
# BUILD_CXX_FLAGS += -isystem ../libs/juce
# BUILD_CXX_FLAGS += -isystem /usr/include/qt4
BUILD_CXX_FLAGS += -isystem /usr/include/qt4
# BUILD_CXX_FLAGS += -isystem ../backend/engine/rtaudio-4.0.11
# BUILD_CXX_FLAGS += -I/opt/mingw32/include



+ 28
- 29
source/utils/CarlaBackendUtils.hpp View File

@@ -12,21 +12,21 @@
* 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 GPL.txt file
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef __CARLA_BACKEND_UTILS_HPP__
#define __CARLA_BACKEND_UTILS_HPP__
#ifndef CARLA_BACKEND_UTILS_HPP_INCLUDED
#define CARLA_BACKEND_UTILS_HPP_INCLUDED

#include "CarlaBackend.hpp"
#include "CarlaString.hpp"

CARLA_BACKEND_START_NAMESPACE

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
const char* PluginOption2Str(const unsigned int& option)
const char* PluginOption2Str(const unsigned int option)
{
switch (option)
{
@@ -54,10 +54,8 @@ const char* PluginOption2Str(const unsigned int& option)
return nullptr;
}

// -------------------------------------------------

static inline
const char* BinaryType2Str(const BinaryType& type)
const char* BinaryType2Str(const BinaryType type)
{
switch (type)
{
@@ -80,7 +78,7 @@ const char* BinaryType2Str(const BinaryType& type)
}

static inline
const char* PluginType2Str(const PluginType& type)
const char* PluginType2Str(const PluginType type)
{
switch (type)
{
@@ -111,7 +109,7 @@ const char* PluginType2Str(const PluginType& type)
}

static inline
const char* PluginCategory2Str(const PluginCategory& category)
const char* PluginCategory2Str(const PluginCategory category)
{
switch (category)
{
@@ -140,7 +138,7 @@ const char* PluginCategory2Str(const PluginCategory& category)
}

static inline
const char* ParameterType2Str(const ParameterType& type)
const char* ParameterType2Str(const ParameterType type)
{
switch (type)
{
@@ -167,7 +165,7 @@ const char* ParameterType2Str(const ParameterType& type)
}

static inline
const char* InternalParametersIndex2Str(const InternalParametersIndex& index)
const char* InternalParametersIndex2Str(const InternalParametersIndex index)
{
switch (index)
{
@@ -196,7 +194,7 @@ const char* InternalParametersIndex2Str(const InternalParametersIndex& index)
}

static inline
const char* OptionsType2Str(const OptionsType& type)
const char* OptionsType2Str(const OptionsType type)
{
switch (type)
{
@@ -218,15 +216,15 @@ const char* OptionsType2Str(const OptionsType& type)
#endif
case OPTION_MAX_PARAMETERS:
return "OPTION_MAX_PARAMETERS";
case OPTION_OSC_UI_TIMEOUT:
return "OPTION_OSC_UI_TIMEOUT";
case OPTION_UI_BRIDGES_TIMEOUT:
return "OPTION_UI_BRIDGES_TIMEOUT";
case OPTION_JACK_AUTOCONNECT:
return "OPTION_JACK_AUTOCONNECT";
case OPTION_JACK_TIMEMASTER:
return "OPTION_JACK_TIMEMASTER";
#ifdef WANT_RTAUDIO
case OPTION_RTAUDIO_NUMBER_PERIODS:
return "OPTION_RTAUDIO_NUMBER_PERIODS";
case OPTION_RTAUDIO_BUFFER_SIZE:
return "OPTION_RTAUDIO_BUFFER_SIZE:";
return "OPTION_RTAUDIO_BUFFER_SIZE";
case OPTION_RTAUDIO_SAMPLE_RATE:
return "OPTION_RTAUDIO_SAMPLE_RATE";
case OPTION_RTAUDIO_DEVICE:
@@ -277,7 +275,7 @@ const char* OptionsType2Str(const OptionsType& type)
}

static inline
const char* CallbackType2Str(const CallbackType& type)
const char* CallbackType2Str(const CallbackType type)
{
switch (type)
{
@@ -360,7 +358,7 @@ const char* CallbackType2Str(const CallbackType& type)
}

static inline
const char* ProcessMode2Str(const ProcessMode& mode)
const char* ProcessMode2Str(const ProcessMode mode)
{
switch (mode)
{
@@ -381,7 +379,7 @@ const char* ProcessMode2Str(const ProcessMode& mode)
}

static inline
const char* TransportMode2Str(const TransportMode& mode)
const char* TransportMode2Str(const TransportMode mode)
{
switch (mode)
{
@@ -399,30 +397,31 @@ const char* TransportMode2Str(const TransportMode& mode)
return nullptr;
}

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
uintptr_t getAddressFromPointer(void* ptr)
{
CARLA_ASSERT(ptr != nullptr);

uintptr_t* addr = (uintptr_t*)&ptr;
uintptr_t* const addr((uintptr_t*)&ptr);
return *addr;
}

template<typename T>
static inline
void* getPointerFromAddress(uintptr_t& addr)
T* getPointerFromAddress(uintptr_t& addr)
{
CARLA_ASSERT(addr != 0);

uintptr_t** const ptr = (uintptr_t**)&addr;
T** const ptr((T**)&addr);
return *ptr;
}

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
const char* getPluginTypeAsString(const PluginType& type)
const char* getPluginTypeAsString(const PluginType type)
{
carla_debug("CarlaBackend::getPluginTypeAsString(%s)", PluginType2Str(type));

@@ -491,7 +490,7 @@ PluginType getPluginTypeFromString(const char* const stype)
return PLUGIN_NONE;
}

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
PluginCategory getPluginCategoryFromName(const char* const name)
@@ -577,4 +576,4 @@ PluginCategory getPluginCategoryFromName(const char* const name)

CARLA_BACKEND_END_NAMESPACE

#endif // __CARLA_BACKEND_UTILS_HPP__
#endif // CARLA_BACKEND_UTILS_HPP_INCLUDED

+ 3
- 5
source/utils/CarlaBridgeUtils.hpp View File

@@ -21,7 +21,7 @@

#include "CarlaRingBuffer.hpp"

// -------------------------------------------------
// -----------------------------------------------------------------------

enum PluginBridgeInfoType {
kPluginBridgeAudioCount = 0,
@@ -68,7 +68,7 @@ const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Hos
//If \a type is 'chunk' or 'binary' \a rvalue refers to chunk file.
#endif

// -------------------------------------------------
// -----------------------------------------------------------------------

struct BridgeShmControl {
// 32 and 64-bit binaries align semaphores differently.
@@ -86,7 +86,7 @@ struct BridgeShmControl {
CARLA_DECLARE_NON_COPY_STRUCT(BridgeShmControl)
};

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
const char* PluginBridgeInfoType2str(const PluginBridgeInfoType type)
@@ -170,6 +170,4 @@ const char* PluginBridgeOpcode2str(const PluginBridgeOpcode opcode)
return nullptr;
}

// -------------------------------------------------

#endif // __CARLA_BRIDGE_UTILS_HPP__

+ 4
- 6
source/utils/CarlaLadspaUtils.hpp View File

@@ -25,7 +25,7 @@

#include <cmath>

// -------------------------------------------------
// -----------------------------------------------------------------------
// Copy RDF object

static inline
@@ -87,7 +87,7 @@ const LADSPA_RDF_Descriptor* ladspa_rdf_dup(const LADSPA_RDF_Descriptor* const o
return newDescriptor;
}

// -------------------------------------------------
// -----------------------------------------------------------------------
// Check if 2 ports match types

static inline
@@ -104,7 +104,7 @@ bool is_ladspa_port_good(const LADSPA_PortDescriptor port1, const LADSPA_PortDes
return true;
}

// -------------------------------------------------
// -----------------------------------------------------------------------
// Check if rdf data matches descriptor

static inline
@@ -137,7 +137,7 @@ bool is_ladspa_rdf_descriptor_valid(const LADSPA_RDF_Descriptor* const rdfDescri
return true;
}

// -------------------------------------------------
// -----------------------------------------------------------------------
// Get default control port value

static inline
@@ -205,6 +205,4 @@ LADSPA_Data get_default_ladspa_port_value(const LADSPA_PortRangeHintDescriptor h
return def;
}

// -------------------------------------------------

#endif // __CARLA_LADSPA_UTILS_HPP__

+ 1
- 3
source/utils/CarlaLibUtils.hpp View File

@@ -24,7 +24,7 @@
# include <dlfcn.h>
#endif

// -------------------------------------------------
// -----------------------------------------------------------------------
// library related calls

static inline
@@ -95,6 +95,4 @@ const char* lib_error(const char* const filename)
#endif
}

// -------------------------------------------------

#endif // __CARLA_LIB_UTILS_HPP__

+ 1
- 1
source/utils/CarlaLogThread.hpp View File

@@ -26,7 +26,7 @@

CARLA_BACKEND_START_NAMESPACE

// -------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------
// Log thread

class LogThread : public QThread


+ 2
- 2
source/utils/CarlaLv2Utils.hpp View File

@@ -64,7 +64,7 @@
#include <QtCore/QMap>
#include <QtCore/QStringList>

// -------------------------------------------------
// -----------------------------------------------------------------------
// Define namespaces and missing prefixes

#define NS_dct "http://purl.org/dc/terms/"
@@ -82,7 +82,7 @@
#define LV2_UI__idle LV2_UI_PREFIX "idle"
#define LV2_UI__makeResident LV2_UI_PREFIX "makeResident"

// -------------------------------------------------
// -----------------------------------------------------------------------
// Non-void versions

#define LV2NV_ATOM_CONTENTS(type, atom) \


+ 9
- 37
source/utils/CarlaMutex.hpp View File

@@ -12,23 +12,17 @@
* 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 GPL.txt file
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef __CARLA_MUTEX_HPP__
#define __CARLA_MUTEX_HPP__
#ifndef CARLA_MUTEX_HPP_INCLUDED
#define CARLA_MUTEX_HPP_INCLUDED

#include "CarlaJuceUtils.hpp"

// #define CPP11_MUTEX
#include <pthread.h>

#ifdef CPP11_MUTEX
# include <mutex>
#else
# include <pthread.h>
#endif

// -------------------------------------------------
// -----------------------------------------------------------------------
// CarlaMutex class

class CarlaMutex
@@ -37,48 +31,32 @@ public:
CarlaMutex()
: fTryLockWasCalled(false)
{
#ifndef CPP11_MUTEX
pthread_mutex_init(&pmutex, nullptr);
#endif
}

~CarlaMutex()
{
#ifndef CPP11_MUTEX
pthread_mutex_destroy(&pmutex);
#endif
}

void lock()
{
#ifdef CPP11_MUTEX
cmutex.lock();
#else
pthread_mutex_lock(&pmutex);
#endif
}

bool tryLock()
{
fTryLockWasCalled = true;

#ifdef CPP11_MUTEX
return cmutex.try_lock();
#else
return (pthread_mutex_trylock(&pmutex) == 0);
#endif
}

void unlock(const bool resetTryLock)
void unlock(/*const bool resetTryLock*/)
{
if (resetTryLock)
fTryLockWasCalled = false;
//if (resetTryLock)
// fTryLockWasCalled = false;

#ifdef CPP11_MUTEX
cmutex.unlock();
#else
pthread_mutex_unlock(&pmutex);
#endif
}

bool wasTryLockCalled()
@@ -110,17 +88,11 @@ public:
};

private:
#ifdef CPP11_MUTEX
std::mutex cmutex;
#else
pthread_mutex_t pmutex;
#endif
bool fTryLockWasCalled;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaMutex)
};

// -------------------------------------------------

#endif // __CARLA_MUTEX_HPP__
#endif // CARLA_MUTEX_HPP_INCLUDED

+ 127
- 129
source/utils/CarlaOscUtils.hpp View File

@@ -12,24 +12,24 @@
* 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 GPL.txt file
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef __CARLA_OSC_UTILS_HPP__
#define __CARLA_OSC_UTILS_HPP__
#ifndef CARLA_OSC_UTILS_HPP_INCLUDED
#define CARLA_OSC_UTILS_HPP_INCLUDED

#include "CarlaJuceUtils.hpp"

#include <lo/lo.h>

// -------------------------------------------------
// -----------------------------------------------------------------------

struct CarlaOscData {
const char* path;
lo_address source;
lo_address target;

CarlaOscData()
CarlaOscData() noexcept
: path(nullptr),
source(nullptr),
target(nullptr) {}
@@ -63,290 +63,288 @@ struct CarlaOscData {
CARLA_DECLARE_NON_COPY_STRUCT(CarlaOscData)
};

// -------------------------------------------------
// -----------------------------------------------------------------------

static inline
void osc_send_configure(const CarlaOscData* const oscData, const char* const key, const char* const value)
void osc_send_configure(const CarlaOscData& oscData, const char* const key, const char* const value)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(key != nullptr);
CARLA_ASSERT(value != nullptr);
carla_debug("osc_send_configure(path:\"%s\", \"%s\", \"%s\")", oscData->path, key, value);
carla_debug("osc_send_configure(path:\"%s\", \"%s\", \"%s\")", oscData.path, key, value);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && key != nullptr && value != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && key != nullptr && value != nullptr)
{
char targetPath[std::strlen(oscData->path)+11];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+11];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/configure");
lo_send(oscData->target, targetPath, "ss", key, value);
lo_send(oscData.target, targetPath, "ss", key, value);
}
}

static inline
void osc_send_control(const CarlaOscData* const oscData, const int32_t index, const float value)
void osc_send_control(const CarlaOscData& oscData, const int32_t index, const float value)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(index != -1); // -1 == PARAMETER_NULL
carla_debug("osc_send_control(path:\"%s\", %i, %f)", oscData->path, index, value);
carla_debug("osc_send_control(path:\"%s\", %i, %f)", oscData.path, index, value);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && index != -1)
if (oscData.path != nullptr && oscData.target != nullptr && index != -1)
{
char targetPath[std::strlen(oscData->path)+9];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+9];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/control");
lo_send(oscData->target, targetPath, "if", index, value);
lo_send(oscData.target, targetPath, "if", index, value);
}
}

static inline
void osc_send_program(const CarlaOscData* const oscData, const int32_t index)
void osc_send_program(const CarlaOscData& oscData, const int32_t index)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(index >= 0);
carla_debug("osc_send_program(path:\"%s\", %i)", oscData->path, index);
carla_debug("osc_send_program(path:\"%s\", %i)", oscData.path, index);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && index >= 0)
if (oscData.path != nullptr && oscData.target != nullptr && index >= 0)
{
char targetPath[std::strlen(oscData->path)+9];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+9];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/program");
lo_send(oscData->target, targetPath, "i", index);
lo_send(oscData.target, targetPath, "i", index);
}
}

static inline
void osc_send_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program)
void osc_send_program(const CarlaOscData& oscData, const int32_t bank, const int32_t program)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(program >= 0);
CARLA_ASSERT(bank >= 0);
carla_debug("osc_send_program(path:\"%s\", %i, %i)", oscData->path, bank, program);
carla_debug("osc_send_program(path:\"%s\", %i, %i)", oscData.path, bank, program);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && bank >= 0 && program >= 0)
if (oscData.path != nullptr && oscData.target != nullptr && bank >= 0 && program >= 0)
{
char targetPath[std::strlen(oscData->path)+9];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+9];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/program");
lo_send(oscData->target, targetPath, "ii", bank, program);
lo_send(oscData.target, targetPath, "ii", bank, program);
}
}

static inline
void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t index)
void osc_send_midi_program(const CarlaOscData& oscData, const int32_t index)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(index >= 0);
carla_debug("osc_send_midi_program(path:\"%s\", %i)", oscData->path, index);
carla_debug("osc_send_midi_program(path:\"%s\", %i)", oscData.path, index);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && index >= 0)
if (oscData.path != nullptr && oscData.target != nullptr && index >= 0)
{
char targetPath[std::strlen(oscData->path)+14];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+14];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/midi-program");
lo_send(oscData->target, targetPath, "i", index);
lo_send(oscData.target, targetPath, "i", index);
}
}

static inline
void osc_send_midi_program(const CarlaOscData* const oscData, const int32_t bank, const int32_t program)
void osc_send_midi_program(const CarlaOscData& oscData, const int32_t bank, const int32_t program)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(program >= 0);
CARLA_ASSERT(bank >= 0);
carla_debug("osc_send_midi_program(path:\"%s\", %i, %i)", oscData->path, bank, program);
carla_debug("osc_send_midi_program(path:\"%s\", %i, %i)", oscData.path, bank, program);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && bank >= 0 && program >= 0)
if (oscData.path != nullptr && oscData.target != nullptr && bank >= 0 && program >= 0)
{
char targetPath[std::strlen(oscData->path)+14];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+14];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/midi-program");
lo_send(oscData->target, targetPath, "ii", bank, program);
lo_send(oscData.target, targetPath, "ii", bank, program);
}
}

static inline
void osc_send_midi(const CarlaOscData* const oscData, const uint8_t buf[4])
void osc_send_midi(const CarlaOscData& oscData, const uint8_t buf[4])
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(buf[0] == 0);
CARLA_ASSERT(buf[1] != 0);
carla_debug("osc_send_midi(path:\"%s\", 0x%X, %03u, %03u)", oscData->path, buf[1], buf[2], buf[3]);
carla_debug("osc_send_midi(path:\"%s\", [0x%X, %03u, %03u])", oscData.path, buf[1], buf[2], buf[3]);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && buf[0] == 0 && buf[1] != 0)
if (oscData.path != nullptr && oscData.target != nullptr && buf[0] == 0 && buf[1] != 0)
{
char targetPath[std::strlen(oscData->path)+6];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+6];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/midi");
lo_send(oscData->target, targetPath, "m", buf);
lo_send(oscData.target, targetPath, "m", buf);
}
}

static inline
void osc_send_sample_rate(const CarlaOscData* const oscData, const float sampleRate)
void osc_send_sample_rate(const CarlaOscData& oscData, const float sampleRate)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(sampleRate > 0.0f);
carla_debug("osc_send_sample_rate(path:\"%s\", %f)", oscData->path, sampleRate);
carla_debug("osc_send_sample_rate(path:\"%s\", %f)", oscData.path, sampleRate);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && sampleRate > 0.0f)
if (oscData.path != nullptr && oscData.target != nullptr && sampleRate > 0.0f)
{
char targetPath[std::strlen(oscData->path)+13];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+13];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/sample-rate");
lo_send(oscData->target, targetPath, "f", sampleRate);
lo_send(oscData.target, targetPath, "f", sampleRate);
}
}

#ifdef BUILD_BRIDGE
static inline
void osc_send_update(const CarlaOscData* const oscData, const char* const url)
void osc_send_update(const CarlaOscData& oscData, const char* const url)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(url != nullptr);
carla_debug("osc_send_update(path:\"%s\", \"%s\")", oscData->path, url);
carla_debug("osc_send_update(path:\"%s\", \"%s\")", oscData.path, url);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && url != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && url != nullptr)
{
char targetPath[std::strlen(oscData->path)+8];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+8];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/update");
lo_send(oscData->target, targetPath, "s", url);
lo_send(oscData.target, targetPath, "s", url);
}
}

static inline
void osc_send_exiting(const CarlaOscData* const oscData)
void osc_send_exiting(const CarlaOscData& oscData)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
carla_debug("osc_send_exiting(path:\"%s\")", oscData->path);
CARLA_ASSERT(oscData.path != nullptr);
carla_debug("osc_send_exiting(path:\"%s\")", oscData.path);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr)
{
char targetPath[std::strlen(oscData->path)+9];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+9];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/exiting");
lo_send(oscData->target, targetPath, "");
lo_send(oscData.target, targetPath, "");
}
}
#endif

static inline
void osc_send_show(const CarlaOscData* const oscData)
void osc_send_show(const CarlaOscData& oscData)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
carla_debug("osc_send_show(path:\"%s\")", oscData->path);
CARLA_ASSERT(oscData.path != nullptr);
carla_debug("osc_send_show(path:\"%s\")", oscData.path);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr)
{
char targetPath[std::strlen(oscData->path)+6];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+6];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/show");
lo_send(oscData->target, targetPath, "");
lo_send(oscData.target, targetPath, "");
}
}

static inline
void osc_send_hide(const CarlaOscData* const oscData)
void osc_send_hide(const CarlaOscData& oscData)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
carla_debug("osc_send_hide(path:\"%s\")", oscData->path);
CARLA_ASSERT(oscData.path != nullptr);
carla_debug("osc_send_hide(path:\"%s\")", oscData.path);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr)
{
char targetPath[std::strlen(oscData->path)+6];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+6];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/hide");
lo_send(oscData->target, targetPath, "");
lo_send(oscData.target, targetPath, "");
}
}

static inline
void osc_send_quit(const CarlaOscData* const oscData)
void osc_send_quit(const CarlaOscData& oscData)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
carla_debug("osc_send_quit(path:\"%s\")", oscData->path);
CARLA_ASSERT(oscData.path != nullptr);
carla_debug("osc_send_quit(path:\"%s\")", oscData.path);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr)
{
char targetPath[std::strlen(oscData->path)+6];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+6];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/quit");
lo_send(oscData->target, targetPath, "");
lo_send(oscData.target, targetPath, "");
}
}

// -------------------------------------------------
// -----------------------------------------------------------------------

#ifdef BUILD_BRIDGE_PLUGIN
static inline
void osc_send_bridge_update(const CarlaOscData* const oscData, const char* const url)
void osc_send_bridge_update(const CarlaOscData& oscData, const char* const url)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(url != nullptr);
carla_debug("osc_send_bridge_update(path:\"%s\", \"%s\")", oscData->path, url);
carla_debug("osc_send_bridge_update(path:\"%s\", \"%s\")", oscData.path, url);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && url != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && url != nullptr)
{
char targetPath[std::strlen(oscData->path)+15];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+15];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/bridge_update");
lo_send(oscData->target, targetPath, "s", url);
lo_send(oscData.target, targetPath, "s", url);
}
}

static inline
void osc_send_bridge_error(const CarlaOscData* const oscData, const char* const error)
void osc_send_bridge_error(const CarlaOscData& oscData, const char* const error)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(error != nullptr);
carla_debug("osc_send_bridge_error(path:\"%s\", \"%s\")", oscData->path, error);
carla_debug("osc_send_bridge_error(path:\"%s\", \"%s\")", oscData.path, error);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && error != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && error != nullptr)
{
char targetPath[std::strlen(oscData->path)+14];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+14];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/bridge_error");
lo_send(oscData->target, targetPath, "s", error);
lo_send(oscData.target, targetPath, "s", error);
}
}
#endif

#if defined(BRIDGE_LV2) || defined(WANT_LV2)
static inline
void osc_send_lv2_atom_transfer(const CarlaOscData* const oscData, const int32_t portIndex, const char* const atomBuf)
void osc_send_lv2_atom_transfer(const CarlaOscData& oscData, const int32_t portIndex, const char* const atomBuf)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(portIndex >= 0);
CARLA_ASSERT(atomBuf != nullptr);
carla_debug("osc_send_lv2_atom_transfer(path:\"%s\", %i, <atomBuf:%p>)", oscData->path, portIndex, atomBuf);
carla_debug("osc_send_lv2_atom_transfer(path:\"%s\", %i, <atomBuf:%p>)", oscData.path, portIndex, atomBuf);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && portIndex >= 0 && atomBuf != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && portIndex >= 0 && atomBuf != nullptr)
{
char targetPath[std::strlen(oscData->path)+19];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+19];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/lv2_atom_transfer");
lo_send(oscData->target, targetPath, "is", portIndex, atomBuf);
lo_send(oscData.target, targetPath, "is", portIndex, atomBuf);
}
}

static inline
void osc_send_lv2_urid_map(const CarlaOscData* const oscData, const uint32_t urid, const char* const uri)
void osc_send_lv2_urid_map(const CarlaOscData& oscData, const uint32_t urid, const char* const uri)
{
CARLA_ASSERT(oscData != nullptr && oscData->path != nullptr);
CARLA_ASSERT(oscData.path != nullptr);
CARLA_ASSERT(urid > 0);
CARLA_ASSERT(uri != nullptr);
carla_debug("osc_send_lv2_urid_map(path:\"%s\", %i, \"%s\")", oscData->path, urid, uri);
carla_debug("osc_send_lv2_urid_map(path:\"%s\", %i, \"%s\")", oscData.path, urid, uri);

if (oscData != nullptr && oscData->path != nullptr && oscData->target != nullptr && urid > 0 && uri != nullptr)
if (oscData.path != nullptr && oscData.target != nullptr && urid > 0 && uri != nullptr)
{
char targetPath[std::strlen(oscData->path)+14];
std::strcpy(targetPath, oscData->path);
char targetPath[std::strlen(oscData.path)+14];
std::strcpy(targetPath, oscData.path);
std::strcat(targetPath, "/lv2_urid_map");
lo_send(oscData->target, targetPath, "is", urid, uri);
lo_send(oscData.target, targetPath, "is", urid, uri);
}
}
#endif

// -------------------------------------------------

#endif // __CARLA_OSC_UTILS_HPP__
#endif // CARLA_OSC_UTILS_HPP_INCLUDED

+ 2
- 2
source/utils/CarlaRingBuffer.hpp View File

@@ -23,7 +23,7 @@

#define RING_BUFFER_SIZE 2048

// -------------------------------------------------
// -----------------------------------------------------------------------
// RingBuffer struct

struct RingBuffer {
@@ -34,7 +34,7 @@ struct RingBuffer {
CARLA_DECLARE_NON_COPY_STRUCT(RingBuffer)
};

// -------------------------------------------------
// -----------------------------------------------------------------------
// RingBufferControl class

class RingBufferControl


+ 1
- 1
source/utils/CarlaShmUtils.hpp View File

@@ -28,7 +28,7 @@ struct shm_t { HANDLE shm; HANDLE map; };
typedef int shm_t;
#endif

// -------------------------------------------------
// -----------------------------------------------------------------------
// shared memory calls

static inline


+ 1
- 1
source/utils/CarlaStateUtils.hpp View File

@@ -26,7 +26,7 @@

CARLA_BACKEND_START_NAMESPACE

// -------------------------------------------------
// -----------------------------------------------------------------------

struct StateParameter {
uint32_t index;


+ 6
- 4
source/utils/CarlaString.hpp View File

@@ -299,11 +299,10 @@ public:
}
}

#ifndef BUILD_ANSI_TEST
// Using '+=' and '-=' temporarily converts char into int

void toLower() noexcept
{
#ifndef BUILD_ANSI_TEST
// Using '+=' temporarily converts char into int
static const char kCharDiff('a' - 'A');

for (size_t i=0; i < fBufferLen; ++i)
@@ -311,10 +310,13 @@ public:
if (fBuffer[i] >= 'A' && fBuffer[i] <= 'Z')
fBuffer[i] += kCharDiff;
}
#endif
}

void toUpper() noexcept
{
#ifndef BUILD_ANSI_TEST
// Using '-=' temporarily converts char into int
static const char kCharDiff('a' - 'A');

for (size_t i=0; i < fBufferLen; ++i)
@@ -322,8 +324,8 @@ public:
if (fBuffer[i] >= 'a' && fBuffer[i] <= 'z')
fBuffer[i] -= kCharDiff;
}
}
#endif
}

// -------------------------------------------------------------------
// public operators


+ 31
- 49
source/utils/CarlaUtils.hpp View File

@@ -131,7 +131,7 @@ void carla_assert_int2(const char* const assertion, const char* const file, cons
static inline
void carla_sleep(const unsigned int secs)
{
CARLA_ASSERT(secs > 0);
CARLA_SAFE_ASSERT_RETURN(secs > 0,);

#ifdef CARLA_OS_WIN
Sleep(secs * 1000);
@@ -143,7 +143,7 @@ void carla_sleep(const unsigned int secs)
static inline
void carla_msleep(const unsigned int msecs)
{
CARLA_ASSERT(msecs > 0);
CARLA_SAFE_ASSERT_RETURN(msecs > 0,);

#ifdef CARLA_OS_WIN
Sleep(msecs);
@@ -158,8 +158,8 @@ void carla_msleep(const unsigned int msecs)
static inline
void carla_setenv(const char* const key, const char* const value)
{
CARLA_ASSERT(key != nullptr);
CARLA_ASSERT(value != nullptr);
CARLA_SAFE_ASSERT_RETURN(key != nullptr,);
CARLA_SAFE_ASSERT_RETURN(value != nullptr,);

#ifdef CARLA_OS_WIN
SetEnvironmentVariableA(key, value);
@@ -174,7 +174,7 @@ void carla_setenv(const char* const key, const char* const value)
static inline
void carla_setprocname(const char* const name)
{
CARLA_ASSERT(name != nullptr);
CARLA_SAFE_ASSERT_RETURN(name != nullptr,);

#if defined(CARLA_OS_HAIKU)
if ((thread_id this_thread = find_thread(nullptr)) != B_NAME_NOT_FOUND)
@@ -199,7 +199,7 @@ void carla_setprocname(const char* const name)
static inline
const char* carla_strdup(const char* const strBuf)
{
CARLA_ASSERT(strBuf != nullptr);
CARLA_SAFE_ASSERT(strBuf != nullptr);

const size_t bufferLen = (strBuf != nullptr) ? std::strlen(strBuf) : 0;
char* const buffer = new char[bufferLen+1];
@@ -241,7 +241,7 @@ template<typename T>
static inline
const T& carla_fixValue(const T& min, const T& max, const T& value)
{
CARLA_ASSERT(max > min);
CARLA_SAFE_ASSERT_RETURN(max > min, max);

if (value <= min)
return min;
@@ -254,12 +254,9 @@ template<typename T>
static inline
void carla_add(T* dataDst, T* dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size != 0);

if (dataDst == nullptr || dataSrc == nullptr || size == 0)
return;
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size != 0,);

for (size_t i=0; i < size; ++i)
*dataDst++ += *dataSrc++;
@@ -269,12 +266,9 @@ template<typename T>
static inline
void carla_add(T* dataDst, const T* dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size != 0);

if (dataDst == nullptr || dataSrc == nullptr || size == 0)
return;
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size != 0,);

for (size_t i=0; i < size; ++i)
*dataDst++ += *dataSrc++;
@@ -284,12 +278,9 @@ template<typename T>
static inline
void carla_copy(T* dataDst, T* dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size != 0);

if (dataDst == nullptr || dataSrc == nullptr || size == 0)
return;
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size != 0,);

for (size_t i=0; i < size; ++i)
*dataDst++ = *dataSrc++;
@@ -299,12 +290,9 @@ template<typename T>
static inline
void carla_copy(T* dataDst, const T* dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size != 0);

if (dataDst == nullptr || dataSrc == nullptr || size == 0)
return;
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size != 0,);

for (size_t i=0; i < size; ++i)
*dataDst++ = *dataSrc++;
@@ -314,11 +302,8 @@ template<typename T>
static inline
void carla_fill(T* data, const size_t size, const T v)
{
CARLA_ASSERT(data != nullptr);
CARLA_ASSERT(size != 0);

if (data == nullptr || size == 0)
return;
CARLA_SAFE_ASSERT_RETURN(data != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size != 0,);

for (size_t i=0; i < size; ++i)
*data++ = v;
@@ -339,9 +324,9 @@ void carla_addFloat(float* const dataDst, float* const dataSrc, const size_t siz
static inline
void carla_copyDouble(double* const dataDst, double* const dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size > 0);
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size > 0,);

std::memcpy(dataDst, dataSrc, size*sizeof(double));
}
@@ -349,9 +334,9 @@ void carla_copyDouble(double* const dataDst, double* const dataSrc, const size_t
static inline
void carla_copyFloat(float* const dataDst, float* const dataSrc, const size_t size)
{
CARLA_ASSERT(dataDst != nullptr);
CARLA_ASSERT(dataSrc != nullptr);
CARLA_ASSERT(size > 0);
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,);
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,);
CARLA_SAFE_ASSERT_RETURN(size > 0,);

std::memcpy(dataDst, dataSrc, size*sizeof(float));
}
@@ -388,11 +373,8 @@ inline float
static inline
void carla_zeroMem(void* const memory, const size_t numBytes)
{
CARLA_ASSERT(memory != nullptr);
CARLA_ASSERT(numBytes != 0);

if (memory == nullptr || numBytes == 0)
return;
CARLA_SAFE_ASSERT_RETURN(memory != nullptr,);
CARLA_SAFE_ASSERT_RETURN(numBytes != 0,);

std::memset(memory, 0, numBytes);
}
@@ -408,8 +390,8 @@ template <typename T>
static inline
void carla_zeroStruct(T* const structure, const size_t count)
{
CARLA_ASSERT(structure != nullptr);
CARLA_ASSERT(count >= 1);
CARLA_SAFE_ASSERT_RETURN(structure != nullptr,);
CARLA_SAFE_ASSERT_RETURN(count != 0,);

std::memset(structure, 0, sizeof(T)*count);
}


+ 2
- 0
source/utils/Lv2AtomQueue.hpp View File

@@ -21,6 +21,8 @@
#include "CarlaLv2Utils.hpp"
#include "CarlaMutex.hpp"

// -----------------------------------------------------------------------

class Lv2AtomQueue
{
public:


+ 10
- 12
source/utils/RtList.hpp View File

@@ -12,11 +12,11 @@
* 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 GPL.txt file
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef __RT_LIST_HPP__
#define __RT_LIST_HPP__
#ifndef RT_LIST_HPP_INCLUDED
#define RT_LIST_HPP_INCLUDED

#include "CarlaUtils.hpp"

@@ -137,7 +137,7 @@ public:
{
if (Data* const data = _allocate())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add_tail(&data->siblings, &fQueue);
++fCount;
return true;
@@ -150,7 +150,7 @@ public:
{
if (Data* const data = _allocate())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add_tail(&data->siblings, it.fEntry->next);
++fCount;
return true;
@@ -163,7 +163,7 @@ public:
{
if (Data* const data = _allocate())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add(&data->siblings, &fQueue);
++fCount;
return true;
@@ -176,7 +176,7 @@ public:
{
if (Data* const data = _allocate())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add(&data->siblings, it.fEntry->prev);
++fCount;
return true;
@@ -461,7 +461,7 @@ public:
{
if (typename List<T>::Data* const data = _allocate_sleepy())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add_tail(&data->siblings, &this->fQueue);
++this->fCount;
}
@@ -471,7 +471,7 @@ public:
{
if (typename List<T>::Data* const data = _allocate_sleepy())
{
std::memcpy(&data->value, &value, sizeof(T));
data->value = value;
list_add(&data->siblings, &this->fQueue);
++this->fCount;
}
@@ -584,6 +584,4 @@ private:
LIST_DECLARATIONS(NonRtListNew)
};

// -----------------------------------------------------------------------

#endif // __RT_LIST_HPP__
#endif // RT_LIST_HPP_INCLUDED

Loading…
Cancel
Save