Control manager thread save with SourceCallbacks

This commit is contained in:
Bruno Herbelin
2021-12-20 00:30:50 +01:00
parent cb3cca8a64
commit 733d08638d
3 changed files with 64 additions and 24 deletions

View File

@@ -36,6 +36,7 @@
#endif #endif
#define CONTROL_OSC_MSG "OSC: " #define CONTROL_OSC_MSG "OSC: "
#define OSC_SEPARATOR '/'
void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m, void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
const IpEndpointName& remoteEndpoint ) const IpEndpointName& remoteEndpoint )
@@ -58,21 +59,41 @@ void Control::RequestListener::ProcessMessage( const osc::ReceivedMessage& m,
if (address.size() == 3 && address.front().compare(APP_NAME) == 0 ){ if (address.size() == 3 && address.front().compare(APP_NAME) == 0 ){
// done with the first part of the OSC address // done with the first part of the OSC address
address.pop_front(); address.pop_front();
// execute next part of the OSC message //
// Execute next part of the OSC message according to target
//
std::string target = address.front(); std::string target = address.front();
std::string attribute = address.back(); std::string attribute = address.back();
// Log target // Log target: just print text in log window
if ( target.compare(OSC_LOG) == 0 ) if ( target.compare(OSC_LOG) == 0 )
{ {
if ( attribute.compare(OSC_LOG_INFO) == 0) if ( attribute.compare(OSC_LOG_INFO) == 0)
Log::Info(CONTROL_OSC_MSG "received '%s' from %s", m.AddressPattern(), sender); Log::Info(CONTROL_OSC_MSG "received '%s' from %s", m.AddressPattern(), sender);
} }
// Output target // Output target: concerns attributes of the rendering output
else if ( target.compare(OSC_OUTPUT) == 0 ) else if ( target.compare(OSC_OUTPUT) == 0 )
{ {
Control::manager().setOutputAttribute(attribute, m.ArgumentStream()); Control::manager().setOutputAttribute(attribute, m.ArgumentStream());
} }
// Current source target // ALL sources target: apply attribute to all sources of the session
else if ( target.compare(OSC_ALL) == 0 )
{
// Loop over selected sources
for (SourceList::iterator it = Mixer::manager().session()->begin(); it != Mixer::manager().session()->end(); ++it) {
// attributes operate on current source
Control::manager().setSourceAttribute( *it, attribute, m.ArgumentStream());
}
}
// Selected sources target: apply attribute to all sources of the selection
else if ( target.compare(OSC_SELECTED) == 0 )
{
// Loop over selected sources
for (SourceList::iterator it = Mixer::selection().begin(); it != Mixer::selection().end(); ++it) {
// attributes operate on current source
Control::manager().setSourceAttribute( *it, attribute, m.ArgumentStream());
}
}
// Current source target: apply attribute to the current sources
else if ( target.compare(OSC_CURRENT) == 0 ) else if ( target.compare(OSC_CURRENT) == 0 )
{ {
// attributes to change current // attributes to change current
@@ -141,6 +162,7 @@ Control::~Control()
receiver_->Break(); receiver_->Break();
delete receiver_; delete receiver_;
} }
} }
bool Control::init() bool Control::init()
@@ -169,11 +191,12 @@ void Control::terminate()
receiver_->AsynchronousBreak(); receiver_->AsynchronousBreak();
} }
void Control::setOutputAttribute(const std::string &attribute, void Control::setOutputAttribute(const std::string &attribute,
osc::ReceivedMessageArgumentStream arguments) osc::ReceivedMessageArgumentStream arguments)
{ {
try { try {
/// '/vimix/output/enable' or '/vimix/output/enable T' or '/vimix/output/enable F' /// e.g. '/vimix/output/enable' or '/vimix/output/enable T' or '/vimix/output/enable F'
if ( attribute.compare(OSC_OUTPUT_ENABLE) == 0) { if ( attribute.compare(OSC_OUTPUT_ENABLE) == 0) {
bool on = true; bool on = true;
if ( !arguments.Eos()) { if ( !arguments.Eos()) {
@@ -181,7 +204,7 @@ void Control::setOutputAttribute(const std::string &attribute,
} }
Settings::application.render.disabled = !on; Settings::application.render.disabled = !on;
} }
/// '/vimix/output/disable' or '/vimix/output/disable T' or '/vimix/output/disable F' /// e.g. '/vimix/output/disable' or '/vimix/output/disable T' or '/vimix/output/disable F'
else if ( attribute.compare(OSC_OUTPUT_DISABLE) == 0) { else if ( attribute.compare(OSC_OUTPUT_DISABLE) == 0) {
bool on = true; bool on = true;
if ( !arguments.Eos()) { if ( !arguments.Eos()) {
@@ -189,7 +212,7 @@ void Control::setOutputAttribute(const std::string &attribute,
} }
Settings::application.render.disabled = on; Settings::application.render.disabled = on;
} }
/// '/vimix/output/fading f 0.2' /// e.g. '/vimix/output/fading f 0.2'
else if ( attribute.compare(OSC_OUTPUT_FADING) == 0) { else if ( attribute.compare(OSC_OUTPUT_FADING) == 0) {
float fading = 0.f; float fading = 0.f;
arguments >> fading >> osc::EndMessage; arguments >> fading >> osc::EndMessage;
@@ -220,21 +243,45 @@ void Control::setSourceAttribute(Source *target, const std::string &attribute,
return; return;
try { try {
/// '/vimix/current/play' or '/vimix/current/play T' or '/vimix/current/play F' /// e.g. '/vimix/current/play' or '/vimix/current/play T' or '/vimix/current/play F'
if ( attribute.compare(OSC_SOURCE_PLAY) == 0) { if ( attribute.compare(OSC_SOURCE_PLAY) == 0) {
bool on = true; bool on = true;
if ( !arguments.Eos()) { if ( !arguments.Eos()) {
arguments >> on >> osc::EndMessage; arguments >> on >> osc::EndMessage;
} }
target->play(on); target->call( new SetPlay(on) );
} }
/// '/vimix/current/pause' or '/vimix/current/pause T' or '/vimix/current/pause F' /// e.g. '/vimix/current/pause' or '/vimix/current/pause T' or '/vimix/current/pause F'
else if ( attribute.compare(OSC_SOURCE_PAUSE) == 0) { else if ( attribute.compare(OSC_SOURCE_PAUSE) == 0) {
bool on = true; bool on = true;
if ( !arguments.Eos()) { if ( !arguments.Eos()) {
arguments >> on >> osc::EndMessage; arguments >> on >> osc::EndMessage;
} }
target->play(!on); target->call( new SetPlay(!on) );
}
/// e.g. '/vimix/current/alpha f 0.3'
else if ( attribute.compare(OSC_SOURCE_ALPHA) == 0) {
float x = 0.f;
arguments >> x >> osc::EndMessage;
target->call( new SetAlpha(x) );
}
/// e.g. '/vimix/current/transparency f 0.7'
else if ( attribute.compare(OSC_SOURCE_TRANSPARENCY) == 0) {
float x = 0.f;
arguments >> x >> osc::EndMessage;
target->call( new SetAlpha(1.f - x) );
}
/// e.g. '/vimix/current/depth f 5.0'
else if ( attribute.compare(OSC_SOURCE_DEPTH) == 0) {
float x = 0.f;
arguments >> x >> osc::EndMessage;
target->call( new SetDepth(x) );
}
/// e.g. '/vimix/current/translation ff 10.0 2.2'
else if ( attribute.compare(OSC_SOURCE_TRANSLATE) == 0) {
float x = 0.f, y = 0.f;
arguments >> x >> y >> osc::EndMessage;
target->call( new Translation( x, y), true );
} }
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
else { else {

View File

@@ -3,8 +3,6 @@
#include "NetworkToolkit.h" #include "NetworkToolkit.h"
#define OSC_SEPARATOR '/'
#define OSC_LOG "log" #define OSC_LOG "log"
#define OSC_LOG_INFO "info" #define OSC_LOG_INFO "info"
@@ -13,6 +11,8 @@
#define OSC_OUTPUT_DISABLE "disable" #define OSC_OUTPUT_DISABLE "disable"
#define OSC_OUTPUT_FADING "fading" #define OSC_OUTPUT_FADING "fading"
#define OSC_ALL "all"
#define OSC_SELECTED "selected"
#define OSC_CURRENT "current" #define OSC_CURRENT "current"
#define OSC_CURRENT_NONE "none" #define OSC_CURRENT_NONE "none"
#define OSC_CURRENT_NEXT "next" #define OSC_CURRENT_NEXT "next"
@@ -21,17 +21,9 @@
#define OSC_SOURCE_PLAY "play" #define OSC_SOURCE_PLAY "play"
#define OSC_SOURCE_PAUSE "pause" #define OSC_SOURCE_PAUSE "pause"
#define OSC_SOURCE_ALPHA "alpha" #define OSC_SOURCE_ALPHA "alpha"
#define OSC_SOURCE_ALPHA_XY "alphaXY" #define OSC_SOURCE_TRANSPARENCY "transparency"
#define OSC_SOURCE_ALPHA_X "alphaX" #define OSC_SOURCE_DEPTH "depth"
#define OSC_SOURCE_ALPHA_Y "alphaY" #define OSC_SOURCE_TRANSLATE "translate"
#define OSC_SOURCE_TRANSPARENT "transparency"
#define OSC_SOURCE_POSITION "position"
#define OSC_SOURCE_POSITION_X "positionX"
#define OSC_SOURCE_POSITION_Y "positionY"
#define OSC_SOURCE_SCALE "scale"
#define OSC_SOURCE_SCALE_X "scaleX"
#define OSC_SOURCE_SCALE_Y "scaleY"
#define OSC_SOURCE_ANGLE "angle"
class Session; class Session;
class Source; class Source;
@@ -77,6 +69,7 @@ private:
static void listen(); static void listen();
RequestListener listener_; RequestListener listener_;
UdpListeningReceiveSocket *receiver_; UdpListeningReceiveSocket *receiver_;
}; };
#endif // CONTROL_H #endif // CONTROL_H

Binary file not shown.