| @@ -1147,7 +1147,6 @@ const char* CarlaEngine::getUniquePluginName(const char* const name) const | |||
| CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr); | |||
| CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); | |||
| carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name); | |||
| CARLA_ENGINE_THREAD_SAFE_SECTION | |||
| CarlaString sname; | |||
| sname = name; | |||
| @@ -263,19 +263,25 @@ public: | |||
| fIsRunning = true; | |||
| // TODO - set RT permissions | |||
| carla_debug("CarlaEngineBridge::run()"); | |||
| carla_stderr("CarlaEngineBridge::run()"); | |||
| while (! shouldExit()) | |||
| for (; ! shouldExit();) | |||
| { | |||
| carla_stderr("running loop"); | |||
| if (! jackbridge_sem_timedwait(&fShmControl.data->runServer, 5)) | |||
| { | |||
| if (errno == ETIMEDOUT) | |||
| { | |||
| carla_stderr("running loop - QUIT TIMED OUT"); | |||
| fIsRunning = false; | |||
| signalShouldExit(); | |||
| return; | |||
| } | |||
| else | |||
| carla_stderr("running loop - OTHER ERROR : %s", std::strerror(errno)); | |||
| } | |||
| else | |||
| carla_stderr("running loop - ALL FINE, WE GOT EVENTS!!!"); | |||
| for (; fShmControl.isDataAvailable();) | |||
| { | |||
| @@ -413,6 +419,7 @@ public: | |||
| case kPluginBridgeOpcodeQuit: | |||
| signalShouldExit(); | |||
| fIsRunning = false; | |||
| break; | |||
| } | |||
| } | |||
| @@ -83,7 +83,8 @@ void CarlaEngineOsc::init(const char* const name) | |||
| } | |||
| lo_server_thread_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this); | |||
| lo_server_thread_start(fServerTCP); | |||
| int ret = lo_server_thread_start(fServerTCP); | |||
| CARLA_SAFE_ASSERT(ret == 0); | |||
| } | |||
| fServerUDP = lo_server_thread_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP); | |||
| @@ -98,7 +99,8 @@ void CarlaEngineOsc::init(const char* const name) | |||
| } | |||
| lo_server_thread_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this); | |||
| lo_server_thread_start(fServerUDP); | |||
| int ret = lo_server_thread_start(fServerUDP); | |||
| CARLA_SAFE_ASSERT(ret == 0); | |||
| } | |||
| CARLA_ASSERT(fName.isNotEmpty()); | |||
| @@ -269,11 +269,13 @@ public: | |||
| pData->active = false; | |||
| } | |||
| if (pData->osc.thread.isRunning() && ! fTimedOut) | |||
| if (pData->osc.thread.isRunning()) | |||
| { | |||
| fShmControl.writeOpcode(kPluginBridgeOpcodeQuit); | |||
| fShmControl.commitWrite(); | |||
| fShmControl.waitForServer(3); | |||
| if (! fTimedOut) | |||
| fShmControl.waitForServer(3); | |||
| } | |||
| if (pData->osc.data.target != nullptr) | |||
| @@ -716,7 +718,12 @@ public: | |||
| } catch(...) {} | |||
| if (! timedOut) | |||
| { | |||
| carla_stdout("woohoo! activate was successful!"); | |||
| fTimedOut = false; | |||
| } | |||
| else | |||
| carla_stdout("beh! activate failed!"); | |||
| } | |||
| void deactivate() noexcept override | |||
| @@ -733,8 +740,9 @@ public: | |||
| timedOut = waitForServer(); | |||
| } catch(...) {} | |||
| if (! timedOut) | |||
| fTimedOut = false; | |||
| (void)timedOut; | |||
| //if (! timedOut) | |||
| // fTimedOut = false; | |||
| } | |||
| void process(float** const inBuffer, float** const outBuffer, const uint32_t frames) override | |||
| @@ -1229,7 +1237,7 @@ public: | |||
| fInfo.copyright = copyright; | |||
| if (pData->name == nullptr) | |||
| pData->name = carla_strdup(realName); | |||
| pData->name = pData->engine->getUniquePluginName(realName); | |||
| break; | |||
| } | |||
| @@ -140,20 +140,20 @@ void CarlaPluginThread::run() | |||
| break; | |||
| case PLUGIN_THREAD_LV2_GUI: | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathTCP()).arg(fPlugin->getId()); | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathUDP()).arg(fPlugin->getId()); | |||
| /* URI */ arguments << (const char*)fLabel; | |||
| /* ui-URI */ arguments << (const char*)fExtra1; | |||
| /* ui-title */ arguments << QString("%1 (GUI)").arg(fPlugin->getName()); | |||
| break; | |||
| case PLUGIN_THREAD_VST_GUI: | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathTCP()).arg(fPlugin->getId()); | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathUDP()).arg(fPlugin->getId()); | |||
| /* filename */ arguments << fPlugin->getFilename(); | |||
| /* ui-title */ arguments << QString("%1 (GUI)").arg(fPlugin->getName()); | |||
| break; | |||
| case PLUGIN_THREAD_BRIDGE: | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathTCP()).arg(fPlugin->getId()); | |||
| /* osc-url */ arguments << QString("%1/%2").arg(fEngine->getOscServerPathUDP()).arg(fPlugin->getId()); | |||
| /* stype */ arguments << (const char*)fExtra1; | |||
| /* filename */ arguments << fPlugin->getFilename(); | |||
| /* name */ arguments << name; | |||
| @@ -123,23 +123,21 @@ void CarlaBridgeClient::oscInit(const char* const url) | |||
| fOsc.init(url); | |||
| } | |||
| bool CarlaBridgeClient::oscIdle() const | |||
| void CarlaBridgeClient::oscClose() | |||
| { | |||
| fOsc.idle(); | |||
| carla_debug("CarlaBridgeClient::oscClose()"); | |||
| #ifdef BUILD_BRIDGE_UI | |||
| return ! fUI.quit; | |||
| #else | |||
| return true; | |||
| #endif | |||
| fOsc.close(); | |||
| } | |||
| void CarlaBridgeClient::oscClose() | |||
| #ifdef BUILD_BRIDGE_UI | |||
| bool CarlaBridgeClient::oscIdle() const | |||
| { | |||
| carla_debug("CarlaBridgeClient::oscClose()"); | |||
| fOsc.idle(); | |||
| fOsc.close(); | |||
| return ! fUI.quit; | |||
| } | |||
| #endif | |||
| bool CarlaBridgeClient::isOscControlRegistered() const noexcept | |||
| { | |||
| @@ -74,9 +74,12 @@ public: | |||
| // osc stuff | |||
| void oscInit(const char* const url); | |||
| bool oscIdle() const; | |||
| void oscClose(); | |||
| #ifdef BUILD_BRIDGE_UI | |||
| bool oscIdle() const; | |||
| #endif | |||
| bool isOscControlRegistered() const noexcept; | |||
| void sendOscUpdate() const; | |||
| @@ -62,7 +62,11 @@ void CarlaBridgeOsc::init(const char* const url) | |||
| fName += CarlaString(std::rand() % 99999); | |||
| #endif | |||
| fServer = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler); | |||
| #ifdef BUILD_BRIDGE_UI | |||
| fServer = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler); | |||
| #else | |||
| fServer = lo_server_thread_new_with_proto(nullptr, LO_UDP, osc_error_handler); | |||
| #endif | |||
| CARLA_SAFE_ASSERT_RETURN(fServer != nullptr,) | |||
| @@ -70,33 +74,34 @@ void CarlaBridgeOsc::init(const char* const url) | |||
| char* const host = lo_url_get_hostname(url); | |||
| char* const port = lo_url_get_port(url); | |||
| fControlData.path = carla_strdup_free(lo_url_get_path(url)); | |||
| fControlData.target = lo_address_new_with_proto(LO_TCP, host, port); | |||
| fControlData.target = lo_address_new_with_proto(LO_UDP, host, port); | |||
| std::free(host); | |||
| std::free(port); | |||
| } | |||
| #ifdef BUILD_BRIDGE_UI | |||
| if (char* const tmpServerPath = lo_server_get_url(fServer)) | |||
| #else | |||
| if (char* const tmpServerPath = lo_server_thread_get_url(fServer)) | |||
| #endif | |||
| { | |||
| fServerPath = tmpServerPath; | |||
| fServerPath += fName; | |||
| std::free(tmpServerPath); | |||
| } | |||
| #ifdef BUILD_BRIDGE_UI | |||
| lo_server_add_method(fServer, nullptr, nullptr, osc_message_handler, this); | |||
| #else | |||
| lo_server_thread_add_method(fServer, nullptr, nullptr, osc_message_handler, this); | |||
| lo_server_thread_start(fServer); | |||
| #endif | |||
| CARLA_ASSERT(fName.isNotEmpty()); | |||
| CARLA_ASSERT(fServerPath.isNotEmpty()); | |||
| } | |||
| void CarlaBridgeOsc::idle() const | |||
| { | |||
| if (fServer == nullptr) | |||
| return; | |||
| for (; lo_server_recv_noblock(fServer, 0) != 0;) {} | |||
| } | |||
| void CarlaBridgeOsc::close() | |||
| { | |||
| CARLA_ASSERT(fControlData.source == nullptr); // must never be used | |||
| @@ -109,8 +114,14 @@ void CarlaBridgeOsc::close() | |||
| if (fServer != nullptr) | |||
| { | |||
| #ifdef BUILD_BRIDGE_UI | |||
| lo_server_del_method(fServer, nullptr, nullptr); | |||
| lo_server_free(fServer); | |||
| #else | |||
| lo_server_thread_del_method(fServer, nullptr, nullptr); | |||
| lo_server_thread_del_method(fServer, nullptr, nullptr); | |||
| lo_server_thread_free(fServer); | |||
| #endif | |||
| fServer = nullptr; | |||
| } | |||
| @@ -122,6 +133,16 @@ void CarlaBridgeOsc::close() | |||
| CARLA_ASSERT(fServer == nullptr); | |||
| } | |||
| #ifdef BUILD_BRIDGE_UI | |||
| void CarlaBridgeOsc::idle() const | |||
| { | |||
| if (fServer == nullptr) | |||
| return; | |||
| for (; lo_server_recv_noblock(fServer, 0) != 0;) {} | |||
| } | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| int CarlaBridgeOsc::handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg) | |||
| @@ -60,9 +60,12 @@ public: | |||
| ~CarlaBridgeOsc(); | |||
| void init(const char* const url); | |||
| void idle() const; | |||
| void close(); | |||
| #ifdef BUILD_BRIDGE_UI | |||
| void idle() const; | |||
| #endif | |||
| // ------------------------------------------------------------------- | |||
| bool isControlRegistered() const noexcept | |||
| @@ -88,7 +91,11 @@ private: | |||
| CarlaOscData fControlData; | |||
| CarlaString fName; | |||
| CarlaString fServerPath; | |||
| #ifdef BUILD_BRIDGE_UI | |||
| lo_server fServer; | |||
| #else | |||
| lo_server_thread fServer; | |||
| #endif | |||
| // ------------------------------------------------------------------- | |||
| @@ -173,7 +173,7 @@ public: | |||
| CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); | |||
| carla_engine_idle(); | |||
| CarlaBridgeClient::oscIdle(); | |||
| //CarlaBridgeClient::oscIdle(); | |||
| if (gSaveNow) | |||
| { | |||
| @@ -591,8 +591,10 @@ int main(int argc, char* argv[]) | |||
| { | |||
| if (useOsc) | |||
| { | |||
| carla_stdout("HERE 001"); | |||
| client.sendOscUpdate(); | |||
| client.sendOscBridgeUpdate(); | |||
| carla_stdout("HERE 002"); | |||
| } | |||
| else | |||
| { | |||
| @@ -604,13 +606,17 @@ int main(int argc, char* argv[]) | |||
| carla_show_custom_ui(0, true); | |||
| } | |||
| } | |||
| carla_stdout("HERE 003"); | |||
| client.ready(!useOsc); | |||
| gIsInitiated = true; | |||
| carla_stdout("HERE 004"); | |||
| client.exec(); | |||
| carla_stdout("HERE 005"); | |||
| carla_set_engine_about_to_close(); | |||
| carla_remove_plugin(0); | |||
| carla_stdout("HERE 006"); | |||
| ret = 0; | |||
| } | |||
| @@ -624,12 +630,17 @@ int main(int argc, char* argv[]) | |||
| ret = 1; | |||
| } | |||
| carla_stdout("HERE 007"); | |||
| // --------------------------------------------------------------------- | |||
| // Close OSC | |||
| if (useOsc) | |||
| { | |||
| carla_stdout("HERE 008"); | |||
| client.oscClose(); | |||
| carla_stdout("HERE 009"); | |||
| } | |||
| return ret; | |||
| } | |||