Browse Source

Use separate thread for osc input

tags/1.9.4
falkTX 10 years ago
parent
commit
e19652cf55
6 changed files with 22 additions and 42 deletions
  1. +0
    -5
      source/backend/CarlaEngine.hpp
  2. +0
    -8
      source/backend/engine/CarlaEngine.cpp
  3. +15
    -23
      source/backend/engine/CarlaEngineOsc.cpp
  4. +5
    -3
      source/backend/engine/CarlaEngineOsc.hpp
  5. +1
    -2
      source/backend/engine/CarlaEngineThread.cpp
  6. +1
    -1
      source/backend/engine/Makefile

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

@@ -983,11 +983,6 @@ public:
bool isOscControlRegistered() const noexcept;
#endif

/*!
* Idle OSC.
*/
void idleOsc() const noexcept;

/*!
* Get OSC TCP server path.
*/


+ 0
- 8
source/backend/engine/CarlaEngine.cpp View File

@@ -1601,7 +1601,6 @@ float CarlaEngine::getOutputPeak(const unsigned int pluginId, const bool isLeft)
void CarlaEngine::callback(const EngineCallbackOpcode action, const unsigned int pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
{
carla_debug("CarlaEngine::callback(%s, %i, %i, %i, %f, \"%s\")", EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
CARLA_ENGINE_THREAD_SAFE_SECTION

if (pData->callback != nullptr)
{
@@ -2013,13 +2012,6 @@ 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();


+ 15
- 23
source/backend/engine/CarlaEngineOsc.cpp View File

@@ -71,32 +71,34 @@ void CarlaEngineOsc::init(const char* const name)
fName = name;
fName.toBasic();

fServerTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP);
fServerTCP = lo_server_thread_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP);

if (fServerTCP != nullptr)
{
if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP))
if (char* const tmpServerPathTCP = lo_server_thread_get_url(fServerTCP))
{
fServerPathTCP = tmpServerPathTCP;
fServerPathTCP += fName;
std::free(tmpServerPathTCP);
}

lo_server_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this);
lo_server_thread_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this);
lo_server_thread_start(fServerTCP);
}

fServerUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP);
fServerUDP = lo_server_thread_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP);

if (fServerUDP != nullptr)
{
if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP))
if (char* const tmpServerPathUDP = lo_server_thread_get_url(fServerUDP))
{
fServerPathUDP = tmpServerPathUDP;
fServerPathUDP += fName;
std::free(tmpServerPathUDP);
}

lo_server_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this);
lo_server_thread_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this);
lo_server_thread_start(fServerUDP);
}

CARLA_ASSERT(fName.isNotEmpty());
@@ -106,19 +108,6 @@ void CarlaEngineOsc::init(const char* const name)
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());
@@ -132,15 +121,17 @@ void CarlaEngineOsc::close()

if (fServerTCP != nullptr)
{
lo_server_del_method(fServerTCP, nullptr, nullptr);
lo_server_free(fServerTCP);
lo_server_thread_stop(fServerTCP);
lo_server_thread_del_method(fServerTCP, nullptr, nullptr);
lo_server_thread_free(fServerTCP);
fServerTCP = nullptr;
}

if (fServerUDP != nullptr)
{
lo_server_del_method(fServerUDP, nullptr, nullptr);
lo_server_free(fServerUDP);
lo_server_thread_stop(fServerUDP);
lo_server_thread_del_method(fServerUDP, nullptr, nullptr);
lo_server_thread_free(fServerUDP);
fServerUDP = nullptr;
}

@@ -165,6 +156,7 @@ 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);
const CarlaCriticalSection::Scope _ccsl(_cs);

if (isTCP)
{


+ 5
- 3
source/backend/engine/CarlaEngineOsc.hpp View File

@@ -20,6 +20,7 @@

#include "CarlaBackend.h"
#include "CarlaOscUtils.hpp"
#include "CarlaMutex.hpp"
#include "CarlaString.hpp"

#define CARLA_ENGINE_OSC_HANDLE_ARGS1 CarlaPlugin* const plugin
@@ -61,7 +62,6 @@ public:
~CarlaEngineOsc();

void init(const char* const name);
void idle() const;
void close();

// -------------------------------------------------------------------
@@ -99,8 +99,10 @@ private:

CarlaString fServerPathTCP;
CarlaString fServerPathUDP;
lo_server fServerTCP;
lo_server fServerUDP;
lo_server_thread fServerTCP;
lo_server_thread fServerUDP;

CarlaCriticalSection _cs;

#ifndef BUILD_BRIDGE
CarlaOscData fControlData; // for carla-control


+ 1
- 2
source/backend/engine/CarlaEngineThread.cpp View File

@@ -111,8 +111,7 @@ void CarlaEngineThread::run()
}
}

fEngine->idleOsc();
carla_msleep(oscRegisted ? 30 : 50);
carla_msleep(25);
}
}



+ 1
- 1
source/backend/engine/Makefile View File

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

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

CARLA_ENGINE_OSC_HPP = CarlaEngineOsc.hpp $(CARLA_BACKEND_H) $(CARLA_OSC_UTILS_HPP) $(CARLA_STRING_HPP)
CARLA_ENGINE_OSC_HPP = CarlaEngineOsc.hpp $(CARLA_BACKEND_H) $(CARLA_OSC_UTILS_HPP) $(CARLA_MUTEX_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)



Loading…
Cancel
Save