@@ -310,13 +310,13 @@ protected: | |||||
* Param \a isInputPort defines wherever this is an input port or not (output otherwise).\n | * Param \a isInputPort defines wherever this is an input port or not (output otherwise).\n | ||||
* Input/output and process mode are constant for the lifetime of the port. | * Input/output and process mode are constant for the lifetime of the port. | ||||
*/ | */ | ||||
CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort); | |||||
CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) noexcept; | |||||
public: | public: | ||||
/*! | /*! | ||||
* The destructor. | * The destructor. | ||||
*/ | */ | ||||
virtual ~CarlaEnginePort(); | |||||
virtual ~CarlaEnginePort() noexcept; | |||||
/*! | /*! | ||||
* Get the type of the port, as provided by the respective subclasses. | * Get the type of the port, as provided by the respective subclasses. | ||||
@@ -355,12 +355,12 @@ public: | |||||
* The constructor.\n | * The constructor.\n | ||||
* All constructor parameters are constant and will never change in the lifetime of the port. | * All constructor parameters are constant and will never change in the lifetime of the port. | ||||
*/ | */ | ||||
CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort); | |||||
CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort) noexcept; | |||||
/*! | /*! | ||||
* The destructor. | * The destructor. | ||||
*/ | */ | ||||
~CarlaEngineAudioPort() override; | |||||
~CarlaEngineAudioPort() noexcept override; | |||||
/*! | /*! | ||||
* Get the type of the port, in this case kEnginePortTypeAudio. | * Get the type of the port, in this case kEnginePortTypeAudio. | ||||
@@ -377,6 +377,7 @@ public: | |||||
/*! | /*! | ||||
* Direct access to the port's audio buffer. | * Direct access to the port's audio buffer. | ||||
* May return null. | |||||
*/ | */ | ||||
float* getBuffer() const noexcept | float* getBuffer() const noexcept | ||||
{ | { | ||||
@@ -401,12 +402,12 @@ public: | |||||
* The constructor.\n | * The constructor.\n | ||||
* All constructor parameters are constant and will never change in the lifetime of the port. | * All constructor parameters are constant and will never change in the lifetime of the port. | ||||
*/ | */ | ||||
CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort); | |||||
CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort) noexcept; | |||||
/*! | /*! | ||||
* The destructor. | * The destructor. | ||||
*/ | */ | ||||
~CarlaEngineCVPort() override; | |||||
~CarlaEngineCVPort() noexcept override; | |||||
/*! | /*! | ||||
* Get the type of the port, in this case kEnginePortTypeCV. | * Get the type of the port, in this case kEnginePortTypeCV. | ||||
@@ -422,12 +423,8 @@ public: | |||||
void initBuffer() noexcept override; | void initBuffer() noexcept override; | ||||
/*! | /*! | ||||
* Set a new buffer size. | |||||
*/ | |||||
void setBufferSize(const uint32_t bufferSize); | |||||
/*! | |||||
* Direct access to the port's buffer. | |||||
* Direct access to the port's CV buffer. | |||||
* May return null. | |||||
*/ | */ | ||||
float* getBuffer() const noexcept | float* getBuffer() const noexcept | ||||
{ | { | ||||
@@ -437,7 +434,6 @@ public: | |||||
#ifndef DOXYGEN | #ifndef DOXYGEN | ||||
protected: | protected: | ||||
float* fBuffer; | float* fBuffer; | ||||
const EngineProcessMode fProcessMode; | |||||
CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort) | CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort) | ||||
#endif | #endif | ||||
@@ -453,12 +449,12 @@ public: | |||||
* The constructor.\n | * The constructor.\n | ||||
* All constructor parameters are constant and will never change in the lifetime of the port. | * All constructor parameters are constant and will never change in the lifetime of the port. | ||||
*/ | */ | ||||
CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort); | |||||
CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort) noexcept; | |||||
/*! | /*! | ||||
* The destructor. | * The destructor. | ||||
*/ | */ | ||||
~CarlaEngineEventPort() override; | |||||
~CarlaEngineEventPort() noexcept override; | |||||
/*! | /*! | ||||
* Get the type of the port, in this case kEnginePortTypeEvent. | * Get the type of the port, in this case kEnginePortTypeEvent. | ||||
@@ -588,7 +584,7 @@ public: | |||||
* Add a new port of type \a portType. | * Add a new port of type \a portType. | ||||
* \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output). | * \note This function does nothing in rack processing mode since ports are static there (2 audio + 1 event for both input and output). | ||||
*/ | */ | ||||
virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput); | |||||
virtual CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) /*noexcept*/; | |||||
#ifndef DOXYGEN | #ifndef DOXYGEN | ||||
protected: | protected: | ||||
@@ -972,6 +968,11 @@ public: | |||||
bool isOscControlRegistered() const noexcept; | bool isOscControlRegistered() const noexcept; | ||||
#endif | #endif | ||||
/*! | |||||
* Idle OSC. | |||||
*/ | |||||
void idleOsc() const noexcept; | |||||
/*! | /*! | ||||
* Get OSC TCP server path. | * Get OSC TCP server path. | ||||
*/ | */ | ||||
@@ -56,14 +56,14 @@ static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, {{ | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Carla Engine port (Abstract) | // Carla Engine port (Abstract) | ||||
CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) | |||||
CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) noexcept | |||||
: fEngine(engine), | : fEngine(engine), | ||||
fIsInput(isInputPort) | fIsInput(isInputPort) | ||||
{ | { | ||||
carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInputPort)); | carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInputPort)); | ||||
} | } | ||||
CarlaEnginePort::~CarlaEnginePort() | |||||
CarlaEnginePort::~CarlaEnginePort() noexcept | |||||
{ | { | ||||
carla_debug("CarlaEnginePort::~CarlaEnginePort()"); | carla_debug("CarlaEnginePort::~CarlaEnginePort()"); | ||||
} | } | ||||
@@ -71,14 +71,14 @@ CarlaEnginePort::~CarlaEnginePort() | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Carla Engine Audio port | // Carla Engine Audio port | ||||
CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort) | |||||
CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort) noexcept | |||||
: CarlaEnginePort(engine, isInputPort), | : CarlaEnginePort(engine, isInputPort), | ||||
fBuffer(nullptr) | fBuffer(nullptr) | ||||
{ | { | ||||
carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInputPort)); | carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInputPort)); | ||||
} | } | ||||
CarlaEngineAudioPort::~CarlaEngineAudioPort() | |||||
CarlaEngineAudioPort::~CarlaEngineAudioPort() noexcept | |||||
{ | { | ||||
carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()"); | carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()"); | ||||
} | } | ||||
@@ -90,51 +90,26 @@ void CarlaEngineAudioPort::initBuffer() noexcept | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Carla Engine CV port | // Carla Engine CV port | ||||
CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort) | |||||
CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort) noexcept | |||||
: CarlaEnginePort(engine, isInputPort), | : CarlaEnginePort(engine, isInputPort), | ||||
fBuffer(nullptr), | |||||
fProcessMode(engine.getProccessMode()) | |||||
fBuffer(nullptr) | |||||
{ | { | ||||
carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s)", bool2str(isInputPort)); | carla_debug("CarlaEngineCVPort::CarlaEngineCVPort(%s)", bool2str(isInputPort)); | ||||
if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | |||||
fBuffer = new float[engine.getBufferSize()]; | |||||
} | } | ||||
CarlaEngineCVPort::~CarlaEngineCVPort() | |||||
CarlaEngineCVPort::~CarlaEngineCVPort() noexcept | |||||
{ | { | ||||
carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()"); | carla_debug("CarlaEngineCVPort::~CarlaEngineCVPort()"); | ||||
if (fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,); | |||||
delete[] fBuffer; | |||||
fBuffer = nullptr; | |||||
} | |||||
} | } | ||||
void CarlaEngineCVPort::initBuffer() noexcept | void CarlaEngineCVPort::initBuffer() noexcept | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,); | |||||
carla_zeroFloat(fBuffer, fEngine.getBufferSize()); | |||||
} | |||||
void CarlaEngineCVPort::setBufferSize(const uint32_t bufferSize) | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(fProcessMode != ENGINE_PROCESS_MODE_SINGLE_CLIENT && fProcessMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS,); | |||||
delete[] fBuffer; | |||||
fBuffer = new float[bufferSize]; | |||||
} | } | ||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Carla Engine Event port | // Carla Engine Event port | ||||
CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort) | |||||
CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort) noexcept | |||||
: CarlaEnginePort(engine, isInputPort), | : CarlaEnginePort(engine, isInputPort), | ||||
fBuffer(nullptr), | fBuffer(nullptr), | ||||
fProcessMode(engine.getProccessMode()) | fProcessMode(engine.getProccessMode()) | ||||
@@ -145,7 +120,7 @@ CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool | |||||
fBuffer = new EngineEvent[kMaxEngineEventInternalCount]; | fBuffer = new EngineEvent[kMaxEngineEventInternalCount]; | ||||
} | } | ||||
CarlaEngineEventPort::~CarlaEngineEventPort() | |||||
CarlaEngineEventPort::~CarlaEngineEventPort() noexcept | |||||
{ | { | ||||
carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()"); | carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()"); | ||||
@@ -302,13 +277,13 @@ CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine) | |||||
CarlaEngineClient::~CarlaEngineClient() | CarlaEngineClient::~CarlaEngineClient() | ||||
{ | { | ||||
CARLA_ASSERT(! fActive); | |||||
CARLA_SAFE_ASSERT(! fActive); | |||||
carla_debug("CarlaEngineClient::~CarlaEngineClient()"); | carla_debug("CarlaEngineClient::~CarlaEngineClient()"); | ||||
} | } | ||||
void CarlaEngineClient::activate() noexcept | void CarlaEngineClient::activate() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(! fActive); | |||||
CARLA_SAFE_ASSERT(! fActive); | |||||
carla_debug("CarlaEngineClient::activate()"); | carla_debug("CarlaEngineClient::activate()"); | ||||
fActive = true; | fActive = true; | ||||
@@ -316,7 +291,7 @@ void CarlaEngineClient::activate() noexcept | |||||
void CarlaEngineClient::deactivate() noexcept | void CarlaEngineClient::deactivate() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(fActive); | |||||
CARLA_SAFE_ASSERT(fActive); | |||||
carla_debug("CarlaEngineClient::deactivate()"); | carla_debug("CarlaEngineClient::deactivate()"); | ||||
fActive = false; | fActive = false; | ||||
@@ -342,23 +317,33 @@ void CarlaEngineClient::setLatency(const uint32_t samples) noexcept | |||||
fLatency = samples; | fLatency = samples; | ||||
} | } | ||||
CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput) | |||||
CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput) /*noexcept*/ | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); | CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); | ||||
carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput)); | carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput)); | ||||
switch (portType) | |||||
{ | |||||
case kEnginePortTypeNull: | |||||
break; | |||||
case kEnginePortTypeAudio: | |||||
return new CarlaEngineAudioPort(fEngine, isInput); | |||||
case kEnginePortTypeCV: | |||||
return new CarlaEngineCVPort(fEngine, isInput); | |||||
case kEnginePortTypeEvent: | |||||
return new CarlaEngineEventPort(fEngine, isInput); | |||||
CarlaEnginePort* ret = nullptr; | |||||
try { | |||||
switch (portType) | |||||
{ | |||||
case kEnginePortTypeNull: | |||||
break; | |||||
case kEnginePortTypeAudio: | |||||
ret = new CarlaEngineAudioPort(fEngine, isInput); | |||||
case kEnginePortTypeCV: | |||||
ret = new CarlaEngineCVPort(fEngine, isInput); | |||||
case kEnginePortTypeEvent: | |||||
ret = new CarlaEngineEventPort(fEngine, isInput); | |||||
} | |||||
} | |||||
catch(...) { | |||||
return nullptr; | |||||
} | } | ||||
if (ret != nullptr) | |||||
return ret; | |||||
carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput)); | carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput)); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
@@ -569,7 +554,6 @@ bool CarlaEngine::init(const char* const clientName) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->bufEvents.out == nullptr, "Invalid engine internal data (err #5)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name"); | CARLA_SAFE_ASSERT_RETURN_ERR(clientName != nullptr && clientName[0] != '\0', "Invalid client name"); | ||||
carla_debug("CarlaEngine::init(\"%s\")", clientName); | carla_debug("CarlaEngine::init(\"%s\")", clientName); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->aboutToClose = false; | pData->aboutToClose = false; | ||||
pData->curPluginCount = 0; | pData->curPluginCount = 0; | ||||
@@ -620,7 +604,7 @@ bool CarlaEngine::init(const char* const clientName) | |||||
#endif | #endif | ||||
pData->nextAction.ready(); | pData->nextAction.ready(); | ||||
pData->thread.start(); | |||||
pData->thread.startThread(); | |||||
callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName()); | callback(ENGINE_CALLBACK_ENGINE_STARTED, 0, 0, 0, 0.0f, getCurrentDriverName()); | ||||
@@ -634,14 +618,13 @@ bool CarlaEngine::close() | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #8)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)"); | ||||
carla_debug("CarlaEngine::close()"); | carla_debug("CarlaEngine::close()"); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->aboutToClose = true; | pData->aboutToClose = true; | ||||
if (pData->curPluginCount != 0) | if (pData->curPluginCount != 0) | ||||
removeAllPlugins(); | removeAllPlugins(); | ||||
pData->thread.stop(500); | |||||
pData->thread.stopThread(500); | |||||
pData->nextAction.ready(); | pData->nextAction.ready(); | ||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
@@ -682,10 +665,9 @@ bool CarlaEngine::close() | |||||
void CarlaEngine::idle() | void CarlaEngine::idle() | ||||
{ | { | ||||
CARLA_ASSERT(pData->nextAction.opcode == kEnginePostActionNull); // TESTING, remove later | |||||
CARLA_ASSERT(pData->nextPluginId == pData->maxPluginNumber); // TESTING, remove later | |||||
CARLA_ASSERT(pData->plugins != nullptr); // this one too maybe | |||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull,); // TESTING, remove later | |||||
CARLA_SAFE_ASSERT_RETURN(pData->nextPluginId == pData->maxPluginNumber,); // TESTING, remove later | |||||
CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr,); // this one too maybe | |||||
for (unsigned int i=0; i < pData->curPluginCount; ++i) | for (unsigned int i=0; i < pData->curPluginCount; ++i) | ||||
{ | { | ||||
@@ -694,6 +676,8 @@ void CarlaEngine::idle() | |||||
if (plugin != nullptr && plugin->isEnabled()) | if (plugin != nullptr && plugin->isEnabled()) | ||||
plugin->idle(); | plugin->idle(); | ||||
} | } | ||||
idleOsc(); | |||||
} | } | ||||
CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const) | CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const) | ||||
@@ -713,7 +697,6 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)"); | CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin params (err #2)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)"); | CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin params (err #3)"); | ||||
carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, uniqueId, extra); | carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, uniqueId, extra); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
unsigned int id; | unsigned int id; | ||||
CarlaPlugin* oldPlugin = nullptr; | CarlaPlugin* oldPlugin = nullptr; | ||||
@@ -973,14 +956,13 @@ bool CarlaEngine::removePlugin(const unsigned int id) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #16)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)"); | CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #1)"); | ||||
carla_debug("CarlaEngine::removePlugin(%i)", id); | carla_debug("CarlaEngine::removePlugin(%i)", id); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaPlugin* const plugin(pData->plugins[id].plugin); | CarlaPlugin* const plugin(pData->plugins[id].plugin); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove"); | CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)"); | CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data (err #17)"); | ||||
pData->thread.stop(500); | |||||
pData->thread.stopThread(500); | |||||
const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS); | const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS); | ||||
const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait); | const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait); | ||||
@@ -993,7 +975,7 @@ bool CarlaEngine::removePlugin(const unsigned int id) | |||||
delete plugin; | delete plugin; | ||||
if (isRunning() && ! pData->aboutToClose) | if (isRunning() && ! pData->aboutToClose) | ||||
pData->thread.start(); | |||||
pData->thread.startThread(); | |||||
callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr); | callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr); | ||||
return true; | return true; | ||||
@@ -1005,12 +987,11 @@ bool CarlaEngine::removeAllPlugins() | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data (err #19)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)"); | ||||
carla_debug("CarlaEngine::removeAllPlugins()"); | carla_debug("CarlaEngine::removeAllPlugins()"); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
if (pData->curPluginCount == 0) | if (pData->curPluginCount == 0) | ||||
return true; | return true; | ||||
pData->thread.stop(500); | |||||
pData->thread.stopThread(500); | |||||
const bool lockWait(isRunning()); | const bool lockWait(isRunning()); | ||||
const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait); | const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait); | ||||
@@ -1036,7 +1017,7 @@ bool CarlaEngine::removeAllPlugins() | |||||
} | } | ||||
if (isRunning() && ! pData->aboutToClose) | if (isRunning() && ! pData->aboutToClose) | ||||
pData->thread.start(); | |||||
pData->thread.startThread(); | |||||
return true; | return true; | ||||
} | } | ||||
@@ -1049,7 +1030,6 @@ const char* CarlaEngine::renamePlugin(const unsigned int id, const char* const n | |||||
CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)"); | CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id (err #2)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name"); | CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name"); | ||||
carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName); | carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaPlugin* const plugin(pData->plugins[id].plugin); | CarlaPlugin* const plugin(pData->plugins[id].plugin); | ||||
@@ -1073,7 +1053,6 @@ bool CarlaEngine::clonePlugin(const unsigned int id) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #27)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)"); | CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id (err #3)"); | ||||
carla_debug("CarlaEngine::clonePlugin(%i)", id); | carla_debug("CarlaEngine::clonePlugin(%i)", id); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaPlugin* const plugin(pData->plugins[id].plugin); | CarlaPlugin* const plugin(pData->plugins[id].plugin); | ||||
@@ -1089,7 +1068,7 @@ bool CarlaEngine::clonePlugin(const unsigned int id) | |||||
if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(), plugin->getExtraStuff())) | if (! addPlugin(plugin->getBinaryType(), plugin->getType(), plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(), plugin->getExtraStuff())) | ||||
return false; | return false; | ||||
CARLA_ASSERT(pluginCountBefore+1 == pData->curPluginCount); | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pluginCountBefore+1 == pData->curPluginCount, "No new plugin found"); | |||||
if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin) | if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin) | ||||
newPlugin->loadSaveState(plugin->getSaveState()); | newPlugin->loadSaveState(plugin->getSaveState()); | ||||
@@ -1103,7 +1082,6 @@ bool CarlaEngine::replacePlugin(const unsigned int id) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data (err #30)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)"); | ||||
carla_debug("CarlaEngine::replacePlugin(%i)", id); | carla_debug("CarlaEngine::replacePlugin(%i)", id); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
// might use this to reset | // might use this to reset | ||||
if (id == pData->curPluginCount || id == pData->maxPluginNumber) | if (id == pData->curPluginCount || id == pData->maxPluginNumber) | ||||
@@ -1133,7 +1111,6 @@ bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)"); | CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id (err #5)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)"); | CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id (err #6)"); | ||||
carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB); | carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaPlugin* const pluginA(pData->plugins[idA].plugin); | CarlaPlugin* const pluginA(pData->plugins[idA].plugin); | ||||
CarlaPlugin* const pluginB(pData->plugins[idB].plugin); | CarlaPlugin* const pluginB(pData->plugins[idB].plugin); | ||||
@@ -1143,7 +1120,7 @@ bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) | |||||
CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data (err #36)"); | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)"); | CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data (err #37)"); | ||||
pData->thread.stop(500); | |||||
pData->thread.stopThread(500); | |||||
const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS); | const bool lockWait(isRunning() && pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS); | ||||
const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait); | const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait); | ||||
@@ -1154,7 +1131,7 @@ bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) | |||||
#endif | #endif | ||||
if (isRunning() && ! pData->aboutToClose) | if (isRunning() && ! pData->aboutToClose) | ||||
pData->thread.start(); | |||||
pData->thread.startThread(); | |||||
return true; | return true; | ||||
} | } | ||||
@@ -1266,7 +1243,6 @@ bool CarlaEngine::loadFile(const char* const filename) | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)"); | CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #1)"); | ||||
carla_debug("CarlaEngine::loadFile(\"%s\")", filename); | carla_debug("CarlaEngine::loadFile(\"%s\")", filename); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
QFileInfo fileInfo(filename); | QFileInfo fileInfo(filename); | ||||
@@ -1398,7 +1374,6 @@ bool CarlaEngine::loadProject(const char* const filename) | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)"); | CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #2)"); | ||||
carla_debug("CarlaEngine::loadProject(\"%s\")", filename); | carla_debug("CarlaEngine::loadProject(\"%s\")", filename); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
QFile file(filename); | QFile file(filename); | ||||
@@ -1501,7 +1476,6 @@ bool CarlaEngine::saveProject(const char* const filename) | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)"); | CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename (err #3)"); | ||||
carla_debug("CarlaEngine::saveProject(\"%s\")", filename); | carla_debug("CarlaEngine::saveProject(\"%s\")", filename); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
QFile file(filename); | QFile file(filename); | ||||
@@ -1651,7 +1625,6 @@ void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int | |||||
void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept | void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept | ||||
{ | { | ||||
carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr); | carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->callback = func; | pData->callback = func; | ||||
pData->callbackPtr = ptr; | pData->callbackPtr = ptr; | ||||
@@ -1665,7 +1638,6 @@ const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const | |||||
CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr); | CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr); | ||||
CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr); | CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr); | ||||
carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter); | carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
const char* ret = nullptr; | const char* ret = nullptr; | ||||
@@ -1681,7 +1653,6 @@ const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const | |||||
void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept | void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept | ||||
{ | { | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->fileCallback = func; | pData->fileCallback = func; | ||||
pData->fileCallbackPtr = ptr; | pData->fileCallbackPtr = ptr; | ||||
@@ -1696,7 +1667,6 @@ bool CarlaEngine::patchbayConnect(const int portA, const int portB) | |||||
CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false); | CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false); | ||||
CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false); | CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false); | ||||
carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB); | carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
if (pData->bufAudio.usePatchbay) | if (pData->bufAudio.usePatchbay) | ||||
{ | { | ||||
@@ -1800,7 +1770,6 @@ bool CarlaEngine::patchbayDisconnect(const uint connectionId) | |||||
CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false); | CARLA_SAFE_ASSERT_RETURN(pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK || pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY, false); | ||||
CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false); | CARLA_SAFE_ASSERT_RETURN(pData->bufAudio.isReady, false); | ||||
carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId); | carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
if (pData->bufAudio.usePatchbay) | if (pData->bufAudio.usePatchbay) | ||||
{ | { | ||||
@@ -1916,7 +1885,6 @@ const char* CarlaEngine::getLastError() const noexcept | |||||
void CarlaEngine::setLastError(const char* const error) const | void CarlaEngine::setLastError(const char* const error) const | ||||
{ | { | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->lastError = error; | pData->lastError = error; | ||||
} | } | ||||
@@ -1934,7 +1902,6 @@ void CarlaEngine::setAboutToClose() noexcept | |||||
void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr) | void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr) | ||||
{ | { | ||||
carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr); | carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE)) | if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE)) | ||||
return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr); | return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr); | ||||
@@ -2050,6 +2017,14 @@ bool CarlaEngine::isOscControlRegistered() const noexcept | |||||
} | } | ||||
#endif | #endif | ||||
void CarlaEngine::idleOsc() const noexcept | |||||
{ | |||||
try { | |||||
pData->osc.idle(); | |||||
} catch(...) {} | |||||
} | |||||
const char* CarlaEngine::getOscServerPathTCP() const noexcept | const char* CarlaEngine::getOscServerPathTCP() const noexcept | ||||
{ | { | ||||
return pData->osc.getServerPathTCP(); | return pData->osc.getServerPathTCP(); | ||||
@@ -2063,7 +2038,6 @@ const char* CarlaEngine::getOscServerPathUDP() const noexcept | |||||
#ifdef BUILD_BRIDGE | #ifdef BUILD_BRIDGE | ||||
void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept | void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept | ||||
{ | { | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
pData->oscData = oscData; | pData->oscData = oscData; | ||||
} | } | ||||
@@ -297,7 +297,7 @@ public: | |||||
pData->sampleRate = fShmControl.readFloat(); | pData->sampleRate = fShmControl.readFloat(); | ||||
carla_stderr("SampleRate: %f", pData->sampleRate); | carla_stderr("SampleRate: %f", pData->sampleRate); | ||||
CarlaThread::start(); | |||||
CarlaThread::startThread(); | |||||
CarlaEngine::init(clientName); | CarlaEngine::init(clientName); | ||||
return true; | return true; | ||||
} | } | ||||
@@ -307,7 +307,7 @@ public: | |||||
carla_debug("CarlaEnginePlugin::close()"); | carla_debug("CarlaEnginePlugin::close()"); | ||||
CarlaEngine::close(); | CarlaEngine::close(); | ||||
CarlaThread::stop(6000); | |||||
CarlaThread::stopThread(6000); | |||||
fShmTime.clear(); | fShmTime.clear(); | ||||
fShmControl.clear(); | fShmControl.clear(); | ||||
@@ -346,14 +346,14 @@ public: | |||||
// TODO - set RT permissions | // TODO - set RT permissions | ||||
carla_debug("CarlaEngineBridge::run()"); | carla_debug("CarlaEngineBridge::run()"); | ||||
for (; ! shouldExit();) | |||||
for (; ! shouldThreadExit();) | |||||
{ | { | ||||
if (! jackbridge_sem_timedwait(&fShmControl.data->runServer, 5)) | if (! jackbridge_sem_timedwait(&fShmControl.data->runServer, 5)) | ||||
{ | { | ||||
if (errno == ETIMEDOUT) | if (errno == ETIMEDOUT) | ||||
{ | { | ||||
fIsRunning = false; | fIsRunning = false; | ||||
signalShouldExit(); | |||||
signalThreadShouldExit(); | |||||
return; | return; | ||||
} | } | ||||
} | } | ||||
@@ -516,7 +516,7 @@ public: | |||||
} | } | ||||
case kPluginBridgeOpcodeQuit: | case kPluginBridgeOpcodeQuit: | ||||
signalShouldExit(); | |||||
signalThreadShouldExit(); | |||||
fIsRunning = false; | fIsRunning = false; | ||||
break; | break; | ||||
} | } | ||||
@@ -549,8 +549,8 @@ EngineInternalEvents::EngineInternalEvents() noexcept | |||||
EngineInternalEvents::~EngineInternalEvents() noexcept | EngineInternalEvents::~EngineInternalEvents() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(in == nullptr); | |||||
CARLA_ASSERT(out == nullptr); | |||||
CARLA_SAFE_ASSERT(in == nullptr); | |||||
CARLA_SAFE_ASSERT(out == nullptr); | |||||
} | } | ||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
@@ -570,7 +570,7 @@ EngineNextAction::EngineNextAction() noexcept | |||||
EngineNextAction::~EngineNextAction() noexcept | EngineNextAction::~EngineNextAction() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(opcode == kEnginePostActionNull); | |||||
CARLA_SAFE_ASSERT(opcode == kEnginePostActionNull); | |||||
} | } | ||||
void EngineNextAction::ready() noexcept | void EngineNextAction::ready() noexcept | ||||
@@ -31,15 +31,6 @@ | |||||
#define CARLA_SAFE_ASSERT_RETURN_ERR(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return false; } | #define CARLA_SAFE_ASSERT_RETURN_ERR(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return false; } | ||||
#define CARLA_SAFE_ASSERT_RETURN_ERRN(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return nullptr; } | #define CARLA_SAFE_ASSERT_RETURN_ERRN(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return nullptr; } | ||||
// ----------------------------------------------------------------------- | |||||
// Global action lock for UI operations, used for osc only | |||||
#ifndef BUILD_BRIDGE | |||||
# define CARLA_ENGINE_THREAD_SAFE_SECTION const CarlaCriticalSection::Scope _ccsl(pData->_cs); | |||||
#else | |||||
# define CARLA_ENGINE_THREAD_SAFE_SECTION | |||||
#endif | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
CARLA_BACKEND_START_NAMESPACE | CARLA_BACKEND_START_NAMESPACE | ||||
@@ -248,10 +239,6 @@ struct CarlaEngineProtectedData { | |||||
EngineInternalTime time; | EngineInternalTime time; | ||||
EngineNextAction nextAction; | EngineNextAction nextAction; | ||||
#ifndef BUILD_BRIDGE | |||||
CarlaCriticalSection _cs; // for handling requests from multiple threads | |||||
#endif | |||||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||||
CarlaEngineProtectedData(CarlaEngine* const engine); | CarlaEngineProtectedData(CarlaEngine* const engine); | ||||
@@ -36,6 +36,7 @@ CARLA_BACKEND_START_NAMESPACE | |||||
#endif | #endif | ||||
class CarlaEngineJack; | class CarlaEngineJack; | ||||
class CarlaEngineJackClient; | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// Fallback data | // Fallback data | ||||
@@ -48,7 +49,7 @@ static const EngineEvent kFallbackJackEngineEvent = { kEngineEventTypeNull, 0, 0 | |||||
class CarlaEngineJackAudioPort : public CarlaEngineAudioPort | class CarlaEngineJackAudioPort : public CarlaEngineAudioPort | ||||
{ | { | ||||
public: | public: | ||||
CarlaEngineJackAudioPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) | |||||
CarlaEngineJackAudioPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) noexcept | |||||
: CarlaEngineAudioPort(engine, isInputPort), | : CarlaEngineAudioPort(engine, isInputPort), | ||||
fClient(client), | fClient(client), | ||||
fPort(port) | fPort(port) | ||||
@@ -57,24 +58,28 @@ public: | |||||
if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | ||||
{ | { | ||||
CARLA_ASSERT(client != nullptr && port != nullptr); | |||||
//if (jack_uuid_t uuid = jackbridge_port_uuid(port)) | |||||
// jackbridge_set_property(client, uuid, "urn:jack:IsControlVoltage", "NO", "text/plain"); | |||||
CARLA_SAFE_ASSERT(client != nullptr && port != nullptr); | |||||
#if 0 | |||||
if (jack_uuid_t uuid = jackbridge_port_uuid(port)) | |||||
jackbridge_set_property(client, uuid, "urn:jack:IsControlVoltage", "NO", "text/plain"); | |||||
#endif | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
CARLA_ASSERT(client == nullptr && port == nullptr); | |||||
CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); | |||||
} | } | ||||
} | } | ||||
~CarlaEngineJackAudioPort() override | |||||
~CarlaEngineJackAudioPort() noexcept override | |||||
{ | { | ||||
carla_debug("CarlaEngineJackAudioPort::~CarlaEngineJackAudioPort()"); | carla_debug("CarlaEngineJackAudioPort::~CarlaEngineJackAudioPort()"); | ||||
if (fClient != nullptr && fPort != nullptr) | if (fClient != nullptr && fPort != nullptr) | ||||
{ | { | ||||
jackbridge_port_unregister(fClient, fPort); | |||||
try { | |||||
jackbridge_port_unregister(fClient, fPort); | |||||
} catch(...) {} | |||||
fClient = nullptr; | fClient = nullptr; | ||||
fPort = nullptr; | fPort = nullptr; | ||||
} | } | ||||
@@ -87,7 +92,13 @@ public: | |||||
const uint32_t bufferSize(fEngine.getBufferSize()); | const uint32_t bufferSize(fEngine.getBufferSize()); | ||||
fBuffer = (float*)jackbridge_port_get_buffer(fPort, bufferSize); | |||||
try { | |||||
fBuffer = (float*)jackbridge_port_get_buffer(fPort, bufferSize); | |||||
} | |||||
catch(...) { | |||||
fBuffer = nullptr; | |||||
return; | |||||
} | |||||
if (! fIsInput) | if (! fIsInput) | ||||
FLOAT_CLEAR(fBuffer, bufferSize); | FLOAT_CLEAR(fBuffer, bufferSize); | ||||
@@ -109,7 +120,7 @@ private: | |||||
class CarlaEngineJackCVPort : public CarlaEngineCVPort | class CarlaEngineJackCVPort : public CarlaEngineCVPort | ||||
{ | { | ||||
public: | public: | ||||
CarlaEngineJackCVPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) | |||||
CarlaEngineJackCVPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) noexcept | |||||
: CarlaEngineCVPort(engine, isInputPort), | : CarlaEngineCVPort(engine, isInputPort), | ||||
fClient(client), | fClient(client), | ||||
fPort(port) | fPort(port) | ||||
@@ -118,24 +129,28 @@ public: | |||||
if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | ||||
{ | { | ||||
CARLA_ASSERT(client != nullptr && port != nullptr); | |||||
//if (jack_uuid_t uuid = jackbridge_port_uuid(port)) | |||||
// jackbridge_set_property(client, uuid, "urn:jack:IsControlVoltage", "YES", "text/plain"); | |||||
CARLA_SAFE_ASSERT(client != nullptr && port != nullptr); | |||||
#if 0 | |||||
if (jack_uuid_t uuid = jackbridge_port_uuid(port)) | |||||
jackbridge_set_property(client, uuid, "urn:jack:IsControlVoltage", "YES", "text/plain"); | |||||
#endif | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
CARLA_ASSERT(client == nullptr && port == nullptr); | |||||
CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); | |||||
} | } | ||||
} | } | ||||
~CarlaEngineJackCVPort() override | |||||
~CarlaEngineJackCVPort() noexcept override | |||||
{ | { | ||||
carla_debug("CarlaEngineJackCVPort::~CarlaEngineJackCVPort()"); | carla_debug("CarlaEngineJackCVPort::~CarlaEngineJackCVPort()"); | ||||
if (fClient != nullptr && fPort != nullptr) | if (fClient != nullptr && fPort != nullptr) | ||||
{ | { | ||||
jackbridge_port_unregister(fClient, fPort); | |||||
try { | |||||
jackbridge_port_unregister(fClient, fPort); | |||||
} catch(...) {} | |||||
fClient = nullptr; | fClient = nullptr; | ||||
fPort = nullptr; | fPort = nullptr; | ||||
} | } | ||||
@@ -148,7 +163,13 @@ public: | |||||
const uint32_t bufferSize(fEngine.getBufferSize()); | const uint32_t bufferSize(fEngine.getBufferSize()); | ||||
fBuffer = (float*)jackbridge_port_get_buffer(fPort, bufferSize); | |||||
try { | |||||
fBuffer = (float*)jackbridge_port_get_buffer(fPort, bufferSize); | |||||
} | |||||
catch(...) { | |||||
fBuffer = nullptr; | |||||
return; | |||||
} | |||||
if (! fIsInput) | if (! fIsInput) | ||||
FLOAT_CLEAR(fBuffer, bufferSize); | FLOAT_CLEAR(fBuffer, bufferSize); | ||||
@@ -170,7 +191,7 @@ private: | |||||
class CarlaEngineJackEventPort : public CarlaEngineEventPort | class CarlaEngineJackEventPort : public CarlaEngineEventPort | ||||
{ | { | ||||
public: | public: | ||||
CarlaEngineJackEventPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) | |||||
CarlaEngineJackEventPort(const CarlaEngine& engine, const bool isInputPort, jack_client_t* const client, jack_port_t* const port) noexcept | |||||
: CarlaEngineEventPort(engine, isInputPort), | : CarlaEngineEventPort(engine, isInputPort), | ||||
fClient(client), | fClient(client), | ||||
fPort(port), | fPort(port), | ||||
@@ -180,21 +201,24 @@ public: | |||||
if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | if (fEngine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || fEngine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | ||||
{ | { | ||||
CARLA_ASSERT(client != nullptr && port != nullptr); | |||||
CARLA_SAFE_ASSERT(client != nullptr && port != nullptr); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
CARLA_ASSERT(client == nullptr && port == nullptr); | |||||
CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); | |||||
} | } | ||||
} | } | ||||
~CarlaEngineJackEventPort() override | |||||
~CarlaEngineJackEventPort() noexcept override | |||||
{ | { | ||||
carla_debug("CarlaEngineJackEventPort::~CarlaEngineJackEventPort()"); | carla_debug("CarlaEngineJackEventPort::~CarlaEngineJackEventPort()"); | ||||
if (fClient != nullptr && fPort != nullptr) | if (fClient != nullptr && fPort != nullptr) | ||||
{ | { | ||||
jackbridge_port_unregister(fClient, fPort); | |||||
try { | |||||
jackbridge_port_unregister(fClient, fPort); | |||||
} catch(...) {} | |||||
fClient = nullptr; | fClient = nullptr; | ||||
fPort = nullptr; | fPort = nullptr; | ||||
} | } | ||||
@@ -205,7 +229,13 @@ public: | |||||
if (fPort == nullptr) | if (fPort == nullptr) | ||||
return CarlaEngineEventPort::initBuffer(); | return CarlaEngineEventPort::initBuffer(); | ||||
fJackBuffer = jackbridge_port_get_buffer(fPort, fEngine.getBufferSize()); | |||||
try { | |||||
fJackBuffer = jackbridge_port_get_buffer(fPort, fEngine.getBufferSize()); | |||||
} | |||||
catch(...) { | |||||
fJackBuffer = nullptr; | |||||
return; | |||||
} | |||||
if (! fIsInput) | if (! fIsInput) | ||||
jackbridge_midi_clear_buffer(fJackBuffer); | jackbridge_midi_clear_buffer(fJackBuffer); | ||||
@@ -219,7 +249,13 @@ public: | |||||
CARLA_SAFE_ASSERT_RETURN(fIsInput, 0); | CARLA_SAFE_ASSERT_RETURN(fIsInput, 0); | ||||
CARLA_SAFE_ASSERT_RETURN(fJackBuffer != nullptr, 0); | CARLA_SAFE_ASSERT_RETURN(fJackBuffer != nullptr, 0); | ||||
return jackbridge_midi_get_event_count(fJackBuffer); | |||||
uint32_t count = 0; | |||||
try { | |||||
count = jackbridge_midi_get_event_count(fJackBuffer); | |||||
} catch(...) {} | |||||
return count; | |||||
} | } | ||||
const EngineEvent& getEvent(const uint32_t index) const noexcept override | const EngineEvent& getEvent(const uint32_t index) const noexcept override | ||||
@@ -237,7 +273,13 @@ public: | |||||
{ | { | ||||
jack_midi_event_t jackEvent; | jack_midi_event_t jackEvent; | ||||
if (! jackbridge_midi_event_get(&jackEvent, fJackBuffer, index)) | |||||
bool test = false; | |||||
try { | |||||
test = jackbridge_midi_event_get(&jackEvent, fJackBuffer, index); | |||||
} catch(...) {} | |||||
if (! test) | |||||
return kFallbackJackEngineEvent; | return kFallbackJackEngineEvent; | ||||
CARLA_SAFE_ASSERT_RETURN(jackEvent.size <= 0xFF /* uint8_t max */, kFallbackJackEngineEvent); | CARLA_SAFE_ASSERT_RETURN(jackEvent.size <= 0xFF /* uint8_t max */, kFallbackJackEngineEvent); | ||||
@@ -273,7 +315,13 @@ public: | |||||
if (size == 0) | if (size == 0) | ||||
return false; | return false; | ||||
return jackbridge_midi_event_write(fJackBuffer, time, data, size); | |||||
bool ret = false; | |||||
try { | |||||
ret = jackbridge_midi_event_write(fJackBuffer, time, data, size); | |||||
} catch(...) {} | |||||
return ret; | |||||
} | } | ||||
bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept override | bool writeMidiEvent(const uint32_t time, const uint8_t channel, const uint8_t port, const uint8_t size, const uint8_t* const data) noexcept override | ||||
@@ -294,7 +342,13 @@ public: | |||||
for (uint8_t i=1; i < size; ++i) | for (uint8_t i=1; i < size; ++i) | ||||
jdata[i] = data[i]; | jdata[i] = data[i]; | ||||
return jackbridge_midi_event_write(fJackBuffer, time, jdata, size); | |||||
bool ret = false; | |||||
try { | |||||
ret = jackbridge_midi_event_write(fJackBuffer, time, jdata, size); | |||||
} catch(...) {} | |||||
return ret; | |||||
} | } | ||||
private: | private: | ||||
@@ -325,11 +379,11 @@ public: | |||||
if (fUseClient) | if (fUseClient) | ||||
{ | { | ||||
CARLA_ASSERT(fClient != nullptr); | |||||
CARLA_SAFE_ASSERT(fClient != nullptr); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
CARLA_ASSERT(fClient == nullptr); | |||||
CARLA_SAFE_ASSERT(fClient == nullptr); | |||||
} | } | ||||
} | } | ||||
@@ -398,7 +452,7 @@ public: | |||||
} | } | ||||
#endif | #endif | ||||
CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) override | |||||
CarlaEnginePort* addPort(const EnginePortType portType, const char* const name, const bool isInput) /*noexcept*/ override | |||||
{ | { | ||||
carla_debug("CarlaEngineJackClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput)); | carla_debug("CarlaEngineJackClient::addPort(%s, \"%s\", %s)", EnginePortType2Str(portType), name, bool2str(isInput)); | ||||
@@ -407,20 +461,22 @@ public: | |||||
// Create JACK port first, if needed | // Create JACK port first, if needed | ||||
if (fUseClient && fClient != nullptr) | if (fUseClient && fClient != nullptr) | ||||
{ | { | ||||
switch (portType) | |||||
{ | |||||
case kEnginePortTypeNull: | |||||
break; | |||||
case kEnginePortTypeAudio: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
case kEnginePortTypeCV: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
case kEnginePortTypeEvent: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
} | |||||
try { | |||||
switch (portType) | |||||
{ | |||||
case kEnginePortTypeNull: | |||||
break; | |||||
case kEnginePortTypeAudio: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
case kEnginePortTypeCV: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
case kEnginePortTypeEvent: | |||||
port = jackbridge_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0); | |||||
break; | |||||
} | |||||
} catch(...) {} | |||||
if (port == nullptr) | if (port == nullptr) | ||||
{ | { | ||||
@@ -530,7 +586,7 @@ public: | |||||
~CarlaEngineJack() override | ~CarlaEngineJack() override | ||||
{ | { | ||||
carla_debug("CarlaEngineJack::~CarlaEngineJack()"); | carla_debug("CarlaEngineJack::~CarlaEngineJack()"); | ||||
CARLA_ASSERT(fClient == nullptr); | |||||
CARLA_SAFE_ASSERT(fClient == nullptr); | |||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
fUsedGroupNames.clear(); | fUsedGroupNames.clear(); | ||||
@@ -583,7 +639,6 @@ public: | |||||
bool init(const char* const clientName) override | bool init(const char* const clientName) override | ||||
{ | { | ||||
carla_debug("CarlaEngineJack::init(\"%s\")", clientName); | carla_debug("CarlaEngineJack::init(\"%s\")", clientName); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
fFreewheel = false; | fFreewheel = false; | ||||
fTransportState = JackTransportStopped; | fTransportState = JackTransportStopped; | ||||
@@ -671,7 +726,6 @@ public: | |||||
bool close() override | bool close() override | ||||
{ | { | ||||
carla_debug("CarlaEngineJack::close()"); | carla_debug("CarlaEngineJack::close()"); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaEngine::close(); | CarlaEngine::close(); | ||||
@@ -718,7 +772,6 @@ public: | |||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
void idle() override | void idle() override | ||||
{ | { | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaEngine::idle(); | CarlaEngine::idle(); | ||||
@@ -771,7 +824,6 @@ public: | |||||
CarlaEngineClient* addClient(CarlaPlugin* const plugin) override | CarlaEngineClient* addClient(CarlaPlugin* const plugin) override | ||||
{ | { | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
jack_client_t* client = nullptr; | jack_client_t* client = nullptr; | ||||
@@ -815,7 +867,6 @@ public: | |||||
CARLA_SAFE_ASSERT_RETURN(id < pData->curPluginCount, nullptr); | CARLA_SAFE_ASSERT_RETURN(id < pData->curPluginCount, nullptr); | ||||
CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr); | CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr); | ||||
CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr); | CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
CarlaPlugin* const plugin(pData->plugins[id].plugin); | CarlaPlugin* const plugin(pData->plugins[id].plugin); | ||||
@@ -895,7 +946,6 @@ public: | |||||
bool patchbayConnect(int portA, int portB) override | bool patchbayConnect(int portA, int portB) override | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
if (fClient == nullptr) | if (fClient == nullptr) | ||||
{ | { | ||||
@@ -920,7 +970,6 @@ public: | |||||
bool patchbayDisconnect(uint connectionId) override | bool patchbayDisconnect(uint connectionId) override | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
for (LinkedList<ConnectionToId>::Itenerator it = fUsedConnections.begin(); it.valid(); it.next()) | for (LinkedList<ConnectionToId>::Itenerator it = fUsedConnections.begin(); it.valid(); it.next()) | ||||
{ | { | ||||
@@ -951,7 +1000,6 @@ public: | |||||
bool patchbayRefresh() override | bool patchbayRefresh() override | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); | ||||
CARLA_ENGINE_THREAD_SAFE_SECTION; | |||||
fLastGroupId = 0; | fLastGroupId = 0; | ||||
fLastPortId = 0; | fLastPortId = 0; | ||||
@@ -1210,13 +1258,15 @@ protected: | |||||
void* const eventIn = jackbridge_port_get_buffer(fRackPorts[kRackPortEventIn], nframes); | void* const eventIn = jackbridge_port_get_buffer(fRackPorts[kRackPortEventIn], nframes); | ||||
void* const eventOut = jackbridge_port_get_buffer(fRackPorts[kRackPortEventOut], nframes); | void* const eventOut = jackbridge_port_get_buffer(fRackPorts[kRackPortEventOut], nframes); | ||||
#if 0 | |||||
// assert buffers | // assert buffers | ||||
CARLA_ASSERT(audioIn1 != nullptr); | |||||
CARLA_ASSERT(audioIn2 != nullptr); | |||||
CARLA_ASSERT(audioOut1 != nullptr); | |||||
CARLA_ASSERT(audioOut2 != nullptr); | |||||
CARLA_ASSERT(eventIn != nullptr); | |||||
CARLA_ASSERT(eventOut != nullptr); | |||||
CARLA_SAFE_ASSERT(audioIn1 != nullptr); | |||||
CARLA_SAFE_ASSERT(audioIn2 != nullptr); | |||||
CARLA_SAFE_ASSERT(audioOut1 != nullptr); | |||||
CARLA_SAFE_ASSERT(audioOut2 != nullptr); | |||||
CARLA_SAFE_ASSERT(eventIn != nullptr); | |||||
CARLA_SAFE_ASSERT(eventOut != nullptr); | |||||
#endif | |||||
// create audio buffers | // create audio buffers | ||||
float* inBuf[2] = { audioIn1, audioIn2 }; | float* inBuf[2] = { audioIn1, audioIn2 }; | ||||
@@ -155,7 +155,7 @@ public: | |||||
pData->bufAudio.inCount = static_cast<uint32_t>(inputChannels.countNumberOfSetBits()); | pData->bufAudio.inCount = static_cast<uint32_t>(inputChannels.countNumberOfSetBits()); | ||||
pData->bufAudio.outCount = static_cast<uint32_t>(outputChannels.countNumberOfSetBits()); | pData->bufAudio.outCount = static_cast<uint32_t>(outputChannels.countNumberOfSetBits()); | ||||
CARLA_ASSERT(pData->bufAudio.outCount > 0); | |||||
CARLA_SAFE_ASSERT(pData->bufAudio.outCount > 0); | |||||
pData->bufAudio.create(pData->bufferSize); | pData->bufAudio.create(pData->bufferSize); | ||||
@@ -255,7 +255,7 @@ public: | |||||
callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO_IN, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); | callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO_IN, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); | ||||
StringArray inputNames(fDevice->getInputChannelNames()); | StringArray inputNames(fDevice->getInputChannelNames()); | ||||
CARLA_ASSERT(inputNames.size() == static_cast<int>(pData->bufAudio.inCount)); | |||||
CARLA_SAFE_ASSERT(inputNames.size() == static_cast<int>(pData->bufAudio.inCount)); | |||||
for (uint i=0; i < pData->bufAudio.inCount; ++i) | for (uint i=0; i < pData->bufAudio.inCount; ++i) | ||||
{ | { | ||||
@@ -280,7 +280,7 @@ public: | |||||
callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO_OUT, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); | callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED, RACK_PATCHBAY_GROUP_AUDIO_OUT, PATCHBAY_ICON_HARDWARE, -1, 0.0f, strBuf); | ||||
StringArray outputNames(fDevice->getOutputChannelNames()); | StringArray outputNames(fDevice->getOutputChannelNames()); | ||||
CARLA_ASSERT(outputNames.size() == static_cast<int>(pData->bufAudio.outCount)); | |||||
CARLA_SAFE_ASSERT(outputNames.size() == static_cast<int>(pData->bufAudio.outCount)); | |||||
for (uint i=0; i < pData->bufAudio.outCount; ++i) | for (uint i=0; i < pData->bufAudio.outCount; ++i) | ||||
{ | { | ||||
@@ -546,7 +546,7 @@ public: | |||||
~CarlaEngineNative() override | ~CarlaEngineNative() override | ||||
{ | { | ||||
CARLA_ASSERT(! fIsActive); | |||||
CARLA_SAFE_ASSERT(! fIsActive); | |||||
carla_debug("CarlaEngineNative::~CarlaEngineNative() - START"); | carla_debug("CarlaEngineNative::~CarlaEngineNative() - START"); | ||||
pData->aboutToClose = true; | pData->aboutToClose = true; | ||||
@@ -42,17 +42,17 @@ CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine) | |||||
fServerTCP(nullptr), | fServerTCP(nullptr), | ||||
fServerUDP(nullptr) | fServerUDP(nullptr) | ||||
{ | { | ||||
CARLA_ASSERT(engine != nullptr); | |||||
CARLA_SAFE_ASSERT(engine != nullptr); | |||||
carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); | carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); | ||||
} | } | ||||
CarlaEngineOsc::~CarlaEngineOsc() | CarlaEngineOsc::~CarlaEngineOsc() | ||||
{ | { | ||||
CARLA_ASSERT(fName.isEmpty()); | |||||
CARLA_ASSERT(fServerPathTCP.isEmpty()); | |||||
CARLA_ASSERT(fServerPathUDP.isEmpty()); | |||||
CARLA_ASSERT(fServerTCP == nullptr); | |||||
CARLA_ASSERT(fServerUDP == nullptr); | |||||
CARLA_SAFE_ASSERT(fName.isEmpty()); | |||||
CARLA_SAFE_ASSERT(fServerPathTCP.isEmpty()); | |||||
CARLA_SAFE_ASSERT(fServerPathUDP.isEmpty()); | |||||
CARLA_SAFE_ASSERT(fServerTCP == nullptr); | |||||
CARLA_SAFE_ASSERT(fServerUDP == nullptr); | |||||
carla_debug("CarlaEngineOsc::~CarlaEngineOsc()"); | carla_debug("CarlaEngineOsc::~CarlaEngineOsc()"); | ||||
} | } | ||||
@@ -71,48 +71,55 @@ void CarlaEngineOsc::init(const char* const name) | |||||
fName = name; | fName = name; | ||||
fName.toBasic(); | fName.toBasic(); | ||||
fServerTCP = lo_server_thread_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP); | |||||
fServerTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP); | |||||
if (fServerTCP != nullptr) | if (fServerTCP != nullptr) | ||||
{ | { | ||||
if (char* const tmpServerPathTCP = lo_server_thread_get_url(fServerTCP)) | |||||
if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP)) | |||||
{ | { | ||||
fServerPathTCP = tmpServerPathTCP; | fServerPathTCP = tmpServerPathTCP; | ||||
fServerPathTCP += fName; | fServerPathTCP += fName; | ||||
std::free(tmpServerPathTCP); | std::free(tmpServerPathTCP); | ||||
} | } | ||||
lo_server_thread_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this); | |||||
int ret = lo_server_thread_start(fServerTCP); | |||||
CARLA_SAFE_ASSERT(ret == 0); | |||||
lo_server_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this); | |||||
} | } | ||||
fServerUDP = lo_server_thread_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP); | |||||
fServerUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP); | |||||
if (fServerUDP != nullptr) | if (fServerUDP != nullptr) | ||||
{ | { | ||||
if (char* const tmpServerPathUDP = lo_server_thread_get_url(fServerUDP)) | |||||
if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP)) | |||||
{ | { | ||||
fServerPathUDP = tmpServerPathUDP; | fServerPathUDP = tmpServerPathUDP; | ||||
fServerPathUDP += fName; | fServerPathUDP += fName; | ||||
std::free(tmpServerPathUDP); | std::free(tmpServerPathUDP); | ||||
} | } | ||||
lo_server_thread_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this); | |||||
int ret = lo_server_thread_start(fServerUDP); | |||||
CARLA_SAFE_ASSERT(ret == 0); | |||||
lo_server_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this); | |||||
} | } | ||||
CARLA_ASSERT(fName.isNotEmpty()); | |||||
CARLA_SAFE_ASSERT(fName.isNotEmpty()); | |||||
CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); | CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); | ||||
CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); | CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); | ||||
CARLA_SAFE_ASSERT(fServerTCP != nullptr); | CARLA_SAFE_ASSERT(fServerTCP != nullptr); | ||||
CARLA_SAFE_ASSERT(fServerUDP != nullptr); | CARLA_SAFE_ASSERT(fServerUDP != nullptr); | ||||
} | } | ||||
void CarlaEngineOsc::idle() const | |||||
{ | |||||
if (fServerTCP != nullptr) { | |||||
while (lo_server_recv_noblock(fServerTCP, 0) != 0) {} | |||||
} | |||||
if (fServerUDP != nullptr) { | |||||
while (lo_server_recv_noblock(fServerUDP, 0) != 0) {} | |||||
} | |||||
} | |||||
void CarlaEngineOsc::close() | void CarlaEngineOsc::close() | ||||
{ | { | ||||
CARLA_ASSERT(fName.isNotEmpty()); | |||||
CARLA_SAFE_ASSERT(fName.isNotEmpty()); | |||||
CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); | CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); | ||||
CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); | CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); | ||||
CARLA_SAFE_ASSERT(fServerTCP != nullptr); | CARLA_SAFE_ASSERT(fServerTCP != nullptr); | ||||
@@ -123,17 +130,15 @@ void CarlaEngineOsc::close() | |||||
if (fServerTCP != nullptr) | if (fServerTCP != nullptr) | ||||
{ | { | ||||
lo_server_thread_stop(fServerTCP); | |||||
lo_server_thread_del_method(fServerTCP, nullptr, nullptr); | |||||
lo_server_thread_free(fServerTCP); | |||||
lo_server_del_method(fServerTCP, nullptr, nullptr); | |||||
lo_server_free(fServerTCP); | |||||
fServerTCP = nullptr; | fServerTCP = nullptr; | ||||
} | } | ||||
if (fServerUDP != nullptr) | if (fServerUDP != nullptr) | ||||
{ | { | ||||
lo_server_thread_stop(fServerUDP); | |||||
lo_server_thread_del_method(fServerUDP, nullptr, nullptr); | |||||
lo_server_thread_free(fServerUDP); | |||||
lo_server_del_method(fServerUDP, nullptr, nullptr); | |||||
lo_server_free(fServerUDP); | |||||
fServerUDP = nullptr; | fServerUDP = nullptr; | ||||
} | } | ||||
@@ -157,16 +162,13 @@ int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, cons | |||||
CARLA_SAFE_ASSERT_RETURN(fName.isNotEmpty(), 1); | CARLA_SAFE_ASSERT_RETURN(fName.isNotEmpty(), 1); | ||||
CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', 1); | CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', 1); | ||||
carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg); | carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg); | ||||
#ifndef BUILD_BRIDGE | |||||
const CarlaCriticalSection::Scope _ccsl(_cs); | |||||
#endif | |||||
if (isTCP) | |||||
//if (isTCP) | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isNotEmpty(), 1); | CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isNotEmpty(), 1); | ||||
CARLA_SAFE_ASSERT_RETURN(fServerTCP != nullptr, 1); | CARLA_SAFE_ASSERT_RETURN(fServerTCP != nullptr, 1); | ||||
} | } | ||||
else | |||||
//else | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1); | CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1); | ||||
CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1); | CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1); | ||||
@@ -20,7 +20,6 @@ | |||||
#include "CarlaBackend.h" | #include "CarlaBackend.h" | ||||
#include "CarlaOscUtils.hpp" | #include "CarlaOscUtils.hpp" | ||||
#include "CarlaMutex.hpp" | |||||
#include "CarlaString.hpp" | #include "CarlaString.hpp" | ||||
#define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin | #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin | ||||
@@ -62,6 +61,7 @@ public: | |||||
~CarlaEngineOsc(); | ~CarlaEngineOsc(); | ||||
void init(const char* const name); | void init(const char* const name); | ||||
void idle() const; | |||||
void close(); | void close(); | ||||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||||
@@ -99,12 +99,11 @@ private: | |||||
CarlaString fServerPathTCP; | CarlaString fServerPathTCP; | ||||
CarlaString fServerPathUDP; | CarlaString fServerPathUDP; | ||||
lo_server_thread fServerTCP; | |||||
lo_server_thread fServerUDP; | |||||
lo_server fServerTCP; | |||||
lo_server fServerUDP; | |||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
CarlaOscData fControlData; // for carla-control | CarlaOscData fControlData; // for carla-control | ||||
CarlaCriticalSection _cs; | |||||
#endif | #endif | ||||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||||
@@ -176,8 +176,8 @@ public: | |||||
~CarlaEngineRtAudio() override | ~CarlaEngineRtAudio() override | ||||
{ | { | ||||
CARLA_ASSERT(fAudioBufIn == nullptr); | |||||
CARLA_ASSERT(fAudioBufOut == nullptr); | |||||
CARLA_SAFE_ASSERT(fAudioBufIn == nullptr); | |||||
CARLA_SAFE_ASSERT(fAudioBufOut == nullptr); | |||||
carla_debug("CarlaEngineRtAudio::~CarlaEngineRtAudio()"); | carla_debug("CarlaEngineRtAudio::~CarlaEngineRtAudio()"); | ||||
fUsedMidiIns.clear(); | fUsedMidiIns.clear(); | ||||
@@ -274,7 +274,7 @@ public: | |||||
pData->bufAudio.inCount = iParams.nChannels; | pData->bufAudio.inCount = iParams.nChannels; | ||||
pData->bufAudio.outCount = oParams.nChannels; | pData->bufAudio.outCount = oParams.nChannels; | ||||
CARLA_ASSERT(pData->bufAudio.outCount > 0); | |||||
CARLA_SAFE_ASSERT(pData->bufAudio.outCount > 0); | |||||
if (pData->bufAudio.inCount > 0) | if (pData->bufAudio.inCount > 0) | ||||
{ | { | ||||
@@ -312,7 +312,7 @@ public: | |||||
bool close() override | bool close() override | ||||
{ | { | ||||
CARLA_ASSERT(fAudioBufOut != nullptr); | |||||
CARLA_SAFE_ASSERT(fAudioBufOut != nullptr); | |||||
carla_debug("CarlaEngineRtAudio::close()"); | carla_debug("CarlaEngineRtAudio::close()"); | ||||
pData->bufAudio.isReady = false; | pData->bufAudio.isReady = false; | ||||
@@ -27,7 +27,7 @@ CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine) | |||||
: CarlaThread("CarlaEngineThread"), | : CarlaThread("CarlaEngineThread"), | ||||
fEngine(engine) | fEngine(engine) | ||||
{ | { | ||||
CARLA_ASSERT(engine != nullptr); | |||||
CARLA_SAFE_ASSERT(engine != nullptr); | |||||
carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine); | carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine); | ||||
} | } | ||||
@@ -47,7 +47,7 @@ void CarlaEngineThread::run() | |||||
bool hasUi, oscRegisted, needsSingleThread; | bool hasUi, oscRegisted, needsSingleThread; | ||||
float value; | float value; | ||||
for (; fEngine->isRunning() && ! shouldExit();) | |||||
for (; fEngine->isRunning() && ! shouldThreadExit();) | |||||
{ | { | ||||
#ifdef BUILD_BRIDGE | #ifdef BUILD_BRIDGE | ||||
oscRegisted = fEngine->isOscBridgeRegistered(); | oscRegisted = fEngine->isOscBridgeRegistered(); | ||||
@@ -8,7 +8,7 @@ include ../Makefile.mk | |||||
# ---------------------------------------------------------------------------------------------------------------------------- | # ---------------------------------------------------------------------------------------------------------------------------- | ||||
CARLA_ENGINE_OSC_HPP = CarlaEngineOsc.hpp $(CARLA_BACKEND_H) $(CARLA_OSC_UTILS_HPP) $(CARLA_MUTEX_HPP) $(CARLA_STRING_HPP) | |||||
CARLA_ENGINE_OSC_HPP = CarlaEngineOsc.hpp $(CARLA_BACKEND_H) $(CARLA_OSC_UTILS_HPP) $(CARLA_STRING_HPP) | |||||
CARLA_ENGINE_THREAD_HPP = CarlaEngineThread.hpp $(CARLA_BACKEND_H) $(CARLA_THREAD_HPP) | CARLA_ENGINE_THREAD_HPP = CarlaEngineThread.hpp $(CARLA_BACKEND_H) $(CARLA_THREAD_HPP) | ||||
CARLA_ENGINE_INTERNAL_HPP = CarlaEngineInternal.hpp $(CARLA_ENGINE_OSC_HPP) $(CARLA_ENGINE_THREAD_HPP) $(CARLA_ENGINE_HPP) $(CARLA_MUTEX_HPP) $(LINKED_LIST_HPP) | CARLA_ENGINE_INTERNAL_HPP = CarlaEngineInternal.hpp $(CARLA_ENGINE_OSC_HPP) $(CARLA_ENGINE_THREAD_HPP) $(CARLA_ENGINE_HPP) $(CARLA_MUTEX_HPP) $(LINKED_LIST_HPP) | ||||
@@ -335,7 +335,7 @@ public: | |||||
pData->active = false; | pData->active = false; | ||||
} | } | ||||
if (pData->osc.thread.isRunning()) | |||||
if (pData->osc.thread.isThreadRunning()) | |||||
{ | { | ||||
fShmControl.writeOpcode(kPluginBridgeOpcodeQuit); | fShmControl.writeOpcode(kPluginBridgeOpcodeQuit); | ||||
fShmControl.commitWrite(); | fShmControl.commitWrite(); | ||||
@@ -351,7 +351,7 @@ public: | |||||
} | } | ||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
pData->osc.thread.stop(3000); | |||||
pData->osc.thread.stopThread(3000); | |||||
if (fNeedsSemDestroy) | if (fNeedsSemDestroy) | ||||
{ | { | ||||
@@ -623,7 +623,7 @@ public: | |||||
void idle() override | void idle() override | ||||
{ | { | ||||
if (! pData->osc.thread.isRunning()) | |||||
if (! pData->osc.thread.isThreadRunning()) | |||||
carla_stderr2("TESTING: Bridge has closed!"); | carla_stderr2("TESTING: Bridge has closed!"); | ||||
CarlaPlugin::idle(); | CarlaPlugin::idle(); | ||||
@@ -1912,25 +1912,26 @@ public: | |||||
std::strncat(shmIdStr, &fShmTime.filename[fShmTime.filename.length()-6], 6); | std::strncat(shmIdStr, &fShmTime.filename[fShmTime.filename.length()-6], 6); | ||||
pData->osc.thread.setOscData(bridgeBinary, label, getPluginTypeAsString(fPluginType), shmIdStr); | pData->osc.thread.setOscData(bridgeBinary, label, getPluginTypeAsString(fPluginType), shmIdStr); | ||||
pData->osc.thread.start(); | |||||
pData->osc.thread.startThread(); | |||||
} | } | ||||
fInitiated = false; | fInitiated = false; | ||||
fLastPongCounter = 0; | fLastPongCounter = 0; | ||||
for (; fLastPongCounter < 100; ++fLastPongCounter) | |||||
for (; fLastPongCounter < 200; ++fLastPongCounter) | |||||
{ | { | ||||
if (fInitiated || ! pData->osc.thread.isRunning()) | |||||
if (fInitiated || ! pData->osc.thread.isThreadRunning()) | |||||
break; | break; | ||||
carla_msleep(50); | |||||
carla_msleep(30); | |||||
pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); | pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); | ||||
pData->engine->idle(); | |||||
} | } | ||||
fLastPongCounter = -1; | fLastPongCounter = -1; | ||||
if (fInitError || ! fInitiated) | if (fInitError || ! fInitiated) | ||||
{ | { | ||||
pData->osc.thread.stop(6000); | |||||
pData->osc.thread.stopThread(6000); | |||||
if (! fInitError) | if (! fInitError) | ||||
pData->engine->setLastError("Timeout while waiting for a response from plugin-bridge\n(or the plugin crashed on initialization?)"); | pData->engine->setLastError("Timeout while waiting for a response from plugin-bridge\n(or the plugin crashed on initialization?)"); | ||||
@@ -121,26 +121,26 @@ CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id) | |||||
: pData(new CarlaPluginProtectedData(engine, id, this)) | : pData(new CarlaPluginProtectedData(engine, id, this)) | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); | CARLA_SAFE_ASSERT_RETURN(engine != nullptr,); | ||||
CARLA_ASSERT(id < engine->getMaxPluginNumber()); | |||||
CARLA_SAFE_ASSERT(id < engine->getMaxPluginNumber()); | |||||
carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id); | carla_debug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id); | ||||
switch (engine->getProccessMode()) | switch (engine->getProccessMode()) | ||||
{ | { | ||||
case ENGINE_PROCESS_MODE_SINGLE_CLIENT: | case ENGINE_PROCESS_MODE_SINGLE_CLIENT: | ||||
case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS: | case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS: | ||||
CARLA_ASSERT(id < MAX_DEFAULT_PLUGINS); | |||||
CARLA_SAFE_ASSERT(id < MAX_DEFAULT_PLUGINS); | |||||
break; | break; | ||||
case ENGINE_PROCESS_MODE_CONTINUOUS_RACK: | case ENGINE_PROCESS_MODE_CONTINUOUS_RACK: | ||||
CARLA_ASSERT(id < MAX_RACK_PLUGINS); | |||||
CARLA_SAFE_ASSERT(id < MAX_RACK_PLUGINS); | |||||
break; | break; | ||||
case ENGINE_PROCESS_MODE_PATCHBAY: | case ENGINE_PROCESS_MODE_PATCHBAY: | ||||
CARLA_ASSERT(id < MAX_PATCHBAY_PLUGINS); | |||||
CARLA_SAFE_ASSERT(id < MAX_PATCHBAY_PLUGINS); | |||||
break; | break; | ||||
case ENGINE_PROCESS_MODE_BRIDGE: | case ENGINE_PROCESS_MODE_BRIDGE: | ||||
CARLA_ASSERT(id == 0); | |||||
CARLA_SAFE_ASSERT(id == 0); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -306,7 +306,7 @@ const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcep | |||||
int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept | int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); | CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -315,14 +315,14 @@ int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept | |||||
unsigned int CarlaPlugin::getOptionsAvailable() const noexcept | unsigned int CarlaPlugin::getOptionsAvailable() const noexcept | ||||
{ | { | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
return 0x0; | return 0x0; | ||||
} | } | ||||
float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept | float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); | CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
return 0.0f; | return 0.0f; | ||||
} | } | ||||
@@ -330,7 +330,7 @@ float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); | CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); | ||||
CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); | CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
return 0.0f; | return 0.0f; | ||||
} | } | ||||
@@ -357,7 +357,7 @@ void CarlaPlugin::getRealName(char* const strBuf) const noexcept | |||||
void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept | void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
strBuf[0] = '\0'; | strBuf[0] = '\0'; | ||||
} | } | ||||
@@ -370,7 +370,7 @@ void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const str | |||||
void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const noexcept | void CarlaPlugin::getParameterText(const uint32_t parameterId, const float, char* const strBuf) const noexcept | ||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
strBuf[0] = '\0'; | strBuf[0] = '\0'; | ||||
} | } | ||||
@@ -384,7 +384,7 @@ void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); | ||||
CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); | CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); | ||||
CARLA_ASSERT(false); // this should never happen | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
strBuf[0] = '\0'; | strBuf[0] = '\0'; | ||||
} | } | ||||
@@ -828,7 +828,7 @@ void CarlaPlugin::setId(const unsigned int newId) noexcept | |||||
void CarlaPlugin::setName(const char* const newName) | void CarlaPlugin::setName(const char* const newName) | ||||
{ | { | ||||
CARLA_ASSERT(newName != nullptr && newName[0] != '\0'); | |||||
CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0',); | |||||
if (pData->name != nullptr) | if (pData->name != nullptr) | ||||
delete[] pData->name; | delete[] pData->name; | ||||
@@ -838,7 +838,7 @@ void CarlaPlugin::setName(const char* const newName) | |||||
void CarlaPlugin::setOption(const unsigned int option, const bool yesNo) | void CarlaPlugin::setOption(const unsigned int option, const bool yesNo) | ||||
{ | { | ||||
CARLA_ASSERT(getOptionsAvailable() & option); | |||||
CARLA_SAFE_ASSERT_RETURN(getOptionsAvailable() & option,); | |||||
if (yesNo) | if (yesNo) | ||||
pData->options |= option; | pData->options |= option; | ||||
@@ -865,7 +865,7 @@ void CarlaPlugin::setEnabled(const bool yesNo) noexcept | |||||
void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT | |||||
CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT | |||||
#endif | #endif | ||||
if (pData->active == active) | if (pData->active == active) | ||||
@@ -902,7 +902,7 @@ void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool se | |||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(value >= 0.0f && value <= 1.0f); | |||||
CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.0f); | |||||
const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value)); | const float fixedValue(carla_fixValue<float>(0.0f, 1.0f, value)); | ||||
@@ -920,7 +920,7 @@ void CarlaPlugin::setDryWet(const float value, const bool sendOsc, const bool se | |||||
void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(value >= 0.0f && value <= 1.27f); | |||||
CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f); | |||||
const float fixedValue(carla_fixValue<float>(0.0f, 1.27f, value)); | const float fixedValue(carla_fixValue<float>(0.0f, 1.27f, value)); | ||||
@@ -938,7 +938,7 @@ void CarlaPlugin::setVolume(const float value, const bool sendOsc, const bool se | |||||
void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | ||||
@@ -956,7 +956,7 @@ void CarlaPlugin::setBalanceLeft(const float value, const bool sendOsc, const bo | |||||
void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | ||||
@@ -974,7 +974,7 @@ void CarlaPlugin::setBalanceRight(const float value, const bool sendOsc, const b | |||||
void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); | |||||
const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | const float fixedValue(carla_fixValue<float>(-1.0f, 1.0f, value)); | ||||
@@ -994,9 +994,9 @@ void CarlaPlugin::setPanning(const float value, const bool sendOsc, const bool s | |||||
void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT | |||||
CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT | |||||
#endif | #endif | ||||
CARLA_ASSERT_INT(channel >= -1 && channel < MAX_MIDI_CHANNELS, channel); | |||||
CARLA_SAFE_ASSERT_RETURN(channel >= -1 && channel < MAX_MIDI_CHANNELS,); | |||||
if (pData->ctrlChannel == channel) | if (pData->ctrlChannel == channel) | ||||
return; | return; | ||||
@@ -1028,7 +1028,7 @@ void CarlaPlugin::setCtrlChannel(const int8_t channel, const bool sendOsc, const | |||||
void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(parameterId < pData->param.count); | |||||
CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); | |||||
#ifdef BUILD_BRIDGE | #ifdef BUILD_BRIDGE | ||||
if (! gIsLoadingProject) | if (! gIsLoadingProject) | ||||
{ | { | ||||
@@ -1058,12 +1058,8 @@ void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float valu | |||||
void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL); | |||||
CARLA_SAFE_ASSERT_RETURN(rindex > PARAMETER_MAX && rindex != PARAMETER_NULL,); | |||||
if (rindex <= PARAMETER_MAX) | |||||
return; | |||||
if (rindex == PARAMETER_NULL) | |||||
return; | |||||
if (rindex == PARAMETER_ACTIVE) | if (rindex == PARAMETER_ACTIVE) | ||||
return setActive((value > 0.0f), sendOsc, sendCallback); | return setActive((value > 0.0f), sendOsc, sendCallback); | ||||
if (rindex == PARAMETER_CTRL_CHANNEL) | if (rindex == PARAMETER_CTRL_CHANNEL) | ||||
@@ -1095,12 +1091,9 @@ void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float | |||||
void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT | |||||
CARLA_ASSERT(parameterId < pData->param.count); | |||||
CARLA_ASSERT_INT(channel < MAX_MIDI_CHANNELS, channel); | |||||
if (channel >= MAX_MIDI_CHANNELS) | |||||
channel = MAX_MIDI_CHANNELS; | |||||
CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT | |||||
CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); | |||||
CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); | |||||
pData->param.data[parameterId].midiChannel = channel; | pData->param.data[parameterId].midiChannel = channel; | ||||
@@ -1124,12 +1117,9 @@ void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t ch | |||||
void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT | |||||
CARLA_ASSERT(parameterId < pData->param.count); | |||||
CARLA_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc); | |||||
if (cc < -1 || cc > 0x5F) | |||||
cc = -1; | |||||
CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT | |||||
CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); | |||||
CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc <= 0x5F,); | |||||
pData->param.data[parameterId].midiCC = cc; | pData->param.data[parameterId].midiCC = cc; | ||||
@@ -1184,9 +1174,9 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c | |||||
{ | { | ||||
CustomData& cData(it.getValue()); | CustomData& cData(it.getValue()); | ||||
CARLA_SAFE_ASSERT_RETURN(cData.type != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(cData.key != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(cData.value != nullptr,); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.type != nullptr && cData.type[0] != '\0'); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.key != nullptr && cData.key[0] != '\0'); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.value != nullptr); | |||||
if (std::strcmp(cData.key, key) == 0) | if (std::strcmp(cData.key, key) == 0) | ||||
{ | { | ||||
@@ -1208,12 +1198,8 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c | |||||
void CarlaPlugin::setChunkData(const char* const stringData) | void CarlaPlugin::setChunkData(const char* const stringData) | ||||
{ | { | ||||
CARLA_ASSERT(stringData != nullptr); | |||||
CARLA_ASSERT(false); // this should never happen | |||||
return; | |||||
// unused | |||||
(void)stringData; | |||||
CARLA_SAFE_ASSERT_RETURN(stringData != nullptr && stringData[0] != '\0',); | |||||
CARLA_SAFE_ASSERT(false); // this should never happen | |||||
} | } | ||||
void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | void CarlaPlugin::setProgram(const int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback) noexcept | ||||
@@ -1387,7 +1373,7 @@ void CarlaPlugin::idle() | |||||
void CarlaPlugin::showCustomUI(const bool yesNo) | void CarlaPlugin::showCustomUI(const bool yesNo) | ||||
{ | { | ||||
CARLA_ASSERT(false); | |||||
CARLA_SAFE_ASSERT(false); | |||||
return; | return; | ||||
// unused | // unused | ||||
@@ -1406,12 +1392,12 @@ void CarlaPlugin::reloadPrograms(const bool) | |||||
void CarlaPlugin::activate() noexcept | void CarlaPlugin::activate() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(! pData->active); | |||||
CARLA_SAFE_ASSERT(! pData->active); | |||||
} | } | ||||
void CarlaPlugin::deactivate() noexcept | void CarlaPlugin::deactivate() noexcept | ||||
{ | { | ||||
CARLA_ASSERT(pData->active); | |||||
CARLA_SAFE_ASSERT(pData->active); | |||||
} | } | ||||
void CarlaPlugin::bufferSizeChanged(const uint32_t) | void CarlaPlugin::bufferSizeChanged(const uint32_t) | ||||
@@ -1651,9 +1637,9 @@ void CarlaPlugin::updateOscData(const lo_address& source, const char* const url) | |||||
{ | { | ||||
const CustomData& cData(it.getValue()); | const CustomData& cData(it.getValue()); | ||||
CARLA_ASSERT(cData.type != nullptr); | |||||
CARLA_ASSERT(cData.key != nullptr); | |||||
CARLA_ASSERT(cData.value != nullptr); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.type != nullptr && cData.type[0] != '\0'); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.key != nullptr && cData.key[0] != '\0'); | |||||
CARLA_SAFE_ASSERT_CONTINUE(cData.value != nullptr); | |||||
if (std::strcmp(cData.type, CUSTOM_DATA_TYPE_STRING) == 0) | if (std::strcmp(cData.type, CUSTOM_DATA_TYPE_STRING) == 0) | ||||
osc_send_configure(pData->osc.data, cData.key, cData.value); | osc_send_configure(pData->osc.data, cData.key, cData.value); | ||||
@@ -1701,7 +1687,7 @@ bool CarlaPlugin::waitForOscGuiShow() | |||||
return true; | return true; | ||||
} | } | ||||
if (pData->osc.thread.isRunning()) | |||||
if (pData->osc.thread.isThreadRunning()) | |||||
carla_msleep(100); | carla_msleep(100); | ||||
else | else | ||||
return false; | return false; | ||||
@@ -1717,9 +1703,9 @@ bool CarlaPlugin::waitForOscGuiShow() | |||||
#ifndef BUILD_BRIDGE | #ifndef BUILD_BRIDGE | ||||
void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback) | void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback) | ||||
{ | { | ||||
CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); | |||||
CARLA_ASSERT(note < MAX_MIDI_NOTE); | |||||
CARLA_ASSERT(velo < MAX_MIDI_VALUE); | |||||
CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); | |||||
CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); | |||||
CARLA_SAFE_ASSERT_RETURN(velo < MAX_MIDI_VALUE,); | |||||
if (! pData->active) | if (! pData->active) | ||||
return; | return; | ||||
@@ -1929,54 +1915,34 @@ void CarlaPlugin::postRtEventsRun() | |||||
void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept | void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(index < getParameterCount()); | |||||
CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),); | |||||
return; | return; | ||||
// unused | // unused | ||||
(void)index; | |||||
(void)value; | (void)value; | ||||
} | } | ||||
void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept | void CarlaPlugin::uiProgramChange(const uint32_t index) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(index < getProgramCount()); | |||||
return; | |||||
// unused | |||||
(void)index; | |||||
CARLA_SAFE_ASSERT_RETURN(index < getProgramCount(),); | |||||
} | } | ||||
void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept | void CarlaPlugin::uiMidiProgramChange(const uint32_t index) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(index < getMidiProgramCount()); | |||||
return; | |||||
// unused | |||||
(void)index; | |||||
CARLA_SAFE_ASSERT_RETURN(index < getMidiProgramCount(),); | |||||
} | } | ||||
void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept | void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); | |||||
CARLA_ASSERT(note < MAX_MIDI_NOTE); | |||||
CARLA_ASSERT(velo > 0 && velo < MAX_MIDI_VALUE); | |||||
return; | |||||
// unused | |||||
(void)channel; | |||||
(void)note; | |||||
(void)velo; | |||||
CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); | |||||
CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); | |||||
CARLA_SAFE_ASSERT_RETURN(velo > 0 && velo < MAX_MIDI_VALUE,); | |||||
} | } | ||||
void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept | void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note) noexcept | ||||
{ | { | ||||
CARLA_ASSERT(channel < MAX_MIDI_CHANNELS); | |||||
CARLA_ASSERT(note < MAX_MIDI_NOTE); | |||||
return; | |||||
// unused | |||||
(void)channel; | |||||
(void)note; | |||||
CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); | |||||
CARLA_SAFE_ASSERT_RETURN(note < MAX_MIDI_NOTE,); | |||||
} | } | ||||
bool CarlaPlugin::canRunInRack() const noexcept | bool CarlaPlugin::canRunInRack() const noexcept | ||||
@@ -68,7 +68,7 @@ CarlaPluginThread::~CarlaPluginThread() | |||||
void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode) | void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode) | ||||
{ | { | ||||
CARLA_ASSERT(! isRunning()); | |||||
CARLA_SAFE_ASSERT(! isThreadRunning()); | |||||
carla_debug("CarlaPluginThread::setMode(%s)", PluginThreadMode2str(mode)); | carla_debug("CarlaPluginThread::setMode(%s)", PluginThreadMode2str(mode)); | ||||
fMode = mode; | fMode = mode; | ||||
@@ -76,7 +76,7 @@ void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode) | |||||
void CarlaPluginThread::setOscData(const char* const binary, const char* const label, const char* const extra1, const char* const extra2) | void CarlaPluginThread::setOscData(const char* const binary, const char* const label, const char* const extra1, const char* const extra2) | ||||
{ | { | ||||
CARLA_ASSERT(! isRunning()); | |||||
CARLA_SAFE_ASSERT(! isThreadRunning()); | |||||
carla_debug("CarlaPluginThread::setOscData(\"%s\", \"%s\", \"%s\", \"%s\")", binary, label, extra1, extra2); | carla_debug("CarlaPluginThread::setOscData(\"%s\", \"%s\", \"%s\", \"%s\")", binary, label, extra1, extra2); | ||||
fBinary = binary; | fBinary = binary; | ||||
@@ -226,12 +226,12 @@ void CarlaPluginThread::run() | |||||
{ | { | ||||
//fProcess->waitForFinished(-1); | //fProcess->waitForFinished(-1); | ||||
while (fProcess->state() != QProcess::NotRunning && ! shouldExit()) | |||||
while (fProcess->state() != QProcess::NotRunning && ! shouldThreadExit()) | |||||
carla_sleep(1); | carla_sleep(1); | ||||
// we only get here if UI was closed or thread asked to exit | // we only get here if UI was closed or thread asked to exit | ||||
if (fProcess->state() != QProcess::NotRunning && shouldExit()) | |||||
if (fProcess->state() != QProcess::NotRunning && shouldThreadExit()) | |||||
{ | { | ||||
fProcess->waitForFinished(static_cast<int>(fEngine->getOptions().uiBridgesTimeout)); | fProcess->waitForFinished(static_cast<int>(fEngine->getOptions().uiBridgesTimeout)); | ||||
@@ -255,7 +255,7 @@ void CarlaPluginThread::run() | |||||
else | else | ||||
{ | { | ||||
fProcess->close(); | fProcess->close(); | ||||
CARLA_ASSERT(fProcess->state() == QProcess::NotRunning); | |||||
CARLA_SAFE_ASSERT(fProcess->state() == QProcess::NotRunning); | |||||
if (fProcess->exitCode() != 0 || fProcess->exitStatus() == QProcess::CrashExit) | if (fProcess->exitCode() != 0 || fProcess->exitStatus() == QProcess::CrashExit) | ||||
carla_stderr("CarlaPluginThread::run() - GUI crashed while opening"); | carla_stderr("CarlaPluginThread::run() - GUI crashed while opening"); | ||||
@@ -269,12 +269,12 @@ void CarlaPluginThread::run() | |||||
case PLUGIN_THREAD_BRIDGE: | case PLUGIN_THREAD_BRIDGE: | ||||
//fProcess->waitForFinished(-1); | //fProcess->waitForFinished(-1); | ||||
while (fProcess->state() != QProcess::NotRunning && ! shouldExit()) | |||||
while (fProcess->state() != QProcess::NotRunning && ! shouldThreadExit()) | |||||
carla_sleep(1); | carla_sleep(1); | ||||
// we only get here if bridge crashed or thread asked to exit | // we only get here if bridge crashed or thread asked to exit | ||||
if (shouldExit()) | |||||
if (shouldThreadExit()) | |||||
{ | { | ||||
fProcess->waitForFinished(500); | fProcess->waitForFinished(500); | ||||
@@ -64,7 +64,7 @@ public: | |||||
{ | { | ||||
showCustomUI(false); | showCustomUI(false); | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
pData->singleMutex.lock(); | pData->singleMutex.lock(); | ||||
@@ -386,7 +386,7 @@ public: | |||||
if (yesNo) | if (yesNo) | ||||
{ | { | ||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
pData->osc.thread.start(); | |||||
pData->osc.thread.startThread(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -399,7 +399,7 @@ public: | |||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
} | } | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
} | } | ||||
@@ -403,7 +403,7 @@ public: | |||||
if (fUi.type == UI::TYPE_OSC) | if (fUi.type == UI::TYPE_OSC) | ||||
{ | { | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -1077,7 +1077,7 @@ public: | |||||
if (yesNo) | if (yesNo) | ||||
{ | { | ||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
pData->osc.thread.start(); | |||||
pData->osc.thread.startThread(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -1088,7 +1088,7 @@ public: | |||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
} | } | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
return; | return; | ||||
} | } | ||||
@@ -91,7 +91,7 @@ public: | |||||
showCustomUI(false); | showCustomUI(false); | ||||
if (fUi.isOsc) | if (fUi.isOsc) | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
pData->singleMutex.lock(); | pData->singleMutex.lock(); | ||||
@@ -391,7 +391,7 @@ public: | |||||
if (yesNo) | if (yesNo) | ||||
{ | { | ||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
pData->osc.thread.start(); | |||||
pData->osc.thread.startThread(); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -404,7 +404,7 @@ public: | |||||
pData->osc.data.free(); | pData->osc.data.free(); | ||||
} | } | ||||
pData->osc.thread.stop(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
pData->osc.thread.stopThread(static_cast<int>(pData->engine->getOptions().uiBridgesTimeout * 2)); | |||||
} | } | ||||
return; | return; | ||||
} | } | ||||
@@ -36,7 +36,7 @@ public: | |||||
NativePluginClass(const NativeHostDescriptor* const host) | NativePluginClass(const NativeHostDescriptor* const host) | ||||
: pHost(host) | : pHost(host) | ||||
{ | { | ||||
CARLA_ASSERT(host != nullptr); | |||||
CARLA_SAFE_ASSERT(host != nullptr); | |||||
} | } | ||||
virtual ~NativePluginClass() | virtual ~NativePluginClass() | ||||
@@ -129,7 +129,7 @@ public: | |||||
~AudioFileThread() override | ~AudioFileThread() override | ||||
{ | { | ||||
CARLA_ASSERT(! isRunning()); | |||||
CARLA_ASSERT(! isThreadRunning()); | |||||
if (fFilePtr != nullptr) | if (fFilePtr != nullptr) | ||||
ad_close(fFilePtr); | ad_close(fFilePtr); | ||||
@@ -140,13 +140,13 @@ public: | |||||
void startNow() | void startNow() | ||||
{ | { | ||||
fNeedsRead = true; | fNeedsRead = true; | ||||
start(); | |||||
startThread(); | |||||
} | } | ||||
void stopNow() | void stopNow() | ||||
{ | { | ||||
fNeedsRead = false; | fNeedsRead = false; | ||||
stop(1000); | |||||
stopThread(1000); | |||||
const CarlaMutex::ScopedLocker sl(fMutex); | const CarlaMutex::ScopedLocker sl(fMutex); | ||||
fPool.reset(); | fPool.reset(); | ||||
@@ -164,7 +164,7 @@ public: | |||||
bool loadFilename(const char* const filename) | bool loadFilename(const char* const filename) | ||||
{ | { | ||||
CARLA_ASSERT(! isRunning()); | |||||
CARLA_ASSERT(! isThreadRunning()); | |||||
CARLA_ASSERT(filename != nullptr); | CARLA_ASSERT(filename != nullptr); | ||||
fPool.startFrame = 0; | fPool.startFrame = 0; | ||||
@@ -351,7 +351,7 @@ public: | |||||
protected: | protected: | ||||
void run() override | void run() override | ||||
{ | { | ||||
while (! shouldExit()) | |||||
while (! shouldThreadExit()) | |||||
{ | { | ||||
const uint64_t lastFrame(kPlayer->getLastFrame()); | const uint64_t lastFrame(kPlayer->getLastFrame()); | ||||
@@ -412,7 +412,7 @@ public: | |||||
protected: | protected: | ||||
void run() override | void run() override | ||||
{ | { | ||||
while (! shouldExit()) | |||||
while (! shouldThreadExit()) | |||||
{ | { | ||||
#ifdef WANT_ZYNADDSUBFX_UI | #ifdef WANT_ZYNADDSUBFX_UI | ||||
Fl::lock(); | Fl::lock(); | ||||
@@ -511,7 +511,7 @@ protected: | |||||
} | } | ||||
#ifdef WANT_ZYNADDSUBFX_UI | #ifdef WANT_ZYNADDSUBFX_UI | ||||
if (shouldExit() || fUi != nullptr) | |||||
if (shouldThreadExit() || fUi != nullptr) | |||||
{ | { | ||||
Fl::lock(); | Fl::lock(); | ||||
delete fUi; | delete fUi; | ||||
@@ -550,7 +550,7 @@ public: | |||||
fIsActive(false), | fIsActive(false), | ||||
fThread(fMaster, host) | fThread(fMaster, host) | ||||
{ | { | ||||
fThread.start(); | |||||
fThread.startThread(); | |||||
for (int i = 0; i < NUM_MIDI_PARTS; ++i) | for (int i = 0; i < NUM_MIDI_PARTS; ++i) | ||||
fMaster->partonoff(i, 1); | fMaster->partonoff(i, 1); | ||||
@@ -736,7 +736,7 @@ protected: | |||||
{ | { | ||||
fMaster = new Master(); | fMaster = new Master(); | ||||
fThread.setMaster(fMaster); | fThread.setMaster(fMaster); | ||||
fThread.start(); | |||||
fThread.startThread(); | |||||
for (int i = 0; i < NUM_MIDI_PARTS; ++i) | for (int i = 0; i < NUM_MIDI_PARTS; ++i) | ||||
fMaster->partonoff(i, 1); | fMaster->partonoff(i, 1); | ||||
@@ -747,7 +747,7 @@ protected: | |||||
//ensure that everything has stopped | //ensure that everything has stopped | ||||
pthread_mutex_lock(&fMaster->mutex); | pthread_mutex_lock(&fMaster->mutex); | ||||
pthread_mutex_unlock(&fMaster->mutex); | pthread_mutex_unlock(&fMaster->mutex); | ||||
fThread.stop(-1); | |||||
fThread.stopThread(-1); | |||||
delete fMaster; | delete fMaster; | ||||
fMaster = nullptr; | fMaster = nullptr; | ||||
@@ -24,6 +24,7 @@ | |||||
#include "CarlaLadspaUtils.hpp" | #include "CarlaLadspaUtils.hpp" | ||||
// #include "CarlaLibUtils.hpp" | // #include "CarlaLibUtils.hpp" | ||||
// #include "CarlaLv2Utils.hpp" | // #include "CarlaLv2Utils.hpp" | ||||
#include "CarlaMathUtils.hpp" | |||||
#include "CarlaOscUtils.hpp" | #include "CarlaOscUtils.hpp" | ||||
#include "CarlaPipeUtils.hpp" | #include "CarlaPipeUtils.hpp" | ||||
// #include "CarlaShmUtils.hpp" | // #include "CarlaShmUtils.hpp" | ||||
@@ -431,7 +431,7 @@ const char* getPluginTypeAsString(const PluginType type) noexcept | |||||
} | } | ||||
static inline | static inline | ||||
PluginType getPluginTypeFromString(const char* const ctype) | |||||
PluginType getPluginTypeFromString(const char* const ctype) noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(ctype != nullptr && ctype[0] != '\0', PLUGIN_NONE); | CARLA_SAFE_ASSERT_RETURN(ctype != nullptr && ctype[0] != '\0', PLUGIN_NONE); | ||||
carla_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype); | carla_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype); | ||||
@@ -475,7 +475,7 @@ PluginType getPluginTypeFromString(const char* const ctype) | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
static inline | static inline | ||||
PluginCategory getPluginCategoryFromName(const char* const name) | |||||
PluginCategory getPluginCategoryFromName(const char* const name) noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', PLUGIN_CATEGORY_NONE); | CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', PLUGIN_CATEGORY_NONE); | ||||
carla_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name); | carla_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name); | ||||
@@ -39,7 +39,7 @@ public: | |||||
~CarlaExternalUI() override | ~CarlaExternalUI() override | ||||
{ | { | ||||
CARLA_ASSERT_INT(fUiState == UiNone, fUiState); | |||||
CARLA_SAFE_ASSERT_INT(fUiState == UiNone, fUiState); | |||||
} | } | ||||
UiState getAndResetUiState() noexcept | UiState getAndResetUiState() noexcept | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* Carla misc utils based on Juce | * Carla misc utils based on Juce | ||||
* Copyright (C) 2013 Raw Material Software Ltd. | * Copyright (C) 2013 Raw Material Software Ltd. | ||||
* Copyright (C) 2013 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2013-2014 Filipe Coelho <falktx@falktx.com> | |||||
* | * | ||||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
* or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
@@ -71,7 +71,7 @@ public: | |||||
LeakedObjectDetector() noexcept { ++(getCounter().numObjects); } | LeakedObjectDetector() noexcept { ++(getCounter().numObjects); } | ||||
LeakedObjectDetector(const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); } | LeakedObjectDetector(const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); } | ||||
~LeakedObjectDetector() | |||||
~LeakedObjectDetector() noexcept | |||||
{ | { | ||||
if (--(getCounter().numObjects) < 0) | if (--(getCounter().numObjects) < 0) | ||||
{ | { | ||||
@@ -100,7 +100,7 @@ private: | |||||
numObjects = 0; | numObjects = 0; | ||||
} | } | ||||
~LeakCounter() | |||||
~LeakCounter() noexcept | |||||
{ | { | ||||
if (numObjects > 0) | if (numObjects > 0) | ||||
{ | { | ||||
@@ -115,10 +115,11 @@ private: | |||||
} | } | ||||
} | } | ||||
// this should be an atomic... | |||||
volatile int numObjects; | volatile int numObjects; | ||||
}; | }; | ||||
static const char* getLeakedObjectClassName() | |||||
static const char* getLeakedObjectClassName() noexcept | |||||
{ | { | ||||
return OwnerClass::getLeakedObjectClassName(); | return OwnerClass::getLeakedObjectClassName(); | ||||
} | } | ||||
@@ -161,8 +162,9 @@ class ScopedValueSetter | |||||
public: | public: | ||||
/** Creates a ScopedValueSetter that will immediately change the specified value to the | /** Creates a ScopedValueSetter that will immediately change the specified value to the | ||||
given new value, and will then reset it to its original value when this object is deleted. | given new value, and will then reset it to its original value when this object is deleted. | ||||
Must be used only for 'noexcept' compatible types. | |||||
*/ | */ | ||||
ScopedValueSetter(ValueType& valueToSet, ValueType newValue) | |||||
ScopedValueSetter(ValueType& valueToSet, ValueType newValue) noexcept | |||||
: value(valueToSet), | : value(valueToSet), | ||||
originalValue(valueToSet) | originalValue(valueToSet) | ||||
{ | { | ||||
@@ -172,14 +174,14 @@ public: | |||||
/** Creates a ScopedValueSetter that will immediately change the specified value to the | /** Creates a ScopedValueSetter that will immediately change the specified value to the | ||||
given new value, and will then reset it to be valueWhenDeleted when this object is deleted. | given new value, and will then reset it to be valueWhenDeleted when this object is deleted. | ||||
*/ | */ | ||||
ScopedValueSetter(ValueType& valueToSet, ValueType newValue, ValueType valueWhenDeleted) | |||||
ScopedValueSetter(ValueType& valueToSet, ValueType newValue, ValueType valueWhenDeleted) noexcept | |||||
: value(valueToSet), | : value(valueToSet), | ||||
originalValue(valueWhenDeleted) | originalValue(valueWhenDeleted) | ||||
{ | { | ||||
valueToSet = newValue; | valueToSet = newValue; | ||||
} | } | ||||
~ScopedValueSetter() | |||||
~ScopedValueSetter() noexcept | |||||
{ | { | ||||
value = originalValue; | value = originalValue; | ||||
} | } | ||||
@@ -64,7 +64,7 @@ const T& carla_max(const T& v1, const T& v2, const T& max) noexcept | |||||
} | } | ||||
/* | /* | ||||
* Fix bounds of 'value', between 'min' and 'max'. | |||||
* Fix bounds of 'value' between 'min' and 'max'. | |||||
*/ | */ | ||||
template<typename T> | template<typename T> | ||||
static inline | static inline | ||||
@@ -79,64 +79,6 @@ const T& carla_fixValue(const T& min, const T& max, const T& value) noexcept | |||||
return value; | return value; | ||||
} | } | ||||
/* | |||||
* Add array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_add(T* dataDst, T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
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++; | |||||
} | |||||
/* | |||||
* Add array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_add(T* dataDst, const T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
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++; | |||||
} | |||||
/* | |||||
* Copy array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_copy(T* dataDst, T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||||
std::memcpy(dataDst, dataSrc, size*sizeof(T)); | |||||
} | |||||
/* | |||||
* Copy array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_copy(T* dataDst, const T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||||
std::memcpy(dataDst, dataSrc, size*sizeof(T)); | |||||
} | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// math functions (extended) | // math functions (extended) | ||||
@@ -567,6 +567,7 @@ public: | |||||
/* | /* | ||||
* Return a duplicate string buffer. | * Return a duplicate string buffer. | ||||
* May throw. | |||||
*/ | */ | ||||
const char* dup() const | const char* dup() const | ||||
{ | { | ||||
@@ -30,7 +30,7 @@ protected: | |||||
/* | /* | ||||
* Constructor. | * Constructor. | ||||
*/ | */ | ||||
CarlaThread(const char* const threadName = nullptr) | |||||
CarlaThread(const char* const threadName = nullptr) noexcept | |||||
: fName(threadName), | : fName(threadName), | ||||
fShouldExit(false) | fShouldExit(false) | ||||
{ | { | ||||
@@ -40,11 +40,11 @@ protected: | |||||
/* | /* | ||||
* Destructor. | * Destructor. | ||||
*/ | */ | ||||
virtual ~CarlaThread() | |||||
virtual ~CarlaThread() noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT(! isRunning()); | |||||
CARLA_SAFE_ASSERT(! isThreadRunning()); | |||||
stop(-1); | |||||
stopThread(-1); | |||||
} | } | ||||
/* | /* | ||||
@@ -56,7 +56,7 @@ public: | |||||
/* | /* | ||||
* Check if the thread is running. | * Check if the thread is running. | ||||
*/ | */ | ||||
bool isRunning() const noexcept | |||||
bool isThreadRunning() const noexcept | |||||
{ | { | ||||
#ifdef CARLA_OS_WIN | #ifdef CARLA_OS_WIN | ||||
return (fHandle.p != nullptr); | return (fHandle.p != nullptr); | ||||
@@ -68,7 +68,7 @@ public: | |||||
/* | /* | ||||
* Check if the thread should exit. | * Check if the thread should exit. | ||||
*/ | */ | ||||
bool shouldExit() const noexcept | |||||
bool shouldThreadExit() const noexcept | |||||
{ | { | ||||
return fShouldExit; | return fShouldExit; | ||||
} | } | ||||
@@ -76,9 +76,9 @@ public: | |||||
/* | /* | ||||
* Start the thread. | * Start the thread. | ||||
*/ | */ | ||||
void start() | |||||
void startThread() noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(! isRunning(),); | |||||
CARLA_SAFE_ASSERT_RETURN(! isThreadRunning(),); | |||||
const CarlaMutex::ScopedLocker sl(fLock); | const CarlaMutex::ScopedLocker sl(fLock); | ||||
@@ -108,24 +108,24 @@ public: | |||||
/* | /* | ||||
* Stop the thread. | * Stop the thread. | ||||
* In the 'timeOutMilliseconds': | * In the 'timeOutMilliseconds': | ||||
* =0 -> no wait | |||||
* >0 -> wait timeout value | |||||
* <0 -> wait forever | |||||
* = 0 -> no wait | |||||
* > 0 -> wait timeout value | |||||
* < 0 -> wait forever | |||||
*/ | */ | ||||
bool stop(const int timeOutMilliseconds) | |||||
bool stopThread(const int timeOutMilliseconds) noexcept | |||||
{ | { | ||||
const CarlaMutex::ScopedLocker sl(fLock); | const CarlaMutex::ScopedLocker sl(fLock); | ||||
if (isRunning()) | |||||
if (isThreadRunning()) | |||||
{ | { | ||||
signalShouldExit(); | |||||
signalThreadShouldExit(); | |||||
if (timeOutMilliseconds != 0) | if (timeOutMilliseconds != 0) | ||||
{ | { | ||||
// Wait for the thread to stop | // Wait for the thread to stop | ||||
int timeOutCheck = (timeOutMilliseconds == 1 || timeOutMilliseconds == -1) ? timeOutMilliseconds : timeOutMilliseconds/2; | int timeOutCheck = (timeOutMilliseconds == 1 || timeOutMilliseconds == -1) ? timeOutMilliseconds : timeOutMilliseconds/2; | ||||
while (isRunning()) | |||||
while (isThreadRunning()) | |||||
{ | { | ||||
carla_msleep(2); | carla_msleep(2); | ||||
@@ -139,7 +139,7 @@ public: | |||||
} | } | ||||
} | } | ||||
if (isRunning()) | |||||
if (isThreadRunning()) | |||||
{ | { | ||||
// should never happen! | // should never happen! | ||||
carla_stderr2("Carla assertion failure: \"! isRunning()\" in file %s, line %i", __FILE__, __LINE__); | carla_stderr2("Carla assertion failure: \"! isRunning()\" in file %s, line %i", __FILE__, __LINE__); | ||||
@@ -147,7 +147,10 @@ public: | |||||
pthread_t threadId = *(const_cast<pthread_t*>(&fHandle)); | pthread_t threadId = *(const_cast<pthread_t*>(&fHandle)); | ||||
_init(); | _init(); | ||||
pthread_cancel(threadId); | |||||
try { | |||||
pthread_cancel(threadId); | |||||
} catch(...) {} | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
@@ -158,7 +161,7 @@ public: | |||||
/* | /* | ||||
* Tell the thread to stop as soon as possible. | * Tell the thread to stop as soon as possible. | ||||
*/ | */ | ||||
void signalShouldExit() noexcept | |||||
void signalThreadShouldExit() noexcept | |||||
{ | { | ||||
fShouldExit = true; | fShouldExit = true; | ||||
} | } | ||||
@@ -179,18 +182,20 @@ private: | |||||
#endif | #endif | ||||
} | } | ||||
void _runEntryPoint() | |||||
void _runEntryPoint() noexcept | |||||
{ | { | ||||
// report ready | // report ready | ||||
fLock.unlock(); | fLock.unlock(); | ||||
run(); | |||||
try { | |||||
run(); | |||||
} catch(...) {} | |||||
// done | // done | ||||
_init(); | _init(); | ||||
} | } | ||||
static void* _entryPoint(void* userData) | |||||
static void* _entryPoint(void* userData) noexcept | |||||
{ | { | ||||
static_cast<CarlaThread*>(userData)->_runEntryPoint(); | static_cast<CarlaThread*>(userData)->_runEntryPoint(); | ||||
return nullptr; | return nullptr; | ||||
@@ -174,30 +174,34 @@ void carla_safe_assert_uint2(const char* const assertion, const char* const file | |||||
* Sleep for 'secs' seconds. | * Sleep for 'secs' seconds. | ||||
*/ | */ | ||||
static inline | static inline | ||||
void carla_sleep(const unsigned int secs) | |||||
void carla_sleep(const unsigned int secs) noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(secs > 0,); | CARLA_SAFE_ASSERT_RETURN(secs > 0,); | ||||
try { | |||||
#ifdef CARLA_OS_WIN | #ifdef CARLA_OS_WIN | ||||
::Sleep(secs * 1000); | ::Sleep(secs * 1000); | ||||
#else | #else | ||||
::sleep(secs); | ::sleep(secs); | ||||
#endif | #endif | ||||
} catch(...) {} | |||||
} | } | ||||
/* | /* | ||||
* Sleep for 'msecs' milliseconds. | * Sleep for 'msecs' milliseconds. | ||||
*/ | */ | ||||
static inline | static inline | ||||
void carla_msleep(const unsigned int msecs) | |||||
void carla_msleep(const unsigned int msecs) noexcept | |||||
{ | { | ||||
CARLA_SAFE_ASSERT_RETURN(msecs > 0,); | CARLA_SAFE_ASSERT_RETURN(msecs > 0,); | ||||
try { | |||||
#ifdef CARLA_OS_WIN | #ifdef CARLA_OS_WIN | ||||
::Sleep(msecs); | ::Sleep(msecs); | ||||
#else | #else | ||||
::usleep(msecs * 1000); | ::usleep(msecs * 1000); | ||||
#endif | #endif | ||||
} catch(...) {} | |||||
} | } | ||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
@@ -213,7 +217,9 @@ void carla_setenv(const char* const key, const char* const value) noexcept | |||||
CARLA_SAFE_ASSERT_RETURN(value != nullptr,); | CARLA_SAFE_ASSERT_RETURN(value != nullptr,); | ||||
#ifdef CARLA_OS_WIN | #ifdef CARLA_OS_WIN | ||||
::SetEnvironmentVariableA(key, value); | |||||
try { | |||||
::SetEnvironmentVariableA(key, value); | |||||
} catch(...) {} | |||||
#else | #else | ||||
::setenv(key, value, 1); | ::setenv(key, value, 1); | ||||
#endif | #endif | ||||
@@ -225,6 +231,7 @@ void carla_setenv(const char* const key, const char* const value) noexcept | |||||
/* | /* | ||||
* Custom 'strdup' function. | * Custom 'strdup' function. | ||||
* Return value is always valid, and must be freed with "delete[] var". | * Return value is always valid, and must be freed with "delete[] var". | ||||
* May throw. | |||||
*/ | */ | ||||
static inline | static inline | ||||
const char* carla_strdup(const char* const strBuf) | const char* carla_strdup(const char* const strBuf) | ||||
@@ -246,6 +253,7 @@ const char* carla_strdup(const char* const strBuf) | |||||
* Custom 'strdup' function. | * Custom 'strdup' function. | ||||
* Calls "std::free(strBuf)". | * Calls "std::free(strBuf)". | ||||
* Return value is always valid, and must be freed with "delete[] var". | * Return value is always valid, and must be freed with "delete[] var". | ||||
* May throw. | |||||
*/ | */ | ||||
static inline | static inline | ||||
const char* carla_strdup_free(char* const strBuf) | const char* carla_strdup_free(char* const strBuf) | ||||
@@ -258,6 +266,68 @@ const char* carla_strdup_free(char* const strBuf) | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// memory functions | // memory functions | ||||
#if 0 | |||||
/* | |||||
* Add array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_add(T* dataDst, T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
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++; | |||||
} | |||||
#endif | |||||
/* | |||||
* Add array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_add(T* dataDst, const T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
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++; | |||||
} | |||||
#if 0 | |||||
/* | |||||
* Copy array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_copy(T* dataDst, T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||||
std::memcpy(dataDst, dataSrc, size*sizeof(T)); | |||||
} | |||||
#endif | |||||
/* | |||||
* Copy array values to another array. | |||||
*/ | |||||
template<typename T> | |||||
static inline | |||||
void carla_copy(T* dataDst, const T* dataSrc, const size_t size) noexcept | |||||
{ | |||||
CARLA_SAFE_ASSERT_RETURN(dataDst != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(dataSrc != nullptr,); | |||||
CARLA_SAFE_ASSERT_RETURN(size > 0,); | |||||
std::memcpy(dataDst, dataSrc, size*sizeof(T)); | |||||
} | |||||
/* | /* | ||||
* Fill an array with a fixed value. | * Fill an array with a fixed value. | ||||
*/ | */ | ||||
@@ -326,7 +396,7 @@ void carla_zeroStruct(T& structure) noexcept | |||||
} | } | ||||
/* | /* | ||||
* Clear an array of struct/class. | |||||
* Clear an array of struct/classes. | |||||
*/ | */ | ||||
template <typename T> | template <typename T> | ||||
static inline | static inline | ||||
@@ -349,7 +419,7 @@ void carla_copyStruct(T& struct1, const T& struct2) noexcept | |||||
} | } | ||||
/* | /* | ||||
* Copy an array of struct/class. | |||||
* Copy an array of struct/classes. | |||||
*/ | */ | ||||
template <typename T> | template <typename T> | ||||
static inline | static inline | ||||
@@ -65,7 +65,7 @@ protected: | |||||
public: | public: | ||||
virtual ~AbstractLinkedList() | virtual ~AbstractLinkedList() | ||||
{ | { | ||||
CARLA_ASSERT(fCount == 0); | |||||
CARLA_SAFE_ASSERT(fCount == 0); | |||||
} | } | ||||
class Itenerator { | class Itenerator { | ||||
@@ -76,9 +76,9 @@ public: | |||||
fEntry2(fEntry->next), | fEntry2(fEntry->next), | ||||
fQueue(queue) | fQueue(queue) | ||||
{ | { | ||||
CARLA_ASSERT(fEntry != nullptr); | |||||
CARLA_ASSERT(fEntry2 != nullptr); | |||||
CARLA_ASSERT(fQueue != nullptr); | |||||
CARLA_SAFE_ASSERT(fEntry != nullptr); | |||||
CARLA_SAFE_ASSERT(fEntry2 != nullptr); | |||||
CARLA_SAFE_ASSERT(fQueue != nullptr); | |||||
} | } | ||||
bool valid() const noexcept | bool valid() const noexcept | ||||
@@ -95,7 +95,7 @@ public: | |||||
T& getValue() noexcept | T& getValue() noexcept | ||||
{ | { | ||||
fData = list_entry(fEntry, Data, siblings); | fData = list_entry(fEntry, Data, siblings); | ||||
CARLA_ASSERT(fData != nullptr); | |||||
CARLA_SAFE_ASSERT(fData != nullptr); | |||||
return fData->value; | return fData->value; | ||||
} | } | ||||
@@ -77,7 +77,7 @@ public: | |||||
} | } | ||||
rtsafe_memory_pool_create(&fHandle, nullptr, fDataSize, minPreallocated, maxPreallocated); | rtsafe_memory_pool_create(&fHandle, nullptr, fDataSize, minPreallocated, maxPreallocated); | ||||
CARLA_ASSERT(fHandle != nullptr); | |||||
CARLA_SAFE_ASSERT(fHandle != nullptr); | |||||
} | } | ||||
bool operator==(const Pool& pool) const noexcept | bool operator==(const Pool& pool) const noexcept | ||||
@@ -132,14 +132,14 @@ public: | |||||
void spliceAppend(RtLinkedList& list, const bool init = true) | void spliceAppend(RtLinkedList& list, const bool init = true) | ||||
{ | { | ||||
CARLA_ASSERT(fMemPool == list.fMemPool); | |||||
CARLA_SAFE_ASSERT_RETURN(fMemPool == list.fMemPool,); | |||||
AbstractLinkedList<T>::spliceAppend(list, init); | AbstractLinkedList<T>::spliceAppend(list, init); | ||||
} | } | ||||
void spliceInsert(RtLinkedList& list, const bool init = true) | void spliceInsert(RtLinkedList& list, const bool init = true) | ||||
{ | { | ||||
CARLA_ASSERT(fMemPool == list.fMemPool); | |||||
CARLA_SAFE_ASSERT_RETURN(fMemPool == list.fMemPool,); | |||||
AbstractLinkedList<T>::spliceInsert(list, init); | AbstractLinkedList<T>::spliceInsert(list, init); | ||||
} | } | ||||