diff --git a/source/backend/CarlaEngine.hpp b/source/backend/CarlaEngine.hpp index 5ea66717a..cddce4212 100644 --- a/source/backend/CarlaEngine.hpp +++ b/source/backend/CarlaEngine.hpp @@ -310,13 +310,13 @@ protected: * 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. */ - CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort); + CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) noexcept; public: /*! * The destructor. */ - virtual ~CarlaEnginePort(); + virtual ~CarlaEnginePort() noexcept; /*! * Get the type of the port, as provided by the respective subclasses. @@ -355,12 +355,12 @@ public: * The constructor.\n * 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. */ - ~CarlaEngineAudioPort() override; + ~CarlaEngineAudioPort() noexcept override; /*! * Get the type of the port, in this case kEnginePortTypeAudio. @@ -377,6 +377,7 @@ public: /*! * Direct access to the port's audio buffer. + * May return null. */ float* getBuffer() const noexcept { @@ -401,12 +402,12 @@ public: * The constructor.\n * 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. */ - ~CarlaEngineCVPort() override; + ~CarlaEngineCVPort() noexcept override; /*! * Get the type of the port, in this case kEnginePortTypeCV. @@ -422,12 +423,8 @@ public: 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 { @@ -437,7 +434,6 @@ public: #ifndef DOXYGEN protected: float* fBuffer; - const EngineProcessMode fProcessMode; CARLA_DECLARE_NON_COPY_CLASS(CarlaEngineCVPort) #endif @@ -453,12 +449,12 @@ public: * The constructor.\n * 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. */ - ~CarlaEngineEventPort() override; + ~CarlaEngineEventPort() noexcept override; /*! * Get the type of the port, in this case kEnginePortTypeEvent. @@ -588,7 +584,7 @@ public: * 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). */ - 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 protected: @@ -972,6 +968,11 @@ public: bool isOscControlRegistered() const noexcept; #endif + /*! + * Idle OSC. + */ + void idleOsc() const noexcept; + /*! * Get OSC TCP server path. */ diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 63e3c8b78..c42e00e46 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -56,14 +56,14 @@ static const EngineEvent kFallbackEngineEvent = { kEngineEventTypeNull, 0, 0, {{ // ----------------------------------------------------------------------- // Carla Engine port (Abstract) -CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) +CarlaEnginePort::CarlaEnginePort(const CarlaEngine& engine, const bool isInputPort) noexcept : fEngine(engine), fIsInput(isInputPort) { carla_debug("CarlaEnginePort::CarlaEnginePort(%s)", bool2str(isInputPort)); } -CarlaEnginePort::~CarlaEnginePort() +CarlaEnginePort::~CarlaEnginePort() noexcept { carla_debug("CarlaEnginePort::~CarlaEnginePort()"); } @@ -71,14 +71,14 @@ CarlaEnginePort::~CarlaEnginePort() // ----------------------------------------------------------------------- // Carla Engine Audio port -CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort) +CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEngine& engine, const bool isInputPort) noexcept : CarlaEnginePort(engine, isInputPort), fBuffer(nullptr) { carla_debug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInputPort)); } -CarlaEngineAudioPort::~CarlaEngineAudioPort() +CarlaEngineAudioPort::~CarlaEngineAudioPort() noexcept { carla_debug("CarlaEngineAudioPort::~CarlaEngineAudioPort()"); } @@ -90,51 +90,26 @@ void CarlaEngineAudioPort::initBuffer() noexcept // ----------------------------------------------------------------------- // Carla Engine CV port -CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort) +CarlaEngineCVPort::CarlaEngineCVPort(const CarlaEngine& engine, const bool isInputPort) noexcept : CarlaEnginePort(engine, isInputPort), - fBuffer(nullptr), - fProcessMode(engine.getProccessMode()) + fBuffer(nullptr) { 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()"); - - 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 { - 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 -CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort) +CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool isInputPort) noexcept : CarlaEnginePort(engine, isInputPort), fBuffer(nullptr), fProcessMode(engine.getProccessMode()) @@ -145,7 +120,7 @@ CarlaEngineEventPort::CarlaEngineEventPort(const CarlaEngine& engine, const bool fBuffer = new EngineEvent[kMaxEngineEventInternalCount]; } -CarlaEngineEventPort::~CarlaEngineEventPort() +CarlaEngineEventPort::~CarlaEngineEventPort() noexcept { carla_debug("CarlaEngineEventPort::~CarlaEngineEventPort()"); @@ -302,13 +277,13 @@ CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine) CarlaEngineClient::~CarlaEngineClient() { - CARLA_ASSERT(! fActive); + CARLA_SAFE_ASSERT(! fActive); carla_debug("CarlaEngineClient::~CarlaEngineClient()"); } void CarlaEngineClient::activate() noexcept { - CARLA_ASSERT(! fActive); + CARLA_SAFE_ASSERT(! fActive); carla_debug("CarlaEngineClient::activate()"); fActive = true; @@ -316,7 +291,7 @@ void CarlaEngineClient::activate() noexcept void CarlaEngineClient::deactivate() noexcept { - CARLA_ASSERT(fActive); + CARLA_SAFE_ASSERT(fActive); carla_debug("CarlaEngineClient::deactivate()"); fActive = false; @@ -342,23 +317,33 @@ void CarlaEngineClient::setLatency(const uint32_t samples) noexcept 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_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)); 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(clientName != nullptr && clientName[0] != '\0', "Invalid client name"); carla_debug("CarlaEngine::init(\"%s\")", clientName); - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->aboutToClose = false; pData->curPluginCount = 0; @@ -620,7 +604,7 @@ bool CarlaEngine::init(const char* const clientName) #endif pData->nextAction.ready(); - pData->thread.start(); + pData->thread.startThread(); 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->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #9)"); carla_debug("CarlaEngine::close()"); - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->aboutToClose = true; if (pData->curPluginCount != 0) removeAllPlugins(); - pData->thread.stop(500); + pData->thread.stopThread(500); pData->nextAction.ready(); #ifndef BUILD_BRIDGE @@ -682,10 +665,9 @@ bool CarlaEngine::close() 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) { @@ -694,6 +676,8 @@ void CarlaEngine::idle() if (plugin != nullptr && plugin->isEnabled()) plugin->idle(); } + + idleOsc(); } 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((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_ENGINE_THREAD_SAFE_SECTION; unsigned int id; 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(id < pData->curPluginCount, "Invalid plugin Id (err #1)"); carla_debug("CarlaEngine::removePlugin(%i)", id); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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->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 CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionRemovePlugin, id, 0, lockWait); @@ -993,7 +975,7 @@ bool CarlaEngine::removePlugin(const unsigned int id) delete plugin; if (isRunning() && ! pData->aboutToClose) - pData->thread.start(); + pData->thread.startThread(); callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr); 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->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #20)"); carla_debug("CarlaEngine::removeAllPlugins()"); - CARLA_ENGINE_THREAD_SAFE_SECTION; if (pData->curPluginCount == 0) return true; - pData->thread.stop(500); + pData->thread.stopThread(500); const bool lockWait(isRunning()); const CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionZeroCount, 0, 0, lockWait); @@ -1036,7 +1017,7 @@ bool CarlaEngine::removeAllPlugins() } if (isRunning() && ! pData->aboutToClose) - pData->thread.start(); + pData->thread.startThread(); 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(newName != nullptr && newName[0] != '\0', "Invalid plugin name"); carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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(id < pData->curPluginCount, "Invalid plugin Id (err #3)"); carla_debug("CarlaEngine::clonePlugin(%i)", id); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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())) 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) 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->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data (err #31)"); carla_debug("CarlaEngine::replacePlugin(%i)", id); - CARLA_ENGINE_THREAD_SAFE_SECTION; // might use this to reset 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(idB < pData->curPluginCount, "Invalid plugin Id (err #6)"); carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB); - CARLA_ENGINE_THREAD_SAFE_SECTION; CarlaPlugin* const pluginA(pData->plugins[idA].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(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 CarlaEngineProtectedData::ScopedActionLock sal(pData, kEnginePostActionSwitchPlugins, idA, idB, lockWait); @@ -1154,7 +1131,7 @@ bool CarlaEngine::switchPlugins(const unsigned int idA, const unsigned int idB) #endif if (isRunning() && ! pData->aboutToClose) - pData->thread.start(); + pData->thread.startThread(); 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_debug("CarlaEngine::loadFile(\"%s\")", filename); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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_debug("CarlaEngine::loadProject(\"%s\")", filename); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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_debug("CarlaEngine::saveProject(\"%s\")", filename); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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 { carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr); - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->callback = func; 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(filter != nullptr, nullptr); 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; @@ -1681,7 +1653,6 @@ const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept { - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->fileCallback = func; 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->bufAudio.isReady, false); carla_debug("CarlaEngineRtAudio::patchbayConnect(%i, %i)", portA, portB); - CARLA_ENGINE_THREAD_SAFE_SECTION; 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->bufAudio.isReady, false); carla_debug("CarlaEngineRtAudio::patchbayDisconnect(%i)", connectionId); - CARLA_ENGINE_THREAD_SAFE_SECTION; if (pData->bufAudio.usePatchbay) { @@ -1916,7 +1885,6 @@ const char* CarlaEngine::getLastError() const noexcept void CarlaEngine::setLastError(const char* const error) const { - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->lastError = error; } @@ -1934,7 +1902,6 @@ void CarlaEngine::setAboutToClose() noexcept 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_ENGINE_THREAD_SAFE_SECTION; 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); @@ -2050,6 +2017,14 @@ bool CarlaEngine::isOscControlRegistered() const noexcept } #endif + +void CarlaEngine::idleOsc() const noexcept +{ + try { + pData->osc.idle(); + } catch(...) {} +} + const char* CarlaEngine::getOscServerPathTCP() const noexcept { return pData->osc.getServerPathTCP(); @@ -2063,7 +2038,6 @@ const char* CarlaEngine::getOscServerPathUDP() const noexcept #ifdef BUILD_BRIDGE void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData) const noexcept { - CARLA_ENGINE_THREAD_SAFE_SECTION; pData->oscData = oscData; } diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index eb7582e3c..800da9659 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -297,7 +297,7 @@ public: pData->sampleRate = fShmControl.readFloat(); carla_stderr("SampleRate: %f", pData->sampleRate); - CarlaThread::start(); + CarlaThread::startThread(); CarlaEngine::init(clientName); return true; } @@ -307,7 +307,7 @@ public: carla_debug("CarlaEnginePlugin::close()"); CarlaEngine::close(); - CarlaThread::stop(6000); + CarlaThread::stopThread(6000); fShmTime.clear(); fShmControl.clear(); @@ -346,14 +346,14 @@ public: // TODO - set RT permissions carla_debug("CarlaEngineBridge::run()"); - for (; ! shouldExit();) + for (; ! shouldThreadExit();) { if (! jackbridge_sem_timedwait(&fShmControl.data->runServer, 5)) { if (errno == ETIMEDOUT) { fIsRunning = false; - signalShouldExit(); + signalThreadShouldExit(); return; } } @@ -516,7 +516,7 @@ public: } case kPluginBridgeOpcodeQuit: - signalShouldExit(); + signalThreadShouldExit(); fIsRunning = false; break; } diff --git a/source/backend/engine/CarlaEngineInternal.cpp b/source/backend/engine/CarlaEngineInternal.cpp index 6a4db9e91..dfc00e202 100644 --- a/source/backend/engine/CarlaEngineInternal.cpp +++ b/source/backend/engine/CarlaEngineInternal.cpp @@ -549,8 +549,8 @@ 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 { - CARLA_ASSERT(opcode == kEnginePostActionNull); + CARLA_SAFE_ASSERT(opcode == kEnginePostActionNull); } void EngineNextAction::ready() noexcept diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 8a154b994..89d37dc0a 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -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_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 @@ -248,10 +239,6 @@ struct CarlaEngineProtectedData { EngineInternalTime time; EngineNextAction nextAction; -#ifndef BUILD_BRIDGE - CarlaCriticalSection _cs; // for handling requests from multiple threads -#endif - // ------------------------------------------------------------------- CarlaEngineProtectedData(CarlaEngine* const engine); diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 2ed054d10..8f88392e6 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -36,6 +36,7 @@ CARLA_BACKEND_START_NAMESPACE #endif class CarlaEngineJack; +class CarlaEngineJackClient; // ----------------------------------------------------------------------- // Fallback data @@ -48,7 +49,7 @@ static const EngineEvent kFallbackJackEngineEvent = { kEngineEventTypeNull, 0, 0 class CarlaEngineJackAudioPort : public CarlaEngineAudioPort { 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), fClient(client), fPort(port) @@ -57,24 +58,28 @@ public: 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 { - CARLA_ASSERT(client == nullptr && port == nullptr); + CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); } } - ~CarlaEngineJackAudioPort() override + ~CarlaEngineJackAudioPort() noexcept override { carla_debug("CarlaEngineJackAudioPort::~CarlaEngineJackAudioPort()"); if (fClient != nullptr && fPort != nullptr) { - jackbridge_port_unregister(fClient, fPort); + try { + jackbridge_port_unregister(fClient, fPort); + } catch(...) {} + fClient = nullptr; fPort = nullptr; } @@ -87,7 +92,13 @@ public: 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) FLOAT_CLEAR(fBuffer, bufferSize); @@ -109,7 +120,7 @@ private: class CarlaEngineJackCVPort : public CarlaEngineCVPort { 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), fClient(client), fPort(port) @@ -118,24 +129,28 @@ public: 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 { - CARLA_ASSERT(client == nullptr && port == nullptr); + CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); } } - ~CarlaEngineJackCVPort() override + ~CarlaEngineJackCVPort() noexcept override { carla_debug("CarlaEngineJackCVPort::~CarlaEngineJackCVPort()"); if (fClient != nullptr && fPort != nullptr) { - jackbridge_port_unregister(fClient, fPort); + try { + jackbridge_port_unregister(fClient, fPort); + } catch(...) {} + fClient = nullptr; fPort = nullptr; } @@ -148,7 +163,13 @@ public: 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) FLOAT_CLEAR(fBuffer, bufferSize); @@ -170,7 +191,7 @@ private: class CarlaEngineJackEventPort : public CarlaEngineEventPort { 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), fClient(client), fPort(port), @@ -180,21 +201,24 @@ public: 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 { - CARLA_ASSERT(client == nullptr && port == nullptr); + CARLA_SAFE_ASSERT(client == nullptr && port == nullptr); } } - ~CarlaEngineJackEventPort() override + ~CarlaEngineJackEventPort() noexcept override { carla_debug("CarlaEngineJackEventPort::~CarlaEngineJackEventPort()"); if (fClient != nullptr && fPort != nullptr) { - jackbridge_port_unregister(fClient, fPort); + try { + jackbridge_port_unregister(fClient, fPort); + } catch(...) {} + fClient = nullptr; fPort = nullptr; } @@ -205,7 +229,13 @@ public: if (fPort == nullptr) 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) jackbridge_midi_clear_buffer(fJackBuffer); @@ -219,7 +249,13 @@ public: CARLA_SAFE_ASSERT_RETURN(fIsInput, 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 @@ -237,7 +273,13 @@ public: { 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; CARLA_SAFE_ASSERT_RETURN(jackEvent.size <= 0xFF /* uint8_t max */, kFallbackJackEngineEvent); @@ -273,7 +315,13 @@ public: if (size == 0) 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 @@ -294,7 +342,13 @@ public: for (uint8_t i=1; i < size; ++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: @@ -325,11 +379,11 @@ public: if (fUseClient) { - CARLA_ASSERT(fClient != nullptr); + CARLA_SAFE_ASSERT(fClient != nullptr); } else { - CARLA_ASSERT(fClient == nullptr); + CARLA_SAFE_ASSERT(fClient == nullptr); } } @@ -398,7 +452,7 @@ public: } #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)); @@ -407,20 +461,22 @@ public: // Create JACK port first, if needed 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) { @@ -530,7 +586,7 @@ public: ~CarlaEngineJack() override { carla_debug("CarlaEngineJack::~CarlaEngineJack()"); - CARLA_ASSERT(fClient == nullptr); + CARLA_SAFE_ASSERT(fClient == nullptr); #ifndef BUILD_BRIDGE fUsedGroupNames.clear(); @@ -583,7 +639,6 @@ public: bool init(const char* const clientName) override { carla_debug("CarlaEngineJack::init(\"%s\")", clientName); - CARLA_ENGINE_THREAD_SAFE_SECTION; fFreewheel = false; fTransportState = JackTransportStopped; @@ -671,7 +726,6 @@ public: bool close() override { carla_debug("CarlaEngineJack::close()"); - CARLA_ENGINE_THREAD_SAFE_SECTION; CarlaEngine::close(); @@ -718,7 +772,6 @@ public: #ifndef BUILD_BRIDGE void idle() override { - CARLA_ENGINE_THREAD_SAFE_SECTION; CarlaEngine::idle(); @@ -771,7 +824,6 @@ public: CarlaEngineClient* addClient(CarlaPlugin* const plugin) override { - CARLA_ENGINE_THREAD_SAFE_SECTION; jack_client_t* client = nullptr; @@ -815,7 +867,6 @@ public: CARLA_SAFE_ASSERT_RETURN(id < pData->curPluginCount, nullptr); CARLA_SAFE_ASSERT_RETURN(pData->plugins != nullptr, nullptr); CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0', nullptr); - CARLA_ENGINE_THREAD_SAFE_SECTION; CarlaPlugin* const plugin(pData->plugins[id].plugin); @@ -895,7 +946,6 @@ public: bool patchbayConnect(int portA, int portB) override { CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); - CARLA_ENGINE_THREAD_SAFE_SECTION; if (fClient == nullptr) { @@ -920,7 +970,6 @@ public: bool patchbayDisconnect(uint connectionId) override { CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); - CARLA_ENGINE_THREAD_SAFE_SECTION; for (LinkedList::Itenerator it = fUsedConnections.begin(); it.valid(); it.next()) { @@ -951,7 +1000,6 @@ public: bool patchbayRefresh() override { CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, false); - CARLA_ENGINE_THREAD_SAFE_SECTION; fLastGroupId = 0; fLastPortId = 0; @@ -1210,13 +1258,15 @@ protected: void* const eventIn = jackbridge_port_get_buffer(fRackPorts[kRackPortEventIn], nframes); void* const eventOut = jackbridge_port_get_buffer(fRackPorts[kRackPortEventOut], nframes); +#if 0 // 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 float* inBuf[2] = { audioIn1, audioIn2 }; diff --git a/source/backend/engine/CarlaEngineJuce.cpp b/source/backend/engine/CarlaEngineJuce.cpp index e45e7d474..b520a53d6 100644 --- a/source/backend/engine/CarlaEngineJuce.cpp +++ b/source/backend/engine/CarlaEngineJuce.cpp @@ -155,7 +155,7 @@ public: pData->bufAudio.inCount = static_cast(inputChannels.countNumberOfSetBits()); pData->bufAudio.outCount = static_cast(outputChannels.countNumberOfSetBits()); - CARLA_ASSERT(pData->bufAudio.outCount > 0); + CARLA_SAFE_ASSERT(pData->bufAudio.outCount > 0); 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); StringArray inputNames(fDevice->getInputChannelNames()); - CARLA_ASSERT(inputNames.size() == static_cast(pData->bufAudio.inCount)); + CARLA_SAFE_ASSERT(inputNames.size() == static_cast(pData->bufAudio.inCount)); 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); StringArray outputNames(fDevice->getOutputChannelNames()); - CARLA_ASSERT(outputNames.size() == static_cast(pData->bufAudio.outCount)); + CARLA_SAFE_ASSERT(outputNames.size() == static_cast(pData->bufAudio.outCount)); for (uint i=0; i < pData->bufAudio.outCount; ++i) { diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index fd5630917..18a15c58c 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -546,7 +546,7 @@ public: ~CarlaEngineNative() override { - CARLA_ASSERT(! fIsActive); + CARLA_SAFE_ASSERT(! fIsActive); carla_debug("CarlaEngineNative::~CarlaEngineNative() - START"); pData->aboutToClose = true; diff --git a/source/backend/engine/CarlaEngineOsc.cpp b/source/backend/engine/CarlaEngineOsc.cpp index bad06993d..5ff3b9ad1 100644 --- a/source/backend/engine/CarlaEngineOsc.cpp +++ b/source/backend/engine/CarlaEngineOsc.cpp @@ -42,17 +42,17 @@ CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine) fServerTCP(nullptr), fServerUDP(nullptr) { - CARLA_ASSERT(engine != nullptr); + CARLA_SAFE_ASSERT(engine != nullptr); carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); } 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()"); } @@ -71,48 +71,55 @@ void CarlaEngineOsc::init(const char* const name) fName = name; 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 (char* const tmpServerPathTCP = lo_server_thread_get_url(fServerTCP)) + if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP)) { fServerPathTCP = tmpServerPathTCP; fServerPathTCP += fName; 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 (char* const tmpServerPathUDP = lo_server_thread_get_url(fServerUDP)) + if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP)) { fServerPathUDP = tmpServerPathUDP; fServerPathUDP += fName; 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(fServerPathUDP.isNotEmpty()); CARLA_SAFE_ASSERT(fServerTCP != 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() { - CARLA_ASSERT(fName.isNotEmpty()); + CARLA_SAFE_ASSERT(fName.isNotEmpty()); CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty()); CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty()); CARLA_SAFE_ASSERT(fServerTCP != nullptr); @@ -123,17 +130,15 @@ void CarlaEngineOsc::close() 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; } 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; } @@ -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(path != nullptr && path[0] != '\0', 1); 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(fServerTCP != nullptr, 1); } - else + //else { CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1); CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1); diff --git a/source/backend/engine/CarlaEngineOsc.hpp b/source/backend/engine/CarlaEngineOsc.hpp index 8c30a9392..469e87c59 100644 --- a/source/backend/engine/CarlaEngineOsc.hpp +++ b/source/backend/engine/CarlaEngineOsc.hpp @@ -20,7 +20,6 @@ #include "CarlaBackend.h" #include "CarlaOscUtils.hpp" -#include "CarlaMutex.hpp" #include "CarlaString.hpp" #define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin @@ -62,6 +61,7 @@ public: ~CarlaEngineOsc(); void init(const char* const name); + void idle() const; void close(); // ------------------------------------------------------------------- @@ -99,12 +99,11 @@ private: CarlaString fServerPathTCP; CarlaString fServerPathUDP; - lo_server_thread fServerTCP; - lo_server_thread fServerUDP; + lo_server fServerTCP; + lo_server fServerUDP; #ifndef BUILD_BRIDGE CarlaOscData fControlData; // for carla-control - CarlaCriticalSection _cs; #endif // ------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index bdbd5c2cf..cb262bd75 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -176,8 +176,8 @@ public: ~CarlaEngineRtAudio() override { - CARLA_ASSERT(fAudioBufIn == nullptr); - CARLA_ASSERT(fAudioBufOut == nullptr); + CARLA_SAFE_ASSERT(fAudioBufIn == nullptr); + CARLA_SAFE_ASSERT(fAudioBufOut == nullptr); carla_debug("CarlaEngineRtAudio::~CarlaEngineRtAudio()"); fUsedMidiIns.clear(); @@ -274,7 +274,7 @@ public: pData->bufAudio.inCount = iParams.nChannels; pData->bufAudio.outCount = oParams.nChannels; - CARLA_ASSERT(pData->bufAudio.outCount > 0); + CARLA_SAFE_ASSERT(pData->bufAudio.outCount > 0); if (pData->bufAudio.inCount > 0) { @@ -312,7 +312,7 @@ public: bool close() override { - CARLA_ASSERT(fAudioBufOut != nullptr); + CARLA_SAFE_ASSERT(fAudioBufOut != nullptr); carla_debug("CarlaEngineRtAudio::close()"); pData->bufAudio.isReady = false; diff --git a/source/backend/engine/CarlaEngineThread.cpp b/source/backend/engine/CarlaEngineThread.cpp index 3151dd6de..071847e23 100644 --- a/source/backend/engine/CarlaEngineThread.cpp +++ b/source/backend/engine/CarlaEngineThread.cpp @@ -27,7 +27,7 @@ CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine) : CarlaThread("CarlaEngineThread"), fEngine(engine) { - CARLA_ASSERT(engine != nullptr); + CARLA_SAFE_ASSERT(engine != nullptr); carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine); } @@ -47,7 +47,7 @@ void CarlaEngineThread::run() bool hasUi, oscRegisted, needsSingleThread; float value; - for (; fEngine->isRunning() && ! shouldExit();) + for (; fEngine->isRunning() && ! shouldThreadExit();) { #ifdef BUILD_BRIDGE oscRegisted = fEngine->isOscBridgeRegistered(); diff --git a/source/backend/engine/Makefile b/source/backend/engine/Makefile index f63b67c3c..49a344cba 100644 --- a/source/backend/engine/Makefile +++ b/source/backend/engine/Makefile @@ -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_INTERNAL_HPP = CarlaEngineInternal.hpp $(CARLA_ENGINE_OSC_HPP) $(CARLA_ENGINE_THREAD_HPP) $(CARLA_ENGINE_HPP) $(CARLA_MUTEX_HPP) $(LINKED_LIST_HPP) diff --git a/source/backend/plugin/BridgePlugin.cpp b/source/backend/plugin/BridgePlugin.cpp index 9f555de65..83fa5b552 100644 --- a/source/backend/plugin/BridgePlugin.cpp +++ b/source/backend/plugin/BridgePlugin.cpp @@ -335,7 +335,7 @@ public: pData->active = false; } - if (pData->osc.thread.isRunning()) + if (pData->osc.thread.isThreadRunning()) { fShmControl.writeOpcode(kPluginBridgeOpcodeQuit); fShmControl.commitWrite(); @@ -351,7 +351,7 @@ public: } pData->osc.data.free(); - pData->osc.thread.stop(3000); + pData->osc.thread.stopThread(3000); if (fNeedsSemDestroy) { @@ -623,7 +623,7 @@ public: void idle() override { - if (! pData->osc.thread.isRunning()) + if (! pData->osc.thread.isThreadRunning()) carla_stderr2("TESTING: Bridge has closed!"); CarlaPlugin::idle(); @@ -1912,25 +1912,26 @@ public: std::strncat(shmIdStr, &fShmTime.filename[fShmTime.filename.length()-6], 6); pData->osc.thread.setOscData(bridgeBinary, label, getPluginTypeAsString(fPluginType), shmIdStr); - pData->osc.thread.start(); + pData->osc.thread.startThread(); } fInitiated = false; fLastPongCounter = 0; - for (; fLastPongCounter < 100; ++fLastPongCounter) + for (; fLastPongCounter < 200; ++fLastPongCounter) { - if (fInitiated || ! pData->osc.thread.isRunning()) + if (fInitiated || ! pData->osc.thread.isThreadRunning()) break; - carla_msleep(50); + carla_msleep(30); pData->engine->callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr); + pData->engine->idle(); } fLastPongCounter = -1; if (fInitError || ! fInitiated) { - pData->osc.thread.stop(6000); + pData->osc.thread.stopThread(6000); if (! fInitError) pData->engine->setLastError("Timeout while waiting for a response from plugin-bridge\n(or the plugin crashed on initialization?)"); diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index aa22aa8d1..4ef0dd078 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -121,26 +121,26 @@ CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id) : pData(new CarlaPluginProtectedData(engine, id, this)) { 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); switch (engine->getProccessMode()) { case ENGINE_PROCESS_MODE_SINGLE_CLIENT: case ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS: - CARLA_ASSERT(id < MAX_DEFAULT_PLUGINS); + CARLA_SAFE_ASSERT(id < MAX_DEFAULT_PLUGINS); break; case ENGINE_PROCESS_MODE_CONTINUOUS_RACK: - CARLA_ASSERT(id < MAX_RACK_PLUGINS); + CARLA_SAFE_ASSERT(id < MAX_RACK_PLUGINS); break; case ENGINE_PROCESS_MODE_PATCHBAY: - CARLA_ASSERT(id < MAX_PATCHBAY_PLUGINS); + CARLA_SAFE_ASSERT(id < MAX_PATCHBAY_PLUGINS); break; case ENGINE_PROCESS_MODE_BRIDGE: - CARLA_ASSERT(id == 0); + CARLA_SAFE_ASSERT(id == 0); break; } } @@ -306,7 +306,7 @@ const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const noexcep int32_t CarlaPlugin::getChunkData(void** const dataPtr) const noexcept { CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); - CARLA_ASSERT(false); // this should never happen + CARLA_SAFE_ASSERT(false); // this should never happen return 0; } @@ -315,14 +315,14 @@ int32_t CarlaPlugin::getChunkData(void** const dataPtr) 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; } float CarlaPlugin::getParameterValue(const uint32_t parameterId) const noexcept { 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; } @@ -330,7 +330,7 @@ float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 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; } @@ -357,7 +357,7 @@ void CarlaPlugin::getRealName(char* const strBuf) const noexcept void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const noexcept { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); - CARLA_ASSERT(false); // this should never happen + CARLA_SAFE_ASSERT(false); // this should never happen 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 { CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); - CARLA_ASSERT(false); // this should never happen + CARLA_SAFE_ASSERT(false); // this should never happen 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(scalePointId < getParameterScalePointCount(parameterId),); - CARLA_ASSERT(false); // this should never happen + CARLA_SAFE_ASSERT(false); // this should never happen strBuf[0] = '\0'; } @@ -828,7 +828,7 @@ void CarlaPlugin::setId(const unsigned int newId) noexcept 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) delete[] pData->name; @@ -838,7 +838,7 @@ void CarlaPlugin::setName(const char* const newName) void CarlaPlugin::setOption(const unsigned int option, const bool yesNo) { - CARLA_ASSERT(getOptionsAvailable() & option); + CARLA_SAFE_ASSERT_RETURN(getOptionsAvailable() & option,); if (yesNo) 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 { #ifndef BUILD_BRIDGE - CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT + CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT #endif if (pData->active == active) @@ -902,7 +902,7 @@ void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool se #ifndef BUILD_BRIDGE 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(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 { - CARLA_ASSERT(value >= 0.0f && value <= 1.27f); + CARLA_SAFE_ASSERT(value >= 0.0f && value <= 1.27f); const float fixedValue(carla_fixValue(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 { - CARLA_ASSERT(value >= -1.0f && value <= 1.0f); + CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); const float fixedValue(carla_fixValue(-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 { - CARLA_ASSERT(value >= -1.0f && value <= 1.0f); + CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); const float fixedValue(carla_fixValue(-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 { - CARLA_ASSERT(value >= -1.0f && value <= 1.0f); + CARLA_SAFE_ASSERT(value >= -1.0f && value <= 1.0f); const float fixedValue(carla_fixValue(-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 { #ifndef BUILD_BRIDGE - CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT + CARLA_SAFE_ASSERT_RETURN(sendOsc || sendCallback,); // never call this from RT #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) 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 { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count,); #ifdef BUILD_BRIDGE 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 { - 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) return setActive((value > 0.0f), sendOsc, sendCallback); 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 { - 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; @@ -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 { - 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; @@ -1184,9 +1174,9 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c { 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) { @@ -1208,12 +1198,8 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c 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 @@ -1387,7 +1373,7 @@ void CarlaPlugin::idle() void CarlaPlugin::showCustomUI(const bool yesNo) { - CARLA_ASSERT(false); + CARLA_SAFE_ASSERT(false); return; // unused @@ -1406,12 +1392,12 @@ void CarlaPlugin::reloadPrograms(const bool) void CarlaPlugin::activate() noexcept { - CARLA_ASSERT(! pData->active); + CARLA_SAFE_ASSERT(! pData->active); } void CarlaPlugin::deactivate() noexcept { - CARLA_ASSERT(pData->active); + CARLA_SAFE_ASSERT(pData->active); } 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()); - 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) osc_send_configure(pData->osc.data, cData.key, cData.value); @@ -1701,7 +1687,7 @@ bool CarlaPlugin::waitForOscGuiShow() return true; } - if (pData->osc.thread.isRunning()) + if (pData->osc.thread.isThreadRunning()) carla_msleep(100); else return false; @@ -1717,9 +1703,9 @@ bool CarlaPlugin::waitForOscGuiShow() #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) { - 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) return; @@ -1929,54 +1915,34 @@ void CarlaPlugin::postRtEventsRun() void CarlaPlugin::uiParameterChange(const uint32_t index, const float value) noexcept { - CARLA_ASSERT(index < getParameterCount()); + CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),); return; // unused - (void)index; (void)value; } 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 { - 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 { - 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 { - 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 diff --git a/source/backend/plugin/CarlaPluginThread.cpp b/source/backend/plugin/CarlaPluginThread.cpp index 2db74787e..5def90063 100644 --- a/source/backend/plugin/CarlaPluginThread.cpp +++ b/source/backend/plugin/CarlaPluginThread.cpp @@ -68,7 +68,7 @@ CarlaPluginThread::~CarlaPluginThread() void CarlaPluginThread::setMode(const CarlaPluginThread::Mode mode) { - CARLA_ASSERT(! isRunning()); + CARLA_SAFE_ASSERT(! isThreadRunning()); carla_debug("CarlaPluginThread::setMode(%s)", PluginThreadMode2str(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) { - CARLA_ASSERT(! isRunning()); + CARLA_SAFE_ASSERT(! isThreadRunning()); carla_debug("CarlaPluginThread::setOscData(\"%s\", \"%s\", \"%s\", \"%s\")", binary, label, extra1, extra2); fBinary = binary; @@ -226,12 +226,12 @@ void CarlaPluginThread::run() { //fProcess->waitForFinished(-1); - while (fProcess->state() != QProcess::NotRunning && ! shouldExit()) + while (fProcess->state() != QProcess::NotRunning && ! shouldThreadExit()) carla_sleep(1); // 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(fEngine->getOptions().uiBridgesTimeout)); @@ -255,7 +255,7 @@ void CarlaPluginThread::run() else { fProcess->close(); - CARLA_ASSERT(fProcess->state() == QProcess::NotRunning); + CARLA_SAFE_ASSERT(fProcess->state() == QProcess::NotRunning); if (fProcess->exitCode() != 0 || fProcess->exitStatus() == QProcess::CrashExit) carla_stderr("CarlaPluginThread::run() - GUI crashed while opening"); @@ -269,12 +269,12 @@ void CarlaPluginThread::run() case PLUGIN_THREAD_BRIDGE: //fProcess->waitForFinished(-1); - while (fProcess->state() != QProcess::NotRunning && ! shouldExit()) + while (fProcess->state() != QProcess::NotRunning && ! shouldThreadExit()) carla_sleep(1); // we only get here if bridge crashed or thread asked to exit - if (shouldExit()) + if (shouldThreadExit()) { fProcess->waitForFinished(500); diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index 6ce57b746..48f54b51d 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -64,7 +64,7 @@ public: { showCustomUI(false); - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } pData->singleMutex.lock(); @@ -386,7 +386,7 @@ public: if (yesNo) { pData->osc.data.free(); - pData->osc.thread.start(); + pData->osc.thread.startThread(); } else { @@ -399,7 +399,7 @@ public: pData->osc.data.free(); } - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } } diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 3a89b0079..ce85cd4a3 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -403,7 +403,7 @@ public: if (fUi.type == UI::TYPE_OSC) { - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } else { @@ -1077,7 +1077,7 @@ public: if (yesNo) { pData->osc.data.free(); - pData->osc.thread.start(); + pData->osc.thread.startThread(); } else { @@ -1088,7 +1088,7 @@ public: pData->osc.data.free(); } - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } return; } diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 64c188825..395789ca5 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -91,7 +91,7 @@ public: showCustomUI(false); if (fUi.isOsc) - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } pData->singleMutex.lock(); @@ -391,7 +391,7 @@ public: if (yesNo) { pData->osc.data.free(); - pData->osc.thread.start(); + pData->osc.thread.startThread(); } else { @@ -404,7 +404,7 @@ public: pData->osc.data.free(); } - pData->osc.thread.stop(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); + pData->osc.thread.stopThread(static_cast(pData->engine->getOptions().uiBridgesTimeout * 2)); } return; } diff --git a/source/modules/CarlaNative.hpp b/source/modules/CarlaNative.hpp index da18b87f6..12e1ce121 100644 --- a/source/modules/CarlaNative.hpp +++ b/source/modules/CarlaNative.hpp @@ -36,7 +36,7 @@ public: NativePluginClass(const NativeHostDescriptor* const host) : pHost(host) { - CARLA_ASSERT(host != nullptr); + CARLA_SAFE_ASSERT(host != nullptr); } virtual ~NativePluginClass() diff --git a/source/modules/native-plugins/audio-base.hpp b/source/modules/native-plugins/audio-base.hpp index 96c15e773..651b65832 100644 --- a/source/modules/native-plugins/audio-base.hpp +++ b/source/modules/native-plugins/audio-base.hpp @@ -129,7 +129,7 @@ public: ~AudioFileThread() override { - CARLA_ASSERT(! isRunning()); + CARLA_ASSERT(! isThreadRunning()); if (fFilePtr != nullptr) ad_close(fFilePtr); @@ -140,13 +140,13 @@ public: void startNow() { fNeedsRead = true; - start(); + startThread(); } void stopNow() { fNeedsRead = false; - stop(1000); + stopThread(1000); const CarlaMutex::ScopedLocker sl(fMutex); fPool.reset(); @@ -164,7 +164,7 @@ public: bool loadFilename(const char* const filename) { - CARLA_ASSERT(! isRunning()); + CARLA_ASSERT(! isThreadRunning()); CARLA_ASSERT(filename != nullptr); fPool.startFrame = 0; @@ -351,7 +351,7 @@ public: protected: void run() override { - while (! shouldExit()) + while (! shouldThreadExit()) { const uint64_t lastFrame(kPlayer->getLastFrame()); diff --git a/source/modules/native-plugins/zynaddsubfx-synth.cpp b/source/modules/native-plugins/zynaddsubfx-synth.cpp index f4b40ad3b..88fbc1b51 100644 --- a/source/modules/native-plugins/zynaddsubfx-synth.cpp +++ b/source/modules/native-plugins/zynaddsubfx-synth.cpp @@ -412,7 +412,7 @@ public: protected: void run() override { - while (! shouldExit()) + while (! shouldThreadExit()) { #ifdef WANT_ZYNADDSUBFX_UI Fl::lock(); @@ -511,7 +511,7 @@ protected: } #ifdef WANT_ZYNADDSUBFX_UI - if (shouldExit() || fUi != nullptr) + if (shouldThreadExit() || fUi != nullptr) { Fl::lock(); delete fUi; @@ -550,7 +550,7 @@ public: fIsActive(false), fThread(fMaster, host) { - fThread.start(); + fThread.startThread(); for (int i = 0; i < NUM_MIDI_PARTS; ++i) fMaster->partonoff(i, 1); @@ -736,7 +736,7 @@ protected: { fMaster = new Master(); fThread.setMaster(fMaster); - fThread.start(); + fThread.startThread(); for (int i = 0; i < NUM_MIDI_PARTS; ++i) fMaster->partonoff(i, 1); @@ -747,7 +747,7 @@ protected: //ensure that everything has stopped pthread_mutex_lock(&fMaster->mutex); pthread_mutex_unlock(&fMaster->mutex); - fThread.stop(-1); + fThread.stopThread(-1); delete fMaster; fMaster = nullptr; diff --git a/source/tests/Utils.cpp b/source/tests/Utils.cpp index 43437120c..6768ebeea 100644 --- a/source/tests/Utils.cpp +++ b/source/tests/Utils.cpp @@ -24,6 +24,7 @@ #include "CarlaLadspaUtils.hpp" // #include "CarlaLibUtils.hpp" // #include "CarlaLv2Utils.hpp" +#include "CarlaMathUtils.hpp" #include "CarlaOscUtils.hpp" #include "CarlaPipeUtils.hpp" // #include "CarlaShmUtils.hpp" diff --git a/source/utils/CarlaBackendUtils.hpp b/source/utils/CarlaBackendUtils.hpp index 1bdd3dcc2..651581efd 100644 --- a/source/utils/CarlaBackendUtils.hpp +++ b/source/utils/CarlaBackendUtils.hpp @@ -431,7 +431,7 @@ const char* getPluginTypeAsString(const PluginType type) noexcept } 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_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype); @@ -475,7 +475,7 @@ PluginType getPluginTypeFromString(const char* const ctype) // ----------------------------------------------------------------------- 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_debug("CarlaBackend::getPluginCategoryFromName(\"%s\")", name); diff --git a/source/utils/CarlaExternalUI.hpp b/source/utils/CarlaExternalUI.hpp index 73f931929..79c724433 100644 --- a/source/utils/CarlaExternalUI.hpp +++ b/source/utils/CarlaExternalUI.hpp @@ -39,7 +39,7 @@ public: ~CarlaExternalUI() override { - CARLA_ASSERT_INT(fUiState == UiNone, fUiState); + CARLA_SAFE_ASSERT_INT(fUiState == UiNone, fUiState); } UiState getAndResetUiState() noexcept diff --git a/source/utils/CarlaJuceUtils.hpp b/source/utils/CarlaJuceUtils.hpp index 34aa658b6..d5f9fff7a 100644 --- a/source/utils/CarlaJuceUtils.hpp +++ b/source/utils/CarlaJuceUtils.hpp @@ -1,7 +1,7 @@ /* * Carla misc utils based on Juce * Copyright (C) 2013 Raw Material Software Ltd. - * Copyright (C) 2013 Filipe Coelho + * Copyright (C) 2013-2014 Filipe Coelho * * 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 @@ -71,7 +71,7 @@ public: LeakedObjectDetector() noexcept { ++(getCounter().numObjects); } LeakedObjectDetector(const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); } - ~LeakedObjectDetector() + ~LeakedObjectDetector() noexcept { if (--(getCounter().numObjects) < 0) { @@ -100,7 +100,7 @@ private: numObjects = 0; } - ~LeakCounter() + ~LeakCounter() noexcept { if (numObjects > 0) { @@ -115,10 +115,11 @@ private: } } + // this should be an atomic... volatile int numObjects; }; - static const char* getLeakedObjectClassName() + static const char* getLeakedObjectClassName() noexcept { return OwnerClass::getLeakedObjectClassName(); } @@ -161,8 +162,9 @@ class ScopedValueSetter public: /** 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. + Must be used only for 'noexcept' compatible types. */ - ScopedValueSetter(ValueType& valueToSet, ValueType newValue) + ScopedValueSetter(ValueType& valueToSet, ValueType newValue) noexcept : value(valueToSet), originalValue(valueToSet) { @@ -172,14 +174,14 @@ public: /** 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. */ - ScopedValueSetter(ValueType& valueToSet, ValueType newValue, ValueType valueWhenDeleted) + ScopedValueSetter(ValueType& valueToSet, ValueType newValue, ValueType valueWhenDeleted) noexcept : value(valueToSet), originalValue(valueWhenDeleted) { valueToSet = newValue; } - ~ScopedValueSetter() + ~ScopedValueSetter() noexcept { value = originalValue; } diff --git a/source/utils/CarlaMathUtils.hpp b/source/utils/CarlaMathUtils.hpp index 0155f798b..22b233539 100644 --- a/source/utils/CarlaMathUtils.hpp +++ b/source/utils/CarlaMathUtils.hpp @@ -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 static inline @@ -79,64 +79,6 @@ const T& carla_fixValue(const T& min, const T& max, const T& value) noexcept return value; } -/* - * Add array values to another array. - */ -template -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 -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 -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 -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) diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp index 687256c59..f8a3df732 100644 --- a/source/utils/CarlaString.hpp +++ b/source/utils/CarlaString.hpp @@ -567,6 +567,7 @@ public: /* * Return a duplicate string buffer. + * May throw. */ const char* dup() const { diff --git a/source/utils/CarlaThread.hpp b/source/utils/CarlaThread.hpp index 9d4dd0275..79c578de3 100644 --- a/source/utils/CarlaThread.hpp +++ b/source/utils/CarlaThread.hpp @@ -30,7 +30,7 @@ protected: /* * Constructor. */ - CarlaThread(const char* const threadName = nullptr) + CarlaThread(const char* const threadName = nullptr) noexcept : fName(threadName), fShouldExit(false) { @@ -40,11 +40,11 @@ protected: /* * 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. */ - bool isRunning() const noexcept + bool isThreadRunning() const noexcept { #ifdef CARLA_OS_WIN return (fHandle.p != nullptr); @@ -68,7 +68,7 @@ public: /* * Check if the thread should exit. */ - bool shouldExit() const noexcept + bool shouldThreadExit() const noexcept { return fShouldExit; } @@ -76,9 +76,9 @@ public: /* * Start the thread. */ - void start() + void startThread() noexcept { - CARLA_SAFE_ASSERT_RETURN(! isRunning(),); + CARLA_SAFE_ASSERT_RETURN(! isThreadRunning(),); const CarlaMutex::ScopedLocker sl(fLock); @@ -108,24 +108,24 @@ public: /* * Stop the thread. * 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); - if (isRunning()) + if (isThreadRunning()) { - signalShouldExit(); + signalThreadShouldExit(); if (timeOutMilliseconds != 0) { // Wait for the thread to stop int timeOutCheck = (timeOutMilliseconds == 1 || timeOutMilliseconds == -1) ? timeOutMilliseconds : timeOutMilliseconds/2; - while (isRunning()) + while (isThreadRunning()) { carla_msleep(2); @@ -139,7 +139,7 @@ public: } } - if (isRunning()) + if (isThreadRunning()) { // should never happen! carla_stderr2("Carla assertion failure: \"! isRunning()\" in file %s, line %i", __FILE__, __LINE__); @@ -147,7 +147,10 @@ public: pthread_t threadId = *(const_cast(&fHandle)); _init(); - pthread_cancel(threadId); + try { + pthread_cancel(threadId); + } catch(...) {} + return false; } } @@ -158,7 +161,7 @@ public: /* * Tell the thread to stop as soon as possible. */ - void signalShouldExit() noexcept + void signalThreadShouldExit() noexcept { fShouldExit = true; } @@ -179,18 +182,20 @@ private: #endif } - void _runEntryPoint() + void _runEntryPoint() noexcept { // report ready fLock.unlock(); - run(); + try { + run(); + } catch(...) {} // done _init(); } - static void* _entryPoint(void* userData) + static void* _entryPoint(void* userData) noexcept { static_cast(userData)->_runEntryPoint(); return nullptr; diff --git a/source/utils/CarlaUtils.hpp b/source/utils/CarlaUtils.hpp index d64823cd2..6d0b9f0a7 100644 --- a/source/utils/CarlaUtils.hpp +++ b/source/utils/CarlaUtils.hpp @@ -174,30 +174,34 @@ void carla_safe_assert_uint2(const char* const assertion, const char* const file * Sleep for 'secs' seconds. */ static inline -void carla_sleep(const unsigned int secs) +void carla_sleep(const unsigned int secs) noexcept { CARLA_SAFE_ASSERT_RETURN(secs > 0,); + try { #ifdef CARLA_OS_WIN ::Sleep(secs * 1000); #else ::sleep(secs); #endif + } catch(...) {} } /* * Sleep for 'msecs' milliseconds. */ static inline -void carla_msleep(const unsigned int msecs) +void carla_msleep(const unsigned int msecs) noexcept { CARLA_SAFE_ASSERT_RETURN(msecs > 0,); + try { #ifdef CARLA_OS_WIN ::Sleep(msecs); #else ::usleep(msecs * 1000); #endif + } catch(...) {} } // ----------------------------------------------------------------------- @@ -213,7 +217,9 @@ void carla_setenv(const char* const key, const char* const value) noexcept CARLA_SAFE_ASSERT_RETURN(value != nullptr,); #ifdef CARLA_OS_WIN - ::SetEnvironmentVariableA(key, value); + try { + ::SetEnvironmentVariableA(key, value); + } catch(...) {} #else ::setenv(key, value, 1); #endif @@ -225,6 +231,7 @@ void carla_setenv(const char* const key, const char* const value) noexcept /* * Custom 'strdup' function. * Return value is always valid, and must be freed with "delete[] var". + * May throw. */ static inline const char* carla_strdup(const char* const strBuf) @@ -246,6 +253,7 @@ const char* carla_strdup(const char* const strBuf) * Custom 'strdup' function. * Calls "std::free(strBuf)". * Return value is always valid, and must be freed with "delete[] var". + * May throw. */ static inline const char* carla_strdup_free(char* const strBuf) @@ -258,6 +266,68 @@ const char* carla_strdup_free(char* const strBuf) // ----------------------------------------------------------------------- // memory functions +#if 0 +/* + * Add array values to another array. + */ +template +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 +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 +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 +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. */ @@ -326,7 +396,7 @@ void carla_zeroStruct(T& structure) noexcept } /* - * Clear an array of struct/class. + * Clear an array of struct/classes. */ template 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 static inline diff --git a/source/utils/LinkedList.hpp b/source/utils/LinkedList.hpp index e47c89462..4afcbfb75 100644 --- a/source/utils/LinkedList.hpp +++ b/source/utils/LinkedList.hpp @@ -65,7 +65,7 @@ protected: public: virtual ~AbstractLinkedList() { - CARLA_ASSERT(fCount == 0); + CARLA_SAFE_ASSERT(fCount == 0); } class Itenerator { @@ -76,9 +76,9 @@ public: fEntry2(fEntry->next), 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 @@ -95,7 +95,7 @@ public: T& getValue() noexcept { fData = list_entry(fEntry, Data, siblings); - CARLA_ASSERT(fData != nullptr); + CARLA_SAFE_ASSERT(fData != nullptr); return fData->value; } diff --git a/source/utils/RtLinkedList.hpp b/source/utils/RtLinkedList.hpp index f4c7c6efd..3dda1783b 100644 --- a/source/utils/RtLinkedList.hpp +++ b/source/utils/RtLinkedList.hpp @@ -77,7 +77,7 @@ public: } 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 @@ -132,14 +132,14 @@ public: void spliceAppend(RtLinkedList& list, const bool init = true) { - CARLA_ASSERT(fMemPool == list.fMemPool); + CARLA_SAFE_ASSERT_RETURN(fMemPool == list.fMemPool,); AbstractLinkedList::spliceAppend(list, init); } void spliceInsert(RtLinkedList& list, const bool init = true) { - CARLA_ASSERT(fMemPool == list.fMemPool); + CARLA_SAFE_ASSERT_RETURN(fMemPool == list.fMemPool,); AbstractLinkedList::spliceInsert(list, init); }